This commit is contained in:
boy0001
2015-09-11 20:09:22 +10:00
parent 37a8861fa0
commit c386f33df8
380 changed files with 43490 additions and 33913 deletions

View File

@ -16,29 +16,29 @@ import com.intellectualcrafters.plot.util.SchematicHandler;
import com.intellectualcrafters.plot.util.SetupUtils;
import com.intellectualcrafters.plot.util.TaskManager;
import com.intellectualcrafters.plot.util.UUIDHandlerImplementation;
import com.sk89q.worldedit.WorldEdit;
public interface IPlotMain {
public interface IPlotMain
{
/**
* Log a message to console
* @param message
*/
void log(String message);
void log(final String message);
/**
* Get the `PlotSquared` directory (e.g. /plugins/PlotSquared or /mods/PlotSquared)
* @return
*/
File getDirectory();
/**
* Wrap a player into a PlotPlayer object
* @param obj
* @return
*/
PlotPlayer wrapPlayer(Object obj);
PlotPlayer wrapPlayer(final Object obj);
/**
* Disable the implementation
* - If a full disable isn't feasibly, just disable what it can
@ -50,32 +50,32 @@ public interface IPlotMain {
* @return
*/
int[] getPluginVersion();
/**
* Get the version of Minecraft that is running
* (used to check what protocols and such are supported)
* @return
*/
int[] getServerVersion();
/**
* Get the nms package prefix
* @return
*/
String getNMSPackage();
/**
* Get the schematic handler
* @return
*/
SchematicHandler initSchematicHandler();
/**
* Get the schematic handler
* @return
*/
ChatManager initChatManager();
/**
* The task manager will run and manage minecraft tasks
* @return
@ -116,7 +116,7 @@ public interface IPlotMain {
* Register the WorldEdit hook
*/
boolean initWorldEdit();
/**
* Register TNT related events (if TNT protection is enabled)
*/
@ -133,7 +133,7 @@ public interface IPlotMain {
* @return
*/
BlockManager initBlockManager();
/**
* Get the EventUtil class
* @return
@ -157,24 +157,24 @@ public interface IPlotMain {
* @return
*/
HybridUtils initHybridUtils();
/**
* Start the metrics task
*/
void startMetrics();
/**
* If a world is already loaded, set the generator (use NMS if required)
* @param world
*/
void setGenerator(String world);
void setGenerator(final String world);
/**
* Get the UUIDHandlerImplementation which will cache and provide UUIDs
* @return
*/
UUIDHandlerImplementation initUUIDHandler();
/**
* Get the InventoryUtil class (used for implementation specific inventory guis)
* @return
@ -186,12 +186,12 @@ public interface IPlotMain {
* @return
*/
boolean initPlotMeConverter();
/**
* Unregister a PlotPlayer from cache e.g. if they have logged off
* @param player
*/
void unregister(PlotPlayer player);
void unregister(final PlotPlayer player);
/**
* Get the generator wrapper for a world (world) and generator (name)
@ -199,7 +199,7 @@ public interface IPlotMain {
* @param name
* @return
*/
PlotGenerator<?> getGenerator(String world, String name);
PlotGenerator<?> getGenerator(final String world, final String name);
/**
* Register the chunk processor which will clean out chunks that have too many blockstates or entities
@ -216,7 +216,7 @@ public interface IPlotMain {
* @return
*/
String getServerName();
/**
* Get the class that will manage player titles
* @return

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -32,71 +32,82 @@ import com.intellectualcrafters.plot.util.EventUtil;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.UUIDHandler;
import com.plotsquared.bukkit.uuid.SQLUUIDHandler;
import com.plotsquared.general.commands.Argument;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "add",
aliases = {"a"},
description = "Allow a user to build while you are online",
usage = "/plot add <player>",
category = CommandCategory.ACTIONS,
permission = "plots.add",
requiredType = RequiredType.NONE
)
public class Add extends SubCommand {
command = "add",
aliases = { "a" },
description = "Allow a user to build while you are online",
usage = "/plot add <player>",
category = CommandCategory.ACTIONS,
permission = "plots.add",
requiredType = RequiredType.NONE)
public class Add extends SubCommand
{
public Add() {
public Add()
{
requiredArguments = new Argument[] {
Argument.PlayerName
Argument.PlayerName
};
}
@Override
public boolean onCommand(PlotPlayer plr, String[] args) {
public boolean onCommand(final PlotPlayer plr, final String[] args)
{
final Location loc = plr.getLocation();
final Plot plot = MainUtil.getPlot(loc);
if (plot == null) {
return !sendMessage(plr, C.NOT_IN_PLOT);
}
if (!plot.hasOwner()) {
if (plot == null) { return !sendMessage(plr, C.NOT_IN_PLOT); }
if (!plot.hasOwner())
{
MainUtil.sendMessage(plr, C.PLOT_UNOWNED);
return false;
}
if (!plot.isOwner(plr.getUUID()) && !Permissions.hasPermission(plr, "plots.admin.command.add")) {
if (!plot.isOwner(plr.getUUID()) && !Permissions.hasPermission(plr, "plots.admin.command.add"))
{
MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
return true;
}
UUID uuid;
if (args[0].equalsIgnoreCase("*")) {
if (args[0].equalsIgnoreCase("*"))
{
uuid = DBFunc.everyone;
} else {
}
else
{
// TODO have a runnable for fetch
uuid = UUIDHandler.getUUID(args[0], null);
}
if (uuid == null) {
if (uuid == null)
{
MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[0]);
return false;
}
if (plot.isOwner(uuid)) {
if (plot.isOwner(uuid))
{
MainUtil.sendMessage(plr, C.ALREADY_OWNER);
return false;
}
if (plot.getMembers().contains(uuid)) {
if (plot.getMembers().contains(uuid))
{
MainUtil.sendMessage(plr, C.ALREADY_ADDED);
return false;
}
if (plot.removeTrusted(uuid)) {
if (plot.removeTrusted(uuid))
{
plot.addMember(uuid);
}
else {
if (plot.getMembers().size() + plot.getTrusted().size() >= PS.get().getPlotWorld(plot.world).MAX_PLOT_MEMBERS) {
else
{
if ((plot.getMembers().size() + plot.getTrusted().size()) >= PS.get().getPlotWorld(plot.world).MAX_PLOT_MEMBERS)
{
MainUtil.sendMessage(plr, C.PLOT_MAX_MEMBERS);
return false;
}
if (plot.getDenied().contains(uuid)) {
if (plot.getDenied().contains(uuid))
{
plot.removeDenied(uuid);
}
plot.addMember(uuid);

View File

@ -29,84 +29,102 @@ import com.intellectualcrafters.plot.object.PlotCluster;
import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.util.ClusterManager;
import com.intellectualcrafters.plot.util.EconHandler;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.Permissions;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "auto",
permission = "plots.auto",
category = CommandCategory.CLAIMING,
requiredType = RequiredType.NONE,
description = "Claim the nearest plot",
aliases = {"a"},
usage = "/plot auto"
)
public class Auto extends SubCommand {
command = "auto",
permission = "plots.auto",
category = CommandCategory.CLAIMING,
requiredType = RequiredType.NONE,
description = "Claim the nearest plot",
aliases = { "a" },
usage = "/plot auto")
public class Auto extends SubCommand
{
public static PlotId getNextPlot(final PlotId id, final int step) {
public static PlotId getNextPlot(final PlotId id, final int step)
{
final int absX = Math.abs(id.x);
final int absY = Math.abs(id.y);
if (absX > absY) {
if (id.x > 0) {
if (absX > absY)
{
if (id.x > 0)
{
return new PlotId(id.x, id.y + 1);
} else {
}
else
{
return new PlotId(id.x, id.y - 1);
}
} else if (absY > absX) {
if (id.y > 0) {
}
else if (absY > absX)
{
if (id.y > 0)
{
return new PlotId(id.x - 1, id.y);
} else {
}
else
{
return new PlotId(id.x + 1, id.y);
}
} else {
if (id.x.equals(id.y) && (id.x > 0)) {
return new PlotId(id.x, id.y + step);
}
if (id.x == absX) {
return new PlotId(id.x, id.y + 1);
}
if (id.y == absY) {
return new PlotId(id.x, id.y - 1);
}
}
else
{
if (id.x.equals(id.y) && (id.x > 0)) { return new PlotId(id.x, id.y + step); }
if (id.x == absX) { return new PlotId(id.x, id.y + 1); }
if (id.y == absY) { return new PlotId(id.x, id.y - 1); }
return new PlotId(id.x + 1, id.y);
}
}
@Override
public boolean onCommand(PlotPlayer plr, String[] args) {
public boolean onCommand(final PlotPlayer plr, final String[] args)
{
String world;
int size_x = 1;
int size_z = 1;
String schematic = "";
if (PS.get().getPlotWorlds().size() == 1) {
if (PS.get().getPlotWorlds().size() == 1)
{
world = PS.get().getPlotWorlds().iterator().next();
} else {
}
else
{
world = plr.getLocation().getWorld();
if (!PS.get().isPlotWorld(world)) {
if (!PS.get().isPlotWorld(world))
{
MainUtil.sendMessage(plr, C.NOT_IN_PLOT_WORLD);
return false;
}
}
if (args.length > 0) {
if (Permissions.hasPermission(plr, "plots.auto.mega")) {
try {
if (args.length > 0)
{
if (Permissions.hasPermission(plr, "plots.auto.mega"))
{
try
{
final String[] split = args[0].split(",");
size_x = Integer.parseInt(split[0]);
size_z = Integer.parseInt(split[1]);
if ((size_x < 1) || (size_z < 1)) {
if ((size_x < 1) || (size_z < 1))
{
MainUtil.sendMessage(plr, "&cError: size<=0");
}
if ((size_x > 4) || (size_z > 4)) {
if ((size_x > 4) || (size_z > 4))
{
MainUtil.sendMessage(plr, "&cError: size>4");
}
if (args.length > 1) {
if (args.length > 1)
{
schematic = args[1];
}
} catch (final Exception e) {
}
catch (final Exception e)
{
size_x = 1;
size_z = 1;
schematic = args[0];
@ -114,32 +132,42 @@ public class Auto extends SubCommand {
// "&cError: Invalid size (X,Y)");
// return false;
}
} else {
}
else
{
schematic = args[0];
// PlayerFunctions.sendMessage(plr, C.NO_PERMISSION);
// return false;
}
}
if ((size_x * size_z) > Settings.MAX_AUTO_SIZE) {
if ((size_x * size_z) > Settings.MAX_AUTO_SIZE)
{
MainUtil.sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS_NUM, Settings.MAX_AUTO_SIZE + "");
return false;
}
final int currentPlots = Settings.GLOBAL_LIMIT ? MainUtil.getPlayerPlotCount(plr) : MainUtil.getPlayerPlotCount(world, plr);
final int diff = currentPlots - MainUtil.getAllowedPlots(plr);
if ((diff + (size_x * size_z)) > 0) {
if (diff < 0) {
if ((diff + (size_x * size_z)) > 0)
{
if (diff < 0)
{
MainUtil.sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS_NUM, (-diff) + "");
} else {
}
else
{
MainUtil.sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS);
}
return false;
}
final PlotWorld pWorld = PS.get().getPlotWorld(world);
if ((EconHandler.manager != null) && pWorld.USE_ECONOMY) {
if ((EconHandler.manager != null) && pWorld.USE_ECONOMY)
{
double cost = pWorld.PLOT_PRICE;
cost = (size_x * size_z) * cost;
if (cost > 0d) {
if (EconHandler.manager.getMoney(plr) < cost) {
if (cost > 0d)
{
if (EconHandler.manager.getMoney(plr) < cost)
{
sendMessage(plr, C.CANNOT_AFFORD_PLOT, "" + cost);
return true;
}
@ -147,13 +175,16 @@ public class Auto extends SubCommand {
sendMessage(plr, C.REMOVED_BALANCE, cost + "");
}
}
if (!schematic.equals("")) {
if (!schematic.equals(""))
{
// if (pWorld.SCHEMATIC_CLAIM_SPECIFY) {
if (!pWorld.SCHEMATICS.contains(schematic.toLowerCase())) {
if (!pWorld.SCHEMATICS.contains(schematic.toLowerCase()))
{
sendMessage(plr, C.SCHEMATIC_INVALID, "non-existent: " + schematic);
return true;
}
if (!Permissions.hasPermission(plr, "plots.claim." + schematic) && !Permissions.hasPermission(plr, "plots.admin.command.schematic")) {
if (!Permissions.hasPermission(plr, "plots.claim." + schematic) && !Permissions.hasPermission(plr, "plots.admin.command.schematic"))
{
MainUtil.sendMessage(plr, C.NO_SCHEMATIC_PERMISSION, schematic);
return true;
}
@ -161,15 +192,15 @@ public class Auto extends SubCommand {
}
final String worldname = world;
final PlotWorld plotworld = PS.get().getPlotWorld(worldname);
if (plotworld.TYPE == 2) {
if (plotworld.TYPE == 2)
{
final Location loc = plr.getLocation();
final Plot plot = MainUtil.getPlot(new Location(worldname, loc.getX(), loc.getY(), loc.getZ()));
if (plot == null) {
return sendMessage(plr, C.NOT_IN_PLOT);
}
if (plot == null) { return sendMessage(plr, C.NOT_IN_PLOT); }
final PlotCluster cluster = plot.getCluster();
// Must be standing in a cluster
if (cluster == null) {
if (cluster == null)
{
MainUtil.sendMessage(plr, C.NOT_IN_CLUSTER);
return false;
}
@ -180,10 +211,12 @@ public class Auto extends SubCommand {
final int width = Math.max((top.x - bot.x) + 1, (top.y - bot.y) + 1);
final int max = width * width;
//
for (int i = 0; i <= max; i++) {
for (int i = 0; i <= max; i++)
{
final PlotId currentId = new PlotId(origin.x + id.x, origin.y + id.y);
final Plot current = MainUtil.getPlot(worldname, currentId);
if (MainUtil.canClaim(plr, current) && (current.getSettings().isMerged() == false) && cluster.equals(current.getCluster())) {
if (MainUtil.canClaim(plr, current) && (current.getSettings().isMerged() == false) && cluster.equals(current.getCluster()))
{
Claim.claimPlot(plr, current, true, true);
return true;
}
@ -194,40 +227,50 @@ public class Auto extends SubCommand {
return false;
}
boolean br = false;
if ((size_x == 1) && (size_z == 1)) {
while (!br) {
if ((size_x == 1) && (size_z == 1))
{
while (!br)
{
final Plot plot = MainUtil.getPlot(worldname, getLastPlot(worldname));
if (MainUtil.canClaim(plr, plot)) {
if (MainUtil.canClaim(plr, plot))
{
Claim.claimPlot(plr, plot, true, true);
br = true;
}
MainUtil.lastPlot.put(worldname, getNextPlot(getLastPlot(worldname), 1));
}
} else {
}
else
{
boolean lastPlot = true;
while (!br) {
while (!br)
{
final PlotId start = getNextPlot(getLastPlot(worldname), 1);
// Checking if the current set of plots is a viable option.
MainUtil.lastPlot.put(worldname, start);
if (lastPlot) {
}
if ((PS.get().getPlot(worldname, start) != null) && (PS.get().getPlot(worldname, start).owner != null)) {
if (lastPlot)
{}
if ((PS.get().getPlot(worldname, start) != null) && (PS.get().getPlot(worldname, start).owner != null))
{
continue;
} else {
}
else
{
lastPlot = false;
}
final PlotId end = new PlotId((start.x + size_x) - 1, (start.y + size_z) - 1);
if (MainUtil.canClaim(plr, worldname, start, end)) {
for (int i = start.x; i <= end.x; i++) {
for (int j = start.y; j <= end.y; j++) {
if (MainUtil.canClaim(plr, worldname, start, end))
{
for (int i = start.x; i <= end.x; i++)
{
for (int j = start.y; j <= end.y; j++)
{
final Plot plot = MainUtil.getPlot(worldname, new PlotId(i, j));
final boolean teleport = ((i == end.x) && (j == end.y));
Claim.claimPlot(plr, plot, teleport, true);
}
}
if (!MainUtil.mergePlots(worldname, MainUtil.getPlotSelectionIds(start, end), true, true)) {
return false;
}
if (!MainUtil.mergePlots(worldname, MainUtil.getPlotSelectionIds(start, end), true, true)) { return false; }
br = true;
}
}
@ -236,8 +279,10 @@ public class Auto extends SubCommand {
return true;
}
public PlotId getLastPlot(final String world) {
if ((MainUtil.lastPlot == null) || !MainUtil.lastPlot.containsKey(world)) {
public PlotId getLastPlot(final String world)
{
if ((MainUtil.lastPlot == null) || !MainUtil.lastPlot.containsKey(world))
{
MainUtil.lastPlot.put(world, new PlotId(0, 0));
}
return MainUtil.lastPlot.get(world);

View File

@ -21,67 +21,65 @@
package com.intellectualcrafters.plot.commands;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.flag.Flag;
import com.intellectualcrafters.plot.flag.FlagManager;
import com.intellectualcrafters.plot.generator.HybridUtils;
import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotAnalysis;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.util.BO3Handler;
import com.intellectualcrafters.plot.util.BlockManager;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.UUIDHandler;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "bo3",
aliases = {"bo2"},
description = "Mark a plot as done",
permission = "plots.bo3",
category = CommandCategory.ACTIONS,
requiredType = RequiredType.NONE
)
public class BO3 extends SubCommand {
command = "bo3",
aliases = { "bo2" },
description = "Mark a plot as done",
permission = "plots.bo3",
category = CommandCategory.ACTIONS,
requiredType = RequiredType.NONE)
public class BO3 extends SubCommand
{
public void noArgs(PlotPlayer plr) {
public void noArgs(final PlotPlayer plr)
{
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot bo3 export [category] [alias] [-r]");
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot bo3 import <file>");
}
@Override
public boolean onCommand(final PlotPlayer plr, final String[] args) {
public boolean onCommand(final PlotPlayer plr, final String[] args)
{
final Location loc = plr.getLocation();
final Plot plot = MainUtil.getPlot(loc);
if (plot == null || !plot.hasOwner()) {
return !sendMessage(plr, C.NOT_IN_PLOT);
}
if ((!plot.isOwner(plr.getUUID())) && !Permissions.hasPermission(plr, "plots.admin.command.bo3")) {
if ((plot == null) || !plot.hasOwner()) { return !sendMessage(plr, C.NOT_IN_PLOT); }
if ((!plot.isOwner(plr.getUUID())) && !Permissions.hasPermission(plr, "plots.admin.command.bo3"))
{
MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
return false;
}
if (args.length == 0) {
if (args.length == 0)
{
noArgs(plr);
return false;
}
switch (args[0].toLowerCase()) {
switch (args[0].toLowerCase())
{
case "output":
case "save":
case "export": {
case "export":
{
return BO3Handler.saveBO3(plr, plot);
}
case "paste":
case "load":
case "import":
case "input": {
case "input":
{
// TODO NOT IMPLEMENTED YET
MainUtil.sendMessage(plr, "NOT IMPLEMENTED YET!!!");
return false;
}
default: {
default:
{
noArgs(plr);
return false;
}

View File

@ -38,83 +38,78 @@ import com.intellectualcrafters.plot.util.UUIDHandler;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "buy",
aliases = {"b"},
description = "Buy the plot you are standing on",
usage = "/plot buy",
permission = "plots.buy",
category = CommandCategory.CLAIMING,
requiredType = RequiredType.NONE
)
public class Buy extends SubCommand {
command = "buy",
aliases = { "b" },
description = "Buy the plot you are standing on",
usage = "/plot buy",
permission = "plots.buy",
category = CommandCategory.CLAIMING,
requiredType = RequiredType.NONE)
public class Buy extends SubCommand
{
@Override
public boolean onCommand(final PlotPlayer plr, final String ... args) {
if (EconHandler.manager == null) {
return sendMessage(plr, C.ECON_DISABLED);
}
public boolean onCommand(final PlotPlayer plr, final String... args)
{
if (EconHandler.manager == null) { return sendMessage(plr, C.ECON_DISABLED); }
final Location loc = plr.getLocation();
final String world = loc.getWorld();
if (!PS.get().isPlotWorld(world)) {
return sendMessage(plr, C.NOT_IN_PLOT_WORLD);
}
if (!PS.get().isPlotWorld(world)) { return sendMessage(plr, C.NOT_IN_PLOT_WORLD); }
Plot plot;
if (args.length > 0) {
try {
if (args.length > 0)
{
try
{
final String[] split = args[0].split(";");
final PlotId id = new PlotId(Integer.parseInt(split[0]), Integer.parseInt(split[1]));
plot = MainUtil.getPlot(world, id);
} catch (final Exception e) {
}
catch (final Exception e)
{
return sendMessage(plr, C.NOT_VALID_PLOT_ID);
}
} else {
}
else
{
plot = MainUtil.getPlot(loc);
}
if (plot == null) {
return sendMessage(plr, C.NOT_IN_PLOT);
}
if (plot == null) { return sendMessage(plr, C.NOT_IN_PLOT); }
final int currentPlots = Settings.GLOBAL_LIMIT ? MainUtil.getPlayerPlotCount(plr) : MainUtil.getPlayerPlotCount(world, plr);
if (currentPlots >= MainUtil.getAllowedPlots(plr)) {
return sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS);
}
if (!plot.hasOwner()) {
return sendMessage(plr, C.PLOT_UNOWNED);
}
if (PlotHandler.isOwner(plot, plr.getUUID())) {
return sendMessage(plr, C.CANNOT_BUY_OWN);
}
if (currentPlots >= MainUtil.getAllowedPlots(plr)) { return sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS); }
if (!plot.hasOwner()) { return sendMessage(plr, C.PLOT_UNOWNED); }
if (PlotHandler.isOwner(plot, plr.getUUID())) { return sendMessage(plr, C.CANNOT_BUY_OWN); }
final Flag flag = FlagManager.getPlotFlag(plot, "price");
if (flag == null) {
return sendMessage(plr, C.NOT_FOR_SALE);
}
if (flag == null) { return sendMessage(plr, C.NOT_FOR_SALE); }
double initPrice = (double) flag.getValue();
double price = initPrice;
final PlotId id = plot.id;
final PlotId id2 = MainUtil.getTopPlot(plot).id;
final int size = MainUtil.getPlotSelectionIds(id, id2).size();
final PlotWorld plotworld = PS.get().getPlotWorld(world);
if (plotworld.USE_ECONOMY) {
if (plotworld.USE_ECONOMY)
{
price += plotworld.PLOT_PRICE * size;
initPrice += plotworld.SELL_PRICE * size;
}
if ((EconHandler.manager != null) && (price > 0d)) {
if (EconHandler.manager.getMoney(plr) < price) {
return sendMessage(plr, C.CANNOT_AFFORD_PLOT, "" + price);
}
if ((EconHandler.manager != null) && (price > 0d))
{
if (EconHandler.manager.getMoney(plr) < price) { return sendMessage(plr, C.CANNOT_AFFORD_PLOT, "" + price); }
EconHandler.manager.withdrawMoney(plr, price);
sendMessage(plr, C.REMOVED_BALANCE, price + "");
EconHandler.manager.depositMoney(UUIDHandler.getUUIDWrapper().getOfflinePlayer(plot.owner), initPrice);
final PlotPlayer owner = UUIDHandler.getPlayer(plot.owner);
if (owner != null) {
if (owner != null)
{
sendMessage(plr, C.PLOT_SOLD, plot.id + "", plr.getName(), initPrice + "");
}
FlagManager.removePlotFlag(plot, "price");
}
Plot top = MainUtil.getTopPlot(plot);
for (PlotId myId : MainUtil.getPlotSelectionIds(plot.id, top.id)) {
Plot myPlot = MainUtil.getPlot(plot.world, myId);
final Plot top = MainUtil.getTopPlot(plot);
for (final PlotId myId : MainUtil.getPlotSelectionIds(plot.id, top.id))
{
final Plot myPlot = MainUtil.getPlot(plot.world, myId);
myPlot.owner = plr.getUUID();
DBFunc.setOwner(plot, myPlot.owner);
}

View File

@ -1,23 +1,21 @@
package com.intellectualcrafters.plot.commands;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.PlotWorld;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "chat",
description = "Toggle plot chat on or off",
usage = "/plot chat [on|off]",
permission = "plots.chat",
category = CommandCategory.ACTIONS,
requiredType = RequiredType.NONE
)
public class Chat extends SubCommand {
command = "chat",
description = "Toggle plot chat on or off",
usage = "/plot chat [on|off]",
permission = "plots.chat",
category = CommandCategory.ACTIONS,
requiredType = RequiredType.NONE)
public class Chat extends SubCommand
{
@Override
public boolean onCommand(final PlotPlayer player, final String ... args) {
return MainCommand.onCommand(player, "plot", new String[] {"toggle", "chat"});
public boolean onCommand(final PlotPlayer player, final String... args)
{
return MainCommand.onCommand(player, "plot", new String[] { "toggle", "chat" });
}
}

View File

@ -37,53 +37,64 @@ import com.intellectualcrafters.plot.util.SchematicHandler.Schematic;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "claim",
aliases = {"c"},
description = "Claim the current plot you're standing on",
category = CommandCategory.CLAIMING,
requiredType = RequiredType.NONE,
permission = "plots.claim",
usage = "/plot claim"
)
public class Claim extends SubCommand {
command = "claim",
aliases = { "c" },
description = "Claim the current plot you're standing on",
category = CommandCategory.CLAIMING,
requiredType = RequiredType.NONE,
permission = "plots.claim",
usage = "/plot claim")
public class Claim extends SubCommand
{
public static boolean claimPlot(final PlotPlayer player, final Plot plot, final boolean teleport, final boolean auto) {
public static boolean claimPlot(final PlotPlayer player, final Plot plot, final boolean teleport, final boolean auto)
{
return claimPlot(player, plot, teleport, "", auto);
}
public static boolean claimPlot(final PlotPlayer player, final Plot plot, final boolean teleport, final String schematic, final boolean auto) {
if (plot.hasOwner() || plot.getSettings().isMerged()) {
return false;
}
public static boolean claimPlot(final PlotPlayer player, final Plot plot, final boolean teleport, final String schematic, final boolean auto)
{
if (plot.hasOwner() || plot.getSettings().isMerged()) { return false; }
final boolean result = EventUtil.manager.callClaim(player, plot, false);
if (result) {
if (result)
{
MainUtil.createPlot(player.getUUID(), plot);
MainUtil.setSign(player.getName(), plot);
MainUtil.sendMessage(player, C.CLAIMED);
final Location loc = player.getLocation();
if (teleport) {
if (teleport)
{
MainUtil.teleportPlayer(player, loc, plot);
}
final String world = plot.world;
final PlotWorld plotworld = PS.get().getPlotWorld(world);
final Plot plot2 = PS.get().getPlot(world, plot.id);
if (plotworld.SCHEMATIC_ON_CLAIM) {
if (plotworld.SCHEMATIC_ON_CLAIM)
{
Schematic sch;
if (schematic.equals("")) {
if (schematic.equals(""))
{
sch = SchematicHandler.manager.getSchematic(plotworld.SCHEMATIC_FILE);
} else {
}
else
{
sch = SchematicHandler.manager.getSchematic(schematic);
if (sch == null) {
if (sch == null)
{
sch = SchematicHandler.manager.getSchematic(plotworld.SCHEMATIC_FILE);
}
}
SchematicHandler.manager.paste(sch, plot2, 0, 0, new RunnableVal<Boolean>() {
SchematicHandler.manager.paste(sch, plot2, 0, 0, new RunnableVal<Boolean>()
{
@Override
public void run() {
if (value) {
public void run()
{
if (value)
{
MainUtil.sendMessage(player, C.SCHEMATIC_PASTE_SUCCESS);
}
else {
else
{
MainUtil.sendMessage(player, C.SCHEMATIC_PASTE_FAILED);
}
}
@ -95,43 +106,38 @@ public class Claim extends SubCommand {
}
@Override
public boolean onCommand(final PlotPlayer plr, final String ... args) {
public boolean onCommand(final PlotPlayer plr, final String... args)
{
String schematic = "";
if (args.length >= 1) {
if (args.length >= 1)
{
schematic = args[0];
}
final Location loc = plr.getLocation();
final Plot plot = MainUtil.getPlot(loc);
if (plot == null) {
return sendMessage(plr, C.NOT_IN_PLOT);
}
if (plot == null) { return sendMessage(plr, C.NOT_IN_PLOT); }
final int currentPlots = Settings.GLOBAL_LIMIT ? MainUtil.getPlayerPlotCount(plr) : MainUtil.getPlayerPlotCount(loc.getWorld(), plr);
if (currentPlots >= MainUtil.getAllowedPlots(plr)) {
return sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS);
}
if (!MainUtil.canClaim(plr, plot)) {
return sendMessage(plr, C.PLOT_IS_CLAIMED);
}
if (currentPlots >= MainUtil.getAllowedPlots(plr)) { return sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS); }
if (!MainUtil.canClaim(plr, plot)) { return sendMessage(plr, C.PLOT_IS_CLAIMED); }
final PlotWorld world = PS.get().getPlotWorld(plot.world);
if ((EconHandler.manager != null) && world.USE_ECONOMY) {
if ((EconHandler.manager != null) && world.USE_ECONOMY)
{
final double cost = world.PLOT_PRICE;
if (cost > 0d) {
if (EconHandler.manager.getMoney(plr) < cost) {
return sendMessage(plr, C.CANNOT_AFFORD_PLOT, "" + cost);
}
if (cost > 0d)
{
if (EconHandler.manager.getMoney(plr) < cost) { return sendMessage(plr, C.CANNOT_AFFORD_PLOT, "" + cost); }
EconHandler.manager.withdrawMoney(plr, cost);
sendMessage(plr, C.REMOVED_BALANCE, cost + "");
}
}
if (!schematic.equals("")) {
if (world.SCHEMATIC_CLAIM_SPECIFY) {
if (!world.SCHEMATICS.contains(schematic.toLowerCase())) {
return sendMessage(plr, C.SCHEMATIC_INVALID, "non-existent: " + schematic);
}
if (!Permissions.hasPermission(plr, "plots.claim." + schematic) && !Permissions.hasPermission(plr, "plots.admin.command.schematic")) {
return sendMessage(plr, C.NO_SCHEMATIC_PERMISSION, schematic);
}
if (!schematic.equals(""))
{
if (world.SCHEMATIC_CLAIM_SPECIFY)
{
if (!world.SCHEMATICS.contains(schematic.toLowerCase())) { return sendMessage(plr, C.SCHEMATIC_INVALID, "non-existent: " + schematic); }
if (!Permissions.hasPermission(plr, "plots.claim." + schematic) && !Permissions.hasPermission(plr, "plots.admin.command.schematic")) { return sendMessage(plr,
C.NO_SCHEMATIC_PERMISSION, schematic); }
}
}
return claimPlot(plr, plot, false, schematic, false) || sendMessage(plr, C.PLOT_NOT_CLAIMED);

View File

@ -38,86 +38,105 @@ import com.intellectualcrafters.plot.util.UUIDHandler;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "clear",
description = "Clear a plot",
permission = "plots.clear",
category = CommandCategory.ACTIONS,
usage = "/plot clear [id]"
)
public class Clear extends SubCommand {
command = "clear",
description = "Clear a plot",
permission = "plots.clear",
category = CommandCategory.ACTIONS,
usage = "/plot clear [id]")
public class Clear extends SubCommand
{
@Override
public boolean onCommand(final PlotPlayer plr, final String ... args) {
public boolean onCommand(final PlotPlayer plr, final String... args)
{
final Location loc = plr.getLocation();
final Plot plot;
if (args.length == 2) {
PlotId id = PlotId.fromString(args[0]);
if (id == null) {
if (args[1].equalsIgnoreCase("mine")) {
Set<Plot> plots = PS.get().getPlots(plr);
if (plots.size() == 0) {
if (args.length == 2)
{
final PlotId id = PlotId.fromString(args[0]);
if (id == null)
{
if (args[1].equalsIgnoreCase("mine"))
{
final Set<Plot> plots = PS.get().getPlots(plr);
if (plots.size() == 0)
{
MainUtil.sendMessage(plr, C.NO_PLOTS);
return false;
}
plot = plots.iterator().next();
}
else {
else
{
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot clear [X;Z|mine]");
return false;
}
}
else {
else
{
plot = MainUtil.getPlot(loc.getWorld(), id);
}
}
else {
else
{
plot = MainUtil.getPlot(loc);
}
if (plot == null) {
if (plot == null)
{
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot clear [X;Z|mine]");
return sendMessage(plr, C.NOT_IN_PLOT);
}
// if (!MainUtil.getTopPlot(plot).equals(MainUtil.getBottomPlot(plot))) {
// return sendMessage(plr, C.UNLINK_REQUIRED);
// }
if (((plot == null) || !plot.hasOwner() || !plot.isOwner(UUIDHandler.getUUID(plr))) && !Permissions.hasPermission(plr, "plots.admin.command.clear")) {
return sendMessage(plr, C.NO_PLOT_PERMS);
}
// if (!MainUtil.getTopPlot(plot).equals(MainUtil.getBottomPlot(plot))) {
// return sendMessage(plr, C.UNLINK_REQUIRED);
// }
if (((plot == null) || !plot.hasOwner() || !plot.isOwner(UUIDHandler.getUUID(plr))) && !Permissions.hasPermission(plr, "plots.admin.command.clear")) { return sendMessage(plr, C.NO_PLOT_PERMS); }
assert plot != null;
if (MainUtil.runners.containsKey(plot)) {
if (MainUtil.runners.containsKey(plot))
{
MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER);
return false;
}
if (FlagManager.getPlotFlag(plot, "done") != null && (!Permissions.hasPermission(plr, "plots.continue") || (Settings.DONE_COUNTS_TOWARDS_LIMIT && MainUtil.getAllowedPlots(plr) >= MainUtil.getPlayerPlotCount(plr)))) {
if ((FlagManager.getPlotFlag(plot, "done") != null)
&& (!Permissions.hasPermission(plr, "plots.continue") || (Settings.DONE_COUNTS_TOWARDS_LIMIT && (MainUtil.getAllowedPlots(plr) >= MainUtil.getPlayerPlotCount(plr)))))
{
MainUtil.sendMessage(plr, C.DONE_ALREADY_DONE);
return false;
}
Runnable runnable = new Runnable() {
final Runnable runnable = new Runnable()
{
@Override
public void run() {
public void run()
{
final long start = System.currentTimeMillis();
final boolean result = MainUtil.clearAsPlayer(plot, plot.owner == null, new Runnable() {
final boolean result = MainUtil.clearAsPlayer(plot, plot.owner == null, new Runnable()
{
@Override
public void run() {
public void run()
{
// If the state changes, then mark it as no longer done
if (FlagManager.getPlotFlag(plot, "done" ) != null) {
if (FlagManager.getPlotFlag(plot, "done") != null)
{
FlagManager.removePlotFlag(plot, "done");
}
if (FlagManager.getPlotFlag(plot, "analysis") != null) {
if (FlagManager.getPlotFlag(plot, "analysis") != null)
{
FlagManager.removePlotFlag(plot, "analysis");
}
MainUtil.sendMessage(plr, C.CLEARING_DONE, "" + (System.currentTimeMillis() - start));
}
});
if (!result) {
if (!result)
{
MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER);
}
}
};
if (Settings.CONFIRM_CLEAR && !(Permissions.hasPermission(plr, "plots.confirm.bypass"))) {
if (Settings.CONFIRM_CLEAR && !(Permissions.hasPermission(plr, "plots.confirm.bypass")))
{
CmdConfirm.addPending(plr, "/plot clear " + plot.id, runnable);
}
else {
else
{
TaskManager.runTask(runnable);
}
return true;

View File

@ -53,60 +53,77 @@ import com.intellectualcrafters.plot.util.UUIDHandler;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "cluster",
aliases = {"clusters"},
category = CommandCategory.ACTIONS,
requiredType = RequiredType.NONE,
permission = "plots.cluster",
description = "Manage a plot cluster"
)
public class Cluster extends SubCommand {
command = "cluster",
aliases = { "clusters" },
category = CommandCategory.ACTIONS,
requiredType = RequiredType.NONE,
permission = "plots.cluster",
description = "Manage a plot cluster")
public class Cluster extends SubCommand
{
@Override
public boolean onCommand(final PlotPlayer plr, final String ... args) {
public boolean onCommand(final PlotPlayer plr, final String... args)
{
// list, create, delete, resize, invite, kick, leave, helpers, tp, sethome
if (args.length == 0) {
if (args.length == 0)
{
// return arguments
MainUtil.sendMessage(plr, C.CLUSTER_AVAILABLE_ARGS);
return false;
}
final String sub = args[0].toLowerCase();
switch (sub) {
switch (sub)
{
case "l":
case "list": {
if (!Permissions.hasPermission(plr, "plots.cluster.list")) {
case "list":
{
if (!Permissions.hasPermission(plr, "plots.cluster.list"))
{
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.list");
return false;
}
if (args.length != 1) {
if (args.length != 1)
{
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster list");
return false;
}
final HashSet<PlotCluster> clusters = ClusterManager.getClusters(plr.getLocation().getWorld());
MainUtil.sendMessage(plr, C.CLUSTER_LIST_HEADING, clusters.size() + "");
for (final PlotCluster cluster : clusters) {
for (final PlotCluster cluster : clusters)
{
// Ignore unmanaged clusters
final String name = "'" + cluster.getName() + "' : " + cluster.toString();
if (UUIDHandler.getUUID(plr).equals(cluster.owner)) {
if (UUIDHandler.getUUID(plr).equals(cluster.owner))
{
MainUtil.sendMessage(plr, C.CLUSTER_LIST_ELEMENT, "&a" + name);
} else if (cluster.helpers.contains(UUIDHandler.getUUID(plr))) {
}
else if (cluster.helpers.contains(UUIDHandler.getUUID(plr)))
{
MainUtil.sendMessage(plr, C.CLUSTER_LIST_ELEMENT, "&3" + name);
} else if (cluster.invited.contains(UUIDHandler.getUUID(plr))) {
}
else if (cluster.invited.contains(UUIDHandler.getUUID(plr)))
{
MainUtil.sendMessage(plr, C.CLUSTER_LIST_ELEMENT, "&9" + name);
} else {
}
else
{
MainUtil.sendMessage(plr, C.CLUSTER_LIST_ELEMENT, cluster.toString());
}
}
return true;
}
case "c":
case "create": {
if (!Permissions.hasPermission(plr, "plots.cluster.create")) {
case "create":
{
if (!Permissions.hasPermission(plr, "plots.cluster.create"))
{
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.create");
return false;
}
if (args.length != 4) {
if (args.length != 4)
{
final PlotId id = ClusterManager.estimatePlotId(plr.getLocation());
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster create <name> <id-bot> <id-top>");
MainUtil.sendMessage(plr, C.CLUSTER_CURRENT_PLOTID, "" + id);
@ -115,37 +132,46 @@ public class Cluster extends SubCommand {
// check pos1 / pos2
PlotId pos1 = MainUtil.parseId(args[2]);
PlotId pos2 = MainUtil.parseId(args[3]);
if ((pos1 == null) || (pos2 == null)) {
if ((pos1 == null) || (pos2 == null))
{
MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_ID);
return false;
}
// check if name is taken
final String name = args[1];
for (final PlotCluster cluster : ClusterManager.getClusters(plr.getLocation().getWorld())) {
if (name.equals(cluster.getName())) {
for (final PlotCluster cluster : ClusterManager.getClusters(plr.getLocation().getWorld()))
{
if (name.equals(cluster.getName()))
{
MainUtil.sendMessage(plr, C.ALIAS_IS_TAKEN);
return false;
}
}
if ((pos2.x < pos1.x) || (pos2.y < pos1.y) ) {
if ((pos2.x < pos1.x) || (pos2.y < pos1.y))
{
pos1 = new PlotId(Math.min(pos1.x, pos2.x), Math.min(pos1.y, pos2.y));
pos2 = new PlotId(Math.max(pos1.x, pos2.x), Math.max(pos1.y, pos2.y));
}
//check if overlap
String world = plr.getLocation().getWorld();
final String world = plr.getLocation().getWorld();
final PlotClusterId id = new PlotClusterId(pos1, pos2);
final HashSet<PlotCluster> intersects = ClusterManager.getIntersects(world, id);
if ((intersects.size() > 0)) {
if ((intersects.size() > 0))
{
MainUtil.sendMessage(plr, C.CLUSTER_INTERSECTION, intersects.size() + "");
return false;
}
// Check if it occupies existing plots
Set<Plot> plots = MainUtil.getPlotSelectionOwned(world, pos1, pos2);
if (plots.size() > 0) {
if (!Permissions.hasPermission(plr, "plots.cluster.create.other")) {
UUID uuid = plr.getUUID();
for (Plot plot : plots) {
if (!plot.isOwner(uuid)) {
final Set<Plot> plots = MainUtil.getPlotSelectionOwned(world, pos1, pos2);
if (plots.size() > 0)
{
if (!Permissions.hasPermission(plr, "plots.cluster.create.other"))
{
final UUID uuid = plr.getUUID();
for (final Plot plot : plots)
{
if (!plot.isOwner(uuid))
{
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.create.other");
return false;
}
@ -155,64 +181,76 @@ public class Cluster extends SubCommand {
// Check allowed cluster size
final PlotCluster cluster = new PlotCluster(world, pos1, pos2, UUIDHandler.getUUID(plr));
int current;
if (Settings.GLOBAL_LIMIT) {
if (Settings.GLOBAL_LIMIT)
{
current = ClusterManager.getPlayerClusterCount(plr);
}
else {
else
{
current = ClusterManager.getPlayerClusterCount(world, plr);
}
int allowed = Permissions.hasPermissionRange(plr, "plots.cluster", Settings.MAX_PLOTS);
if (current + cluster.getArea() > allowed) {
final int allowed = Permissions.hasPermissionRange(plr, "plots.cluster", Settings.MAX_PLOTS);
if ((current + cluster.getArea()) > allowed)
{
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster." + (current + cluster.getArea()));
return false;
}
// Set the generator (if applicable)
PlotWorld plotworld = PS.get().getPlotWorld(world);
if (plotworld == null) {
final PlotWorld plotworld = PS.get().getPlotWorld(world);
if (plotworld == null)
{
PS.get().config.createSection("worlds." + world);
PS.get().loadWorld(world, PS.get().IMP.getGenerator(world, null));
}
else {
else
{
String gen_string = PS.get().config.getString("worlds." + world + "." + "generator.plugin");
if (gen_string == null) {
if (gen_string == null)
{
gen_string = "PlotSquared";
}
PlotGenerator<?> wrapper = PS.get().IMP.getGenerator(world, gen_string);
if (wrapper.isFull()) {
final PlotGenerator<?> wrapper = PS.get().IMP.getGenerator(world, gen_string);
if (wrapper.isFull())
{
wrapper.augment(cluster, plotworld);
}
else {
else
{
MainUtil.sendMessage(plr, C.SETUP_INVALID_GENERATOR, StringMan.join(SetupUtils.generators.keySet(), ","));
return false;
}
// BukkitPlotGenerator generator;
// if (gen_string == null) {
// generator = new HybridGen(world);
// } else {
// ChunkGenerator chunkgen = (ChunkGenerator) PS.get().IMP.getGenerator(world, gen_string).generator;
// if (chunkgen instanceof BukkitPlotGenerator) {
// generator = (BukkitPlotGenerator) chunkgen;
// }
// else {
// MainUtil.sendMessage(plr, C.SETUP_INVALID_GENERATOR, StringMan.join(SetupUtils.generators.keySet(), ","));
// return false;
// }
// }
// new AugmentedPopulator(world, generator, cluster, plotworld.TERRAIN == 2, plotworld.TERRAIN != 2);
// BukkitPlotGenerator generator;
// if (gen_string == null) {
// generator = new HybridGen(world);
// } else {
// ChunkGenerator chunkgen = (ChunkGenerator) PS.get().IMP.getGenerator(world, gen_string).generator;
// if (chunkgen instanceof BukkitPlotGenerator) {
// generator = (BukkitPlotGenerator) chunkgen;
// }
// else {
// MainUtil.sendMessage(plr, C.SETUP_INVALID_GENERATOR, StringMan.join(SetupUtils.generators.keySet(), ","));
// return false;
// }
// }
// new AugmentedPopulator(world, generator, cluster, plotworld.TERRAIN == 2, plotworld.TERRAIN != 2);
}
// create cluster
cluster.settings.setAlias(name);
DBFunc.createCluster(world, cluster);
if (!ClusterManager.clusters.containsKey(world)) {
if (!ClusterManager.clusters.containsKey(world))
{
ClusterManager.clusters.put(world, new HashSet<PlotCluster>());
}
ClusterManager.clusters.get(world).add(cluster);
// Add any existing plots to the current cluster
for (Plot plot : plots) {
if (plot.hasOwner()) {
Flag flag = new Flag(FlagManager.getFlag("cluster"), cluster);
for (final Plot plot : plots)
{
if (plot.hasOwner())
{
final Flag flag = new Flag(FlagManager.getFlag("cluster"), cluster);
FlagManager.addPlotFlag(plot, flag);
if (!cluster.isAdded(plot.owner)) {
if (!cluster.isAdded(plot.owner))
{
cluster.invited.add(plot.owner);
DBFunc.setInvited(world, cluster, plot.owner);
}
@ -223,50 +261,65 @@ public class Cluster extends SubCommand {
}
case "disband":
case "del":
case "delete": {
if (!Permissions.hasPermission(plr, "plots.cluster.delete")) {
case "delete":
{
if (!Permissions.hasPermission(plr, "plots.cluster.delete"))
{
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.delete");
return false;
}
if ((args.length != 1) && (args.length != 2)) {
if ((args.length != 1) && (args.length != 2))
{
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster delete [name]");
return false;
}
PlotCluster cluster;
if (args.length == 2) {
if (args.length == 2)
{
cluster = ClusterManager.getCluster(plr.getLocation().getWorld(), args[1]);
if (cluster == null) {
if (cluster == null)
{
MainUtil.sendMessage(plr, C.INVALID_CLUSTER, args[1]);
return false;
}
} else {
}
else
{
cluster = ClusterManager.getCluster(plr.getLocation());
if (cluster == null) {
if (cluster == null)
{
MainUtil.sendMessage(plr, C.NOT_IN_CLUSTER);
return false;
}
}
if (!cluster.owner.equals(UUIDHandler.getUUID(plr))) {
if (!Permissions.hasPermission(plr, "plots.cluster.delete.other")) {
if (!cluster.owner.equals(UUIDHandler.getUUID(plr)))
{
if (!Permissions.hasPermission(plr, "plots.cluster.delete.other"))
{
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.delete.other");
return false;
}
}
final PlotWorld plotworld = PS.get().getPlotWorld(plr.getLocation().getWorld());
if (plotworld.TYPE == 2) {
if (plotworld.TYPE == 2)
{
final ArrayList<Plot> toRemove = new ArrayList<>();
for (final Plot plot : PS.get().getPlotsInWorld(plr.getLocation().getWorld())) {
for (final Plot plot : PS.get().getPlotsInWorld(plr.getLocation().getWorld()))
{
final PlotCluster other = ClusterManager.getCluster(plot);
if (cluster.equals(other)) {
if (cluster.equals(other))
{
toRemove.add(plot);
}
}
for (final Plot plot : toRemove) {
for (final Plot plot : toRemove)
{
plot.unclaim();
}
}
DBFunc.delete(cluster);
if (plotworld.TYPE == 2) {
if (plotworld.TYPE == 2)
{
SetupUtils.manager.removePopulator(plr.getLocation().getWorld(), cluster);
}
ClusterManager.last = null;
@ -276,36 +329,44 @@ public class Cluster extends SubCommand {
return true;
}
case "res":
case "resize": {
if (!Permissions.hasPermission(plr, "plots.cluster.resize")) {
case "resize":
{
if (!Permissions.hasPermission(plr, "plots.cluster.resize"))
{
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.resize");
return false;
}
if (args.length != 3) {
if (args.length != 3)
{
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster resize <pos1> <pos2>");
return false;
}
// check pos1 / pos2
PlotId pos1 = MainUtil.parseId(args[1]);
PlotId pos2 = MainUtil.parseId(args[2]);
if ((pos1 == null) || (pos2 == null)) {
if ((pos1 == null) || (pos2 == null))
{
MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_ID);
return false;
}
if ((pos2.x < pos1.x) || (pos2.y < pos1.y) ) {
if ((pos2.x < pos1.x) || (pos2.y < pos1.y))
{
pos1 = new PlotId(Math.min(pos1.x, pos2.x), Math.min(pos1.y, pos2.y));
pos2 = new PlotId(Math.max(pos1.x, pos2.x), Math.max(pos1.y, pos2.y));
}
// check if in cluster
Location loc = plr.getLocation();
String world = loc.getWorld();
final Location loc = plr.getLocation();
final String world = loc.getWorld();
final PlotCluster cluster = ClusterManager.getCluster(loc);
if (cluster == null) {
if (cluster == null)
{
MainUtil.sendMessage(plr, C.NOT_IN_CLUSTER);
return false;
}
if (!cluster.hasHelperRights(UUIDHandler.getUUID(plr))) {
if (!Permissions.hasPermission(plr, "plots.cluster.resize.other")) {
if (!cluster.hasHelperRights(UUIDHandler.getUUID(plr)))
{
if (!Permissions.hasPermission(plr, "plots.cluster.resize.other"))
{
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.resize.other");
return false;
}
@ -313,46 +374,56 @@ public class Cluster extends SubCommand {
//check if overlap
final PlotClusterId id = new PlotClusterId(pos1, pos2);
final HashSet<PlotCluster> intersects = ClusterManager.getIntersects(world, id);
if (intersects.size() > 1) {
if (intersects.size() > 1)
{
MainUtil.sendMessage(plr, C.CLUSTER_INTERSECTION, (intersects.size() - 1) + "");
return false;
}
HashSet<Plot> existing = MainUtil.getPlotSelectionOwned(world, cluster.getP1(), cluster.getP2());
HashSet<Plot> newplots = MainUtil.getPlotSelectionOwned(world, pos1, pos2);
HashSet<Plot> removed = ((HashSet<Plot>) existing.clone());
final HashSet<Plot> existing = MainUtil.getPlotSelectionOwned(world, cluster.getP1(), cluster.getP2());
final HashSet<Plot> newplots = MainUtil.getPlotSelectionOwned(world, pos1, pos2);
final HashSet<Plot> removed = ((HashSet<Plot>) existing.clone());
removed.removeAll(newplots);
// Check expand / shrink
if (removed.size() > 0) {
if (!Permissions.hasPermission(plr, "plots.cluster.resize.shrink")) {
if (removed.size() > 0)
{
if (!Permissions.hasPermission(plr, "plots.cluster.resize.shrink"))
{
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.resize.shrink");
return false;
}
}
newplots.removeAll(existing);
if (newplots.size() > 0) {
if (!Permissions.hasPermission(plr, "plots.cluster.resize.expand")) {
if (newplots.size() > 0)
{
if (!Permissions.hasPermission(plr, "plots.cluster.resize.expand"))
{
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.resize.expand");
return false;
}
}
// Check allowed cluster size
int current;
if (Settings.GLOBAL_LIMIT) {
if (Settings.GLOBAL_LIMIT)
{
current = ClusterManager.getPlayerClusterCount(plr);
}
else {
else
{
current = ClusterManager.getPlayerClusterCount(world, plr);
}
current -= cluster.getArea() + (1 + pos2.x - pos1.x) * (1 + pos2.y - pos1.y);
int allowed = Permissions.hasPermissionRange(plr, "plots.cluster", Settings.MAX_PLOTS);
if (current + cluster.getArea() > allowed) {
current -= cluster.getArea() + (((1 + pos2.x) - pos1.x) * ((1 + pos2.y) - pos1.y));
final int allowed = Permissions.hasPermissionRange(plr, "plots.cluster", Settings.MAX_PLOTS);
if ((current + cluster.getArea()) > allowed)
{
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster." + (current + cluster.getArea()));
return false;
}
for (Plot plot : removed) {
for (final Plot plot : removed)
{
FlagManager.removePlotFlag(plot, "cluster");
}
for (Plot plot : newplots) {
for (final Plot plot : newplots)
{
FlagManager.addPlotFlag(plot, new Flag(FlagManager.getFlag("cluster"), cluster));
}
// resize cluster
@ -362,76 +433,95 @@ public class Cluster extends SubCommand {
}
case "reg":
case "regenerate":
case "regen": {
if (!Permissions.hasPermission(plr, "plots.cluster.delete")) {
case "regen":
{
if (!Permissions.hasPermission(plr, "plots.cluster.delete"))
{
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.regen");
return false;
}
if ((args.length != 1) && (args.length != 2)) {
if ((args.length != 1) && (args.length != 2))
{
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster regen [name]");
return false;
}
PlotCluster cluster;
if (args.length == 2) {
if (args.length == 2)
{
cluster = ClusterManager.getCluster(plr.getLocation().getWorld(), args[1]);
if (cluster == null) {
if (cluster == null)
{
MainUtil.sendMessage(plr, C.INVALID_CLUSTER, args[1]);
return false;
}
} else {
}
else
{
cluster = ClusterManager.getCluster(plr.getLocation());
if (cluster == null) {
if (cluster == null)
{
MainUtil.sendMessage(plr, C.NOT_IN_CLUSTER);
return false;
}
}
if (!cluster.owner.equals(UUIDHandler.getUUID(plr))) {
if (!Permissions.hasPermission(plr, "plots.cluster.regen.other")) {
if (!cluster.owner.equals(UUIDHandler.getUUID(plr)))
{
if (!Permissions.hasPermission(plr, "plots.cluster.regen.other"))
{
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.regen.other");
return false;
}
}
long start = System.currentTimeMillis();
final long start = System.currentTimeMillis();
ClusterManager.regenCluster(cluster);
MainUtil.sendMessage(plr, C.CLUSTER_REGENERATED, (System.currentTimeMillis() - start) + "");
return true;
}
case "add":
case "inv":
case "invite": {
if (!Permissions.hasPermission(plr, "plots.cluster.invite")) {
case "invite":
{
if (!Permissions.hasPermission(plr, "plots.cluster.invite"))
{
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.invite");
return false;
}
if (args.length != 2) {
if (args.length != 2)
{
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster invite <player>");
return false;
}
// check if in cluster
final PlotCluster cluster = ClusterManager.getCluster(plr.getLocation());
if (cluster == null) {
if (cluster == null)
{
MainUtil.sendMessage(plr, C.NOT_IN_CLUSTER);
return false;
}
if (!cluster.hasHelperRights(UUIDHandler.getUUID(plr))) {
if (!Permissions.hasPermission(plr, "plots.cluster.invite.other")) {
if (!cluster.hasHelperRights(UUIDHandler.getUUID(plr)))
{
if (!Permissions.hasPermission(plr, "plots.cluster.invite.other"))
{
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.invite.other");
return false;
}
}
// check uuid
final UUID uuid = UUIDHandler.getUUID(args[1], null);
if (uuid == null) {
if (uuid == null)
{
MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[2]);
return false;
}
if (!cluster.isAdded(uuid)) {
if (!cluster.isAdded(uuid))
{
// add the user if not added
cluster.invited.add(uuid);
final String world = plr.getLocation().getWorld();
DBFunc.setInvited(world, cluster, uuid);
final PlotPlayer player = UUIDHandler.getPlayer(uuid);
if (player != null) {
if (player != null)
{
MainUtil.sendMessage(player, C.CLUSTER_INVITED, cluster.getName());
}
}
@ -440,51 +530,63 @@ public class Cluster extends SubCommand {
}
case "k":
case "remove":
case "kick": {
if (!Permissions.hasPermission(plr, "plots.cluster.kick")) {
case "kick":
{
if (!Permissions.hasPermission(plr, "plots.cluster.kick"))
{
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.kick");
return false;
}
if (args.length != 2) {
if (args.length != 2)
{
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster kick <player>");
return false;
}
final PlotCluster cluster = ClusterManager.getCluster(plr.getLocation());
if (cluster == null) {
if (cluster == null)
{
MainUtil.sendMessage(plr, C.NOT_IN_CLUSTER);
return false;
}
if (!cluster.hasHelperRights(UUIDHandler.getUUID(plr))) {
if (!Permissions.hasPermission(plr, "plots.cluster.kick.other")) {
if (!cluster.hasHelperRights(UUIDHandler.getUUID(plr)))
{
if (!Permissions.hasPermission(plr, "plots.cluster.kick.other"))
{
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.kick.other");
return false;
}
}
// check uuid
final UUID uuid = UUIDHandler.getUUID(args[1], null);
if (uuid == null) {
if (uuid == null)
{
MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[1]);
return false;
}
// Can't kick if the player is yourself, the owner, or not added to the cluster
if (uuid.equals(UUIDHandler.getUUID(plr)) || uuid.equals(cluster.owner) || !cluster.isAdded(uuid)) {
if (uuid.equals(UUIDHandler.getUUID(plr)) || uuid.equals(cluster.owner) || !cluster.isAdded(uuid))
{
MainUtil.sendMessage(plr, C.CANNOT_KICK_PLAYER, cluster.getName());
return false;
}
if (cluster.helpers.contains(uuid)) {
if (cluster.helpers.contains(uuid))
{
cluster.helpers.remove(uuid);
DBFunc.removeHelper(cluster, uuid);
}
cluster.invited.remove(uuid);
DBFunc.removeInvited(cluster, uuid);
final PlotPlayer player = UUIDHandler.getPlayer(uuid);
if (player != null) {
if (player != null)
{
MainUtil.sendMessage(player, C.CLUSTER_REMOVED, cluster.getName());
}
for (final Plot plot : new ArrayList<>(PS.get().getPlots(plr.getLocation().getWorld(), uuid))) {
for (final Plot plot : new ArrayList<>(PS.get().getPlots(plr.getLocation().getWorld(), uuid)))
{
final PlotCluster current = ClusterManager.getCluster(plot);
if ((current != null) && current.equals(cluster)) {
final String world = plr.getLocation().getWorld();
if ((current != null) && current.equals(cluster))
{
plr.getLocation().getWorld();
plot.unclaim();
}
}
@ -492,49 +594,62 @@ public class Cluster extends SubCommand {
return true;
}
case "quit":
case "leave": {
if (!Permissions.hasPermission(plr, "plots.cluster.leave")) {
case "leave":
{
if (!Permissions.hasPermission(plr, "plots.cluster.leave"))
{
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.leave");
return false;
}
if ((args.length != 1) && (args.length != 2)) {
if ((args.length != 1) && (args.length != 2))
{
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster leave [name]");
return false;
}
PlotCluster cluster;
if (args.length == 2) {
if (args.length == 2)
{
cluster = ClusterManager.getCluster(plr.getLocation().getWorld(), args[1]);
if (cluster == null) {
if (cluster == null)
{
MainUtil.sendMessage(plr, C.INVALID_CLUSTER, args[1]);
return false;
}
} else {
}
else
{
cluster = ClusterManager.getCluster(plr.getLocation());
if (cluster == null) {
if (cluster == null)
{
MainUtil.sendMessage(plr, C.NOT_IN_CLUSTER);
return false;
}
}
final UUID uuid = UUIDHandler.getUUID(plr);
if (!cluster.isAdded(uuid)) {
if (!cluster.isAdded(uuid))
{
MainUtil.sendMessage(plr, C.CLUSTER_NOT_ADDED);
return false;
}
if (uuid.equals(cluster.owner)) {
if (uuid.equals(cluster.owner))
{
MainUtil.sendMessage(plr, C.CLUSTER_CANNOT_LEAVE);
return false;
}
if (cluster.helpers.contains(uuid)) {
if (cluster.helpers.contains(uuid))
{
cluster.helpers.remove(uuid);
DBFunc.removeHelper(cluster, uuid);
}
cluster.invited.remove(uuid);
DBFunc.removeInvited(cluster, uuid);
MainUtil.sendMessage(plr, C.CLUSTER_REMOVED, cluster.getName());
for (final Plot plot : new ArrayList<>(PS.get().getPlots(plr.getLocation().getWorld(), uuid))) {
for (final Plot plot : new ArrayList<>(PS.get().getPlots(plr.getLocation().getWorld(), uuid)))
{
final PlotCluster current = ClusterManager.getCluster(plot);
if ((current != null) && current.equals(cluster)) {
final String world = plr.getLocation().getWorld();
if ((current != null) && current.equals(cluster))
{
plr.getLocation().getWorld();
plot.unclaim();
}
}
@ -542,31 +657,38 @@ public class Cluster extends SubCommand {
}
case "admin":
case "helper":
case "helpers": {
if (!Permissions.hasPermission(plr, "plots.cluster.helpers")) {
case "helpers":
{
if (!Permissions.hasPermission(plr, "plots.cluster.helpers"))
{
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.helpers");
return false;
}
if (args.length != 3) {
if (args.length != 3)
{
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster helpers <add|remove> <player>");
return false;
}
final PlotCluster cluster = ClusterManager.getCluster(plr.getLocation());
if (cluster == null) {
if (cluster == null)
{
MainUtil.sendMessage(plr, C.NOT_IN_CLUSTER);
return false;
}
final UUID uuid = UUIDHandler.getUUID(args[2], null);
if (uuid == null) {
if (uuid == null)
{
MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[2]);
return false;
}
if (args[1].toLowerCase().equals("add")) {
if (args[1].toLowerCase().equals("add"))
{
cluster.helpers.add(uuid);
DBFunc.setHelper(cluster, uuid);
return MainUtil.sendMessage(plr, C.CLUSTER_ADDED_HELPER);
}
if (args[1].toLowerCase().equals("remove")) {
if (args[1].toLowerCase().equals("remove"))
{
cluster.helpers.remove(uuid);
DBFunc.removeHelper(cluster, uuid);
return MainUtil.sendMessage(plr, C.CLUSTER_REMOVED_HELPER);
@ -576,23 +698,29 @@ public class Cluster extends SubCommand {
}
case "spawn":
case "home":
case "tp": {
if (!Permissions.hasPermission(plr, "plots.cluster.tp")) {
case "tp":
{
if (!Permissions.hasPermission(plr, "plots.cluster.tp"))
{
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.tp");
return false;
}
if (args.length != 2) {
if (args.length != 2)
{
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster tp <name>");
return false;
}
final PlotCluster cluster = ClusterManager.getCluster(plr.getLocation().getWorld(), args[1]);
if (cluster == null) {
if (cluster == null)
{
MainUtil.sendMessage(plr, C.INVALID_CLUSTER, args[1]);
return false;
}
final UUID uuid = UUIDHandler.getUUID(plr);
if (!cluster.isAdded(uuid)) {
if (!Permissions.hasPermission(plr, "plots.cluster.tp.other")) {
if (!cluster.isAdded(uuid))
{
if (!Permissions.hasPermission(plr, "plots.cluster.tp.other"))
{
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.tp.other");
return false;
}
@ -603,32 +731,41 @@ public class Cluster extends SubCommand {
case "i":
case "info":
case "show":
case "information": {
if (!Permissions.hasPermission(plr, "plots.cluster.info")) {
case "information":
{
if (!Permissions.hasPermission(plr, "plots.cluster.info"))
{
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.info");
return false;
}
if ((args.length != 1) && (args.length != 2)) {
if ((args.length != 1) && (args.length != 2))
{
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster info [name]");
return false;
}
PlotCluster cluster;
if (args.length == 2) {
if (args.length == 2)
{
cluster = ClusterManager.getCluster(plr.getLocation().getWorld(), args[1]);
if (cluster == null) {
if (cluster == null)
{
MainUtil.sendMessage(plr, C.INVALID_CLUSTER, args[1]);
return false;
}
} else {
}
else
{
cluster = ClusterManager.getCluster(plr.getLocation());
if (cluster == null) {
if (cluster == null)
{
MainUtil.sendMessage(plr, C.NOT_IN_CLUSTER);
return false;
}
}
final String id = cluster.toString();
String owner = UUIDHandler.getName(cluster.owner);
if (owner == null) {
if (owner == null)
{
owner = "unknown";
}
final String name = cluster.getName();
@ -645,22 +782,28 @@ public class Cluster extends SubCommand {
}
case "sh":
case "setspawn":
case "sethome": {
if (!Permissions.hasPermission(plr, "plots.cluster.sethome")) {
case "sethome":
{
if (!Permissions.hasPermission(plr, "plots.cluster.sethome"))
{
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.sethome");
return false;
}
if ((args.length != 1) && (args.length != 2)) {
if ((args.length != 1) && (args.length != 2))
{
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster sethome");
return false;
}
final PlotCluster cluster = ClusterManager.getCluster(plr.getLocation());
if (cluster == null) {
if (cluster == null)
{
MainUtil.sendMessage(plr, C.NOT_IN_CLUSTER);
return false;
}
if (!cluster.hasHelperRights(UUIDHandler.getUUID(plr))) {
if (!Permissions.hasPermission(plr, "plots.cluster.sethome.other")) {
if (!cluster.hasHelperRights(UUIDHandler.getUUID(plr)))
{
if (!Permissions.hasPermission(plr, "plots.cluster.sethome.other"))
{
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.sethome.other");
return false;
}

View File

@ -1,58 +1,59 @@
package com.intellectualcrafters.plot.commands;
/**
* CommandCategory
*
* @author Citymonstret
* @author Empire92
*/
public enum CommandCategory {
/**
* Claiming Commands
*
* Such as: /plot claim
*/
CLAIMING("Claiming"),
/**
* Teleportation Commands
*
* Such as: /plot visit
*/
TELEPORT("Teleportation"),
/**
* Action Commands
*
* Such as: /plot clear
*/
ACTIONS("Actions"),
/**
* Information Commands
*
* Such as: /plot info
*/
INFO("Information"),
/**
* Debug Commands
*
* Such as: /plot debug
*/
DEBUG("Debug");
/**
* The category name (Readable)
*/
private final String name;
/**
* Constructor
*
* @param name readable name
*/
CommandCategory(final String name) {
this.name = name;
}
@Override
public String toString() {
return this.name;
}
}
package com.intellectualcrafters.plot.commands;
/**
* CommandCategory
*
*/
public enum CommandCategory
{
/**
* Claiming Commands
*
* Such as: /plot claim
*/
CLAIMING("Claiming"),
/**
* Teleportation Commands
*
* Such as: /plot visit
*/
TELEPORT("Teleportation"),
/**
* Action Commands
*
* Such as: /plot clear
*/
ACTIONS("Actions"),
/**
* Information Commands
*
* Such as: /plot info
*/
INFO("Information"),
/**
* Debug Commands
*
* Such as: /plot debug
*/
DEBUG("Debug");
/**
* The category name (Readable)
*/
private final String name;
/**
* Constructor
*
* @param name readable name
*/
CommandCategory(final String name)
{
this.name = name;
}
@Override
public String toString()
{
return name;

View File

@ -1,52 +1,54 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
// PlotSquared - A plot manager and world generator for the Bukkit API /
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
// /
// This program is free software; you can redistribute it and/or modify /
// it under the terms of the GNU General Public License as published by /
// the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.commands;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.Permissions;
/**
* Created by Citymonstret on 2014-08-03.
*
* @author Citymonstret
*/
public class CommandPermission {
/**
* Permission Node
*/
public final String permission;
/**
* @param permission Command Permission
*/
public CommandPermission(final String permission) {
this.permission = permission.toLowerCase();
}
/**
* @param player Does the player have the permission?
*
* @return true of player has the required permission node
*/
public boolean hasPermission(final PlotPlayer player) {
return Permissions.hasPermission(player, this.permission);
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////
// PlotSquared - A plot manager and world generator for the Bukkit API /
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
// /
// This program is free software; you can redistribute it and/or modify /
// it under the terms of the GNU General Public License as published by /
// the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.commands;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.Permissions;
/**
* Created by Citymonstret on 2014-08-03.
*
*/
public class CommandPermission
{
/**
* Permission Node
*/
public final String permission;
/**
* @param permission Command Permission
*/
public CommandPermission(final String permission)
{
this.permission = permission.toLowerCase();
}
/**
* @param player Does the player have the permission?
*
* @return true of player has the required permission node
*/
public boolean hasPermission(final PlotPlayer player)
{
return Permissions.hasPermission(player, permission);
}

View File

@ -36,56 +36,66 @@ import com.intellectualcrafters.plot.util.UUIDHandler;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "comment",
aliases = {"msg"},
description = "Comment on a plot",
category = CommandCategory.ACTIONS,
requiredType = RequiredType.NONE,
permission = "plots.comment"
)
public class Comment extends SubCommand {
command = "comment",
aliases = { "msg" },
description = "Comment on a plot",
category = CommandCategory.ACTIONS,
requiredType = RequiredType.NONE,
permission = "plots.comment")
public class Comment extends SubCommand
{
@Override
public boolean onCommand(PlotPlayer player, String[] args) {
if (args.length < 2) {
sendMessage(player, C.COMMENT_SYNTAX, StringMan.join(CommentManager.inboxes.keySet(),"|"));
public boolean onCommand(final PlotPlayer player, final String[] args)
{
if (args.length < 2)
{
sendMessage(player, C.COMMENT_SYNTAX, StringMan.join(CommentManager.inboxes.keySet(), "|"));
return false;
}
CommentInbox inbox = CommentManager.inboxes.get(args[0].toLowerCase());
if (inbox == null) {
sendMessage(player, C.COMMENT_SYNTAX, StringMan.join(CommentManager.inboxes.keySet(),"|"));
final CommentInbox inbox = CommentManager.inboxes.get(args[0].toLowerCase());
if (inbox == null)
{
sendMessage(player, C.COMMENT_SYNTAX, StringMan.join(CommentManager.inboxes.keySet(), "|"));
return false;
}
Plot plot;
Location loc = player.getLocation();
PlotId id = PlotId.fromString(args[1]);
final Location loc = player.getLocation();
final PlotId id = PlotId.fromString(args[1]);
int index;
if (id != null) {
if (args.length < 4) {
sendMessage(player, C.COMMENT_SYNTAX, StringMan.join(CommentManager.inboxes.keySet(),"|"));
if (id != null)
{
if (args.length < 4)
{
sendMessage(player, C.COMMENT_SYNTAX, StringMan.join(CommentManager.inboxes.keySet(), "|"));
return false;
}
index = 2;
plot = MainUtil.getPlot(loc.getWorld(), id);
}
else {
else
{
index = 1;
plot = MainUtil.getPlot(loc);
}
if (!inbox.canWrite(plot, player)) {
if (!inbox.canWrite(plot, player))
{
sendMessage(player, C.NO_PERM_INBOX, "");
return false;
}
String message = StringMan.join(Arrays.copyOfRange(args,index, args.length), " ");
PlotComment comment = new PlotComment(loc.getWorld(), id, message, player.getName(), inbox.toString(), System.currentTimeMillis());
boolean result = inbox.addComment(plot, comment);
if (!result) {
final String message = StringMan.join(Arrays.copyOfRange(args, index, args.length), " ");
final PlotComment comment = new PlotComment(loc.getWorld(), id, message, player.getName(), inbox.toString(), System.currentTimeMillis());
final boolean result = inbox.addComment(plot, comment);
if (!result)
{
sendMessage(player, C.NO_PLOT_INBOX, "");
sendMessage(player, C.COMMENT_SYNTAX, StringMan.join(CommentManager.inboxes.keySet(),"|"));
sendMessage(player, C.COMMENT_SYNTAX, StringMan.join(CommentManager.inboxes.keySet(), "|"));
return false;
}
for (PlotPlayer pp : UUIDHandler.getPlayers().values()) {
if (pp.getAttribute("chatspy")) {
for (final PlotPlayer pp : UUIDHandler.getPlayers().values())
{
if (pp.getAttribute("chatspy"))
{
MainUtil.sendMessage(pp, "/plot comment " + StringMan.join(args, " "));
}
}

View File

@ -36,42 +36,51 @@ import com.intellectualcrafters.plot.util.MathMan;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "condense",
permission = "plots.admin",
description = "Condense a plotworld",
category = CommandCategory.DEBUG,
requiredType = RequiredType.CONSOLE
)
public class Condense extends SubCommand {
command = "condense",
permission = "plots.admin",
description = "Condense a plotworld",
category = CommandCategory.DEBUG,
requiredType = RequiredType.CONSOLE)
public class Condense extends SubCommand
{
public static boolean TASK = false;
@Override
public boolean onCommand(final PlotPlayer plr, String ... args) {
if ((args.length != 2) && (args.length != 3)) {
public boolean onCommand(final PlotPlayer plr, final String... args)
{
if ((args.length != 2) && (args.length != 3))
{
MainUtil.sendMessage(plr, "/plot condense <world> <start|stop|info> [radius]");
return false;
}
final String worldname = args[0];
if (!BlockManager.manager.isWorld(worldname) || !PS.get().isPlotWorld(worldname)) {
if (!BlockManager.manager.isWorld(worldname) || !PS.get().isPlotWorld(worldname))
{
MainUtil.sendMessage(plr, "INVALID WORLD");
return false;
}
switch (args[1].toLowerCase()) {
case "start": {
if (args.length == 2) {
switch (args[1].toLowerCase())
{
case "start":
{
if (args.length == 2)
{
MainUtil.sendMessage(plr, "/plot condense " + worldname + " start <radius>");
return false;
}
if (TASK) {
if (TASK)
{
MainUtil.sendMessage(plr, "TASK ALREADY STARTED");
return false;
}
if (args.length == 2) {
if (args.length == 2)
{
MainUtil.sendMessage(plr, "/plot condense " + worldname + " start <radius>");
return false;
}
if (!MathMan.isInteger(args[2])) {
if (!MathMan.isInteger(args[2]))
{
MainUtil.sendMessage(plr, "INVALID RADIUS");
return false;
}
@ -79,61 +88,76 @@ public class Condense extends SubCommand {
final Collection<Plot> plots = PS.get().getPlotsInWorld(worldname);
final int size = plots.size();
final int minimum_radius = (int) Math.ceil((Math.sqrt(size) / 2) + 1);
if (radius < minimum_radius) {
if (radius < minimum_radius)
{
MainUtil.sendMessage(plr, "RADIUS TOO SMALL");
return false;
}
final List<PlotId> to_move = new ArrayList<>(getPlots(plots, radius));
final List<PlotId> free = new ArrayList<>();
PlotId start = new PlotId(0, 0);
while ((start.x <= minimum_radius) && (start.y <= minimum_radius)) {
while ((start.x <= minimum_radius) && (start.y <= minimum_radius))
{
final Plot plot = MainUtil.getPlot(worldname, start);
if (!plot.hasOwner()) {
if (!plot.hasOwner())
{
free.add(plot.id);
}
start = Auto.getNextPlot(start, 1);
}
if (free.size() == 0 || to_move.size() == 0) {
if ((free.size() == 0) || (to_move.size() == 0))
{
MainUtil.sendMessage(plr, "NO FREE PLOTS FOUND");
return false;
}
MainUtil.move(MainUtil.getPlot(worldname, to_move.get(0)), MainUtil.getPlot(worldname, free.get(0)), new Runnable() {
MainUtil.move(MainUtil.getPlot(worldname, to_move.get(0)), MainUtil.getPlot(worldname, free.get(0)), new Runnable()
{
@Override
public void run() {
if (!TASK) {
public void run()
{
if (!TASK)
{
MainUtil.sendMessage(plr, "CONDENSE TASK CANCELLED");
return;
}
to_move.remove(0);
free.remove(0);
int index = 0;
for (final PlotId id : to_move) {
for (final PlotId id : to_move)
{
final Plot plot = MainUtil.getPlot(worldname, id);
if (plot.hasOwner()) {
if (plot.hasOwner())
{
break;
}
index++;
}
for (int i = 0; i < index; i++) {
for (int i = 0; i < index; i++)
{
to_move.remove(0);
}
index = 0;
for (final PlotId id : free) {
for (final PlotId id : free)
{
final Plot plot = MainUtil.getPlot(worldname, id);
if (!plot.hasOwner()) {
if (!plot.hasOwner())
{
break;
}
index++;
}
for (int i = 0; i < index; i++) {
for (int i = 0; i < index; i++)
{
free.remove(0);
}
if (to_move.size() == 0) {
if (to_move.size() == 0)
{
MainUtil.sendMessage(plr, "TASK COMPLETE. PLEASE VERIFY THAT NO NEW PLOTS HAVE BEEN CLAIMED DURING TASK.");
TASK = false;
return;
}
if (free.size() == 0) {
if (free.size() == 0)
{
MainUtil.sendMessage(plr, "TASK FAILED. NO FREE PLOTS FOUND!");
TASK = false;
return;
@ -146,8 +170,10 @@ public class Condense extends SubCommand {
MainUtil.sendMessage(plr, "TASK STARTED...");
return true;
}
case "stop": {
if (!TASK) {
case "stop":
{
if (!TASK)
{
MainUtil.sendMessage(plr, "TASK ALREADY STOPPED");
return false;
}
@ -155,12 +181,15 @@ public class Condense extends SubCommand {
MainUtil.sendMessage(plr, "TASK STOPPED");
return true;
}
case "info": {
if (args.length == 2) {
case "info":
{
if (args.length == 2)
{
MainUtil.sendMessage(plr, "/plot condense " + worldname + " info <radius>");
return false;
}
if (!MathMan.isInteger(args[2])) {
if (!MathMan.isInteger(args[2]))
{
MainUtil.sendMessage(plr, "INVALID RADIUS");
return false;
}
@ -168,7 +197,8 @@ public class Condense extends SubCommand {
final Collection<Plot> plots = PS.get().getPlotsInWorld(worldname);
final int size = plots.size();
final int minimum_radius = (int) Math.ceil((Math.sqrt(size) / 2) + 1);
if (radius < minimum_radius) {
if (radius < minimum_radius)
{
MainUtil.sendMessage(plr, "RADIUS TOO SMALL");
return false;
}
@ -189,10 +219,13 @@ public class Condense extends SubCommand {
return false;
}
public Set<PlotId> getPlots(final Collection<Plot> plots, final int radius) {
public Set<PlotId> getPlots(final Collection<Plot> plots, final int radius)
{
final HashSet<PlotId> outside = new HashSet<>();
for (final Plot plot : plots) {
if ((plot.id.x > radius) || (plot.id.x < -radius) || (plot.id.y > radius) || (plot.id.y < -radius)) {
for (final Plot plot : plots)
{
if ((plot.id.x > radius) || (plot.id.x < -radius) || (plot.id.y > radius) || (plot.id.y < -radius))
{
outside.add(plot.id);
}
}

View File

@ -20,7 +20,6 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.commands;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.object.CmdInstance;
import com.intellectualcrafters.plot.object.PlotPlayer;
@ -30,26 +29,29 @@ import com.intellectualcrafters.plot.util.TaskManager;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "confirm",
permission = "plots.use",
description = "Confirm an action",
category = CommandCategory.ACTIONS
)
public class Confirm extends SubCommand {
command = "confirm",
permission = "plots.use",
description = "Confirm an action",
category = CommandCategory.ACTIONS)
public class Confirm extends SubCommand
{
@Override
public boolean onCommand(final PlotPlayer plr, final String ... args) {
CmdInstance command = CmdConfirm.getPending(plr);
if (command == null) {
MainUtil.sendMessage(plr, C.FAILED_CONFIRM);
return false;
}
CmdConfirm.removePending(plr);
if (System.currentTimeMillis() - command.timestamp > 20000) {
MainUtil.sendMessage(plr, C.FAILED_CONFIRM);
return false;
}
TaskManager.runTask(command.command);
return true;
@Override
public boolean onCommand(final PlotPlayer plr, final String... args)
{
final CmdInstance command = CmdConfirm.getPending(plr);
if (command == null)
{
MainUtil.sendMessage(plr, C.FAILED_CONFIRM);
return false;
}
CmdConfirm.removePending(plr);
if ((System.currentTimeMillis() - command.timestamp) > 20000)
{
MainUtil.sendMessage(plr, C.FAILED_CONFIRM);
return false;
}
TaskManager.runTask(command.command);
return true;
}
}

View File

@ -22,49 +22,46 @@ package com.intellectualcrafters.plot.commands;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.flag.Flag;
import com.intellectualcrafters.plot.flag.FlagManager;
import com.intellectualcrafters.plot.generator.HybridUtils;
import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotAnalysis;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.util.BlockManager;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.UUIDHandler;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "continue",
description = "Continue a plot that was previously marked as done",
permission = "plots.continue",
category = CommandCategory.ACTIONS,
requiredType = RequiredType.NONE
)
public class Continue extends SubCommand {
command = "continue",
description = "Continue a plot that was previously marked as done",
permission = "plots.continue",
category = CommandCategory.ACTIONS,
requiredType = RequiredType.NONE)
public class Continue extends SubCommand
{
@Override
public boolean onCommand(final PlotPlayer plr, final String[] args) {
public boolean onCommand(final PlotPlayer plr, final String[] args)
{
final Location loc = plr.getLocation();
final Plot plot = MainUtil.getPlot(loc);
if (plot == null || !plot.hasOwner()) {
return !sendMessage(plr, C.NOT_IN_PLOT);
}
if ((!plot.isOwner(plr.getUUID())) && !Permissions.hasPermission(plr, "plots.admin.command.continue")) {
if ((plot == null) || !plot.hasOwner()) { return !sendMessage(plr, C.NOT_IN_PLOT); }
if ((!plot.isOwner(plr.getUUID())) && !Permissions.hasPermission(plr, "plots.admin.command.continue"))
{
MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
return false;
}
if (!plot.getSettings().flags.containsKey("done")) {
if (!plot.getSettings().flags.containsKey("done"))
{
MainUtil.sendMessage(plr, C.DONE_NOT_DONE);
return false;
}
if (Settings.DONE_COUNTS_TOWARDS_LIMIT && MainUtil.getAllowedPlots(plr) >= MainUtil.getPlayerPlotCount(plr)) {
if (Settings.DONE_COUNTS_TOWARDS_LIMIT && (MainUtil.getAllowedPlots(plr) >= MainUtil.getPlayerPlotCount(plr)))
{
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.admin.command.continue");
return false;
}
if (MainUtil.runners.containsKey(plot)) {
if (MainUtil.runners.containsKey(plot))
{
MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER);
return false;
}

View File

@ -31,53 +31,61 @@ import com.plotsquared.general.commands.Argument;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "copy",
permission = "plots.copy",
aliases = {"copypaste"},
category = CommandCategory.ACTIONS,
description = "Copy a plot",
usage = "/plot copy <X;Z>",
requiredType = RequiredType.NONE
)
public class Copy extends SubCommand {
command = "copy",
permission = "plots.copy",
aliases = { "copypaste" },
category = CommandCategory.ACTIONS,
description = "Copy a plot",
usage = "/plot copy <X;Z>",
requiredType = RequiredType.NONE)
public class Copy extends SubCommand
{
public Copy() {
public Copy()
{
requiredArguments = new Argument[] {
Argument.PlotID
Argument.PlotID
};
}
@Override
public boolean onCommand(final PlotPlayer plr, final String ... args) {
public boolean onCommand(final PlotPlayer plr, final String... args)
{
final Location loc = plr.getLocation();
final Plot plot1 = MainUtil.getPlot(loc);
if (plot1 == null) {
return !MainUtil.sendMessage(plr, C.NOT_IN_PLOT);
}
if (!plot1.isAdded(plr.getUUID()) && !Permissions.hasPermission(plr, C.PERMISSION_ADMIN.s())) {
if (plot1 == null) { return !MainUtil.sendMessage(plr, C.NOT_IN_PLOT); }
if (!plot1.isAdded(plr.getUUID()) && !Permissions.hasPermission(plr, C.PERMISSION_ADMIN.s()))
{
MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
return false;
}
final String world = loc.getWorld();
final PlotId plot2 = MainUtil.parseId(args[0]);
if ((plot2 == null)) {
if ((plot2 == null))
{
MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_ID);
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot copy <X;Z>");
return false;
}
if (plot1.id.equals(plot2)) {
if (plot1.id.equals(plot2))
{
MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_ID);
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot copy <X;Z>");
return false;
}
if (MainUtil.copy(world, plot1.id, plot2, new Runnable() {
if (MainUtil.copy(world, plot1.id, plot2, new Runnable()
{
@Override
public void run() {
public void run()
{
MainUtil.sendMessage(plr, C.COPY_SUCCESS);
}
})) {
}))
{
return true;
} else {
}
else
{
MainUtil.sendMessage(plr, C.REQUIRES_UNOWNED);
return false;
}

View File

@ -31,26 +31,23 @@ import com.intellectualcrafters.plot.util.MainUtil;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "createroadschematic",
aliases = {"crs"},
category = CommandCategory.DEBUG,
requiredType = RequiredType.NONE,
permission = "plots.createroadschematic",
description = "Add a road schematic to your world using the roads around your current plot",
usage = "/plot createroadschematic"
)
public class CreateRoadSchematic extends SubCommand {
command = "createroadschematic",
aliases = { "crs" },
category = CommandCategory.DEBUG,
requiredType = RequiredType.NONE,
permission = "plots.createroadschematic",
description = "Add a road schematic to your world using the roads around your current plot",
usage = "/plot createroadschematic")
public class CreateRoadSchematic extends SubCommand
{
@Override
public boolean onCommand(final PlotPlayer player, final String ... args) {
public boolean onCommand(final PlotPlayer player, final String... args)
{
final Location loc = player.getLocation();
final Plot plot = MainUtil.getPlot(loc);
if (plot == null) {
return sendMessage(player, C.NOT_IN_PLOT);
}
if (!(PS.get().getPlotWorld(loc.getWorld()) instanceof HybridPlotWorld)) {
return sendMessage(player, C.NOT_IN_PLOT_WORLD);
}
if (plot == null) { return sendMessage(player, C.NOT_IN_PLOT); }
if (!(PS.get().getPlotWorld(loc.getWorld()) instanceof HybridPlotWorld)) { return sendMessage(player, C.NOT_IN_PLOT_WORLD); }
HybridUtils.manager.setupRoadSchematic(plot);
MainUtil.sendMessage(player, "&6Saved new road schematic. To test the road, fly to a few other plots and use /plot debugroadregen");
return true;

View File

@ -3,12 +3,10 @@ package com.intellectualcrafters.plot.commands;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.database.MySQL;
import com.intellectualcrafters.plot.database.SQLManager;
@ -21,35 +19,45 @@ import com.intellectualcrafters.plot.util.TaskManager;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "database",
aliases = {"convert"},
category = CommandCategory.DEBUG,
permission = "plots.database",
description = "Convert/Backup Storage",
requiredType = RequiredType.CONSOLE,
usage = "/plots database [world] <sqlite|mysql|import>"
)
public class Database extends SubCommand {
command = "database",
aliases = { "convert" },
category = CommandCategory.DEBUG,
permission = "plots.database",
description = "Convert/Backup Storage",
requiredType = RequiredType.CONSOLE,
usage = "/plots database [world] <sqlite|mysql|import>"
public static void insertPlots(final SQLManager manager, final ArrayList<Plot> plots, final PlotPlayer player) {
TaskManager.runTaskAsync(new Runnable() {
)
public class Database extends SubCommand
{
public static void insertPlots(final SQLManager manager, final ArrayList<Plot> plots, final PlotPlayer player)
{
TaskManager.runTaskAsync(new Runnable()
{
@Override
public void run() {
try {
public void run()
{
try
{
final ArrayList<Plot> ps = new ArrayList<>();
for (final Plot p : plots) {
for (final Plot p : plots)
{
ps.add(p);
}
MainUtil.sendMessage(player, "&6Starting...");
manager.createPlotsAndData(ps, new Runnable() {
manager.createPlotsAndData(ps, new Runnable()
{
@Override
public void run() {
public void run()
{
MainUtil.sendMessage(player, "&6Database conversion finished!");
manager.close();
}
});
} catch (final Exception e) {
}
catch (final Exception e)
{
MainUtil.sendMessage(player, "Failed to insert plot objects, see stacktrace for info");
e.printStackTrace();
}
@ -58,42 +66,54 @@ public class Database extends SubCommand {
}
@Override
public boolean onCommand(final PlotPlayer player, String[] args) {
if (args.length < 1) {
public boolean onCommand(final PlotPlayer player, String[] args)
{
if (args.length < 1)
{
MainUtil.sendMessage(player, "/plot database [world] <sqlite|mysql>");
return false;
}
ArrayList<Plot> plots;
if (PS.get().isPlotWorld(args[0])) {
if (PS.get().isPlotWorld(args[0]))
{
plots = PS.get().sortPlotsByTemp(PS.get().getPlotsInWorld(args[0]));
args = Arrays.copyOfRange(args, 1, args.length);
}
else {
else
{
plots = PS.get().sortPlotsByTemp(PS.get().getPlotsRaw());
}
if (args.length < 1) {
if (args.length < 1)
{
MainUtil.sendMessage(player, "/plot database [world] <sqlite|mysql|import>");
MainUtil.sendMessage(player, "[arg] indicates an optional argument");
return false;
}
try {
try
{
com.intellectualcrafters.plot.database.Database implementation;
String prefix = "";
switch (args[0].toLowerCase()) {
case "import": {
if (args.length < 2) {
switch (args[0].toLowerCase())
{
case "import":
{
if (args.length < 2)
{
MainUtil.sendMessage(player, "/plot database import [sqlite file] [prefix]");
return false;
}
MainUtil.sendMessage(player, "&6Starting...");
implementation = new SQLite(PS.get().IMP.getDirectory() + File.separator + args[1] + ".db");
SQLManager manager = new SQLManager(implementation, (args.length == 3) ? args[2] : "", true);
ConcurrentHashMap<String, ConcurrentHashMap<PlotId, Plot>> map = manager.getPlots();
final SQLManager manager = new SQLManager(implementation, (args.length == 3) ? args[2] : "", true);
final ConcurrentHashMap<String, ConcurrentHashMap<PlotId, Plot>> map = manager.getPlots();
plots = new ArrayList<Plot>();
for (Entry<String, ConcurrentHashMap<PlotId, Plot>> entry : map.entrySet()) {
for (Entry<PlotId, Plot> entry2 : entry.getValue().entrySet()) {
Plot plot = entry2.getValue();
if (PS.get().getPlot(plot.world, plot.id) != null) {
for (final Entry<String, ConcurrentHashMap<PlotId, Plot>> entry : map.entrySet())
{
for (final Entry<PlotId, Plot> entry2 : entry.getValue().entrySet())
{
final Plot plot = entry2.getValue();
if (PS.get().getPlot(plot.world, plot.id) != null)
{
MainUtil.sendMessage(player, "Skipping duplicate plot: " + plot + " | id=" + plot.temp);
continue;
}
@ -101,43 +121,44 @@ public class Database extends SubCommand {
plots.add(entry2.getValue());
}
}
DBFunc.createPlotsAndData(plots, new Runnable() {
DBFunc.createPlotsAndData(plots, new Runnable()
{
@Override
public void run() {
public void run()
{
MainUtil.sendMessage(player, "&6Database conversion finished!");
}
});
return true;
}
case "mysql":
if (args.length < 6) {
return MainUtil.sendMessage(player, "/plot database mysql [host] [port] [username] [password] [database] {prefix}");
}
if (args.length < 6) { return MainUtil.sendMessage(player, "/plot database mysql [host] [port] [username] [password] [database] {prefix}"); }
final String host = args[1];
final String port = args[2];
final String username = args[3];
final String password = args[4];
final String database = args[5];
if (args.length > 6) {
if (args.length > 6)
{
prefix = args[6];
}
implementation = new MySQL(host, port, database, username, password);
break;
case "sqlite":
if (args.length < 2) {
return MainUtil.sendMessage(player, "/plot database sqlite [file]");
}
if (args.length < 2) { return MainUtil.sendMessage(player, "/plot database sqlite [file]"); }
implementation = new SQLite(PS.get().IMP.getDirectory() + File.separator + args[1] + ".db");
break;
default:
return MainUtil.sendMessage(player, "/plot database [sqlite/mysql]");
}
try {
try
{
final SQLManager manager = new SQLManager(implementation, prefix, true);
insertPlots(manager, plots, player);
return true;
}
catch (Exception e) {
catch (final Exception e)
{
MainUtil.sendMessage(player, "$1Failed to save plots, read stacktrace for info");
MainUtil.sendMessage(player, "&d==== Here is an ugly stacktrace, if you are interested in those things ===");
e.printStackTrace();
@ -146,7 +167,8 @@ public class Database extends SubCommand {
return false;
}
}
catch (Exception e) {
catch (final Exception e)
{
MainUtil.sendMessage(player, "$1Failed to open connection, read stacktrace for info");
MainUtil.sendMessage(player, "&d==== Here is an ugly stacktrace, if you are interested in those things ===");
e.printStackTrace();

View File

@ -28,19 +28,22 @@ import com.intellectualcrafters.plot.util.MainUtil;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "debug",
category = CommandCategory.DEBUG,
description = "Show debug information",
usage = "/plot debug [msg]",
permission = "plots.admin"
)
public class Debug extends SubCommand {
command = "debug",
category = CommandCategory.DEBUG,
description = "Show debug information",
usage = "/plot debug [msg]",
permission = "plots.admin")
public class Debug extends SubCommand
{
@Override
public boolean onCommand(PlotPlayer plr, String[] args) {
if ((args.length > 0) && args[0].equalsIgnoreCase("msg")) {
public boolean onCommand(final PlotPlayer plr, final String[] args)
{
if ((args.length > 0) && args[0].equalsIgnoreCase("msg"))
{
final StringBuilder msg = new StringBuilder();
for (final C c : C.values()) {
for (final C c : C.values())
{
msg.append(c.s()).append("\n");
}
MainUtil.sendMessage(plr, msg.toString());
@ -56,7 +59,8 @@ public class Debug extends SubCommand {
}
{
final StringBuilder worlds = new StringBuilder("");
for (final String world : PS.get().getPlotWorlds()) {
for (final String world : PS.get().getPlotWorlds())
{
worlds.append(world).append(" ");
}
information.append(header);
@ -77,11 +81,13 @@ public class Debug extends SubCommand {
return true;
}
private String getSection(final String line, final String val) {
private String getSection(final String line, final String val)
{
return line.replaceAll("%val%", val) + "\n";
}
private String getLine(final String line, final String var, final Object val) {
private String getLine(final String line, final String var, final Object val)
{
return line.replaceAll("%var%", var).replaceAll("%val%", "" + val) + "\n";
}
}

View File

@ -9,24 +9,28 @@ import com.intellectualcrafters.plot.object.PlotPlayer;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "debugallowunsafe",
description = "Allow unsafe actions until toggled off",
usage = "/plot debugallowunsafe",
category = CommandCategory.DEBUG,
requiredType = RequiredType.NONE,
permission = "plots.debugallowunsafe"
)
public class DebugAllowUnsafe extends SubCommand {
command = "debugallowunsafe",
description = "Allow unsafe actions until toggled off",
usage = "/plot debugallowunsafe",
category = CommandCategory.DEBUG,
requiredType = RequiredType.NONE,
permission = "plots.debugallowunsafe")
public class DebugAllowUnsafe extends SubCommand
{
public static final List<UUID> unsafeAllowed = new ArrayList<>();
@Override
public boolean onCommand(final PlotPlayer plr, final String ... args) {
if (unsafeAllowed.contains(plr.getUUID())) {
public boolean onCommand(final PlotPlayer plr, final String... args)
{
if (unsafeAllowed.contains(plr.getUUID()))
{
unsafeAllowed.remove(plr.getUUID());
sendMessage(plr, C.DEBUGALLOWUNSAFE_OFF);
} else {
}
else
{
unsafeAllowed.add(plr.getUUID());
sendMessage(plr, C.DEBUGALLOWUNSAFE_ON);
}

View File

@ -43,25 +43,29 @@ import com.intellectualcrafters.plot.util.UUIDHandler;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "debugclaimtest",
description = "If you accidentally delete your database, this command will attempt to restore all plots based on the data from plot sighs. Execution time may vary",
category = CommandCategory.DEBUG,
requiredType = RequiredType.CONSOLE,
permission = "plots.debugclaimtest"
)
public class DebugClaimTest extends SubCommand {
command = "debugclaimtest",
description = "If you accidentally delete your database, this command will attempt to restore all plots based on the data from plot sighs. Execution time may vary",
category = CommandCategory.DEBUG,
requiredType = RequiredType.CONSOLE,
permission = "plots.debugclaimtest")
public class DebugClaimTest extends SubCommand
{
public static boolean claimPlot(final PlotPlayer player, final Plot plot, final boolean teleport) {
public static boolean claimPlot(final PlotPlayer player, final Plot plot, final boolean teleport)
{
return claimPlot(player, plot, teleport, "");
}
public static boolean claimPlot(final PlotPlayer player, final Plot plot, final boolean teleport, final String schematic) {
public static boolean claimPlot(final PlotPlayer player, final Plot plot, final boolean teleport, final String schematic)
{
final boolean result = EventUtil.manager.callClaim(player, plot, false);
if (result) {
if (result)
{
MainUtil.createPlot(player.getUUID(), plot);
MainUtil.setSign(player.getName(), plot);
MainUtil.sendMessage(player, C.CLAIMED);
if (teleport) {
if (teleport)
{
MainUtil.teleportPlayer(player, player.getLocation(), plot);
}
}
@ -69,81 +73,103 @@ public class DebugClaimTest extends SubCommand {
}
@Override
public boolean onCommand(PlotPlayer plr, String[] args) {
if (args.length < 3) {
return !MainUtil.sendMessage(null, "If you accidentally delete your database, this command will attempt to restore all plots based on the data from the plot signs. \n\n&cMissing world arg /plot debugclaimtest {world} {PlotId min} {PlotId max}");
}
public boolean onCommand(final PlotPlayer plr, final String[] args)
{
if (args.length < 3) { return !MainUtil
.sendMessage(
null,
"If you accidentally delete your database, this command will attempt to restore all plots based on the data from the plot signs. \n\n&cMissing world arg /plot debugclaimtest {world} {PlotId min} {PlotId max}"); }
final String world = args[0];
if (!BlockManager.manager.isWorld(world) || !PS.get().isPlotWorld(world)) {
return !MainUtil.sendMessage(null, "&cInvalid plot world!");
}
if (!BlockManager.manager.isWorld(world) || !PS.get().isPlotWorld(world)) { return !MainUtil.sendMessage(null, "&cInvalid plot world!"); }
PlotId min, max;
try {
final String[] split1 = args[1].split(";");
final String[] split2 = args[2].split(";");
try
{
args[1].split(";");
args[2].split(";");
min = PlotId.fromString(args[1]);
max = PlotId.fromString(args[2]);
} catch (final Exception e) {
return !MainUtil.sendMessage(null, "&cInvalid min/max values. &7The values are to Plot IDs in the format &cX;Y &7where X;Y are the plot coords\nThe conversion will only check the plots in the selected area.");
}
catch (final Exception e)
{
return !MainUtil.sendMessage(null,
"&cInvalid min/max values. &7The values are to Plot IDs in the format &cX;Y &7where X;Y are the plot coords\nThe conversion will only check the plots in the selected area.");
}
MainUtil.sendMessage(null, "&3Sign Block&8->&3PlotSquared&8: &7Beginning sign to plot conversion. This may take a while...");
MainUtil.sendMessage(null, "&3Sign Block&8->&3PlotSquared&8: Found an excess of 250,000 chunks. Limiting search radius... (~3.8 min)");
final PlotManager manager = PS.get().getPlotManager(world);
final PlotWorld plotworld = PS.get().getPlotWorld(world);
final ArrayList<Plot> plots = new ArrayList<>();
for (final PlotId id : MainUtil.getPlotSelectionIds(min, max)) {
for (final PlotId id : MainUtil.getPlotSelectionIds(min, max))
{
final Plot plot = MainUtil.getPlot(world, id);
if (PS.get().getPlot(world, plot.id) != null) {
if (PS.get().getPlot(world, plot.id) != null)
{
MainUtil.sendMessage(null, " - &cDB Already contains: " + plot.id);
continue;
}
final Location loc = manager.getSignLoc(plotworld, plot);
final ChunkLoc chunk = new ChunkLoc(loc.getX() >> 4, loc.getZ() >> 4);
final boolean result = ChunkManager.manager.loadChunk(world, chunk, false);
if (!result) {
if (!result)
{
continue;
}
final String[] lines = BlockManager.manager.getSign(loc);
if (lines != null) {
if (lines != null)
{
String line = lines[2];
if ((line != null) && (line.length() > 2)) {
if ((line != null) && (line.length() > 2))
{
line = line.substring(2);
final BiMap<StringWrapper, UUID> map = UUIDHandler.getUuidMap();
UUID uuid = (map.get(new StringWrapper(line)));
if (uuid == null) {
for (final StringWrapper string : map.keySet()) {
if (string.value.toLowerCase().startsWith(line.toLowerCase())) {
if (uuid == null)
{
for (final StringWrapper string : map.keySet())
{
if (string.value.toLowerCase().startsWith(line.toLowerCase()))
{
uuid = map.get(string);
break;
}
}
}
if (uuid == null) {
if (uuid == null)
{
uuid = UUIDHandler.getUUID(line, null);
}
if (uuid != null) {
if (uuid != null)
{
MainUtil.sendMessage(null, " - &aFound plot: " + plot.id + " : " + line);
plot.owner = uuid;
plots.add(plot);
} else {
}
else
{
MainUtil.sendMessage(null, " - &cInvalid playername: " + plot.id + " : " + line);
}
}
}
}
if (plots.size() > 0) {
if (plots.size() > 0)
{
MainUtil.sendMessage(null, "&3Sign Block&8->&3PlotSquared&8: &7Updating '" + plots.size() + "' plots!");
DBFunc.createPlotsAndData(plots, new Runnable() {
DBFunc.createPlotsAndData(plots, new Runnable()
{
@Override
public void run() {
public void run()
{
MainUtil.sendMessage(null, "&6Database update finished!");
}
});
for (final Plot plot : plots) {
for (final Plot plot : plots)
{
PS.get().updatePlot(plot);
}
MainUtil.sendMessage(null, "&3Sign Block&8->&3PlotSquared&8: &7Complete!");
} else {
}
else
{
MainUtil.sendMessage(null, "No plots were found for the given search.");
}
return true;

View File

@ -33,36 +33,34 @@ import com.intellectualcrafters.plot.util.UUIDHandler;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "debugclear",
aliases = {"fastclear"},
description = "Clear a plot using a fast experiment algorithm",
category = CommandCategory.DEBUG
)
public class DebugClear extends SubCommand {
command = "debugclear",
aliases = { "fastclear" },
description = "Clear a plot using a fast experiment algorithm",
category = CommandCategory.DEBUG)
public class DebugClear extends SubCommand
{
@Override
public boolean onCommand(final PlotPlayer plr, String[] args) {
public boolean onCommand(final PlotPlayer plr, final String[] args)
{
final Location loc = plr.getLocation();
final Plot plot = MainUtil.getPlot(loc);
if ((plot == null) || !(PS.get().getPlotWorld(loc.getWorld()) instanceof SquarePlotWorld)) {
return sendMessage(plr, C.NOT_IN_PLOT);
}
if (!MainUtil.getTopPlot(plot).equals(MainUtil.getBottomPlot(plot))) {
return sendMessage(plr, C.UNLINK_REQUIRED);
}
if ((!plot.hasOwner() || !plot.isOwner(UUIDHandler.getUUID(plr))) && !Permissions.hasPermission(plr, "plots.admin.command.debugclear")) {
return sendMessage(plr, C.NO_PLOT_PERMS);
}
if ((plot == null) || !(PS.get().getPlotWorld(loc.getWorld()) instanceof SquarePlotWorld)) { return sendMessage(plr, C.NOT_IN_PLOT); }
if (!MainUtil.getTopPlot(plot).equals(MainUtil.getBottomPlot(plot))) { return sendMessage(plr, C.UNLINK_REQUIRED); }
if ((!plot.hasOwner() || !plot.isOwner(UUIDHandler.getUUID(plr))) && !Permissions.hasPermission(plr, "plots.admin.command.debugclear")) { return sendMessage(plr, C.NO_PLOT_PERMS); }
final Location pos1 = MainUtil.getPlotBottomLoc(loc.getWorld(), plot.id).add(1, 0, 1);
final Location pos2 = MainUtil.getPlotTopLoc(loc.getWorld(), plot.id);
if (MainUtil.runners.containsKey(plot)) {
if (MainUtil.runners.containsKey(plot))
{
MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER);
return false;
}
MainUtil.runners.put(plot, 1);
ChunkManager.manager.regenerateRegion(pos1, pos2, new Runnable() {
ChunkManager.manager.regenerateRegion(pos1, pos2, new Runnable()
{
@Override
public void run() {
public void run()
{
MainUtil.runners.remove(plot);
MainUtil.sendMessage(plr, "&aDone!");
}

View File

@ -65,7 +65,6 @@ import com.intellectualcrafters.plot.util.EventUtil;
import com.intellectualcrafters.plot.util.ExpireManager;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.MathMan;
import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.SchematicHandler;
import com.intellectualcrafters.plot.util.SetupUtils;
import com.intellectualcrafters.plot.util.StringMan;
@ -73,61 +72,67 @@ import com.intellectualcrafters.plot.util.TaskManager;
import com.intellectualcrafters.plot.util.UUIDHandler;
import com.plotsquared.bukkit.util.BukkitHybridUtils;
import com.plotsquared.general.commands.Command;
import com.plotsquared.general.commands.CommandCaller;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "debugexec",
permission = "plots.admin",
description = "Mutli-purpose debug command",
aliases = {"exec"},
category = CommandCategory.DEBUG
)
public class DebugExec extends SubCommand {
command = "debugexec",
permission = "plots.admin",
description = "Mutli-purpose debug command",
aliases = { "exec" },
category = CommandCategory.DEBUG)
public class DebugExec extends SubCommand
{
private ScriptEngine engine;
private Bindings scope;
public DebugExec() {
try {
File file = new File(PS.get().IMP.getDirectory(), "scripts" + File.separator + "start.js");
if (file.exists()) {
public DebugExec()
{
try
{
final File file = new File(PS.get().IMP.getDirectory(), "scripts" + File.separator + "start.js");
if (file.exists())
{
init();
String script = StringMan.join(Files.readLines(new File(new File(PS.get().IMP.getDirectory() + File.separator + "scripts"), "start.js"), StandardCharsets.UTF_8), System.getProperty("line.separator"));
scope.put("THIS", this);
scope.put("PlotPlayer", ConsolePlayer.getConsole());
engine.eval(script, scope);
final String script = StringMan.join(Files.readLines(new File(new File(PS.get().IMP.getDirectory() + File.separator + "scripts"), "start.js"), StandardCharsets.UTF_8),
System.getProperty("line.separator"));
scope.put("THIS", this);
scope.put("PlotPlayer", ConsolePlayer.getConsole());
engine.eval(script, scope);
}
} catch (Exception e) {
}
catch (final Exception e)
{}
}
public ScriptEngine getEngine() {
public ScriptEngine getEngine()
{
return engine;
}
public Bindings getScope() {
public Bindings getScope()
{
return scope;
}
public void init() {
if (engine != null) {
return;
}
public void init()
{
if (engine != null) { return; }
engine = (new ScriptEngineManager(null)).getEngineByName("nashorn");
if (engine == null) {
if (engine == null)
{
engine = (new ScriptEngineManager(null)).getEngineByName("JavaScript");
}
ScriptContext context = new SimpleScriptContext();
final ScriptContext context = new SimpleScriptContext();
scope = context.getBindings(ScriptContext.ENGINE_SCOPE);
// stuff
scope.put("MainUtil", new MainUtil());
scope.put("Settings", new Settings());
scope.put("StringMan", new StringMan());
scope.put("MathMan", new MathMan());
scope.put("FlagManager", new FlagManager());
// Classes
scope.put("Location", Location.class);
scope.put("PlotBlock", PlotBlock.class);
@ -135,7 +140,7 @@ public class DebugExec extends SubCommand {
scope.put("PlotId", PlotId.class);
scope.put("Runnable", Runnable.class);
scope.put("RunnableVal", RunnableVal.class);
// Instances
scope.put("PS", PS.get());
scope.put("TaskManager", PS.get().TASK);
@ -152,112 +157,143 @@ public class DebugExec extends SubCommand {
scope.put("HybridUtils", HybridUtils.manager);
scope.put("IMP", PS.get().IMP);
scope.put("MainCommand", MainCommand.getInstance());
// enums
for (Enum<?> value : C.values()) {
for (final Enum<?> value : C.values())
{
scope.put("C_" + value.name(), value);
}
}
@Override
public boolean onCommand(final PlotPlayer player, String... args) {
public boolean onCommand(final PlotPlayer player, final String... args)
{
final List<String> allowed_params = Arrays.asList("calibrate-analysis", "remove-flag", "stop-expire", "start-expire", "show-expired", "update-expired", "seen", "trim-check");
if (args.length > 0) {
if (args.length > 0)
{
final String arg = args[0].toLowerCase();
String script;
boolean async = false;
switch (arg) {
case "analyze": {
Plot plot = MainUtil.getPlot(player.getLocation());
if (plot == null) {
switch (arg)
{
case "analyze":
{
final Plot plot = MainUtil.getPlot(player.getLocation());
if (plot == null)
{
MainUtil.sendMessage(player, C.NOT_IN_PLOT);
return false;
}
PlotAnalysis analysis = plot.getComplexity();
if (analysis != null) {
int complexity = analysis.getComplexity();
final PlotAnalysis analysis = plot.getComplexity();
if (analysis != null)
{
final int complexity = analysis.getComplexity();
MainUtil.sendMessage(player, "Changes: " + analysis.changes);
MainUtil.sendMessage(player, "Complexity: " + complexity);
return true;
}
MainUtil.sendMessage(player, "$1Starting task...");
HybridUtils.manager.analyzePlot(plot, new RunnableVal<PlotAnalysis>() {
HybridUtils.manager.analyzePlot(plot, new RunnableVal<PlotAnalysis>()
{
@Override
public void run() {
public void run()
{
MainUtil.sendMessage(player, "$1Done: $2use $3/plot debugexec analyze$2 for more information");
}
});
return true;
}
case "calibrate-analysis": {
if (args.length != 2) {
case "calibrate-analysis":
{
if (args.length != 2)
{
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot debugexec analyze <threshold>");
MainUtil.sendMessage(player, "$1<threshold> $2= $1The percentage of plots you want to clear (100 clears 100% of plots so no point calibrating it)");
return false;
}
double threshold;
try {
try
{
threshold = Integer.parseInt(args[1]) / 100d;
}
catch (NumberFormatException e) {
catch (final NumberFormatException e)
{
MainUtil.sendMessage(player, "$2Invalid threshold: " + args[1]);
MainUtil.sendMessage(player, "$1<threshold> $2= $1The percentage of plots you want to clear as a number between 0 - 100");
return false;
}
PlotAnalysis.calcOptimalModifiers(new Runnable() {
PlotAnalysis.calcOptimalModifiers(new Runnable()
{
@Override
public void run() {
public void run()
{
MainUtil.sendMessage(player, "$1Thank you for calibrating PlotSquared plot expiry");
}
}, threshold);
return true;
}
case "stop-expire": {
if (ExpireManager.task != -1) {
case "stop-expire":
{
if (ExpireManager.task != -1)
{
PS.get().TASK.cancelTask(ExpireManager.task);
} else {
}
else
{
return MainUtil.sendMessage(player, "Task already halted");
}
ExpireManager.task = -1;
return MainUtil.sendMessage(player, "Cancelled task.");
}
case "remove-flag": {
if (args.length != 2) {
case "remove-flag":
{
if (args.length != 2)
{
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot debugexec remove-flag <flag>");
return false;
}
String flag = args[1];
for (Plot plot : PS.get().getPlots()) {
if (FlagManager.getPlotFlag(plot, flag) != null) {
final String flag = args[1];
for (final Plot plot : PS.get().getPlots())
{
if (FlagManager.getPlotFlag(plot, flag) != null)
{
FlagManager.removePlotFlag(plot, flag);
}
}
return MainUtil.sendMessage(player, "Cleared flag: " + flag);
return MainUtil.sendMessage(player, "Cleared flag: " + flag);
}
case "start-rgar": {
if (args.length != 2) {
case "start-rgar":
{
if (args.length != 2)
{
MainUtil.sendMessage(player, "&cInvalid syntax: /plot debugexec start-rgar <world>");
return false;
}
boolean result;
if (!PS.get().isPlotWorld(args[1])) {
if (!PS.get().isPlotWorld(args[1]))
{
MainUtil.sendMessage(player, C.NOT_VALID_PLOT_WORLD, args[1]);
return false;
}
if (BukkitHybridUtils.regions != null) {
result = ((BukkitHybridUtils)(HybridUtils.manager)).scheduleRoadUpdate(args[1], BukkitHybridUtils.regions, 0);
if (HybridUtils.regions != null)
{
result = ((BukkitHybridUtils) (HybridUtils.manager)).scheduleRoadUpdate(args[1], HybridUtils.regions, 0);
}
else {
else
{
result = HybridUtils.manager.scheduleRoadUpdate(args[1], 0);
}
if (!result) {
if (!result)
{
MainUtil.sendMessage(player, "&cCannot schedule mass schematic update! (Is one already in progress?)");
return false;
}
return true;
}
case "stop-rgar": {
if (!HybridUtils.UPDATE) {
case "stop-rgar":
{
if (!HybridUtils.UPDATE)
{
MainUtil.sendMessage(player, "&cTASK NOT RUNNING!");
return false;
}
@ -265,55 +301,53 @@ public class DebugExec extends SubCommand {
MainUtil.sendMessage(player, "&cCancelling task... (please wait)");
return true;
}
case "start-expire": {
if (ExpireManager.task == -1) {
case "start-expire":
{
if (ExpireManager.task == -1)
{
ExpireManager.runTask();
} else {
}
else
{
return MainUtil.sendMessage(player, "Plot expiry task already started");
}
return MainUtil.sendMessage(player, "Started plot expiry task");
}
case "update-expired": {
if (args.length > 1) {
case "update-expired":
{
if (args.length > 1)
{
final String world = args[1];
if (!BlockManager.manager.isWorld(world)) {
return MainUtil.sendMessage(player, "Invalid world: " + args[1]);
}
if (!BlockManager.manager.isWorld(world)) { return MainUtil.sendMessage(player, "Invalid world: " + args[1]); }
MainUtil.sendMessage(player, "Updating expired plot list");
ExpireManager.updateExpired(args[1]);
return true;
}
return MainUtil.sendMessage(player, "Use /plot debugexec update-expired <world>");
}
case "show-expired": {
if (args.length > 1) {
case "show-expired":
{
if (args.length > 1)
{
final String world = args[1];
if (!BlockManager.manager.isWorld(world)) {
return MainUtil.sendMessage(player, "Invalid world: " + args[1]);
}
if (!ExpireManager.expiredPlots.containsKey(args[1])) {
return MainUtil.sendMessage(player, "No task for world: " + args[1]);
}
if (!BlockManager.manager.isWorld(world)) { return MainUtil.sendMessage(player, "Invalid world: " + args[1]); }
if (!ExpireManager.expiredPlots.containsKey(args[1])) { return MainUtil.sendMessage(player, "No task for world: " + args[1]); }
MainUtil.sendMessage(player, "Expired plots (" + ExpireManager.expiredPlots.get(args[1]).size() + "):");
for (final Plot plot : ExpireManager.expiredPlots.get(args[1])) {
for (final Plot plot : ExpireManager.expiredPlots.get(args[1]))
{
MainUtil.sendMessage(player, " - " + plot.world + ";" + plot.id.x + ";" + plot.id.y + ";" + UUIDHandler.getName(plot.owner) + " : " + ExpireManager.dates.get(plot.owner));
}
return true;
}
return MainUtil.sendMessage(player, "Use /plot debugexec show-expired <world>");
}
case "seen": {
if (args.length != 2) {
return MainUtil.sendMessage(player, "Use /plot debugexec seen <player>");
}
case "seen":
{
if (args.length != 2) { return MainUtil.sendMessage(player, "Use /plot debugexec seen <player>"); }
final UUID uuid = UUIDHandler.getUUID(args[1], null);
if (uuid == null) {
return MainUtil.sendMessage(player, "player not found: " + args[1]);
}
if (uuid == null) { return MainUtil.sendMessage(player, "player not found: " + args[1]); }
final OfflinePlotPlayer op = UUIDHandler.getUUIDWrapper().getOfflinePlayer(uuid);
if ((op == null) || (op.getLastPlayed() == 0)) {
return MainUtil.sendMessage(player, "player hasn't connected before: " + args[1]);
}
if ((op == null) || (op.getLastPlayed() == 0)) { return MainUtil.sendMessage(player, "player hasn't connected before: " + args[1]); }
final Timestamp stamp = new Timestamp(op.getLastPlayed());
final Date date = new Date(stamp.getTime());
MainUtil.sendMessage(player, "PLAYER: " + args[1]);
@ -323,34 +357,40 @@ public class DebugExec extends SubCommand {
MainUtil.sendMessage(player, "Local: " + date.toLocaleString());
return true;
}
case "trim-check": {
if (args.length != 2) {
case "trim-check":
{
if (args.length != 2)
{
MainUtil.sendMessage(player, "Use /plot debugexec trim-check <world>");
MainUtil.sendMessage(player, "&7 - Generates a list of regions to trim");
return MainUtil.sendMessage(player, "&7 - Run after plot expiry has run");
}
final String world = args[1];
if (!BlockManager.manager.isWorld(world) || !PS.get().isPlotWorld(args[1])) {
return MainUtil.sendMessage(player, "Invalid world: " + args[1]);
}
if (!BlockManager.manager.isWorld(world) || !PS.get().isPlotWorld(args[1])) { return MainUtil.sendMessage(player, "Invalid world: " + args[1]); }
final ArrayList<ChunkLoc> empty = new ArrayList<>();
final boolean result = Trim.getTrimRegions(empty, world, new Runnable() {
final boolean result = Trim.getTrimRegions(empty, world, new Runnable()
{
@Override
public void run() {
public void run()
{
Trim.sendMessage("Processing is complete! Here's how many chunks would be deleted:");
Trim.sendMessage(" - MCA #: " + empty.size());
Trim.sendMessage(" - CHUNKS: " + (empty.size() * 1024) + " (max)");
Trim.sendMessage("Exporting log for manual approval...");
final File file = new File(PS.get().IMP.getDirectory() + File.separator + "trim.txt");
PrintWriter writer;
try {
try
{
writer = new PrintWriter(file);
for (final ChunkLoc loc : empty) {
for (final ChunkLoc loc : empty)
{
writer.println(world + "/region/r." + loc.x + "." + loc.z + ".mca");
}
writer.close();
Trim.sendMessage("File saved to 'plugins/PlotSquared/trim.txt'");
} catch (final FileNotFoundException e) {
}
catch (final FileNotFoundException e)
{
e.printStackTrace();
Trim.sendMessage("File failed to save! :(");
}
@ -360,7 +400,8 @@ public class DebugExec extends SubCommand {
Trim.sendMessage(" - Add 31 to each number to get the end position");
}
});
if (!result) {
if (!result)
{
MainUtil.sendMessage(player, "Trim task already started!");
}
return result;
@ -368,90 +409,120 @@ public class DebugExec extends SubCommand {
case "h":
case "he":
case "?":
case "help": {
case "help":
{
MainUtil.sendMessage(player, "Possible sub commands: /plot debugexec <" + StringMan.join(allowed_params, "|") + ">");
return false;
}
case "addcmd": {
try {
final String cmd = StringMan.join(Files.readLines(new File(new File(PS.get().IMP.getDirectory() + File.separator + "scripts"), args[1]), StandardCharsets.UTF_8), System.getProperty("line.separator"));
Command<PlotPlayer> subcommand = new Command<PlotPlayer>(args[1].split("\\.")[0]) {
@Override
public boolean onCommand(PlotPlayer plr, String[] args) {
try {
scope.put("PlotPlayer", plr);
scope.put("args", args);
engine.eval(cmd, scope);
return true;
} catch (ScriptException e) {
e.printStackTrace();
MainUtil.sendMessage(player, C.COMMAND_WENT_WRONG);
return false;
case "addcmd":
{
try
{
final String cmd = StringMan.join(Files.readLines(new File(new File(PS.get().IMP.getDirectory() + File.separator + "scripts"), args[1]), StandardCharsets.UTF_8),
System.getProperty("line.separator"));
final Command<PlotPlayer> subcommand = new Command<PlotPlayer>(args[1].split("\\.")[0])
{
@Override
public boolean onCommand(final PlotPlayer plr, final String[] args)
{
try
{
scope.put("PlotPlayer", plr);
scope.put("args", args);
engine.eval(cmd, scope);
return true;
}
catch (final ScriptException e)
{
e.printStackTrace();
MainUtil.sendMessage(player, C.COMMAND_WENT_WRONG);
return false;
}
}
}
};
MainCommand.getInstance().addCommand(subcommand);
return true;
};
MainCommand.getInstance().addCommand(subcommand);
return true;
}
catch (Exception e) {
catch (final Exception e)
{
e.printStackTrace();
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot debugexec addcmd <file>");
return false;
}
}
case "runasync": {
case "runasync":
{
async = true;
}
case "run": {
try {
script = StringMan.join(Files.readLines(new File(new File(PS.get().IMP.getDirectory() + File.separator + "scripts"), args[1]), StandardCharsets.UTF_8), System.getProperty("line.separator"));
if (args.length > 2) {
HashMap<String, String> replacements = new HashMap<>();
for (int i = 2; i < args.length; i++) {
replacements.put("%s" + (i-2), args[i]);
case "run":
{
try
{
script = StringMan.join(Files.readLines(new File(new File(PS.get().IMP.getDirectory() + File.separator + "scripts"), args[1]), StandardCharsets.UTF_8),
System.getProperty("line.separator"));
if (args.length > 2)
{
final HashMap<String, String> replacements = new HashMap<>();
for (int i = 2; i < args.length; i++)
{
replacements.put("%s" + (i - 2), args[i]);
}
script = StringMan.replaceFromMap(script, replacements);
}
} catch (IOException e) {
}
catch (final IOException e)
{
e.printStackTrace();
return false;
}
break;
}
default: {
default:
{
script = StringMan.join(args, " ");
}
}
if (!ConsolePlayer.isConsole(player)) {
if (!ConsolePlayer.isConsole(player))
{
MainUtil.sendMessage(player, C.NOT_CONSOLE);
return false;
}
init();
scope.put("PlotPlayer", player);
PS.debug("> " + script);
try {
if (async) {
try
{
if (async)
{
final String toExec = script;
TaskManager.runTaskAsync(new Runnable() {
TaskManager.runTaskAsync(new Runnable()
{
@Override
public void run() {
long start = System.currentTimeMillis();
try {
public void run()
{
final long start = System.currentTimeMillis();
try
{
engine.eval(toExec, scope);
} catch (ScriptException e) {
}
catch (final ScriptException e)
{
e.printStackTrace();
}
PS.log("> " + (System.currentTimeMillis() - start) + "ms");
}
});
}
else {
long start = System.currentTimeMillis();
else
{
final long start = System.currentTimeMillis();
engine.eval(script, scope);
PS.log("> " + (System.currentTimeMillis() - start) + "ms");
}
return true;
} catch (ScriptException e) {
}
catch (final ScriptException e)
{
e.printStackTrace();
return false;
}

View File

@ -32,36 +32,39 @@ import com.intellectualcrafters.plot.util.TaskManager;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "fill",
permission = "plots.fill",
description = "Fill or surround a plot in bedrock",
usage = "/plot fill",
aliases = {"debugfill"},
category = CommandCategory.DEBUG,
requiredType = RequiredType.NONE
)
public class DebugFill extends SubCommand {
command = "fill",
permission = "plots.fill",
description = "Fill or surround a plot in bedrock",
usage = "/plot fill",
aliases = { "debugfill" },
category = CommandCategory.DEBUG,
requiredType = RequiredType.NONE)
public class DebugFill extends SubCommand
{
@Override
public boolean onCommand(final PlotPlayer player, final String ... args) {
if (args.length != 1 || (!args[0].equalsIgnoreCase("outline") && !args[0].equalsIgnoreCase("all"))) {
public boolean onCommand(final PlotPlayer player, final String... args)
{
if ((args.length != 1) || (!args[0].equalsIgnoreCase("outline") && !args[0].equalsIgnoreCase("all")))
{
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot fill <outline|all>");
return true;
}
final Location loc = player.getLocation();
final Plot plot = MainUtil.getPlot(loc);
if (plot == null) {
return !sendMessage(player, C.NOT_IN_PLOT);
}
if (!plot.hasOwner()) {
if (plot == null) { return !sendMessage(player, C.NOT_IN_PLOT); }
if (!plot.hasOwner())
{
MainUtil.sendMessage(player, C.PLOT_UNOWNED);
return false;
}
if (!plot.isOwner(player.getUUID()) && !Permissions.hasPermission(player, "plots.admin.command.fill")) {
if (!plot.isOwner(player.getUUID()) && !Permissions.hasPermission(player, "plots.admin.command.fill"))
{
MainUtil.sendMessage(player, C.NO_PLOT_PERMS);
return true;
}
if (MainUtil.runners.containsKey(plot)) {
if (MainUtil.runners.containsKey(plot))
{
MainUtil.sendMessage(player, C.WAIT_FOR_TIMER);
return false;
}
@ -69,89 +72,119 @@ public class DebugFill extends SubCommand {
final Location top = MainUtil.getPlotTopLoc(plot.world, plot.id);
MainUtil.sendMessage(player, "&cPreparing task");
MainUtil.runners.put(plot, 1);
SetBlockQueue.addNotify(new Runnable() {
SetBlockQueue.addNotify(new Runnable()
{
@Override
public void run() {
TaskManager.runTaskAsync(new Runnable() {
public void run()
{
TaskManager.runTaskAsync(new Runnable()
{
@Override
public void run() {
public void run()
{
MainUtil.sendMessage(player, "&7 - Starting");
if (args[0].equalsIgnoreCase("all")) {
if (args[0].equalsIgnoreCase("all"))
{
int height = 255;
PlotBlock block = new PlotBlock((short) 7, (byte) 0);
PlotBlock air = new PlotBlock((short) 0, (byte) 0);
if (args.length > 2) {
try {
final PlotBlock air = new PlotBlock((short) 0, (byte) 0);
if (args.length > 2)
{
try
{
block = new PlotBlock(Short.parseShort(args[1]), (byte) 0);
if (args.length == 3) {
if (args.length == 3)
{
height = Integer.parseInt(args[2]);
}
}
catch (Exception e) {
catch (final Exception e)
{
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot fill all <id> <height>");
MainUtil.runners.remove(plot);
return;
}
}
for (int y = 0; y <= height; y++) {
for (int x = bottom.getX(); x <= top.getX(); x++) {
for (int z = bottom.getZ(); z <= top.getZ(); z++) {
for (int y = 0; y <= height; y++)
{
for (int x = bottom.getX(); x <= top.getX(); x++)
{
for (int z = bottom.getZ(); z <= top.getZ(); z++)
{
SetBlockQueue.setBlock(plot.world, x, y, z, block);
}
}
}
for (int y = height + 1; y <= 255; y++) {
for (int x = bottom.getX(); x <= top.getX(); x++) {
for (int z = bottom.getZ(); z <= top.getZ(); z++) {
for (int y = height + 1; y <= 255; y++)
{
for (int x = bottom.getX(); x <= top.getX(); x++)
{
for (int z = bottom.getZ(); z <= top.getZ(); z++)
{
SetBlockQueue.setBlock(plot.world, x, y, z, air);
}
}
}
SetBlockQueue.addNotify(new Runnable() {
SetBlockQueue.addNotify(new Runnable()
{
@Override
public void run() {
public void run()
{
MainUtil.runners.remove(plot);
MainUtil.sendMessage(player, "&aFill task complete!");
}
});
}
else if (args[0].equals("outline")) {
else if (args[0].equals("outline"))
{
int x, z;
z = bottom.getZ();
for (x = bottom.getX(); x <= (top.getX() - 1); x++) {
for (int y = 1; y <= 255; y++) {
for (x = bottom.getX(); x <= (top.getX() - 1); x++)
{
for (int y = 1; y <= 255; y++)
{
SetBlockQueue.setBlock(plot.world, x, y, z, 7);
}
}
x = top.getX();
for (z = bottom.getZ(); z <= (top.getZ() - 1); z++) {
for (int y = 1; y <= 255; y++) {
for (z = bottom.getZ(); z <= (top.getZ() - 1); z++)
{
for (int y = 1; y <= 255; y++)
{
SetBlockQueue.setBlock(plot.world, x, y, z, 7);
}
}
z = top.getZ();
for (x = top.getX(); x >= (bottom.getX() + 1); x--) {
for (int y = 1; y <= 255; y++) {
for (x = top.getX(); x >= (bottom.getX() + 1); x--)
{
for (int y = 1; y <= 255; y++)
{
SetBlockQueue.setBlock(plot.world, x, y, z, 7);
}
}
x = bottom.getX();
for (z = top.getZ(); z >= (bottom.getZ() + 1); z--) {
for (int y = 1; y <= 255; y++) {
for (z = top.getZ(); z >= (bottom.getZ() + 1); z--)
{
for (int y = 1; y <= 255; y++)
{
SetBlockQueue.setBlock(plot.world, x, y, z, 7);
}
}
SetBlockQueue.addNotify(new Runnable() {
SetBlockQueue.addNotify(new Runnable()
{
@Override
public void run() {
public void run()
{
MainUtil.sendMessage(player, "&aWalls complete! The ceiling will take a while :(");
bottom.setY(255);
top.add(1,0,1);
top.add(1, 0, 1);
SetBlockQueue.setSlow(true);
MainUtil.setSimpleCuboidAsync(plot.world, bottom, top, new PlotBlock((short) 7, (byte) 0));
SetBlockQueue.addNotify(new Runnable() {
SetBlockQueue.addNotify(new Runnable()
{
@Override
public void run() {
public void run()
{
MainUtil.runners.remove(plot);
MainUtil.sendMessage(player, "&aFill task complete!");
SetBlockQueue.setSlow(false);

View File

@ -37,40 +37,47 @@ import com.plotsquared.general.commands.Argument;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "debugfixflags",
usage = "/plot debugfixflags <world>",
permission = "plots.debugfixflags",
description = "Attempt to fix all flags for a world",
requiredType = RequiredType.CONSOLE,
category = CommandCategory.DEBUG
)
public class DebugFixFlags extends SubCommand {
command = "debugfixflags",
usage = "/plot debugfixflags <world>",
permission = "plots.debugfixflags",
description = "Attempt to fix all flags for a world",
requiredType = RequiredType.CONSOLE,
category = CommandCategory.DEBUG)
public class DebugFixFlags extends SubCommand
{
public DebugFixFlags() {
public DebugFixFlags()
{
requiredArguments = new Argument[] {
Argument.String
Argument.String
};
}
@Override
public boolean onCommand(PlotPlayer plr, String[] args) {
public boolean onCommand(final PlotPlayer plr, final String[] args)
{
final String world = args[0];
if (!BlockManager.manager.isWorld(world) || !PS.get().isPlotWorld(world)) {
if (!BlockManager.manager.isWorld(world) || !PS.get().isPlotWorld(world))
{
MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_WORLD, args[0]);
return false;
}
MainUtil.sendMessage(plr, "&8--- &6Starting task &8 ---");
for (final Plot plot : PS.get().getPlotsInWorld(world)) {
for (final Plot plot : PS.get().getPlotsInWorld(world))
{
final HashMap<String, Flag> flags = plot.getSettings().flags;
Iterator<Entry<String, Flag>> i = flags.entrySet().iterator();
final Iterator<Entry<String, Flag>> i = flags.entrySet().iterator();
boolean changed = false;
while (i.hasNext()) {
if (FlagManager.getFlag(i.next().getKey()) == null) {
while (i.hasNext())
{
if (FlagManager.getFlag(i.next().getKey()) == null)
{
changed = true;
i.remove();
}
}
if (changed) {
if (changed)
{
DBFunc.setFlags(plot, plot.getSettings().flags.values());
}
}

View File

@ -28,22 +28,26 @@ import com.intellectualcrafters.plot.object.PlotPlayer;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "debugloadtest",
permission = "plots.debugloadtest",
description = "This debug command will force the reload of all plots in the DB",
usage = "/plot debugloadtest",
category = CommandCategory.DEBUG,
requiredType = RequiredType.CONSOLE
)
public class DebugLoadTest extends SubCommand {
command = "debugloadtest",
permission = "plots.debugloadtest",
description = "This debug command will force the reload of all plots in the DB",
usage = "/plot debugloadtest",
category = CommandCategory.DEBUG,
requiredType = RequiredType.CONSOLE)
public class DebugLoadTest extends SubCommand
{
@Override
public boolean onCommand(PlotPlayer plr, String[] args) {
try {
public boolean onCommand(final PlotPlayer plr, final String[] args)
{
try
{
final Field fPlots = PS.class.getDeclaredField("plots");
fPlots.setAccessible(true);
fPlots.set(null, DBFunc.getPlots());
} catch (final Exception e) {
}
catch (final Exception e)
{
PS.debug("&3===FAILED&3===");
e.printStackTrace();
PS.debug("&3===END OF STACKTRACE===");

View File

@ -15,30 +15,37 @@ import com.plotsquared.bukkit.BukkitMain;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "debugpaste",
aliases = {"dp"},
usage = "/plot debugpaste",
description = "Upload settings.yml & latest.log to hastebin",
permission = "plots.debugpaste",
category = CommandCategory.DEBUG
)
public class DebugPaste extends SubCommand {
command = "debugpaste",
aliases = { "dp" },
usage = "/plot debugpaste",
description = "Upload settings.yml & latest.log to hastebin",
permission = "plots.debugpaste",
category = CommandCategory.DEBUG)
public class DebugPaste extends SubCommand
{
@Override
public boolean onCommand(final PlotPlayer plr, String[] args) {
TaskManager.runTaskAsync(new Runnable() {
public boolean onCommand(final PlotPlayer plr, final String[] args)
{
TaskManager.runTaskAsync(new Runnable()
{
@Override
public void run() {
try {
String settingsYML = HastebinUtility.upload(PS.get().configFile);
public void run()
{
try
{
final String settingsYML = HastebinUtility.upload(PS.get().configFile);
String latestLOG;
try {
try
{
latestLOG = HastebinUtility.upload(new File(BukkitMain.THIS.getDirectory(), "../../logs/latest.log"));
} catch(final Exception e) {
}
catch (final Exception e)
{
plr.sendMessage("&clatest.log is too big to be pasted, will ignore");
latestLOG = "too big :(";
}
StringBuilder b = new StringBuilder();
final StringBuilder b = new StringBuilder();
b.append("# Welcome to this paste\n# It is meant to provide us at IntellectualSites with better information about your problem\n\n# We will start with some informational files\n");
b.append("links.settings_yml: '").append(settingsYML).append("'\n");
b.append("links.latest_log: '").append(latestLOG).append("'\n");
@ -47,11 +54,12 @@ public class DebugPaste extends SubCommand {
b.append("version.bukkit: '").append(Bukkit.getBukkitVersion()).append("'\n");
b.append("online_mode: ").append(Bukkit.getServer().getOnlineMode()).append("\n");
b.append("plugins:");
for (final Plugin p : Bukkit.getPluginManager().getPlugins()) {
for (final Plugin p : Bukkit.getPluginManager().getPlugins())
{
b.append("\n ").append(p.getName()).append(":\n ").append("version: '").append(p.getDescription().getVersion()).append("'").append("\n enabled: ").append(p.isEnabled());
}
b.append("\n\n# YAY! Now, let's see what we can find in your JVM\n");
Runtime runtime = Runtime.getRuntime();
final Runtime runtime = Runtime.getRuntime();
b.append("memory.free: ").append(runtime.freeMemory()).append("\n");
b.append("memory.max: ").append(runtime.maxMemory()).append("\n");
b.append("java.specification.version: '").append(System.getProperty("java.specification.version")).append("'\n");
@ -63,9 +71,11 @@ public class DebugPaste extends SubCommand {
b.append("# Okay :D Great. You are now ready to create your bug report!");
b.append("\n# You can do so at https://github.com/IntellectualSites/PlotSquared/issues");
String link = HastebinUtility.upload(b.toString());
final String link = HastebinUtility.upload(b.toString());
plr.sendMessage(C.DEBUG_REPORT_CREATED.s().replace("%url%", link));
} catch (IOException e) {
}
catch (final IOException e)
{
e.printStackTrace();
}
}

View File

@ -35,44 +35,49 @@ import com.intellectualcrafters.plot.util.MathMan;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "debugroadregen",
usage = "/plot debugroadregen",
requiredType = RequiredType.NONE,
description = "Regenerate all roads based on the road schematic",
category = CommandCategory.DEBUG,
permission = "plots.debugroadregen"
)
public class DebugRoadRegen extends SubCommand {
command = "debugroadregen",
usage = "/plot debugroadregen",
requiredType = RequiredType.NONE,
description = "Regenerate all roads based on the road schematic",
category = CommandCategory.DEBUG,
permission = "plots.debugroadregen")
public class DebugRoadRegen extends SubCommand
{
@Override
public boolean onCommand(final PlotPlayer player, final String ... args) {
public boolean onCommand(final PlotPlayer player, final String... args)
{
final Location loc = player.getLocation();
final String world = loc.getWorld();
PlotWorld plotworld = PS.get().getPlotWorld(world);
if (!(plotworld instanceof HybridPlotWorld)) {
return sendMessage(player, C.NOT_IN_PLOT_WORLD);
}
Plot plot = player.getCurrentPlot();
if (plot == null) {
final PlotWorld plotworld = PS.get().getPlotWorld(world);
if (!(plotworld instanceof HybridPlotWorld)) { return sendMessage(player, C.NOT_IN_PLOT_WORLD); }
final Plot plot = player.getCurrentPlot();
if (plot == null)
{
final ChunkLoc chunk = new ChunkLoc(loc.getX() >> 4, loc.getZ() >> 4);
int extend = 0;
if (args.length == 1) {
if (MathMan.isInteger(args[0])) {
try {
if (args.length == 1)
{
if (MathMan.isInteger(args[0]))
{
try
{
extend = Integer.parseInt(args[0]);
}
catch (Exception e) {
catch (final Exception e)
{
C.NOT_VALID_NUMBER.send(player, "(0, <EXTEND HEIGHT>)");
return false;
}
}
}
boolean result = HybridUtils.manager.regenerateRoad(world, chunk, extend);
final boolean result = HybridUtils.manager.regenerateRoad(world, chunk, extend);
MainUtil.sendMessage(player, "&6Regenerating chunk: " + chunk.x + "," + chunk.z + "\n&6 - Result: " + (result == true ? "&aSuccess" : "&cFailed"));
MainUtil.sendMessage(player, "&cTo regenerate all roads: /plot regenallroads");
}
else {
HybridPlotManager manager = (HybridPlotManager) PS.get().getPlotManager(world);
else
{
final HybridPlotManager manager = (HybridPlotManager) PS.get().getPlotManager(world);
manager.createRoadEast(plotworld, plot);
manager.createRoadSouth(plotworld, plot);
manager.createRoadSouthEast(plotworld, plot);

View File

@ -30,23 +30,26 @@ import com.intellectualcrafters.plot.util.MainUtil;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "debugsavetest",
permission = "plots.debugsavetest",
category = CommandCategory.DEBUG,
requiredType = RequiredType.CONSOLE,
usage = "/plot debugsavetest",
description = "This command will force the recreation of all plots in the DB"
)
public class DebugSaveTest extends SubCommand {
command = "debugsavetest",
permission = "plots.debugsavetest",
category = CommandCategory.DEBUG,
requiredType = RequiredType.CONSOLE,
usage = "/plot debugsavetest",
description = "This command will force the recreation of all plots in the DB")
public class DebugSaveTest extends SubCommand
{
@Override
public boolean onCommand(PlotPlayer plr, String[] args) {
public boolean onCommand(final PlotPlayer plr, final String[] args)
{
final ArrayList<Plot> plots = new ArrayList<Plot>();
plots.addAll(PS.get().getPlots());
MainUtil.sendMessage(null, "&6Starting `DEBUGSAVETEST`");
DBFunc.createPlotsAndData(plots, new Runnable() {
DBFunc.createPlotsAndData(plots, new Runnable()
{
@Override
public void run() {
public void run()
{
MainUtil.sendMessage(null, "&6Database sync finished!");
}
});

View File

@ -36,7 +36,6 @@ import org.bukkit.Bukkit;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.database.AbstractDB;
import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.object.OfflinePlotPlayer;
@ -55,54 +54,64 @@ import com.plotsquared.general.commands.Argument;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "uuidconvert",
permission = "plots.admin",
description = "Debug UUID conversion",
usage = "/plot uuidconvert <lower|offline|online>",
requiredType = RequiredType.CONSOLE,
category = CommandCategory.DEBUG
)
public class DebugUUID extends SubCommand {
command = "uuidconvert",
permission = "plots.admin",
description = "Debug UUID conversion",
usage = "/plot uuidconvert <lower|offline|online>",
requiredType = RequiredType.CONSOLE,
category = CommandCategory.DEBUG)
public class DebugUUID extends SubCommand
{
public DebugUUID() {
public DebugUUID()
{
requiredArguments = new Argument[] {
Argument.String
Argument.String
};
}
@Override
public boolean onCommand(final PlotPlayer plr, final String[] args) {
PlotPlayer player = null;
public boolean onCommand(final PlotPlayer plr, final String[] args)
{
final PlotPlayer player = null;
final UUIDWrapper currentUUIDWrapper = UUIDHandler.getUUIDWrapper();
final UUIDWrapper newWrapper;
switch (args[0].toLowerCase()) {
case "lower": {
switch (args[0].toLowerCase())
{
case "lower":
{
newWrapper = new LowerOfflineUUIDWrapper();
break;
}
case "offline": {
case "offline":
{
newWrapper = new OfflineUUIDWrapper();
break;
}
case "online": {
case "online":
{
newWrapper = new DefaultUUIDWrapper();
break;
}
default: {
try {
Class<?> clazz = Class.forName(args[0]);
default:
{
try
{
final Class<?> clazz = Class.forName(args[0]);
newWrapper = (UUIDWrapper) clazz.newInstance();
}
catch (Exception e) {
catch (final Exception e)
{
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot uuidconvert <lower|offline|online>");
return false;
}
}
}
if (args.length != 2 || !args[1].equals("-o")) {
if ((args.length != 2) || !args[1].equals("-o"))
{
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot uuidconvert " + args[0] + " - o");
MainUtil.sendMessage(player, "&cBe aware of the following!");
MainUtil.sendMessage(player, "&8 - &cUse the database command or another method to backup your plots beforehand");
@ -113,22 +122,24 @@ public class DebugUUID extends SubCommand {
MainUtil.sendMessage(player, "&7Retype the command with the override parameter when ready :)");
return false;
}
if (currentUUIDWrapper.getClass().getCanonicalName().equals(newWrapper.getClass().getCanonicalName())) {
if (currentUUIDWrapper.getClass().getCanonicalName().equals(newWrapper.getClass().getCanonicalName()))
{
MainUtil.sendMessage(player, "&cUUID mode already in use!");
return false;
}
MainUtil.sendConsoleMessage("&6Beginning UUID mode conversion");
MainUtil.sendConsoleMessage("&7 - Disconnecting players");
for (PlotPlayer pp : UUIDHandler.getPlayers().values()) {
for (final PlotPlayer pp : UUIDHandler.getPlayers().values())
{
pp.kick("PlotSquared UUID conversion has been initiated. You may reconnect when finished.");
}
MainUtil.sendConsoleMessage("&7 - Initializing map");
final HashMap<UUID, UUID> uCMap = new HashMap<UUID, UUID>();
final HashMap<UUID, UUID> uCReverse = new HashMap<UUID, UUID>();
MainUtil.sendConsoleMessage("&7 - Collecting playerdata");
final HashSet<String> worlds = new HashSet<>();
@ -136,212 +147,269 @@ public class DebugUUID extends SubCommand {
worlds.add("world");
final HashSet<UUID> uuids = new HashSet<>();
final HashSet<String> names = new HashSet<>();
for (final String worldname : worlds) {
for (final String worldname : worlds)
{
final File playerdataFolder = new File(worldname + File.separator + "playerdata");
String[] dat = playerdataFolder.list(new FilenameFilter() {
String[] dat = playerdataFolder.list(new FilenameFilter()
{
@Override
public boolean accept(final File f, final String s) {
public boolean accept(final File f, final String s)
{
return s.endsWith(".dat");
}
});
if (dat != null) {
for (final String current : dat) {
if (dat != null)
{
for (final String current : dat)
{
final String s = current.replaceAll(".dat$", "");
try {
try
{
final UUID uuid = UUID.fromString(s);
uuids.add(uuid);
} catch (final Exception e) {
}
catch (final Exception e)
{
MainUtil.sendMessage(plr, C.PREFIX.s() + "Invalid playerdata: " + current);
}
}
}
final File playersFolder = new File(worldname + File.separator + "players");
dat = playersFolder.list(new FilenameFilter() {
dat = playersFolder.list(new FilenameFilter()
{
@Override
public boolean accept(final File f, final String s) {
public boolean accept(final File f, final String s)
{
return s.endsWith(".dat");
}
});
if (dat != null) {
for (final String current : dat) {
if (dat != null)
{
for (final String current : dat)
{
names.add(current.replaceAll(".dat$", ""));
}
}
}
MainUtil.sendConsoleMessage("&7 - Populating map");
UUID uuid2;
final UUIDWrapper wrapper = new DefaultUUIDWrapper();
for (UUID uuid : uuids) {
try {
for (UUID uuid : uuids)
{
try
{
final OfflinePlotPlayer op = wrapper.getOfflinePlayer(uuid);
uuid = currentUUIDWrapper.getUUID(op);
uuid2 = newWrapper.getUUID(op);
if (!uuid.equals(uuid2) && !uCMap.containsKey(uuid) && !uCReverse.containsKey(uuid2)) {
if (!uuid.equals(uuid2) && !uCMap.containsKey(uuid) && !uCReverse.containsKey(uuid2))
{
uCMap.put(uuid, uuid2);
uCReverse.put(uuid2, uuid);
}
} catch (final Throwable e) {
}
catch (final Throwable e)
{
MainUtil.sendMessage(plr, C.PREFIX.s() + "&6Invalid playerdata: " + uuid.toString() + ".dat");
}
}
for (final String name : names) {
for (final String name : names)
{
final UUID uuid = currentUUIDWrapper.getUUID(name);
uuid2 = newWrapper.getUUID(name);
if (!uuid.equals(uuid2)) {
if (!uuid.equals(uuid2))
{
uCMap.put(uuid, uuid2);
uCReverse.put(uuid2, uuid);
}
}
if (uCMap.size() == 0) {
if (uCMap.size() == 0)
{
MainUtil.sendConsoleMessage("&c - Error! Attempting to repopulate");
for (OfflinePlotPlayer op : currentUUIDWrapper.getOfflinePlayers()) {
if (op.getLastPlayed() != 0) {
// String name = op.getName();
// StringWrapper wrap = new StringWrapper(name);
UUID uuid = currentUUIDWrapper.getUUID(op);
for (final OfflinePlotPlayer op : currentUUIDWrapper.getOfflinePlayers())
{
if (op.getLastPlayed() != 0)
{
// String name = op.getName();
// StringWrapper wrap = new StringWrapper(name);
final UUID uuid = currentUUIDWrapper.getUUID(op);
uuid2 = newWrapper.getUUID(op);
if (!uuid.equals(uuid2)) {
if (!uuid.equals(uuid2))
{
uCMap.put(uuid, uuid2);
uCReverse.put(uuid2, uuid);
}
}
}
if (uCMap.size() == 0) {
if (uCMap.size() == 0)
{
MainUtil.sendConsoleMessage("&cError. Failed to collect UUIDs!");
return false;
}
else {
else
{
MainUtil.sendConsoleMessage("&a - Successfully repopulated");
}
}
MainUtil.sendConsoleMessage("&7 - Replacing cache");
TaskManager.runTaskAsync(new Runnable() {
TaskManager.runTaskAsync(new Runnable()
{
@Override
public void run() {
for (Entry<UUID, UUID> entry : uCMap.entrySet()) {
String name = UUIDHandler.getName(entry.getKey());
if (name != null) {
public void run()
{
for (final Entry<UUID, UUID> entry : uCMap.entrySet())
{
final String name = UUIDHandler.getName(entry.getKey());
if (name != null)
{
UUIDHandler.add(new StringWrapper(name), entry.getValue());
}
}
MainUtil.sendConsoleMessage("&7 - Scanning for applicable files (uuids.txt)");
File file = new File(PS.get().IMP.getDirectory(), "uuids.txt");
if (file.exists()) {
try {
List<String> lines = Files.readAllLines(file.toPath(), StandardCharsets.UTF_8);
for (String line : lines) {
try {
final File file = new File(PS.get().IMP.getDirectory(), "uuids.txt");
if (file.exists())
{
try
{
final List<String> lines = Files.readAllLines(file.toPath(), StandardCharsets.UTF_8);
for (String line : lines)
{
try
{
line = line.trim();
if (line.length() == 0) {
if (line.length() == 0)
{
continue;
}
line = line.replaceAll("[\\|][0-9]+[\\|][0-9]+[\\|]", "");
String[] split = line.split("\\|");
String name = split[0];
if (name.length() == 0 || name.length() > 16 || !StringMan.isAlphanumericUnd(name)) {
final String[] split = line.split("\\|");
final String name = split[0];
if ((name.length() == 0) || (name.length() > 16) || !StringMan.isAlphanumericUnd(name))
{
continue;
}
UUID old = currentUUIDWrapper.getUUID(name);
if (old == null) {
final UUID old = currentUUIDWrapper.getUUID(name);
if (old == null)
{
continue;
}
UUID now = newWrapper.getUUID(name);
final UUID now = newWrapper.getUUID(name);
UUIDHandler.add(new StringWrapper(name), now);
uCMap.put(old, now);
uCReverse.put(now, old);
}
catch (Exception e2) {
catch (final Exception e2)
{
e2.printStackTrace();
}
}
} catch (IOException e) {
}
catch (final IOException e)
{
e.printStackTrace();
}
}
MainUtil.sendConsoleMessage("&7 - Replacing wrapper");
UUIDHandler.setUUIDWrapper(newWrapper);
MainUtil.sendConsoleMessage("&7 - Updating plot objects");
for (Plot plot : PS.get().getPlotsRaw()) {
UUID value = uCMap.get(plot.owner);
if (value != null) {
for (final Plot plot : PS.get().getPlotsRaw())
{
final UUID value = uCMap.get(plot.owner);
if (value != null)
{
plot.owner = value;
}
plot.getTrusted().clear();
plot.getMembers().clear();
plot.getDenied().clear();
}
MainUtil.sendConsoleMessage("&7 - Deleting database");
final AbstractDB database = DBFunc.dbManager;
boolean result = database.deleteTables();
final boolean result = database.deleteTables();
MainUtil.sendConsoleMessage("&7 - Creating tables");
try {
try
{
database.createTables();
if (!result) {
if (!result)
{
MainUtil.sendConsoleMessage("&cConversion failed! Attempting recovery");
for (Plot plot : PS.get().getPlots()) {
UUID value = uCReverse.get(plot.owner);
if (value != null) {
for (final Plot plot : PS.get().getPlots())
{
final UUID value = uCReverse.get(plot.owner);
if (value != null)
{
plot.owner = value;
}
}
database.createPlotsAndData(new ArrayList<>(PS.get().getPlots()), new Runnable() {
database.createPlotsAndData(new ArrayList<>(PS.get().getPlots()), new Runnable()
{
@Override
public void run() {
public void run()
{
MainUtil.sendMessage(null, "&6Recovery was successful!");
}
});
return;
}
}
catch (Exception e) {
catch (final Exception e)
{
e.printStackTrace();
return;
}
if (newWrapper instanceof OfflineUUIDWrapper) {
if (newWrapper instanceof OfflineUUIDWrapper)
{
PS.get().config.set("UUID.force-lowercase", false);
PS.get().config.set("UUID.offline", true);
}
else if (newWrapper instanceof LowerOfflineUUIDWrapper) {
else if (newWrapper instanceof LowerOfflineUUIDWrapper)
{
PS.get().config.set("UUID.force-lowercase", true);
PS.get().config.set("UUID.offline", true);
}
else if (newWrapper instanceof DefaultUUIDWrapper) {
else if (newWrapper instanceof DefaultUUIDWrapper)
{
PS.get().config.set("UUID.force-lowercase", false);
PS.get().config.set("UUID.offline", false);
}
try {
try
{
PS.get().config.save(PS.get().configFile);
}
catch (Exception e) {
catch (final Exception e)
{
MainUtil.sendConsoleMessage("Could not save configuration. It will need to be manuall set!");
}
MainUtil.sendConsoleMessage("&7 - Populating tables");
TaskManager.runTaskAsync(new Runnable() {
TaskManager.runTaskAsync(new Runnable()
{
@Override
public void run() {
ArrayList<Plot> plots = new ArrayList<>(PS.get().getPlots());
database.createPlotsAndData(plots, new Runnable() {
public void run()
{
final ArrayList<Plot> plots = new ArrayList<>(PS.get().getPlots());
database.createPlotsAndData(plots, new Runnable()
{
@Override
public void run() {
public void run()
{
MainUtil.sendConsoleMessage("&aConversion complete!");
}
});
}
});
MainUtil.sendConsoleMessage("&aIt is now safe for players to join");
MainUtil.sendConsoleMessage("&cConversion is still in progress, you will be notified when it is complete");
}

View File

@ -36,66 +36,73 @@ import com.intellectualcrafters.plot.util.UUIDHandler;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "delete",
permission = "plots.delete",
description = "Delete a plot",
usage = "/plot delete",
aliases = {"dispose", "del"},
category = CommandCategory.ACTIONS,
requiredType = RequiredType.NONE
)
public class Delete extends SubCommand {
command = "delete",
permission = "plots.delete",
description = "Delete a plot",
usage = "/plot delete",
aliases = { "dispose", "del" },
category = CommandCategory.ACTIONS,
requiredType = RequiredType.NONE)
public class Delete extends SubCommand
{
@Override
public boolean onCommand(final PlotPlayer plr, final String[] args) {
public boolean onCommand(final PlotPlayer plr, final String[] args)
{
final Location loc = plr.getLocation();
final Plot plot = MainUtil.getPlot(loc);
if (plot == null) {
return !sendMessage(plr, C.NOT_IN_PLOT);
}
if (!MainUtil.getTopPlot(plot).equals(MainUtil.getBottomPlot(plot))) {
return !sendMessage(plr, C.UNLINK_REQUIRED);
}
if (((!plot.hasOwner() || !plot.isOwner(plr.getUUID()))) && !Permissions.hasPermission(plr, "plots.admin.command.delete")) {
return !sendMessage(plr, C.NO_PLOT_PERMS);
}
if (plot == null) { return !sendMessage(plr, C.NOT_IN_PLOT); }
if (!MainUtil.getTopPlot(plot).equals(MainUtil.getBottomPlot(plot))) { return !sendMessage(plr, C.UNLINK_REQUIRED); }
if (((!plot.hasOwner() || !plot.isOwner(plr.getUUID()))) && !Permissions.hasPermission(plr, "plots.admin.command.delete")) { return !sendMessage(plr, C.NO_PLOT_PERMS); }
final PlotWorld pWorld = PS.get().getPlotWorld(plot.world);
if (MainUtil.runners.containsKey(plot)) {
if (MainUtil.runners.containsKey(plot))
{
MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER);
return false;
}
Runnable runnable = new Runnable() {
final Runnable runnable = new Runnable()
{
@Override
public void run() {
if ((EconHandler.manager != null) && pWorld.USE_ECONOMY && plot.hasOwner() && plot.isOwner(UUIDHandler.getUUID(plr))) {
public void run()
{
if ((EconHandler.manager != null) && pWorld.USE_ECONOMY && plot.hasOwner() && plot.isOwner(UUIDHandler.getUUID(plr)))
{
final double c = pWorld.SELL_PRICE;
if (c > 0d) {
if (c > 0d)
{
EconHandler.manager.depositMoney(plr, c);
sendMessage(plr, C.ADDED_BALANCE, c + "");
}
}
if (plot.unclaim()) {
if (plot.unclaim())
{
final long start = System.currentTimeMillis();
final boolean result = MainUtil.clearAsPlayer(plot, true, new Runnable() {
final boolean result = MainUtil.clearAsPlayer(plot, true, new Runnable()
{
@Override
public void run() {
public void run()
{
MainUtil.sendMessage(plr, C.CLEARING_DONE, "" + (System.currentTimeMillis() - start));
}
});
if (!result) {
if (!result)
{
MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER);
}
}
else {
else
{
MainUtil.sendMessage(plr, C.UNCLAIM_FAILED);
}
}
};
if (Settings.CONFIRM_DELETE && !(Permissions.hasPermission(plr, "plots.confirm.bypass"))) {
if (Settings.CONFIRM_DELETE && !(Permissions.hasPermission(plr, "plots.confirm.bypass")))
{
CmdConfirm.addPending(plr, "/plot delete " + plot.id, runnable);
}
else {
else
{
TaskManager.runTask(runnable);
}
return true;

View File

@ -37,57 +37,68 @@ import com.plotsquared.general.commands.Argument;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "deny",
aliases = {"d"},
description = "Deny a user from a plot",
usage = "/plot deny <player>",
category = CommandCategory.ACTIONS,
requiredType = RequiredType.NONE
)
public class Deny extends SubCommand {
command = "deny",
aliases = { "d" },
description = "Deny a user from a plot",
usage = "/plot deny <player>",
category = CommandCategory.ACTIONS,
requiredType = RequiredType.NONE)
public class Deny extends SubCommand
{
public Deny() {
public Deny()
{
requiredArguments = new Argument[] {
Argument.PlayerName
Argument.PlayerName
};
}
@Override
public boolean onCommand(final PlotPlayer plr, final String[] args) {
public boolean onCommand(final PlotPlayer plr, final String[] args)
{
final Location loc = plr.getLocation();
final Plot plot = MainUtil.getPlot(loc);
if (plot == null) {
return !sendMessage(plr, C.NOT_IN_PLOT);
}
if ((plot == null) || !plot.hasOwner()) {
if (plot == null) { return !sendMessage(plr, C.NOT_IN_PLOT); }
if ((plot == null) || !plot.hasOwner())
{
MainUtil.sendMessage(plr, C.PLOT_UNOWNED);
return false;
}
if (!plot.isOwner(plr.getUUID()) && !Permissions.hasPermission(plr, "plots.admin.command.deny")) {
if (!plot.isOwner(plr.getUUID()) && !Permissions.hasPermission(plr, "plots.admin.command.deny"))
{
MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
return true;
}
UUID uuid;
if (args[0].equalsIgnoreCase("*")) {
if (args[0].equalsIgnoreCase("*"))
{
uuid = DBFunc.everyone;
} else {
}
else
{
uuid = UUIDHandler.getUUID(args[0], null);
}
if (uuid == null) {
if (UUIDHandler.implementation instanceof SQLUUIDHandler) {
if (uuid == null)
{
if (UUIDHandler.implementation instanceof SQLUUIDHandler)
{
MainUtil.sendMessage(plr, C.INVALID_PLAYER_WAIT, args[0]);
} else {
}
else
{
MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[0]);
}
return false;
}
if (plot.isOwner(uuid)) {
if (plot.isOwner(uuid))
{
MainUtil.sendMessage(plr, C.ALREADY_OWNER);
return false;
}
if (plot.getDenied().contains(uuid)) {
if (plot.getDenied().contains(uuid))
{
MainUtil.sendMessage(plr, C.ALREADY_ADDED);
return false;
}
@ -96,15 +107,18 @@ public class Deny extends SubCommand {
plot.addDenied(uuid);
EventUtil.manager.callDenied(plr, plot, uuid, true);
MainUtil.sendMessage(plr, C.DENIED_ADDED);
if (!uuid.equals(DBFunc.everyone)) {
if (!uuid.equals(DBFunc.everyone))
{
handleKick(uuid, plot);
}
return true;
}
private void handleKick(final UUID uuid, final Plot plot) {
PlotPlayer pp = UUIDHandler.getPlayer(uuid);
if (pp != null && plot.equals(MainUtil.getPlot(pp.getLocation()))) {
private void handleKick(final UUID uuid, final Plot plot)
{
final PlotPlayer pp = UUIDHandler.getPlayer(uuid);
if ((pp != null) && plot.equals(MainUtil.getPlot(pp.getLocation())))
{
pp.teleport(BlockManager.manager.getSpawn(pp.getLocation().getWorld()));
MainUtil.sendMessage(pp, C.YOU_GOT_DENIED);
}

View File

@ -30,53 +30,57 @@ import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotAnalysis;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.util.BlockManager;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.UUIDHandler;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "done",
aliases = {"submit"},
description = "Mark a plot as done",
permission = "plots.done",
category = CommandCategory.ACTIONS,
requiredType = RequiredType.NONE
)
public class Done extends SubCommand {
command = "done",
aliases = { "submit" },
description = "Mark a plot as done",
permission = "plots.done",
category = CommandCategory.ACTIONS,
requiredType = RequiredType.NONE)
public class Done extends SubCommand
{
@Override
public boolean onCommand(final PlotPlayer plr, final String[] args) {
public boolean onCommand(final PlotPlayer plr, final String[] args)
{
final Location loc = plr.getLocation();
final Plot plot = MainUtil.getPlot(loc);
if (plot == null || !plot.hasOwner()) {
return !sendMessage(plr, C.NOT_IN_PLOT);
}
if ((!plot.isOwner(plr.getUUID())) && !Permissions.hasPermission(plr, "plots.admin.command.done")) {
if ((plot == null) || !plot.hasOwner()) { return !sendMessage(plr, C.NOT_IN_PLOT); }
if ((!plot.isOwner(plr.getUUID())) && !Permissions.hasPermission(plr, "plots.admin.command.done"))
{
MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
return false;
}
if (plot.getSettings().flags.containsKey("done")) {
if (plot.getSettings().flags.containsKey("done"))
{
MainUtil.sendMessage(plr, C.DONE_ALREADY_DONE);
return false;
}
if (MainUtil.runners.containsKey(plot)) {
if (MainUtil.runners.containsKey(plot))
{
MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER);
return false;
}
MainUtil.runners.put(plot, 1);
MainUtil.sendMessage(plr, C.GENERATING_LINK);
HybridUtils.manager.analyzePlot(plot, new RunnableVal<PlotAnalysis>() {
HybridUtils.manager.analyzePlot(plot, new RunnableVal<PlotAnalysis>()
{
@Override
public void run() {
public void run()
{
MainUtil.runners.remove(plot);
if (value == null || value.getComplexity() >= Settings.CLEAR_THRESHOLD) {
Flag flag = new Flag(FlagManager.getFlag("done"), (System.currentTimeMillis() / 1000));
if ((value == null) || (value.getComplexity() >= Settings.CLEAR_THRESHOLD))
{
final Flag flag = new Flag(FlagManager.getFlag("done"), (System.currentTimeMillis() / 1000));
FlagManager.addPlotFlag(plot, flag);
MainUtil.sendMessage(plr, C.DONE_SUCCESS);
}
else {
else
{
MainUtil.sendMessage(plr, C.DONE_INSUFFICIENT_COMPLEXITY);
}
}

View File

@ -17,52 +17,58 @@ import com.intellectualcrafters.plot.util.TaskManager;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "download",
aliases = {"dl"},
category = CommandCategory.ACTIONS,
requiredType = RequiredType.NONE,
description = "Download your plot",
permission = "plots.download"
)
public class Download extends SubCommand {
command = "download",
aliases = { "dl" },
category = CommandCategory.ACTIONS,
requiredType = RequiredType.NONE,
description = "Download your plot",
permission = "plots.download")
public class Download extends SubCommand
{
@Override
public boolean onCommand(final PlotPlayer plr, final String[] args) {
if (!Settings.METRICS) {
public boolean onCommand(final PlotPlayer plr, final String[] args)
{
if (!Settings.METRICS)
{
MainUtil.sendMessage(plr, "&cPlease enable metrics in order to use this command.\n&7 - Or host it yourself if you don't like the free service");
return false;
}
final String world = plr.getLocation().getWorld();
if (!PS.get().isPlotWorld(world)) {
return !sendMessage(plr, C.NOT_IN_PLOT_WORLD);
}
if (!PS.get().isPlotWorld(world)) { return !sendMessage(plr, C.NOT_IN_PLOT_WORLD); }
final Plot plot = MainUtil.getPlot(plr.getLocation());
if (plot == null) {
return !sendMessage(plr, C.NOT_IN_PLOT);
}
if (!plot.hasOwner()) {
if (plot == null) { return !sendMessage(plr, C.NOT_IN_PLOT); }
if (!plot.hasOwner())
{
MainUtil.sendMessage(plr, C.PLOT_UNOWNED);
return false;
}
if ((!plot.isOwner(plr.getUUID()) || (Settings.DOWNLOAD_REQUIRES_DONE && FlagManager.getPlotFlag(plot, "done") != null)) && !Permissions.hasPermission(plr, "plots.admin.command.download")) {
if ((!plot.isOwner(plr.getUUID()) || (Settings.DOWNLOAD_REQUIRES_DONE && (FlagManager.getPlotFlag(plot, "done") != null))) && !Permissions.hasPermission(plr, "plots.admin.command.download"))
{
MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
return false;
}
if (MainUtil.runners.containsKey(plot)) {
if (MainUtil.runners.containsKey(plot))
{
MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER);
return false;
}
MainUtil.runners.put(plot, 1);
MainUtil.sendMessage(plr, C.GENERATING_LINK);
SchematicHandler.manager.getCompoundTag(plot.world, plot.id, new RunnableVal<CompoundTag>() {
SchematicHandler.manager.getCompoundTag(plot.world, plot.id, new RunnableVal<CompoundTag>()
{
@Override
public void run() {
TaskManager.runTaskAsync(new Runnable() {
public void run()
{
TaskManager.runTaskAsync(new Runnable()
{
@Override
public void run() {
URL url = SchematicHandler.manager.upload(value, null, null);
if (url == null) {
public void run()
{
final URL url = SchematicHandler.manager.upload(value, null, null);
if (url == null)
{
MainUtil.sendMessage(plr, C.GENERATING_LINK_FAILED);
MainUtil.runners.remove(plot);
return;

View File

@ -39,24 +39,26 @@ import com.intellectualcrafters.plot.util.StringMan;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "flag",
aliases = {"f"},
usage = "/plot flag <set|remove|add|list|info> <flag> <value>",
description = "Manage plot flags",
category = CommandCategory.ACTIONS,
requiredType = RequiredType.NONE,
permission = "plots.flag"
)
public class FlagCmd extends SubCommand {
command = "flag",
aliases = { "f" },
usage = "/plot flag <set|remove|add|list|info> <flag> <value>",
description = "Manage plot flags",
category = CommandCategory.ACTIONS,
requiredType = RequiredType.NONE,
permission = "plots.flag")
public class FlagCmd extends SubCommand
{
@Override
public String getUsage() {
public String getUsage()
{
return super.getUsage().replaceAll("<flag>", StringMan.join(FlagManager.getFlags(), "|"));
}
@Override
public boolean onCommand(final PlotPlayer player, final String ... args) {
public boolean onCommand(final PlotPlayer player, final String... args)
{
/*
* plot flag set fly true
* plot flag remove fly
@ -64,40 +66,50 @@ public class FlagCmd extends SubCommand {
* plot flag add use 2,4
* plot flag list
*/
if (args.length == 0) {
if (args.length == 0)
{
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot flag <set|remove|add|list|info>");
return false;
}
final Location loc = player.getLocation();
final Plot plot = MainUtil.getPlot(loc);
if (plot == null) {
if (plot == null)
{
MainUtil.sendMessage(player, C.NOT_IN_PLOT);
return false;
}
if (!plot.hasOwner()) {
if (!plot.hasOwner())
{
sendMessage(player, C.PLOT_NOT_CLAIMED);
return false;
}
if (!plot.isOwner(player.getUUID()) && !Permissions.hasPermission(player, "plots.set.flag.other")) {
if (!plot.isOwner(player.getUUID()) && !Permissions.hasPermission(player, "plots.set.flag.other"))
{
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.set.flag.other");
return false;
}
if (args.length > 1 && FlagManager.isReserved(args[1])) {
if ((args.length > 1) && FlagManager.isReserved(args[1]))
{
MainUtil.sendMessage(player, C.NOT_VALID_FLAG);
return false;
}
switch (args[0].toLowerCase()) {
case "info": {
if (!Permissions.hasPermission(player, "plots.set.flag")) {
switch (args[0].toLowerCase())
{
case "info":
{
if (!Permissions.hasPermission(player, "plots.set.flag"))
{
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.flag.info");
return false;
}
if (args.length != 2) {
if (args.length != 2)
{
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot flag info <flag>");
return false;
}
final AbstractFlag af = FlagManager.getFlag(args[1]);
if (af == null) {
if (af == null)
{
MainUtil.sendMessage(player, C.NOT_VALID_FLAG);
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot flag info <flag>");
return false;
@ -110,73 +122,92 @@ public class FlagCmd extends SubCommand {
MainUtil.sendMessage(player, C.FLAG_DESC, af.getValueDesc());
return true;
}
case "set": {
if (!Permissions.hasPermission(player, "plots.set.flag")) {
case "set":
{
if (!Permissions.hasPermission(player, "plots.set.flag"))
{
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.set.flag");
return false;
}
if (args.length < 3) {
if (args.length < 3)
{
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot flag set <flag> <value>");
return false;
}
final AbstractFlag af = FlagManager.getFlag(args[1].toLowerCase());
if (af == null) {
if (af == null)
{
MainUtil.sendMessage(player, C.NOT_VALID_FLAG);
return false;
}
final String value = StringMan.join(Arrays.copyOfRange(args, 2, args.length), " ");
if (!Permissions.hasPermission(player, "plots.set.flag." + args[1].toLowerCase() + "." + value.toLowerCase())) {
if (!Permissions.hasPermission(player, "plots.set.flag." + args[1].toLowerCase() + "." + value.toLowerCase()))
{
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.set.flag." + args[1].toLowerCase() + "." + value.toLowerCase());
return false;
}
final Object parsed = af.parseValueRaw(value);
if (parsed == null) {
if (parsed == null)
{
MainUtil.sendMessage(player, "&c" + af.getValueDesc());
return false;
}
final Flag flag = new Flag(FlagManager.getFlag(args[1].toLowerCase(), true), parsed);
final boolean result = FlagManager.addPlotFlag(plot, flag);
if (!result) {
if (!result)
{
MainUtil.sendMessage(player, C.FLAG_NOT_ADDED);
return false;
}
MainUtil.sendMessage(player, C.FLAG_ADDED);
return true;
}
case "remove": {
if (!Permissions.hasPermission(player, "plots.flag.remove")) {
case "remove":
{
if (!Permissions.hasPermission(player, "plots.flag.remove"))
{
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.flag.remove");
return false;
}
if ((args.length != 2) && (args.length != 3)) {
if ((args.length != 2) && (args.length != 3))
{
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot flag remove <flag> [values]");
return false;
}
final AbstractFlag af = FlagManager.getFlag(args[1].toLowerCase());
if (af == null) {
if (af == null)
{
MainUtil.sendMessage(player, C.NOT_VALID_FLAG);
return false;
}
final Flag flag = FlagManager.getPlotFlagAbs(plot, args[1].toLowerCase());
if (!Permissions.hasPermission(player, "plots.set.flag." + args[1].toLowerCase())) {
for (String entry : args[2].split(",")) {
if (!Permissions.hasPermission(player, "plots.set.flag." + args[1].toLowerCase() + "." + entry)) {
if (!Permissions.hasPermission(player, "plots.set.flag." + args[1].toLowerCase()))
{
for (final String entry : args[2].split(","))
{
if (!Permissions.hasPermission(player, "plots.set.flag." + args[1].toLowerCase() + "." + entry))
{
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.set.flag." + args[1].toLowerCase() + "." + entry);
return false;
}
}
}
if (flag == null) {
if (flag == null)
{
MainUtil.sendMessage(player, C.FLAG_NOT_IN_PLOT);
return false;
}
if ((args.length == 3) && flag.getAbstractFlag().isList()) {
if ((args.length == 3) && flag.getAbstractFlag().isList())
{
final String value = StringMan.join(Arrays.copyOfRange(args, 2, args.length), " ");
((FlagValue.ListValue) flag.getAbstractFlag().value).remove(flag.getValue(), value);
DBFunc.setFlags(plot, plot.getSettings().flags.values());
} else {
}
else
{
final boolean result = FlagManager.removePlotFlag(plot, flag.getKey());
if (!result) {
if (!result)
{
MainUtil.sendMessage(player, C.FLAG_NOT_REMOVED);
return false;
}
@ -184,23 +215,30 @@ public class FlagCmd extends SubCommand {
MainUtil.sendMessage(player, C.FLAG_REMOVED);
return true;
}
case "add": {
if (!Permissions.hasPermission(player, "plots.flag.add")) {
case "add":
{
if (!Permissions.hasPermission(player, "plots.flag.add"))
{
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.flag.add");
return false;
}
if (args.length < 3) {
if (args.length < 3)
{
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot flag add <flag> <values>");
return false;
}
final AbstractFlag af = FlagManager.getFlag(args[1].toLowerCase());
if (af == null) {
if (af == null)
{
MainUtil.sendMessage(player, C.NOT_VALID_FLAG);
return false;
}
if (!Permissions.hasPermission(player, "plots.set.flag." + args[1].toLowerCase())) {
for (String entry : args[2].split(",")) {
if (!Permissions.hasPermission(player, "plots.set.flag." + args[1].toLowerCase() + "." + entry)) {
if (!Permissions.hasPermission(player, "plots.set.flag." + args[1].toLowerCase()))
{
for (final String entry : args[2].split(","))
{
if (!Permissions.hasPermission(player, "plots.set.flag." + args[1].toLowerCase() + "." + entry))
{
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.set.flag." + args[1].toLowerCase() + "." + entry);
return false;
}
@ -208,18 +246,23 @@ public class FlagCmd extends SubCommand {
}
final String value = StringMan.join(Arrays.copyOfRange(args, 2, args.length), " ");
final Object parsed = af.parseValueRaw(value);
if (parsed == null) {
if (parsed == null)
{
MainUtil.sendMessage(player, "&c" + af.getValueDesc());
return false;
}
Flag flag = FlagManager.getPlotFlag(plot, args[1].toLowerCase());
if ((flag == null) || !flag.getAbstractFlag().isList()) {
if ((flag == null) || !flag.getAbstractFlag().isList())
{
flag = new Flag(FlagManager.getFlag(args[1].toLowerCase(), true), parsed);
} else {
}
else
{
((FlagValue.ListValue) flag.getAbstractFlag().value).add(flag.getValue(), value);
}
final boolean result = FlagManager.addPlotFlag(plot, flag);
if (!result) {
if (!result)
{
MainUtil.sendMessage(player, C.FLAG_NOT_ADDED);
return false;
}
@ -227,26 +270,32 @@ public class FlagCmd extends SubCommand {
MainUtil.sendMessage(player, C.FLAG_ADDED);
return true;
}
case "list": {
if (!Permissions.hasPermission(player, "plots.flag.list")) {
case "list":
{
if (!Permissions.hasPermission(player, "plots.flag.list"))
{
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.flag.list");
return false;
}
if (args.length != 1) {
if (args.length != 1)
{
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot flag list");
return false;
}
final HashMap<String, ArrayList<String>> flags = new HashMap<>();
for (final AbstractFlag af : FlagManager.getFlags()) {
for (final AbstractFlag af : FlagManager.getFlags())
{
final String type = af.value.getClass().getSimpleName().replaceAll("Value", "");
if (!flags.containsKey(type)) {
if (!flags.containsKey(type))
{
flags.put(type, new ArrayList<String>());
}
flags.get(type).add(af.getKey());
}
String message = "";
String prefix = "";
for (final String flag : flags.keySet()) {
for (final String flag : flags.keySet())
{
message += prefix + "&6" + flag + ": &7" + StringMan.join(flags.get(flag), ", ");
prefix = "\n";
}

View File

@ -9,79 +9,86 @@ import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.object.ConsolePlayer;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.StringMan;
import com.plotsquared.general.commands.Command;
public class GenerateDocs {
public static void main(String[] args) {
public class GenerateDocs
{
public static void main(final String[] args)
{
MainCommand.getInstance().addCommand(new WE_Anywhere());
MainCommand.getInstance().addCommand(new Cluster());
ArrayList<Command<PlotPlayer>> commands = MainCommand.getInstance().getCommands();
final ArrayList<Command<PlotPlayer>> commands = MainCommand.getInstance().getCommands();
log("### Want to document some commands?");
log(" - This page is automatically generated");
log(" - Fork the project and add a javadoc comment to one of the command classes");
log(" - Then do a pull request and it will be added to this page");
log("");
log("# Contents");
for (CommandCategory category : CommandCategory.values()) {
for (final CommandCategory category : CommandCategory.values())
{
log("###### " + category.name());
for (Command<PlotPlayer> command : MainCommand.getCommands(category, null)) {
log(" - [/plot " + command.getCommand() + "](https://github.com/IntellectualSites/PlotSquared/wiki/Commands#" + command.getCommand() +") ");
for (final Command<PlotPlayer> command : MainCommand.getCommands(category, null))
{
log(" - [/plot " + command.getCommand() + "](https://github.com/IntellectualSites/PlotSquared/wiki/Commands#" + command.getCommand() + ") ");
}
log("");
}
log("# Commands");
for (Command<PlotPlayer> command : commands) {
for (final Command<PlotPlayer> command : commands)
{
printCommand(command);
}
}
public static void printCommand(Command<PlotPlayer> command) {
try {
String clazz = command.getClass().getSimpleName();
String name = command.getCommand();
public static void printCommand(final Command<PlotPlayer> command)
{
try
{
final String clazz = command.getClass().getSimpleName();
final String name = command.getCommand();
// Header
String source = "https://github.com/IntellectualSites/PlotSquared/tree/master/src/main/java/com/intellectualcrafters/plot/commands/" + clazz + ".java";
final String source = "https://github.com/IntellectualSites/PlotSquared/tree/master/src/main/java/com/intellectualcrafters/plot/commands/" + clazz + ".java";
log("## [" + name.toUpperCase() + "](" + source + ") ");
File file = new File("src/main/java/com/intellectualcrafters/plot/commands/" + clazz + ".java");
List<String> lines = Files.readAllLines(file.toPath(), StandardCharsets.UTF_8);
List<String> perms = getPerms(name, lines);
String comment = getComments(lines);
final File file = new File("src/main/java/com/intellectualcrafters/plot/commands/" + clazz + ".java");
final List<String> lines = Files.readAllLines(file.toPath(), StandardCharsets.UTF_8);
final List<String> perms = getPerms(name, lines);
final String comment = getComments(lines);
log("#### Description");
log("`" + command.getDescription() + "`");
if (comment.length() > 0) {
if (comment.length() > 0)
{
log("##### Comments");
log("``` java");
log(comment);
log("```");
}
log("#### Usage");
log("`" + command.getUsage().replaceAll("\\{label\\}", "plot") + "`");
if (command.getRequiredType() != RequiredType.NONE) {
if (command.getRequiredType() != RequiredType.NONE)
{
log("#### Required callers");
log("`" + command.getRequiredType().name() + "`");
}
Set<String> aliases = command.getAliases();
if (aliases.size() > 0) {
final Set<String> aliases = command.getAliases();
if (aliases.size() > 0)
{
log("#### Aliases");
log("`" + StringMan.getString(command.getAliases()) + "`");
}
log("#### Permissions");
log("##### Primary");
log(" - `" + command.getPermission() + "` ");
if (perms.size() > 0) {
if (perms.size() > 0)
{
log("");
log("##### Other");
log(" - `" + StringMan.join(perms, "`\n - `") + "`");
@ -90,54 +97,68 @@ public class GenerateDocs {
log("***");
log("");
}
catch (Exception e) {
catch (final Exception e)
{
e.printStackTrace();
}
}
public static List<String> getPerms(String cmd, List<String> lines) {
ArrayList<String> perms = new ArrayList<String>();
Pattern p = Pattern.compile("\"([^\"]*)\"");
for (String line : lines) {
if (line.contains("Permissions.hasPermission(")) {
Matcher m = p.matcher(line);
while (m.find()) {
public static List<String> getPerms(final String cmd, final List<String> lines)
{
final ArrayList<String> perms = new ArrayList<String>();
final Pattern p = Pattern.compile("\"([^\"]*)\"");
for (final String line : lines)
{
if (line.contains("Permissions.hasPermission("))
{
final Matcher m = p.matcher(line);
while (m.find())
{
String perm = m.group(1);
if (perm.endsWith(".")) {
if (perm.endsWith("."))
{
perm += "<arg>";
}
if (perm.startsWith(".")) {
if (perm.startsWith("."))
{
perms.set(perms.size() - 1, perms.get(perms.size() - 1) + perm);
}
else if (perm.contains(".")) {
else if (perm.contains("."))
{
perms.add(perm);
}
}
}
}
switch (cmd.toLowerCase()) {
switch (cmd.toLowerCase())
{
case "auto":
case "claim": {
case "claim":
{
perms.add("plots.plot.#");
break;
}
}
return perms;
}
public static String getComments(List<String> lines) {
StringBuilder result = new StringBuilder();
for (String line : lines) {
public static String getComments(final List<String> lines)
{
final StringBuilder result = new StringBuilder();
for (String line : lines)
{
line = line.trim();
if (line.startsWith("/** ") || line.startsWith("*/ ") || line.startsWith("* ")) {
if (line.startsWith("/** ") || line.startsWith("*/ ") || line.startsWith("* "))
{
line = (line.replaceAll("/[*][*] ", "").replaceAll("[*]/ ", "").replaceAll("[*] ", "")).trim();
result.append(line + "\n");
}
}
return result.toString().trim();
}
public static void log(String s) {
public static void log(final String s)
{
System.out.println(s);
}
}

View File

@ -4,15 +4,16 @@ import com.intellectualcrafters.plot.object.PlotPlayer;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "help",
description = "Get this help menu",
aliases = {"he"},
category = CommandCategory.INFO
)
public class Help extends SubCommand {
command = "help",
description = "Get this help menu",
aliases = { "he" },
category = CommandCategory.INFO)
public class Help extends SubCommand
{
@Override
public boolean onCommand(final PlotPlayer plr, final String[] args) {
public boolean onCommand(final PlotPlayer plr, final String[] args)
{
return true;
}
}

View File

@ -23,7 +23,6 @@ package com.intellectualcrafters.plot.commands;
import java.util.ArrayList;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.PS.SortType;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotPlayer;
@ -31,42 +30,53 @@ import com.intellectualcrafters.plot.util.MainUtil;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "home",
aliases = {"h"},
description = "Go to your plot",
usage = "/plot home [id|alias]",
category = CommandCategory.TELEPORT,
requiredType = RequiredType.NONE
)
public class Home extends SubCommand {
command = "home",
aliases = { "h" },
description = "Go to your plot",
usage = "/plot home [id|alias]",
category = CommandCategory.TELEPORT,
requiredType = RequiredType.NONE)
public class Home extends SubCommand
{
private Plot isAlias(final String a) {
for (final Plot p : PS.get().getPlots()) {
if ((p.getSettings().getAlias().length() > 0) && p.getSettings().getAlias().equalsIgnoreCase(a)) {
return p;
}
private Plot isAlias(final String a)
{
for (final Plot p : PS.get().getPlots())
{
if ((p.getSettings().getAlias().length() > 0) && p.getSettings().getAlias().equalsIgnoreCase(a)) { return p; }
}
return null;
}
@Override
public boolean onCommand(final PlotPlayer plr, String[] args) {
public boolean onCommand(final PlotPlayer plr, String[] args)
{
final ArrayList<Plot> plots = PS.get().sortPlotsByTemp(PS.get().getPlots(plr));//PS.get().sortPlots(PS.get().getPlots(plr), SortType.CREATION_DATE, null);
if (plots.size() == 1) {
if (plots.size() == 1)
{
MainUtil.teleportPlayer(plr, plr.getLocation(), plots.get(0));
return true;
} else if (plots.size() > 1) {
if (args.length < 1) {
}
else if (plots.size() > 1)
{
if (args.length < 1)
{
args = new String[] { "1" };
}
int id = 0;
try {
try
{
id = Integer.parseInt(args[0]);
} catch (final Exception e) {
}
catch (final Exception e)
{
Plot temp;
if ((temp = isAlias(args[0])) != null) {
if (temp.hasOwner()) {
if (temp.isOwner(plr.getUUID())) {
if ((temp = isAlias(args[0])) != null)
{
if (temp.hasOwner())
{
if (temp.isOwner(plr.getUUID()))
{
MainUtil.teleportPlayer(plr, plr.getLocation(), temp);
return true;
}
@ -77,19 +87,23 @@ public class Home extends SubCommand {
MainUtil.sendMessage(plr, C.NOT_VALID_NUMBER, "(1, " + plots.size() + ")");
return true;
}
if ((id > (plots.size())) || (id < 1)) {
if ((id > (plots.size())) || (id < 1))
{
MainUtil.sendMessage(plr, C.NOT_VALID_NUMBER, "(1, " + plots.size() + ")");
return false;
}
MainUtil.teleportPlayer(plr, plr.getLocation(), plots.get(id - 1));
return true;
} else {
}
else
{
MainUtil.sendMessage(plr, C.FOUND_NO_PLOTS);
return true;
}
}
public void teleportPlayer(final PlotPlayer player, final Plot plot) {
public void teleportPlayer(final PlotPlayer player, final Plot plot)
{
MainUtil.teleportPlayer(player, player.getLocation(), plot);
}
}

View File

@ -35,46 +35,54 @@ import com.intellectualcrafters.plot.util.StringMan;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "inbox",
description = "Review the comments for a plot",
usage = "/plot inbox [inbox] [delete <index>|clear|page]",
permission = "plots.inbox",
category = CommandCategory.ACTIONS,
requiredType = RequiredType.NONE
)
public class Inbox extends SubCommand {
public void displayComments(PlotPlayer player, List<PlotComment> oldComments, int page) {
if (oldComments == null || oldComments.size() == 0) {
command = "inbox",
description = "Review the comments for a plot",
usage = "/plot inbox [inbox] [delete <index>|clear|page]",
permission = "plots.inbox",
category = CommandCategory.ACTIONS,
requiredType = RequiredType.NONE)
public class Inbox extends SubCommand
{
public void displayComments(final PlotPlayer player, final List<PlotComment> oldComments, int page)
{
if ((oldComments == null) || (oldComments.size() == 0))
{
MainUtil.sendMessage(player, C.INBOX_EMPTY);
return;
}
PlotComment[] comments = oldComments.toArray(new PlotComment[oldComments.size()]);
if (page < 0) {
final PlotComment[] comments = oldComments.toArray(new PlotComment[oldComments.size()]);
if (page < 0)
{
page = 0;
}
// Get the total pages
// int totalPages = ((int) Math.ceil(12 *
final int totalPages = (int) Math.ceil(comments.length / 12);
if (page > totalPages) {
if (page > totalPages)
{
page = totalPages;
}
// Only display 12 per page
int max = (page * 12) + 12;
if (max > comments.length) {
if (max > comments.length)
{
max = comments.length;
}
final StringBuilder string = new StringBuilder();
string.append(StringMan.replaceAll(C.COMMENT_LIST_HEADER_PAGED.s(), "%amount%", comments.length, "%cur", page + 1, "%max", totalPages + 1, "%word", "all") + "\n");
PlotComment c;
// This might work xD
for (int x = (page * 12); x < max; x++) {
for (int x = (page * 12); x < max; x++)
{
c = comments[x];
String color;
if (player.getName().equals(c.senderName)) {
if (player.getName().equals(c.senderName))
{
color = "&a";
}
else {
else
{
color = "&7";
}
string.append("&8[&7#" + x + "&8][&7" + c.world + ";" + c.id + "&8][&6" + c.senderName + "&8]" + color + c.comment + "\n");
@ -83,32 +91,43 @@ public class Inbox extends SubCommand {
}
@Override
public boolean onCommand(final PlotPlayer player, final String[] args) {
public boolean onCommand(final PlotPlayer player, final String[] args)
{
final Plot plot = MainUtil.getPlot(player.getLocation());
if (args.length == 0) {
if (args.length == 0)
{
sendMessage(player, C.COMMAND_SYNTAX, "/plot inbox [inbox] [delete <index>|clear|page]");
for (final CommentInbox inbox : CommentManager.inboxes.values()) {
if (inbox.canRead(plot, player)) {
if (!inbox.getComments(plot, new RunnableVal() {
for (final CommentInbox inbox : CommentManager.inboxes.values())
{
if (inbox.canRead(plot, player))
{
if (!inbox.getComments(plot, new RunnableVal()
{
@Override
public void run() {
if (value != null) {
public void run()
{
if (value != null)
{
int total = 0;
int unread = 0;
for (PlotComment comment : (ArrayList<PlotComment>) value) {
for (final PlotComment comment : (ArrayList<PlotComment>) value)
{
total++;
if (comment.timestamp > CommentManager.getTimestamp(player, inbox.toString())) {
if (comment.timestamp > CommentManager.getTimestamp(player, inbox.toString()))
{
unread++;
}
}
if (total != 0) {
if (total != 0)
{
String color;
if (unread > 0) {
if (unread > 0)
{
color = "&c";
}
else {
else
{
color = "";
}
sendMessage(player, C.INBOX_ITEM, color + inbox.toString() + " (" + total + "/" + unread + ")");
@ -117,7 +136,8 @@ public class Inbox extends SubCommand {
}
sendMessage(player, C.INBOX_ITEM, inbox.toString());
}
})) {
}))
{
sendMessage(player, C.INBOX_ITEM, inbox.toString());
}
}
@ -125,94 +145,120 @@ public class Inbox extends SubCommand {
return false;
}
final CommentInbox inbox = CommentManager.inboxes.get(args[0].toLowerCase());
if (inbox == null) {
sendMessage(player, C.INVALID_INBOX, StringMan.join(CommentManager.inboxes.keySet(),", "));
if (inbox == null)
{
sendMessage(player, C.INVALID_INBOX, StringMan.join(CommentManager.inboxes.keySet(), ", "));
return false;
}
player.setMeta("inbox:" + inbox.toString(), System.currentTimeMillis());
final int page;
if (args.length > 1) {
switch (args[1].toLowerCase()) {
case "delete": {
if (!inbox.canModify(plot, player)) {
if (args.length > 1)
{
switch (args[1].toLowerCase())
{
case "delete":
{
if (!inbox.canModify(plot, player))
{
sendMessage(player, C.NO_PERM_INBOX_MODIFY);
return false;
}
if (args.length != 3) {
if (args.length != 3)
{
sendMessage(player, C.COMMAND_SYNTAX, "/plot inbox " + inbox.toString() + " delete <index>");
}
final int index;
try {
try
{
index = Integer.parseInt(args[2]);
if (index < 1) {
if (index < 1)
{
sendMessage(player, C.NOT_VALID_INBOX_INDEX, index + "");
return false;
}
}
catch (NumberFormatException e) {
catch (final NumberFormatException e)
{
sendMessage(player, C.COMMAND_SYNTAX, "/plot inbox " + inbox.toString() + " delete <index>");
return false;
}
if (!inbox.getComments(plot, new RunnableVal() {
if (!inbox.getComments(plot, new RunnableVal()
{
@Override
public void run() {
List<PlotComment> comments = (List<PlotComment>) value;
if (index > comments.size()) {
public void run()
{
final List<PlotComment> comments = (List<PlotComment>) value;
if (index > comments.size())
{
sendMessage(player, C.NOT_VALID_INBOX_INDEX, index + "");
}
PlotComment comment = comments.get(index - 1);
final PlotComment comment = comments.get(index - 1);
inbox.removeComment(plot, comment);
plot.getSettings().removeComment(comment);
MainUtil.sendMessage(player, C.COMMENT_REMOVED, comment.comment);
}
})) {
}))
{
sendMessage(player, C.NOT_IN_PLOT);
return false;
}
return true;
}
case "clear": {
if (!inbox.canModify(plot, player)) {
case "clear":
{
if (!inbox.canModify(plot, player))
{
sendMessage(player, C.NO_PERM_INBOX_MODIFY);
}
inbox.clearInbox(plot);
ArrayList<PlotComment> comments = plot.getSettings().getComments(inbox.toString());
if (comments != null) {
final ArrayList<PlotComment> comments = plot.getSettings().getComments(inbox.toString());
if (comments != null)
{
plot.getSettings().removeComments(comments);
}
MainUtil.sendMessage(player, C.COMMENT_REMOVED, "*");
return true;
}
default: {
try {
page = Integer.parseInt(args[1]) ;
default:
{
try
{
page = Integer.parseInt(args[1]);
}
catch (NumberFormatException e) {
catch (final NumberFormatException e)
{
sendMessage(player, C.COMMAND_SYNTAX, "/plot inbox [inbox] [delete <index>|clear|page]");
return false;
}
}
}
}
else {
else
{
page = 1;
}
if (!inbox.canRead(plot, player)) {
if (!inbox.canRead(plot, player))
{
sendMessage(player, C.NO_PERM_INBOX);
return false;
}
if (!inbox.getComments(plot, new RunnableVal() {
if (!inbox.getComments(plot, new RunnableVal()
{
@Override
public void run() {
List<PlotComment> comments = (List<PlotComment>) value;
public void run()
{
final List<PlotComment> comments = (List<PlotComment>) value;
displayComments(player, comments, page);
}
})) {
if (plot == null) {
}))
{
if (plot == null)
{
sendMessage(player, C.NOT_IN_PLOT);
}
else {
else
{
sendMessage(player, C.PLOT_UNOWNED);
}
return false;

View File

@ -25,7 +25,6 @@ import java.util.Collection;
import java.util.UUID;
import java.util.regex.Matcher;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.database.DBFunc;
@ -37,7 +36,6 @@ import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotInventory;
import com.intellectualcrafters.plot.object.PlotItemStack;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.util.BlockManager;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.StringMan;
@ -46,52 +44,56 @@ import com.intellectualcrafters.plot.util.UUIDHandler;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "info",
aliases = {"i"},
description = "Display plot info",
usage = "/plot info <id>",
category = CommandCategory.INFO
)
public class Info extends SubCommand {
command = "info",
aliases = { "i" },
description = "Display plot info",
usage = "/plot info <id>",
category = CommandCategory.INFO)
public class Info extends SubCommand
{
public static String getPlayerList(final Collection<UUID> uuids) {
ArrayList<UUID> l = new ArrayList<>(uuids);
if ((l == null) || (l.size() < 1)) {
return C.NONE.s();
}
public static String getPlayerList(final Collection<UUID> uuids)
{
final ArrayList<UUID> l = new ArrayList<>(uuids);
if ((l == null) || (l.size() < 1)) { return C.NONE.s(); }
final String c = C.PLOT_USER_LIST.s();
final StringBuilder list = new StringBuilder();
for (int x = 0; x < l.size(); x++) {
if ((x + 1) == l.size()) {
for (int x = 0; x < l.size(); x++)
{
if ((x + 1) == l.size())
{
list.append(c.replace("%user%", getPlayerName(l.get(x))).replace(",", ""));
} else {
}
else
{
list.append(c.replace("%user%", getPlayerName(l.get(x))));
}
}
return list.toString();
}
public static String getPlayerName(final UUID uuid) {
if (uuid == null) {
return C.UNKNOWN.s();
}
if (uuid.equals(DBFunc.everyone) || uuid.toString().equalsIgnoreCase(DBFunc.everyone.toString())) {
return "everyone";
}
public static String getPlayerName(final UUID uuid)
{
if (uuid == null) { return C.UNKNOWN.s(); }
if (uuid.equals(DBFunc.everyone) || uuid.toString().equalsIgnoreCase(DBFunc.everyone.toString())) { return "everyone"; }
final String name = UUIDHandler.getName(uuid);
if (name == null) {
return "unknown";
}
if (name == null) { return "unknown"; }
return name;
}
@Override
public boolean onCommand(final PlotPlayer player, String[] args) {
public boolean onCommand(final PlotPlayer player, String[] args)
{
String arg = null;
Plot plot;
if (args.length > 0) arg = args[0] + "";
if (arg != null) {
switch (arg) {
if (args.length > 0)
{
arg = args[0] + "";
}
if (arg != null)
{
switch (arg)
{
case "trusted":
case "alias":
case "inv":
@ -107,49 +109,66 @@ public class Info extends SubCommand {
break;
default:
plot = MainUtil.getPlotFromString(player, arg, false);
if (args.length == 2) {
if (args.length == 2)
{
arg = args[1];
}
else {
else
{
arg = null;
}
break;
}
}
else {
else
{
plot = MainUtil.getPlotFromString(player, null, false);
}
if (plot == null && arg != null) {
if ((plot == null) && (arg != null))
{
plot = MainUtil.getPlotFromString(player, null, false);
}
if (plot == null) {
if (plot == null)
{
MainUtil.sendMessage(player, C.NOT_IN_PLOT);
return false;
}
if (arg != null) {
if (args.length == 1) {
if (arg != null)
{
if (args.length == 1)
{
args = new String[0];
}
else {
else
{
args = new String[] { args[1] };
}
}
if ((args.length == 1) && args[0].equalsIgnoreCase("inv")) {
PlotInventory inv = new PlotInventory(player) {
if ((args.length == 1) && args[0].equalsIgnoreCase("inv"))
{
final PlotInventory inv = new PlotInventory(player)
{
@Override
public boolean onClick(int index) {
public boolean onClick(final int index)
{
// TODO InfoInventory not implemented yet!!!!!!!!
// See plot rating or musicsubcommand on examples
return false;
}
};
UUID uuid = player.getUUID();
String name = MainUtil.getName(plot.owner);
inv.setItem(1, new PlotItemStack(388, (short) 0, 1, "&cPlot Info", new String[] { "&cID: &6" + plot.getId().toString(), "&cOwner: &6" + name, "&cAlias: &6" + plot.getSettings().getAlias(), "&cBiome: &6" + plot.getBiome().toString().replaceAll("_", "").toLowerCase(), "&cCan Build: &6" + plot.isAdded(uuid), "&cIs Denied: &6" + plot.isDenied(uuid)}));
inv.setItem(1, new PlotItemStack(388, (short) 0, 1, "&cTrusted", new String[] {"&cAmount: &6" + plot.getTrusted().size(), "&8Click to view a list of the trusted users"}));
inv.setItem(1, new PlotItemStack(388, (short) 0, 1, "&cMembers", new String[] {"&cAmount: &6" + plot.getMembers().size(), "&8Click to view a list of plot members"}));
inv.setItem(1, new PlotItemStack(388, (short) 0, 1, "&cDenied", new String[] {"&cDenied", "&cAmount: &6" + plot.getDenied().size(), "&8Click to view a list of denied players"}));
inv.setItem(1, new PlotItemStack(388, (short) 0, 1, "&cFlags", new String[] {"&cFlags", "&cAmount: &6" + plot.getSettings().flags.size(), "&8Click to view a list of plot flags"}));
final UUID uuid = player.getUUID();
final String name = MainUtil.getName(plot.owner);
inv.setItem(1, new PlotItemStack(388, (short) 0, 1, "&cPlot Info", new String[] {
"&cID: &6" + plot.getId().toString(),
"&cOwner: &6" + name,
"&cAlias: &6" + plot.getSettings().getAlias(),
"&cBiome: &6" + plot.getBiome().toString().replaceAll("_", "").toLowerCase(),
"&cCan Build: &6" + plot.isAdded(uuid),
"&cIs Denied: &6" + plot.isDenied(uuid) }));
inv.setItem(1, new PlotItemStack(388, (short) 0, 1, "&cTrusted", new String[] { "&cAmount: &6" + plot.getTrusted().size(), "&8Click to view a list of the trusted users" }));
inv.setItem(1, new PlotItemStack(388, (short) 0, 1, "&cMembers", new String[] { "&cAmount: &6" + plot.getMembers().size(), "&8Click to view a list of plot members" }));
inv.setItem(1, new PlotItemStack(388, (short) 0, 1, "&cDenied", new String[] { "&cDenied", "&cAmount: &6" + plot.getDenied().size(), "&8Click to view a list of denied players" }));
inv.setItem(1, new PlotItemStack(388, (short) 0, 1, "&cFlags", new String[] { "&cFlags", "&cAmount: &6" + plot.getSettings().flags.size(), "&8Click to view a list of plot flags" }));
inv.openInventory();
return true;
}
@ -162,27 +181,33 @@ public class Info extends SubCommand {
trustedEveryone = (plot.getMembers() != null) && plot.getMembers().contains(DBFunc.everyone);
}
// Unclaimed?
if (!hasOwner && !containsEveryone && !trustedEveryone) {
if (!hasOwner && !containsEveryone && !trustedEveryone)
{
MainUtil.sendMessage(player, C.PLOT_INFO_UNCLAIMED, (plot.id.x + ";" + plot.id.y));
return true;
}
String info = C.PLOT_INFO.s();
if (arg != null) {
if (arg != null)
{
info = getCaption(arg);
if (info == null) {
if (info == null)
{
MainUtil.sendMessage(player, "&6Categories&7: &amembers&7, &aalias&7, &abiome&7, &adenied&7, &aflags&7, &aid&7, &asize&7, &atrusted&7, &aowner&7, &arating");
return false;
}
formatAndSend(info, plot.world, plot, player, true);
}
else {
else
{
formatAndSend(info, plot.world, plot, player, false);
}
return true;
}
private String getCaption(final String string) {
switch (string) {
private String getCaption(final String string)
{
switch (string)
{
case "trusted":
return C.PLOT_INFO_TRUSTED.s();
case "alias":
@ -208,25 +233,29 @@ public class Info extends SubCommand {
}
}
private void formatAndSend(String info, final String world, final Plot plot, final PlotPlayer player, final boolean full) {
private void formatAndSend(String info, final String world, final Plot plot, final PlotPlayer player, final boolean full)
{
final PlotId id = plot.id;
final PlotId id2 = MainUtil.getTopPlot(plot).id;
final int num = MainUtil.getPlotSelectionIds(id, id2).size();
final String alias = plot.getSettings().getAlias().length() > 0 ? plot.getSettings().getAlias() : C.NONE.s();
Location top = MainUtil.getPlotTopLoc(world, plot.id);
Location bot = MainUtil.getPlotBottomLoc(world, plot.id).add(1, 0, 1);
final Location top = MainUtil.getPlotTopLoc(world, plot.id);
final Location bot = MainUtil.getPlotBottomLoc(world, plot.id).add(1, 0, 1);
final String biome = BlockManager.manager.getBiome(plot.world, bot.getX() + ((top.getX() - bot.getX()) / 2), bot.getZ() + ((top.getZ() - bot.getZ()) / 2));
final String trusted = getPlayerList(plot.getTrusted());
final String members = getPlayerList(plot.getMembers());
final String denied = getPlayerList(plot.getDenied());
Flag descriptionFlag = FlagManager.getPlotFlag(plot, "description");
final Flag descriptionFlag = FlagManager.getPlotFlag(plot, "description");
final String description = descriptionFlag == null ? C.NONE.s() : descriptionFlag.getValueString();
final String flags = StringMan.replaceFromMap("$2" + (StringMan.join(FlagManager.getPlotFlags(plot.world, plot.getSettings(), true).values(), "").length() > 0 ? StringMan.join(FlagManager.getPlotFlags(plot.world, plot.getSettings(), true).values(), "$1, $2") : C.NONE.s()), C.replacements);
final String flags = StringMan.replaceFromMap(
"$2"
+ (StringMan.join(FlagManager.getPlotFlags(plot.world, plot.getSettings(), true).values(), "").length() > 0 ? StringMan.join(FlagManager.getPlotFlags(plot.world, plot.getSettings(), true)
.values(), "$1, $2") : C.NONE.s()), C.replacements);
final boolean build = plot.isAdded(player.getUUID());
String owner = plot.owner == null ? "unowned" : getPlayerList(plot.getOwners());
final String owner = plot.owner == null ? "unowned" : getPlayerList(plot.getOwners());
info = info.replaceAll("%alias%", alias);
info = info.replaceAll("%id%", id.toString());
@ -242,27 +271,34 @@ public class Info extends SubCommand {
info = info.replaceAll("%flags%", Matcher.quoteReplacement(flags));
info = info.replaceAll("%build%", build + "");
info = info.replaceAll("%desc%", "No description set.");
if (info.contains("%rating%")) {
if (info.contains("%rating%"))
{
final String newInfo = info;
TaskManager.runTaskAsync(new Runnable() {
TaskManager.runTaskAsync(new Runnable()
{
@Override
public void run() {
public void run()
{
int max = 10;
if (Settings.RATING_CATEGORIES != null && Settings.RATING_CATEGORIES.size() > 0) {
if ((Settings.RATING_CATEGORIES != null) && (Settings.RATING_CATEGORIES.size() > 0))
{
max = 8;
}
String info;
if (full && Settings.RATING_CATEGORIES != null && Settings.RATING_CATEGORIES.size() > 1) {
if (full && (Settings.RATING_CATEGORIES != null) && (Settings.RATING_CATEGORIES.size() > 1))
{
String rating = "";
String prefix = "";
double[] ratings = MainUtil.getAverageRatings(plot);
for (int i = 0; i < ratings.length; i++) {
final double[] ratings = MainUtil.getAverageRatings(plot);
for (int i = 0; i < ratings.length; i++)
{
rating += prefix + Settings.RATING_CATEGORIES.get(i) + "=" + String.format("%.1f", ratings[i]);
prefix = ",";
}
info = newInfo.replaceAll("%rating%", rating);
}
else {
else
{
info = newInfo.replaceAll("%rating%", String.format("%.1f", MainUtil.getAverageRating(plot)) + "/" + max);
}
MainUtil.sendMessage(player, C.PLOT_INFO_HEADER);

View File

@ -31,38 +31,41 @@ import com.intellectualcrafters.plot.util.UUIDHandler;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "kick",
aliases = {"k"},
description = "Kick a player from your plot",
permission = "plots.kick",
category = CommandCategory.ACTIONS,
requiredType = RequiredType.NONE
)
public class Kick extends SubCommand {
command = "kick",
aliases = { "k" },
description = "Kick a player from your plot",
permission = "plots.kick",
category = CommandCategory.ACTIONS,
requiredType = RequiredType.NONE)
public class Kick extends SubCommand
{
@Override
public boolean onCommand(final PlotPlayer plr, final String[] args) {
public boolean onCommand(final PlotPlayer plr, final String[] args)
{
final Location loc = plr.getLocation();
final Plot plot = MainUtil.getPlot(loc);
if (plot == null) {
return !sendMessage(plr, C.NOT_IN_PLOT);
}
if (plot == null || ((!plot.hasOwner() || !plot.isOwner(plr.getUUID())) && !Permissions.hasPermission(plr, "plots.admin.command.kick"))) {
if (plot == null) { return !sendMessage(plr, C.NOT_IN_PLOT); }
if ((plot == null) || ((!plot.hasOwner() || !plot.isOwner(plr.getUUID())) && !Permissions.hasPermission(plr, "plots.admin.command.kick")))
{
MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
return false;
}
if (args.length != 1) {
if (args.length != 1)
{
MainUtil.sendMessage(plr, "&c/plot kick <player>");
return false;
}
final PlotPlayer player = UUIDHandler.getPlayer(args[0]);
if (player == null) {
if (player == null)
{
MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[0]);
return false;
}
Location otherLoc = player.getLocation();
if (!plr.getLocation().getWorld().equals(otherLoc.getWorld()) || !plot.equals(MainUtil.getPlot(otherLoc))) {
final Location otherLoc = player.getLocation();
if (!plr.getLocation().getWorld().equals(otherLoc.getWorld()) || !plot.equals(MainUtil.getPlot(otherLoc)))
{
MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[0]);
return false;
}

View File

@ -23,7 +23,6 @@ package com.intellectualcrafters.plot.commands;
import java.util.UUID;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.object.OfflinePlotPlayer;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.UUIDHandler;
@ -31,38 +30,40 @@ import com.plotsquared.general.commands.Argument;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "limit",
permission = "plots.limit",
description = "Set or increment player plot claim limits",
aliases = {"setlimit"},
usage = "/plot limit <player> <expression>",
category = CommandCategory.DEBUG
)
public class Limit extends SubCommand {
command = "limit",
permission = "plots.limit",
description = "Set or increment player plot claim limits",
aliases = { "setlimit" },
usage = "/plot limit <player> <expression>",
category = CommandCategory.DEBUG)
public class Limit extends SubCommand
{
public Limit() {
public Limit()
{
requiredArguments = new Argument[] {
Argument.String,
Argument.String
Argument.String,
Argument.String
};
}
@Override
public boolean onCommand(final PlotPlayer plr, final String[] args) {
UUID uuid = UUIDHandler.getUUID(args[0], null);
if (uuid == null) {
public boolean onCommand(final PlotPlayer plr, final String[] args)
{
final UUID uuid = UUIDHandler.getUUID(args[0], null);
if (uuid == null)
{
MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[0]);
return false;
}
OfflinePlotPlayer op = UUIDHandler.getUUIDWrapper().getOfflinePlayer(uuid);
UUIDHandler.getUUIDWrapper().getOfflinePlayer(uuid);
// get current plot limit
// increase
// EconHandler.manager.setPermission(op, perm, value);
// EconHandler.manager.setPermission(op, perm, value);
plr.sendMessage("TODO");
return true;
}
}

View File

@ -19,90 +19,106 @@ import com.intellectualcrafters.plot.util.TaskManager;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "load",
aliases = {"restore"},
category = CommandCategory.ACTIONS,
requiredType = RequiredType.NONE,
description = "Load your plot",
permission = "plots.load",
usage = "/plot restore"
)
public class Load extends SubCommand {
command = "load",
aliases = { "restore" },
category = CommandCategory.ACTIONS,
requiredType = RequiredType.NONE,
description = "Load your plot",
permission = "plots.load",
usage = "/plot restore")
public class Load extends SubCommand
{
@Override
public boolean onCommand(final PlotPlayer plr, final String[] args) {
if (!Settings.METRICS) {
public boolean onCommand(final PlotPlayer plr, final String[] args)
{
if (!Settings.METRICS)
{
MainUtil.sendMessage(plr, "&cPlease enable metrics in order to use this command.\n&7 - Or host it yourself if you don't like the free service");
return false;
}
final String world = plr.getLocation().getWorld();
if (!PS.get().isPlotWorld(world)) {
return !sendMessage(plr, C.NOT_IN_PLOT_WORLD);
}
if (!PS.get().isPlotWorld(world)) { return !sendMessage(plr, C.NOT_IN_PLOT_WORLD); }
final Plot plot = MainUtil.getPlot(plr.getLocation());
if (plot == null) {
return !sendMessage(plr, C.NOT_IN_PLOT);
}
if (!plot.hasOwner()) {
if (plot == null) { return !sendMessage(plr, C.NOT_IN_PLOT); }
if (!plot.hasOwner())
{
MainUtil.sendMessage(plr, C.PLOT_UNOWNED);
return false;
}
if (!plot.isOwner(plr.getUUID()) && !Permissions.hasPermission(plr, "plots.admin.command.load")) {
if (!plot.isOwner(plr.getUUID()) && !Permissions.hasPermission(plr, "plots.admin.command.load"))
{
MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
return false;
}
if (MainUtil.runners.containsKey(plot)) {
if (MainUtil.runners.containsKey(plot))
{
MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER);
return false;
}
if (args.length != 0) {
if (args.length == 1) {
if (args.length != 0)
{
if (args.length == 1)
{
// TODO load save here
List<String> schematics = (List<String>) plr.getMeta("plot_schematics");
if (schematics == null) {
final List<String> schematics = (List<String>) plr.getMeta("plot_schematics");
if (schematics == null)
{
// No schematics found:
MainUtil.sendMessage(plr, C.LOAD_NULL);
return false;
}
String schem;
try {
try
{
schem = schematics.get(Integer.parseInt(args[0]) - 1);
}
catch (Exception e) {
catch (final Exception e)
{
// use /plot load <index>
MainUtil.sendMessage(plr, C.NOT_VALID_NUMBER, "(1, " + schematics.size() + ")");
return false;
}
final URL url;
try {
try
{
url = new URL(Settings.WEB_URL + "saves/" + plr.getUUID() + "/" + schem + ".schematic");
} catch (MalformedURLException e) {
}
catch (final MalformedURLException e)
{
e.printStackTrace();
MainUtil.sendMessage(plr, C.LOAD_FAILED);
return false;
}
MainUtil.runners.put(plot, 1);
MainUtil.sendMessage(plr, C.GENERATING_COMPONENT);
TaskManager.runTaskAsync(new Runnable() {
TaskManager.runTaskAsync(new Runnable()
{
@Override
public void run() {
Schematic schematic = SchematicHandler.manager.getSchematic(url);
if (schematic == null) {
public void run()
{
final Schematic schematic = SchematicHandler.manager.getSchematic(url);
if (schematic == null)
{
MainUtil.runners.remove(plot);
sendMessage(plr, C.SCHEMATIC_INVALID, "non-existent or not in gzip format");
return;
}
SchematicHandler.manager.paste(schematic, plot, 0, 0, new RunnableVal<Boolean>() {
SchematicHandler.manager.paste(schematic, plot, 0, 0, new RunnableVal<Boolean>()
{
@Override
public void run() {
public void run()
{
MainUtil.runners.remove(plot);
if (this.value) {
if (value)
{
sendMessage(plr, C.SCHEMATIC_PASTE_SUCCESS);
}
else {
else
{
sendMessage(plr, C.SCHEMATIC_PASTE_FAILED);
}
}
@ -115,18 +131,22 @@ public class Load extends SubCommand {
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot load <index>");
return false;
}
// list schematics
List<String> schematics = (List<String>) plr.getMeta("plot_schematics");
if (schematics == null) {
final List<String> schematics = (List<String>) plr.getMeta("plot_schematics");
if (schematics == null)
{
MainUtil.runners.put(plot, 1);
TaskManager.runTaskAsync(new Runnable() {
TaskManager.runTaskAsync(new Runnable()
{
@Override
public void run() {
List<String> schematics = SchematicHandler.manager.getSaves(plr.getUUID());
public void run()
{
final List<String> schematics = SchematicHandler.manager.getSaves(plr.getUUID());
MainUtil.runners.remove(plot);
if (schematics == null || schematics.size() == 0) {
if ((schematics == null) || (schematics.size() == 0))
{
MainUtil.sendMessage(plr, C.LOAD_FAILED);
return;
}
@ -135,76 +155,91 @@ public class Load extends SubCommand {
}
});
}
else {
else
{
displaySaves(plr, 0);
}
return true;
}
public void displaySaves(PlotPlayer player, int page) {
List<String> schematics = (List<String>) player.getMeta("plot_schematics");
for (int i = 0; i < Math.min(schematics.size(), 32); i++) {
try {
String schem = schematics.get(i);
String[] split = schem.split("_");
if (split.length != 6) {
public void displaySaves(final PlotPlayer player, final int page)
{
final List<String> schematics = (List<String>) player.getMeta("plot_schematics");
for (int i = 0; i < Math.min(schematics.size(), 32); i++)
{
try
{
final String schem = schematics.get(i);
final String[] split = schem.split("_");
if (split.length != 6)
{
continue;
}
String time = secToTime((System.currentTimeMillis() / 1000) - (Long.parseLong(split[0])));
String world = split[1];
PlotId id = PlotId.fromString(split[2] + ";" + split[3]);
String size = split[4];
String server = split[5].replaceAll(".schematic", "");
final String time = secToTime((System.currentTimeMillis() / 1000) - (Long.parseLong(split[0])));
final String world = split[1];
final PlotId id = PlotId.fromString(split[2] + ";" + split[3]);
final String size = split[4];
final String server = split[5].replaceAll(".schematic", "");
String color;
if (PS.get().IMP.getServerName().replaceAll("[^A-Za-z0-9]", "").equals(server)) {
if (PS.get().IMP.getServerName().replaceAll("[^A-Za-z0-9]", "").equals(server))
{
color = "$4";
}
else {
else
{
color = "$1";
}
MainUtil.sendMessage(player, "$3[$2" + (i + 1) + "$3] " + color + time + "$3 | " + color + world + ";" + id + "$3 | " + color + size + "x" + size);
}
catch (Exception e) {
catch (final Exception e)
{
e.printStackTrace();
}
}
MainUtil.sendMessage(player, C.LOAD_LIST);
}
public String secToTime(long time) {
StringBuilder toreturn = new StringBuilder();
public String secToTime(long time)
{
final StringBuilder toreturn = new StringBuilder();
int years = 0;
int weeks = 0;
int days = 0;
int hours = 0;
int minutes = 0;
if (time>=33868800) {
years = (int) (time/33868800);
time-=years*33868800;
toreturn.append(years+"y ");
if (time >= 33868800)
{
years = (int) (time / 33868800);
time -= years * 33868800;
toreturn.append(years + "y ");
}
if (time>=604800) {
weeks = (int) (time/604800);
time-=weeks*604800;
toreturn.append(weeks+"w ");
if (time >= 604800)
{
weeks = (int) (time / 604800);
time -= weeks * 604800;
toreturn.append(weeks + "w ");
}
if (time>=86400) {
days = (int) (time/86400);
time-=days*86400;
toreturn.append(days+"d ");
if (time >= 86400)
{
days = (int) (time / 86400);
time -= days * 86400;
toreturn.append(days + "d ");
}
if (time>=3600) {
hours = (int) (time/3600);
time-=hours*3600;
toreturn.append(hours+"h ");
if (time >= 3600)
{
hours = (int) (time / 3600);
time -= hours * 3600;
toreturn.append(hours + "h ");
}
if (time>=60) {
minutes = (int) (time/60);
time-=minutes*60;
toreturn.append(minutes+"m ");
if (time >= 60)
{
minutes = (int) (time / 60);
time -= minutes * 60;
toreturn.append(minutes + "m ");
}
if (toreturn.equals("")||time>0){
toreturn.append((time)+"s ");
if (toreturn.equals("") || (time > 0))
{
toreturn.append((time) + "s ");
}
return toreturn.toString().trim();
}

View File

@ -42,22 +42,24 @@ import com.intellectualcrafters.plot.util.UUIDHandler;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "merge",
aliases = {"m"},
description = "Merge the plot you are standing on, with another plot",
permission = "plots.merge",
usage = "/plot merge [direction]",
category = CommandCategory.ACTIONS,
requiredType = RequiredType.NONE
)
public class Merge extends SubCommand {
command = "merge",
aliases = { "m" },
description = "Merge the plot you are standing on, with another plot",
permission = "plots.merge",
usage = "/plot merge [direction]",
category = CommandCategory.ACTIONS,
requiredType = RequiredType.NONE)
public class Merge extends SubCommand
{
public final static String[] values = new String[] { "north", "east", "south", "west" };
public final static String[] aliases = new String[] { "n", "e", "s", "w" };
public static String direction(float yaw) {
public static String direction(float yaw)
{
yaw = yaw / 90;
final int i = Math.round(yaw);
switch (i) {
switch (i)
{
case -4:
case 0:
case 4:
@ -77,25 +79,28 @@ public class Merge extends SubCommand {
}
@Override
public boolean onCommand(final PlotPlayer plr, final String[] args) {
public boolean onCommand(final PlotPlayer plr, final String[] args)
{
final Location loc = plr.getLocationFull();
final Plot plot = MainUtil.getPlot(loc);
if (plot == null) {
return !sendMessage(plr, C.NOT_IN_PLOT);
}
if ((plot == null) || !plot.hasOwner()) {
if (plot == null) { return !sendMessage(plr, C.NOT_IN_PLOT); }
if ((plot == null) || !plot.hasOwner())
{
MainUtil.sendMessage(plr, C.PLOT_UNOWNED);
return false;
}
final boolean admin = Permissions.hasPermission(plr, "plots.admin.command.merge");
if (!plot.isOwner(plr.getUUID()) && !admin) {
if (!plot.isOwner(plr.getUUID()) && !admin)
{
MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
return false;
}
int direction = -1;
if (args.length == 0) {
switch (direction(plr.getLocationFull().getYaw())) {
if (args.length == 0)
{
switch (direction(plr.getLocationFull().getYaw()))
{
case "NORTH":
direction = 0;
break;
@ -110,20 +115,25 @@ public class Merge extends SubCommand {
break;
}
}
else {
if (args[0].equalsIgnoreCase("all")) {
plot.autoMerge(args.length != 2 || !args[1].equalsIgnoreCase("false"));
else
{
if (args[0].equalsIgnoreCase("all"))
{
plot.autoMerge((args.length != 2) || !args[1].equalsIgnoreCase("false"));
MainUtil.sendMessage(plr, C.SUCCESS_MERGE);
return true;
}
for (int i = 0; i < values.length; i++) {
if (args[0].equalsIgnoreCase(values[i]) || args[0].equalsIgnoreCase(aliases[i])) {
for (int i = 0; i < values.length; i++)
{
if (args[0].equalsIgnoreCase(values[i]) || args[0].equalsIgnoreCase(aliases[i]))
{
direction = i;
break;
}
}
}
if (direction == -1) {
if (direction == -1)
{
MainUtil.sendMessage(plr, C.SUBCOMMAND_SET_OPTIONS_HEADER.s() + StringMan.join(values, C.BLOCK_LIST_SEPARATER.s()));
MainUtil.sendMessage(plr, C.DIRECTION.s().replaceAll("%dir%", direction(loc.getYaw())));
return false;
@ -132,7 +142,8 @@ public class Merge extends SubCommand {
PlotId top = MainUtil.getTopPlot(plot).id;
ArrayList<PlotId> selPlots;
final String world = loc.getWorld();
switch (direction) {
switch (direction)
{
case 0: // north = -y
selPlots = MainUtil.getMaxPlotSelectionIds(world, new PlotId(bot.x, bot.y - 1), new PlotId(top.x, top.y));
break;
@ -148,8 +159,9 @@ public class Merge extends SubCommand {
default:
return false;
}
int size = selPlots.size();
if (Permissions.hasPermissionRange(plr, "plots.merge", Settings.MAX_PLOTS) < size) {
final int size = selPlots.size();
if (Permissions.hasPermissionRange(plr, "plots.merge", Settings.MAX_PLOTS) < size)
{
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.merge." + size);
return false;
}
@ -164,20 +176,24 @@ public class Merge extends SubCommand {
final ArrayList<PlotId> plots = MainUtil.getMaxPlotSelectionIds(world, bot, top);
boolean multiMerge = false;
final HashSet<UUID> multiUUID = new HashSet<UUID>();
HashSet<PlotId> multiPlots = new HashSet<>();
final HashSet<PlotId> multiPlots = new HashSet<>();
final UUID u1 = plot.owner;
for (final PlotId myid : plots) {
for (final PlotId myid : plots)
{
final Plot myplot = PS.get().getPlot(world, myid);
if (myplot == null || myplot.owner == null) {
if ((myplot == null) || (myplot.owner == null))
{
MainUtil.sendMessage(plr, C.NO_PERM_MERGE.s().replaceAll("%plot%", myid.toString()));
return false;
}
UUID u2 = myplot.owner;
if (u2.equals(u1)) {
final UUID u2 = myplot.owner;
if (u2.equals(u1))
{
continue;
}
PlotPlayer p2 = UUIDHandler.getPlayer(u2);
if (p2 == null) {
final PlotPlayer p2 = UUIDHandler.getPlayer(u2);
if (p2 == null)
{
MainUtil.sendMessage(plr, C.NO_PERM_MERGE.s().replaceAll("%plot%", myid.toString()));
return false;
}
@ -185,30 +201,40 @@ public class Merge extends SubCommand {
multiPlots.add(myid);
multiUUID.add(u2);
}
if (multiMerge) {
if (!Permissions.hasPermission(plr, C.PERMISSION_MERGE_OTHER)) {
if (multiMerge)
{
if (!Permissions.hasPermission(plr, C.PERMISSION_MERGE_OTHER))
{
MainUtil.sendMessage(plr, C.NO_PERMISSION, C.PERMISSION_MERGE_OTHER.s());
return false;
}
for (final UUID uuid : multiUUID) {
PlotPlayer accepter = UUIDHandler.getPlayer(uuid);
CmdConfirm.addPending(accepter, C.MERGE_REQUEST_CONFIRM.s().replaceAll("%s", plr.getName()), new Runnable() {
for (final UUID uuid : multiUUID)
{
final PlotPlayer accepter = UUIDHandler.getPlayer(uuid);
CmdConfirm.addPending(accepter, C.MERGE_REQUEST_CONFIRM.s().replaceAll("%s", plr.getName()), new Runnable()
{
@Override
public void run() {
PlotPlayer accepter = UUIDHandler.getPlayer(uuid);
public void run()
{
final PlotPlayer accepter = UUIDHandler.getPlayer(uuid);
multiUUID.remove(uuid);
if (multiUUID.size() == 0) {
PlotPlayer pp = UUIDHandler.getPlayer(u1);
if (pp == null) {
if (multiUUID.size() == 0)
{
final PlotPlayer pp = UUIDHandler.getPlayer(u1);
if (pp == null)
{
sendMessage(accepter, C.MERGE_NOT_VALID);
return;
}
final PlotWorld plotWorld = PS.get().getPlotWorld(world);
if ((EconHandler.manager != null) && plotWorld.USE_ECONOMY) {
if ((EconHandler.manager != null) && plotWorld.USE_ECONOMY)
{
double cost = plotWorld.MERGE_PRICE;
cost = plots.size() * cost;
if (cost > 0d) {
if (EconHandler.manager.getMoney(plr) < cost) {
if (cost > 0d)
{
if (EconHandler.manager.getMoney(plr) < cost)
{
sendMessage(plr, C.CANNOT_AFFORD_MERGE, cost + "");
return;
}
@ -217,7 +243,8 @@ public class Merge extends SubCommand {
}
}
final boolean result = EventUtil.manager.callMerge(world, plot, plots);
if (!result) {
if (!result)
{
MainUtil.sendMessage(plr, "&cMerge has been cancelled");
return;
}
@ -233,11 +260,14 @@ public class Merge extends SubCommand {
return true;
}
final PlotWorld plotWorld = PS.get().getPlotWorld(world);
if ((EconHandler.manager != null) && plotWorld.USE_ECONOMY) {
if ((EconHandler.manager != null) && plotWorld.USE_ECONOMY)
{
double cost = plotWorld.MERGE_PRICE;
cost = plots.size() * cost;
if (cost > 0d) {
if (EconHandler.manager.getMoney(plr) < cost) {
if (cost > 0d)
{
if (EconHandler.manager.getMoney(plr) < cost)
{
sendMessage(plr, C.CANNOT_AFFORD_MERGE, cost + "");
return false;
}
@ -246,7 +276,8 @@ public class Merge extends SubCommand {
}
}
final boolean result = EventUtil.manager.callMerge(world, plot, plots);
if (!result) {
if (!result)
{
MainUtil.sendMessage(plr, "&cMerge has been cancelled");
return false;
}

View File

@ -33,68 +33,79 @@ import com.plotsquared.general.commands.Argument;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "move",
description = "Move a plot",
aliases = {"debugmove"},
permission = "plots.move",
category = CommandCategory.ACTIONS,
requiredType = RequiredType.NONE
)
public class Move extends SubCommand {
command = "move",
description = "Move a plot",
aliases = { "debugmove" },
permission = "plots.move",
category = CommandCategory.ACTIONS,
requiredType = RequiredType.NONE)
public class Move extends SubCommand
{
public Move() {
public Move()
{
requiredArguments = new Argument[] {
Argument.PlotID
Argument.PlotID
};
}
@Override
public boolean onCommand(final PlotPlayer plr, final String[] args) {
public boolean onCommand(final PlotPlayer plr, final String[] args)
{
final Location loc = plr.getLocation();
final Plot plot1 = MainUtil.getPlot(loc);
if (plot1 == null) {
return !sendMessage(plr, C.NOT_IN_PLOT);
}
if (!plot1.isAdded(plr.getUUID()) && !Permissions.hasPermission(plr, C.PERMISSION_ADMIN.s())) {
if (plot1 == null) { return !sendMessage(plr, C.NOT_IN_PLOT); }
if (!plot1.isAdded(plr.getUUID()) && !Permissions.hasPermission(plr, C.PERMISSION_ADMIN.s()))
{
MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
return false;
}
final String world = loc.getWorld();
final PlotId plot2id = MainUtil.parseId(args[0]);
if ((plot2id == null)) {
if ((plot2id == null))
{
MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_ID);
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot move <X;Z>");
return false;
}
String world2;
if (args.length == 2) {
PlotWorld other = PS.get().getPlotWorld(args[1]);
PlotWorld current = PS.get().getPlotWorld(loc.getWorld());
if (other == null || current == null || !other.equals(current)) {
if (args.length == 2)
{
final PlotWorld other = PS.get().getPlotWorld(args[1]);
final PlotWorld current = PS.get().getPlotWorld(loc.getWorld());
if ((other == null) || (current == null) || !other.equals(current))
{
MainUtil.sendMessage(plr, C.PLOTWORLD_INCOMPATIBLE);
return false;
}
world2 = other.worldname;
world2 = other.worldname;
}
else {
world2 = world;
else
{
world2 = world;
}
Plot plot2 = MainUtil.getPlot(world2, plot2id);
if (plot1.equals(plot2)) {
final Plot plot2 = MainUtil.getPlot(world2, plot2id);
if (plot1.equals(plot2))
{
MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_ID);
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot move <X;Z>");
return false;
}
if (MainUtil.move(plot1, plot2, new Runnable() {
if (MainUtil.move(plot1, plot2, new Runnable()
{
@Override
public void run() {
public void run()
{
MainUtil.sendMessage(plr, C.MOVE_SUCCESS);
}
})) {
}))
{
return true;
} else {
}
else
{
MainUtil.sendMessage(plr, C.REQUIRES_UNOWNED);
return false;
}

View File

@ -34,53 +34,60 @@ import com.intellectualcrafters.plot.util.MainUtil;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "music",
permission = "plots.music",
description = "Player music in a plot",
usage = "/plot music",
category = CommandCategory.ACTIONS,
requiredType = RequiredType.NONE
)
public class MusicSubcommand extends SubCommand {
command = "music",
permission = "plots.music",
description = "Player music in a plot",
usage = "/plot music",
category = CommandCategory.ACTIONS,
requiredType = RequiredType.NONE)
public class MusicSubcommand extends SubCommand
{
@Override
public boolean onCommand(final PlotPlayer player, final String[] args) {
public boolean onCommand(final PlotPlayer player, final String[] args)
{
final Location loc = player.getLocation();
final Plot plot = MainUtil.getPlot(loc);
if (plot == null) {
return !sendMessage(player, C.NOT_IN_PLOT);
}
if (!plot.isAdded(player.getUUID())) {
if (plot == null) { return !sendMessage(player, C.NOT_IN_PLOT); }
if (!plot.isAdded(player.getUUID()))
{
sendMessage(player, C.NO_PLOT_PERMS);
return true;
}
PlotInventory inv = new PlotInventory(player, 2, "Plot Jukebox") {
public boolean onClick(int index) {
PlotItemStack item = getItem(index);
final PlotInventory inv = new PlotInventory(player, 2, "Plot Jukebox")
{
@Override
public boolean onClick(final int index)
{
final PlotItemStack item = getItem(index);
if (item == null) {
return true;
return true;
}
int id = item.id == 7 ? 0 : item.id;
if (id == 0) {
final int id = item.id == 7 ? 0 : item.id;
if (id == 0)
{
FlagManager.removePlotFlag(plot, "music");
}
else {
else
{
FlagManager.addPlotFlag(plot, new Flag(FlagManager.getFlag("music"), id));
}
return false;
}
};
int index = 0;
for (int i = 2256; i < 2268; i++) {
String name = "&r&6" + BlockManager.manager.getClosestMatchingName(new PlotBlock((short) i, (byte) 0));
String[] lore = {"&r&aClick to play!"};
PlotItemStack item = new PlotItemStack(i, (byte) 0, 1, name, lore);
for (int i = 2256; i < 2268; i++)
{
final String name = "&r&6" + BlockManager.manager.getClosestMatchingName(new PlotBlock((short) i, (byte) 0));
final String[] lore = { "&r&aClick to play!" };
final PlotItemStack item = new PlotItemStack(i, (byte) 0, 1, name, lore);
inv.setItem(index, item);
index++;
}
if (player.getMeta("music") != null) {
String name = "&r&6Cancel music";
String[] lore = {"&r&cClick to cancel!"};
if (player.getMeta("music") != null)
{
final String name = "&r&6Cancel music";
final String[] lore = { "&r&cClick to cancel!" };
inv.setItem(index, new PlotItemStack(7, (short) 0, 1, name, lore));
}
inv.openInventory();

View File

@ -35,128 +35,147 @@ import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.UUIDHandler;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "purge",
permission = "plots.admin",
description = "Purge all plots for a world",
category = CommandCategory.ACTIONS,
requiredType = RequiredType.CONSOLE
)
public class Purge extends SubCommand {
public PlotId getId(final String id) {
try {
command = "purge",
permission = "plots.admin",
description = "Purge all plots for a world",
category = CommandCategory.ACTIONS,
requiredType = RequiredType.CONSOLE)
public class Purge extends SubCommand
{
public PlotId getId(final String id)
{
try
{
final String[] split = id.split(";");
return new PlotId(Integer.parseInt(split[0]), Integer.parseInt(split[1]));
} catch (final Exception e) {
}
catch (final Exception e)
{
return null;
}
}
@Override
public boolean onCommand(final PlotPlayer plr, final String[] args) {
if (args.length == 1) {
public boolean onCommand(final PlotPlayer plr, final String[] args)
{
if (args.length == 1)
{
final String arg = args[0].toLowerCase();
final PlotId id = getId(arg);
if (id != null) {
if (id != null)
{
MainUtil.sendMessage(plr, "/plot purxe x;z &l<world>");
return false;
}
final UUID uuid = UUIDHandler.getUUID(args[0], null);
if (uuid != null) {
if (uuid != null)
{
MainUtil.sendMessage(plr, "/plot purge " + args[0] + " &l<world>");
return false;
}
if (arg.equals("player")) {
if (arg.equals("player"))
{
MainUtil.sendMessage(plr, "/plot purge &l<player> <world>");
return false;
}
if (arg.equals("unowned")) {
if (arg.equals("unowned"))
{
MainUtil.sendMessage(plr, "/plot purge unowned &l<world>");
return false;
}
if (arg.equals("unknown")) {
if (arg.equals("unknown"))
{
MainUtil.sendMessage(plr, "/plot purge unknown &l<world>");
return false;
}
if (arg.equals("all")) {
if (arg.equals("all"))
{
MainUtil.sendMessage(plr, "/plot purge all &l<world>");
return false;
}
MainUtil.sendMessage(plr, C.PURGE_SYNTAX);
return false;
}
if (args.length != 2) {
if (args.length != 2)
{
MainUtil.sendMessage(plr, C.PURGE_SYNTAX);
return false;
}
final String worldname = args[1];
if (!PS.get().getAllPlotsRaw().containsKey(worldname)) {
if (!PS.get().getAllPlotsRaw().containsKey(worldname))
{
MainUtil.sendMessage(plr, "INVALID WORLD");
return false;
}
final String arg = args[0].toLowerCase();
final PlotId id = getId(arg);
if (id != null) {
if (id != null)
{
final HashSet<Integer> ids = new HashSet<Integer>();
final int DBid = DBFunc.getId(MainUtil.getPlot(worldname, id));
if (DBid != Integer.MAX_VALUE) {
if (DBid != Integer.MAX_VALUE)
{
ids.add(DBid);
}
DBFunc.purgeIds(worldname, ids);
return finishPurge(DBid == Integer.MAX_VALUE ? 1 : 0);
}
if (arg.equals("all")) {
if (arg.equals("all"))
{
final Set<PlotId> ids = PS.get().getPlots(worldname).keySet();
int length = ids.size();
if (length == 0) {
return MainUtil.sendMessage(null, "&cNo plots found");
}
final int length = ids.size();
if (length == 0) { return MainUtil.sendMessage(null, "&cNo plots found"); }
DBFunc.purge(worldname, ids);
return finishPurge(length);
}
if (arg.equals("unknown")) {
if (arg.equals("unknown"))
{
final Collection<Plot> plots = PS.get().getPlotsInWorld(worldname);
final Set<PlotId> ids = new HashSet<>();
for (final Plot plot : plots) {
if (plot.owner != null) {
for (final Plot plot : plots)
{
if (plot.owner != null)
{
final String name = UUIDHandler.getName(plot.owner);
if (name == null) {
if (name == null)
{
ids.add(plot.id);
}
}
}
int length = ids.size();
if (length == 0) {
return MainUtil.sendMessage(null, "&cNo plots found");
}
final int length = ids.size();
if (length == 0) { return MainUtil.sendMessage(null, "&cNo plots found"); }
DBFunc.purge(worldname, ids);
return finishPurge(length);
}
if (arg.equals("unowned")) {
if (arg.equals("unowned"))
{
final Collection<Plot> plots = PS.get().getPlotsInWorld(worldname);
final Set<PlotId> ids = new HashSet<>();
for (final Plot plot : plots) {
if (plot.owner == null) {
for (final Plot plot : plots)
{
if (plot.owner == null)
{
ids.add(plot.id);
}
}
int length = ids.size();
if (length == 0) {
return MainUtil.sendMessage(null, "&cNo plots found");
}
final int length = ids.size();
if (length == 0) { return MainUtil.sendMessage(null, "&cNo plots found"); }
DBFunc.purge(worldname, ids);
return finishPurge(length);
}
final UUID uuid = UUIDHandler.getUUID(args[0], null);
if (uuid != null) {
if (uuid != null)
{
final Set<Plot> plots = PS.get().getPlots(worldname, uuid);
final Set<PlotId> ids = new HashSet<>();
for (final Plot plot : plots) {
for (final Plot plot : plots)
{
ids.add(plot.id);
}
int length = ids.size();
final int length = ids.size();
DBFunc.purge(worldname, ids);
return finishPurge(length);
}
@ -164,7 +183,8 @@ public class Purge extends SubCommand {
return false;
}
private boolean finishPurge(final int amount) {
private boolean finishPurge(final int amount)
{
MainUtil.sendMessage(null, C.PURGE_SUCCESS, amount + "");
return false;
}

View File

@ -28,13 +28,11 @@ import java.util.Map.Entry;
import java.util.UUID;
import org.apache.commons.lang.mutable.MutableInt;
import org.bukkit.Bukkit;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.flag.FlagManager;
import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotInventory;
@ -46,47 +44,60 @@ import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.MathMan;
import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.TaskManager;
import com.plotsquared.bukkit.events.PlotRateEvent;
import com.plotsquared.general.commands.Command;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "rate",
permission = "plots.rate",
description = "Rate the plot",
usage = "/plot rate [#|next]",
aliases = {"rt"},
category = CommandCategory.ACTIONS,
requiredType = RequiredType.NONE
)
public class Rate extends SubCommand {
command = "rate",
permission = "plots.rate",
description = "Rate the plot",
usage = "/plot rate [#|next]",
aliases = { "rt" },
category = CommandCategory.ACTIONS,
requiredType = RequiredType.NONE)
public class Rate extends SubCommand
{
@Override
public boolean onCommand(final PlotPlayer player, final String[] args) {
if (args.length == 1) {
if (args[0].equalsIgnoreCase("next")) {
ArrayList<Plot> plots = new ArrayList<>(PS.get().getPlots());
Collections.sort(plots, new Comparator<Plot>() {
public boolean onCommand(final PlotPlayer player, final String[] args)
{
if (args.length == 1)
{
if (args[0].equalsIgnoreCase("next"))
{
final ArrayList<Plot> plots = new ArrayList<>(PS.get().getPlots());
Collections.sort(plots, new Comparator<Plot>()
{
@Override
public int compare(Plot p1, Plot p2) {
public int compare(final Plot p1, final Plot p2)
{
double v1 = 0;
double v2 = 0;
if (p1.getSettings().ratings != null) {
for (Entry<UUID, Rating> entry : p1.getRatings().entrySet()) {
if (p1.getSettings().ratings != null)
{
for (final Entry<UUID, Rating> entry : p1.getRatings().entrySet())
{
v1 -= 11 - entry.getValue().getAverageRating();
}
}
if (p2.getSettings().ratings != null) {
for (Entry<UUID, Rating> entry : p2.getRatings().entrySet()) {
if (p2.getSettings().ratings != null)
{
for (final Entry<UUID, Rating> entry : p2.getRatings().entrySet())
{
v2 -= 11 - entry.getValue().getAverageRating();
}
}
return v2 > v1 ? 1 : -1;
}
});
UUID uuid = player.getUUID();
for (Plot p : plots) {
if ((!Settings.REQUIRE_DONE || p.getSettings().flags.containsKey("done")) && p.isBasePlot() && (p.getSettings().ratings == null || !p.getSettings().ratings.containsKey(uuid)) && !p.isAdded(uuid)) {
final UUID uuid = player.getUUID();
for (final Plot p : plots)
{
if ((!Settings.REQUIRE_DONE || p.getSettings().flags.containsKey("done"))
&& p.isBasePlot()
&& ((p.getSettings().ratings == null) || !p.getSettings().ratings.containsKey(uuid))
&& !p.isAdded(uuid))
{
MainUtil.teleportPlayer(player, player.getLocation(), p);
MainUtil.sendMessage(player, C.RATE_THIS);
return true;
@ -98,40 +109,49 @@ public class Rate extends SubCommand {
}
final Location loc = player.getLocation();
final Plot plot = MainUtil.getPlot(loc);
if (plot == null) {
return !sendMessage(player, C.NOT_IN_PLOT);
}
if (!plot.hasOwner()) {
if (plot == null) { return !sendMessage(player, C.NOT_IN_PLOT); }
if (!plot.hasOwner())
{
sendMessage(player, C.RATING_NOT_OWNED);
return false;
}
if (plot.isOwner(player.getUUID())) {
if (plot.isOwner(player.getUUID()))
{
sendMessage(player, C.RATING_NOT_YOUR_OWN);
return false;
}
if (Settings.REQUIRE_DONE && !plot.getSettings().flags.containsKey("done")) {
if (Settings.REQUIRE_DONE && !plot.getSettings().flags.containsKey("done"))
{
sendMessage(player, C.RATING_NOT_DONE);
return false;
}
if (Settings.RATING_CATEGORIES != null && Settings.RATING_CATEGORIES.size() != 0) {
final Runnable run = new Runnable() {
if ((Settings.RATING_CATEGORIES != null) && (Settings.RATING_CATEGORIES.size() != 0))
{
final Runnable run = new Runnable()
{
@Override
public void run() {
if (plot.getSettings().ratings.containsKey(player.getUUID())) {
public void run()
{
if (plot.getSettings().ratings.containsKey(player.getUUID()))
{
sendMessage(player, C.RATING_ALREADY_EXISTS, plot.getId().toString());
return;
}
final MutableInt index = new MutableInt(0);
final MutableInt rating = new MutableInt(0);
String title = Settings.RATING_CATEGORIES.get(0);
PlotInventory inventory = new PlotInventory(player, 1, title) {
public boolean onClick(int i) {
final String title = Settings.RATING_CATEGORIES.get(0);
final PlotInventory inventory = new PlotInventory(player, 1, title)
{
@Override
public boolean onClick(final int i)
{
rating.add((i + 1) * Math.pow(10, index.intValue()));
index.increment();
if (index.intValue() >= Settings.RATING_CATEGORIES.size()) {
if (index.intValue() >= Settings.RATING_CATEGORIES.size())
{
close();
int rV = rating.intValue();
Rating result = EventUtil.manager.callRating(player, plot, new Rating(rV));
final int rV = rating.intValue();
final Rating result = EventUtil.manager.callRating(player, plot, new Rating(rV));
plot.getSettings().ratings.put(player.getUUID(), result.getAggregate());
DBFunc.setRating(plot, player.getUUID(), rV);
sendMessage(player, C.RATING_APPLIED, plot.getId().toString());
@ -139,9 +159,11 @@ public class Rate extends SubCommand {
return false;
}
setTitle(Settings.RATING_CATEGORIES.get(index.intValue()));
if (Permissions.hasPermission(player, "plots.comment")) {
Command<PlotPlayer> command = MainCommand.getInstance().getCommand("comment");
if (command != null) {
if (Permissions.hasPermission(player, "plots.comment"))
{
final Command<PlotPlayer> command = MainCommand.getInstance().getCommand("comment");
if (command != null)
{
MainUtil.sendMessage(player, C.COMMENT_THIS, command.getUsage().replaceAll("{label}", "plot"));
}
}
@ -160,11 +182,15 @@ public class Rate extends SubCommand {
inventory.openInventory();
}
};
if (plot.getSettings().ratings == null) {
if (!Settings.CACHE_RATINGS) {
TaskManager.runTaskAsync(new Runnable() {
if (plot.getSettings().ratings == null)
{
if (!Settings.CACHE_RATINGS)
{
TaskManager.runTaskAsync(new Runnable()
{
@Override
public void run() {
public void run()
{
plot.getSettings().ratings = DBFunc.getRatings(plot);
run.run();
}
@ -176,43 +202,54 @@ public class Rate extends SubCommand {
run.run();
return true;
}
if (args.length < 1) {
if (args.length < 1)
{
sendMessage(player, C.RATING_NOT_VALID);
return true;
}
final String arg = args[0];
final int rating;
if (MathMan.isInteger(arg) && arg.length() < 3 && arg.length() > 0) {
if (MathMan.isInteger(arg) && (arg.length() < 3) && (arg.length() > 0))
{
rating = Integer.parseInt(arg);
if (rating > 10) {
if (rating > 10)
{
sendMessage(player, C.RATING_NOT_VALID);
return false;
}
}
else {
else
{
sendMessage(player, C.RATING_NOT_VALID);
return false;
}
final UUID uuid = player.getUUID();
final Runnable run = new Runnable() {
final Runnable run = new Runnable()
{
@Override
public void run() {
if (plot.getSettings().ratings.containsKey(uuid)) {
public void run()
{
if (plot.getSettings().ratings.containsKey(uuid))
{
sendMessage(player, C.RATING_ALREADY_EXISTS, plot.getId().toString());
return;
}
Rating result = EventUtil.manager.callRating(player, plot, new Rating(rating));
int resultVal = result.getAggregate();
final Rating result = EventUtil.manager.callRating(player, plot, new Rating(rating));
final int resultVal = result.getAggregate();
plot.getSettings().ratings.put(uuid, resultVal);
DBFunc.setRating(plot, uuid, resultVal);
sendMessage(player, C.RATING_APPLIED, plot.getId().toString());
}
};
if (plot.getSettings().ratings == null) {
if (!Settings.CACHE_RATINGS) {
TaskManager.runTaskAsync(new Runnable() {
if (plot.getSettings().ratings == null)
{
if (!Settings.CACHE_RATINGS)
{
TaskManager.runTaskAsync(new Runnable()
{
@Override
public void run() {
public void run()
{
plot.getSettings().ratings = DBFunc.getRatings(plot);
run.run();
}

View File

@ -35,30 +35,35 @@ import com.plotsquared.general.commands.Argument;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "regenallroads",
description = "Regenerate all roads in the map using the set road schematic",
aliases = {"rgar"},
usage = "/plot regenallroads <world>",
category = CommandCategory.DEBUG,
requiredType = RequiredType.CONSOLE,
permission = "plots.regenallroads"
)
public class RegenAllRoads extends SubCommand {
command = "regenallroads",
description = "Regenerate all roads in the map using the set road schematic",
aliases = { "rgar" },
usage = "/plot regenallroads <world>",
category = CommandCategory.DEBUG,
requiredType = RequiredType.CONSOLE,
permission = "plots.regenallroads")
public class RegenAllRoads extends SubCommand
{
public RegenAllRoads() {
public RegenAllRoads()
{
requiredArguments = new Argument[] {
Argument.String
Argument.String
};
}
@Override
public boolean onCommand(final PlotPlayer plr, final String[] args) {
public boolean onCommand(final PlotPlayer plr, final String[] args)
{
int height = 0;
if (args.length == 2) {
try {
if (args.length == 2)
{
try
{
height = Integer.parseInt(args[1]);
}
catch (NumberFormatException e) {
catch (final NumberFormatException e)
{
MainUtil.sendMessage(plr, C.NOT_VALID_NUMBER, "(0, 256)");
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot regenallroads <world> [height]");
return false;
@ -66,7 +71,8 @@ public class RegenAllRoads extends SubCommand {
}
final String name = args[0];
final PlotManager manager = PS.get().getPlotManager(name);
if ((manager == null) || !(manager instanceof HybridPlotManager)) {
if ((manager == null) || !(manager instanceof HybridPlotManager))
{
MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_WORLD);
return false;
}
@ -76,7 +82,8 @@ public class RegenAllRoads extends SubCommand {
MainUtil.sendMessage(plr, "&6Potential chunks to update: &7" + (chunks.size() * 1024));
MainUtil.sendMessage(plr, "&6Estimated time: &7" + (chunks.size()) + " seconds");
final boolean result = HybridUtils.manager.scheduleRoadUpdate(name, height);
if (!result) {
if (!result)
{
MainUtil.sendMessage(plr, "&cCannot schedule mass schematic update! (Is one already in progress?)");
return false;
}

View File

@ -29,30 +29,35 @@ import com.intellectualcrafters.plot.util.MainUtil;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "reload",
permission = "plots.admin.command.reload",
description = "Reload configurations",
usage = "/plot reload",
category = CommandCategory.INFO
)
public class Reload extends SubCommand {
command = "reload",
permission = "plots.admin.command.reload",
description = "Reload configurations",
usage = "/plot reload",
category = CommandCategory.INFO)
public class Reload extends SubCommand
{
@Override
public boolean onCommand(final PlotPlayer plr, final String[] args) {
try {
public boolean onCommand(final PlotPlayer plr, final String[] args)
{
try
{
// The following won't affect world generation, as that has to be
// loaded during startup unfortunately.
PS.get().config.load(PS.get().configFile);
PS.get().setupConfig();
C.load(PS.get().translationFile);
for (final String pw : PS.get().getPlotWorlds()) {
for (final String pw : PS.get().getPlotWorlds())
{
final PlotWorld plotworld = PS.get().getPlotWorld(pw);
ConfigurationSection section = PS.get().config.getConfigurationSection("worlds." + pw);
final ConfigurationSection section = PS.get().config.getConfigurationSection("worlds." + pw);
plotworld.saveConfiguration(section);
plotworld.loadDefaultConfiguration(section);
}
MainUtil.sendMessage(plr, C.RELOADED_CONFIGS);
} catch (final Exception e) {
}
catch (final Exception e)
{
e.printStackTrace();
MainUtil.sendMessage(plr, C.RELOAD_FAILED);
}

View File

@ -36,73 +36,84 @@ import com.plotsquared.general.commands.Argument;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "remove",
aliases = {"r"},
description = "Remove a player from a plot",
usage = "/plot remove <player>",
category = CommandCategory.ACTIONS,
requiredType = RequiredType.NONE,
permission = "plots.remove"
)
public class Remove extends SubCommand {
command = "remove",
aliases = { "r" },
description = "Remove a player from a plot",
usage = "/plot remove <player>",
category = CommandCategory.ACTIONS,
requiredType = RequiredType.NONE,
permission = "plots.remove")
public class Remove extends SubCommand
{
public Remove() {
public Remove()
{
requiredArguments = new Argument[] {
Argument.PlayerName
Argument.PlayerName
};
}
@Override
public boolean onCommand(final PlotPlayer plr, final String[] args) {
if (args.length != 1) {
public boolean onCommand(final PlotPlayer plr, final String[] args)
{
if (args.length != 1)
{
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot remove <player>");
return true;
}
final Location loc = plr.getLocation();
final Plot plot = MainUtil.getPlot(loc);
if (plot == null) {
return !sendMessage(plr, C.NOT_IN_PLOT);
}
if ((plot == null) || !plot.hasOwner()) {
if (plot == null) { return !sendMessage(plr, C.NOT_IN_PLOT); }
if ((plot == null) || !plot.hasOwner())
{
MainUtil.sendMessage(plr, C.PLOT_UNOWNED);
return false;
}
if (!plot.isOwner(plr.getUUID()) && !Permissions.hasPermission(plr, "plots.admin.command.remove")) {
if (!plot.isOwner(plr.getUUID()) && !Permissions.hasPermission(plr, "plots.admin.command.remove"))
{
MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
return true;
}
int count = 0;
switch (args[0]) {
case "unknown": {
ArrayList<UUID> toRemove = new ArrayList<>();
HashSet<UUID> all = new HashSet<>();
switch (args[0])
{
case "unknown":
{
final ArrayList<UUID> toRemove = new ArrayList<>();
final HashSet<UUID> all = new HashSet<>();
all.addAll(plot.getMembers());
all.addAll(plot.getTrusted());
all.addAll(plot.getDenied());
for (UUID uuid : all) {
if (UUIDHandler.getName(uuid) == null) {
for (final UUID uuid : all)
{
if (UUIDHandler.getName(uuid) == null)
{
toRemove.add(uuid);
count++;
}
}
for (UUID uuid : toRemove) {
for (final UUID uuid : toRemove)
{
plot.removeDenied(uuid);
plot.removeTrusted(uuid);
plot.removeMember(uuid);
}
break;
}
case "*": {
ArrayList<UUID> toRemove = new ArrayList<>();
HashSet<UUID> all = new HashSet<>();
case "*":
{
final ArrayList<UUID> toRemove = new ArrayList<>();
final HashSet<UUID> all = new HashSet<>();
all.addAll(plot.getMembers());
all.addAll(plot.getTrusted());
all.addAll(plot.getDenied());
for (UUID uuid : all) {
for (final UUID uuid : all)
{
toRemove.add(uuid);
count++;
}
for (UUID uuid : toRemove) {
for (final UUID uuid : toRemove)
{
plot.removeDenied(uuid);
plot.removeTrusted(uuid);
plot.removeMember(uuid);
@ -110,33 +121,47 @@ public class Remove extends SubCommand {
break;
}
default:
UUID uuid = UUIDHandler.getUUID(args[0], null);
if (uuid != null) {
if (plot.getTrusted().contains(uuid)) {
if (plot.removeTrusted(uuid)) {
final UUID uuid = UUIDHandler.getUUID(args[0], null);
if (uuid != null)
{
if (plot.getTrusted().contains(uuid))
{
if (plot.removeTrusted(uuid))
{
count++;
}
} else if (plot.getMembers().contains(uuid)) {
if (plot.removeMember(uuid)) {
}
else if (plot.getMembers().contains(uuid))
{
if (plot.removeMember(uuid))
{
count++;
}
} else if (plot.getDenied().contains(uuid)) {
if (plot.removeDenied(uuid)) {
}
else if (plot.getDenied().contains(uuid))
{
if (plot.removeDenied(uuid))
{
count++;
}
}
}
break;
}
if (count == 0) {
if (UUIDHandler.implementation instanceof SQLUUIDHandler) {
if (count == 0)
{
if (UUIDHandler.implementation instanceof SQLUUIDHandler)
{
MainUtil.sendMessage(plr, C.INVALID_PLAYER_WAIT, args[0]);
} else {
}
else
{
MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[0]);
}
return false;
}
else {
else
{
MainUtil.sendMessage(plr, C.REMOVED_PLAYERS, count + "");
}
return true;

View File

@ -2,13 +2,16 @@ package com.intellectualcrafters.plot.commands;
import com.plotsquared.general.commands.CommandCaller;
public enum RequiredType {
public enum RequiredType
{
CONSOLE,
PLAYER,
NONE;
public boolean allows(CommandCaller player) {
switch (this) {
public boolean allows(final CommandCaller player)
{
switch (this)
{
case NONE:
return true;
default:

View File

@ -19,66 +19,73 @@ import com.intellectualcrafters.plot.util.TaskManager;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "save",
aliases = {"backup"},
description = "Save your plot",
category = CommandCategory.ACTIONS,
requiredType = RequiredType.NONE,
permission = "plots.save"
)
public class Save extends SubCommand {
command = "save",
aliases = { "backup" },
description = "Save your plot",
category = CommandCategory.ACTIONS,
requiredType = RequiredType.NONE,
permission = "plots.save")
public class Save extends SubCommand
{
@Override
public boolean onCommand(final PlotPlayer plr, final String[] args) {
if (!Settings.METRICS) {
public boolean onCommand(final PlotPlayer plr, final String[] args)
{
if (!Settings.METRICS)
{
MainUtil.sendMessage(plr, "&cPlease enable metrics in order to use this command.\n&7 - Or host it yourself if you don't like the free service");
return false;
}
final String world = plr.getLocation().getWorld();
if (!PS.get().isPlotWorld(world)) {
return !sendMessage(plr, C.NOT_IN_PLOT_WORLD);
}
if (!PS.get().isPlotWorld(world)) { return !sendMessage(plr, C.NOT_IN_PLOT_WORLD); }
final Plot plot = MainUtil.getPlot(plr.getLocation());
if (plot == null) {
return !sendMessage(plr, C.NOT_IN_PLOT);
}
if (!plot.hasOwner()) {
if (plot == null) { return !sendMessage(plr, C.NOT_IN_PLOT); }
if (!plot.hasOwner())
{
MainUtil.sendMessage(plr, C.PLOT_UNOWNED);
return false;
}
if (!plot.isOwner(plr.getUUID()) && !Permissions.hasPermission(plr, "plots.admin.command.save")) {
if (!plot.isOwner(plr.getUUID()) && !Permissions.hasPermission(plr, "plots.admin.command.save"))
{
MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
return false;
}
if (MainUtil.runners.containsKey(plot)) {
if (MainUtil.runners.containsKey(plot))
{
MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER);
return false;
}
MainUtil.runners.put(plot, 1);
SchematicHandler.manager.getCompoundTag(plot.world, plot.id, new RunnableVal<CompoundTag>() {
SchematicHandler.manager.getCompoundTag(plot.world, plot.id, new RunnableVal<CompoundTag>()
{
@Override
public void run() {
TaskManager.runTaskAsync(new Runnable() {
public void run()
{
TaskManager.runTaskAsync(new Runnable()
{
@Override
public void run() {
String time = (System.currentTimeMillis() / 1000) + "";
String name = PS.get().IMP.getServerName().replaceAll("[^A-Za-z0-9]", "");
int size = plot.getTop().getX() - plot.getBottom().getX() + 1;
PlotId id = plot.id;
String world = plot.world.replaceAll("[^A-Za-z0-9]", "");
String file = time + "_" + world + "_" + id.x + "_" + id.y + "_" + size + "_" + name;
UUID uuid = plr.getUUID();
URL url = SchematicHandler.manager.upload(value, uuid, file);
if (url == null) {
public void run()
{
final String time = (System.currentTimeMillis() / 1000) + "";
final String name = PS.get().IMP.getServerName().replaceAll("[^A-Za-z0-9]", "");
final int size = (plot.getTop().getX() - plot.getBottom().getX()) + 1;
final PlotId id = plot.id;
final String world = plot.world.replaceAll("[^A-Za-z0-9]", "");
final String file = time + "_" + world + "_" + id.x + "_" + id.y + "_" + size + "_" + name;
final UUID uuid = plr.getUUID();
final URL url = SchematicHandler.manager.upload(value, uuid, file);
if (url == null)
{
MainUtil.sendMessage(plr, C.SAVE_FAILED);
MainUtil.runners.remove(plot);
return;
}
MainUtil.sendMessage(plr, C.SAVE_SUCCESS);
List<String> schematics = (List<String>) plr.getMeta("plot_schematics");
if (schematics != null) {
final List<String> schematics = (List<String>) plr.getMeta("plot_schematics");
if (schematics != null)
{
schematics.add(file);
}
MainUtil.runners.remove(plot);

View File

@ -23,7 +23,6 @@ package com.intellectualcrafters.plot.commands;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Map;
import java.util.UUID;
import com.intellectualcrafters.plot.PS;
@ -32,7 +31,6 @@ import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.object.ConsolePlayer;
import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.util.MainUtil;
@ -45,93 +43,107 @@ import com.plotsquared.general.commands.CommandDeclaration;
// TODO Add sub-subcommands
@CommandDeclaration(
command = "schematic",
permission = "plots.schematic",
description = "Schematic command",
aliases = {"sch"},
category = CommandCategory.ACTIONS,
usage = "/plot schematic <arg...>"
)
public class SchematicCmd extends SubCommand {
command = "schematic",
permission = "plots.schematic",
description = "Schematic command",
aliases = { "sch" },
category = CommandCategory.ACTIONS,
usage = "/plot schematic <arg...>")
public class SchematicCmd extends SubCommand
{
private int counter = 0;
private boolean running = false;
private int task;
@Override
public boolean onCommand(final PlotPlayer plr, final String ... args) {
if (args.length < 1) {
public boolean onCommand(final PlotPlayer plr, final String... args)
{
if (args.length < 1)
{
sendMessage(plr, C.SCHEMATIC_MISSING_ARG);
return true;
}
final String arg = args[0].toLowerCase();
final String file;
final Schematic schematic;
switch (arg) {
case "paste": {
if (!Permissions.hasPermission(plr, "plots.schematic.paste")) {
switch (arg)
{
case "paste":
{
if (!Permissions.hasPermission(plr, "plots.schematic.paste"))
{
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.schematic.paste");
return false;
}
if (args.length < 2) {
if (args.length < 2)
{
sendMessage(plr, C.SCHEMATIC_MISSING_ARG);
break;
}
final Location loc = plr.getLocation();
final Plot plot = MainUtil.getPlot(loc);
if (plot == null) {
return !sendMessage(plr, C.NOT_IN_PLOT);
}
if (!plot.hasOwner()) {
if (plot == null) { return !sendMessage(plr, C.NOT_IN_PLOT); }
if (!plot.hasOwner())
{
MainUtil.sendMessage(plr, C.PLOT_UNOWNED);
return false;
}
if (!plot.isOwner(plr.getUUID()) && !Permissions.hasPermission(plr, "plots.admin.command.schematic.paste")) {
if (!plot.isOwner(plr.getUUID()) && !Permissions.hasPermission(plr, "plots.admin.command.schematic.paste"))
{
MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
return false;
}
if (this.running) {
if (running)
{
MainUtil.sendMessage(plr, "&cTask is already running.");
return false;
}
final String location = args[1];
this.running = true;
this.counter = 0;
TaskManager.runTaskAsync(new Runnable() {
running = true;
TaskManager.runTaskAsync(new Runnable()
{
@Override
public void run() {
public void run()
{
Schematic schematic;
if (location.startsWith("url:")) {
try {
UUID uuid = UUID.fromString(location.substring(4));
URL base = new URL(Settings.WEB_URL);
URL url = new URL(base, "uploads/" + uuid + ".schematic");
if (location.startsWith("url:"))
{
try
{
final UUID uuid = UUID.fromString(location.substring(4));
final URL base = new URL(Settings.WEB_URL);
final URL url = new URL(base, "uploads/" + uuid + ".schematic");
schematic = SchematicHandler.manager.getSchematic(url);
}
catch (Exception e) {
catch (final Exception e)
{
e.printStackTrace();
sendMessage(plr, C.SCHEMATIC_INVALID, "non-existent url: " + location);
SchematicCmd.this.running = false;
running = false;
return;
}
}
else {
else
{
schematic = SchematicHandler.manager.getSchematic(location);
}
if (schematic == null) {
SchematicCmd.this.running = false;
if (schematic == null)
{
running = false;
sendMessage(plr, C.SCHEMATIC_INVALID, "non-existent or not in gzip format");
return;
}
SchematicHandler.manager.paste(schematic, plot, 0, 0, new RunnableVal<Boolean>() {
SchematicHandler.manager.paste(schematic, plot, 0, 0, new RunnableVal<Boolean>()
{
@Override
public void run() {
SchematicCmd.this.running = false;
if (this.value) {
public void run()
{
running = false;
if (value)
{
sendMessage(plr, C.SCHEMATIC_PASTE_SUCCESS);
}
else {
else
{
sendMessage(plr, C.SCHEMATIC_PASTE_FAILED);
}
}
@ -140,31 +152,37 @@ public class SchematicCmd extends SubCommand {
});
break;
}
case "test": {
if (!Permissions.hasPermission(plr, "plots.schematic.test")) {
case "test":
{
if (!Permissions.hasPermission(plr, "plots.schematic.test"))
{
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.schematic.test");
return false;
}
if (args.length < 2) {
if (args.length < 2)
{
sendMessage(plr, C.SCHEMATIC_MISSING_ARG);
return false;
}
final Location loc = plr.getLocation();
final Plot plot = MainUtil.getPlot(loc);
if (plot == null) {
if (plot == null)
{
sendMessage(plr, C.NOT_IN_PLOT);
return false;
}
file = args[1];
schematic = SchematicHandler.manager.getSchematic(file);
if (schematic == null) {
if (schematic == null)
{
sendMessage(plr, C.SCHEMATIC_INVALID, "non-existent");
return false;
}
final int l1 = schematic.getSchematicDimension().getX();
final int l2 = schematic.getSchematicDimension().getZ();
final int length = MainUtil.getPlotWidth(loc.getWorld(), plot.id);
if ((l1 < length) || (l2 < length)) {
if ((l1 < length) || (l2 < length))
{
sendMessage(plr, C.SCHEMATIC_INVALID, String.format("Wrong size (x: %s, z: %d) vs %d ", l1, l2, length));
break;
}
@ -172,82 +190,97 @@ public class SchematicCmd extends SubCommand {
break;
}
case "saveall":
case "exportall": {
if (!ConsolePlayer.isConsole(plr)) {
case "exportall":
{
if (!ConsolePlayer.isConsole(plr))
{
MainUtil.sendMessage(plr, C.NOT_CONSOLE);
return false;
}
if (args.length != 2) {
if (args.length != 2)
{
MainUtil.sendMessage(null, "&cNeed world arg. Use &7/plots sch exportall <world>");
return false;
}
Collection<Plot> plots = PS.get().getPlotsInWorld(args[1]);
if ((plots.size() == 0)) {
final Collection<Plot> plots = PS.get().getPlotsInWorld(args[1]);
if ((plots.size() == 0))
{
MainUtil.sendMessage(plr, "&cInvalid world. Use &7/plots sch exportall <world>");
return false;
}
boolean result = SchematicHandler.manager.exportAll(plots, null, null, new Runnable() {
@Override
public void run() {
MainUtil.sendMessage(plr, "&aFinished mass export");
}
});
if (!result) {
MainUtil.sendMessage(plr, "&cTask is already running.");
final boolean result = SchematicHandler.manager.exportAll(plots, null, null, new Runnable()
{
@Override
public void run()
{
MainUtil.sendMessage(plr, "&aFinished mass export");
}
});
if (!result)
{
MainUtil.sendMessage(plr, "&cTask is already running.");
return false;
}
else {
MainUtil.sendMessage(plr, "&3PlotSquared&8->&3Schemaitc&8: &7Mass export has started. This may take a while.");
MainUtil.sendMessage(plr, "&3PlotSquared&8->&3Schemaitc&8: &7Found &c" + plots.size() + "&7 plots...");
else
{
MainUtil.sendMessage(plr, "&3PlotSquared&8->&3Schemaitc&8: &7Mass export has started. This may take a while.");
MainUtil.sendMessage(plr, "&3PlotSquared&8->&3Schemaitc&8: &7Found &c" + plots.size() + "&7 plots...");
}
break;
}
case "export":
case "save": {
if (!Permissions.hasPermission(plr, "plots.schematic.save")) {
case "save":
{
if (!Permissions.hasPermission(plr, "plots.schematic.save"))
{
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.schematic.save");
return false;
}
if (this.running) {
if (running)
{
MainUtil.sendMessage(plr, "&cTask is already running.");
return false;
}
final String world;
final Plot p2;
final Location loc = plr.getLocation();
final Plot plot = MainUtil.getPlot(loc);
if (plot == null) {
return !sendMessage(plr, C.NOT_IN_PLOT);
}
if (!plot.hasOwner()) {
if (plot == null) { return !sendMessage(plr, C.NOT_IN_PLOT); }
if (!plot.hasOwner())
{
MainUtil.sendMessage(plr, C.PLOT_UNOWNED);
return false;
}
if (!plot.isOwner(plr.getUUID()) && !Permissions.hasPermission(plr, "plots.admin.command.schematic.save")) {
if (!plot.isOwner(plr.getUUID()) && !Permissions.hasPermission(plr, "plots.admin.command.schematic.save"))
{
MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
return false;
}
p2 = plot;
world = loc.getWorld();
Collection<Plot> plots = new ArrayList<Plot>();
loc.getWorld();
final Collection<Plot> plots = new ArrayList<Plot>();
plots.add(p2);
boolean result = SchematicHandler.manager.exportAll(plots, null, null, new Runnable() {
@Override
public void run() {
MainUtil.sendMessage(plr, "&aFinished export");
SchematicCmd.this.running = false;
}
});
if (!result) {
MainUtil.sendMessage(plr, "&cTask is already running.");
final boolean result = SchematicHandler.manager.exportAll(plots, null, null, new Runnable()
{
@Override
public void run()
{
MainUtil.sendMessage(plr, "&aFinished export");
running = false;
}
});
if (!result)
{
MainUtil.sendMessage(plr, "&cTask is already running.");
return false;
}
else {
MainUtil.sendMessage(plr, "&7Starting export...");
else
{
MainUtil.sendMessage(plr, "&7Starting export...");
}
break;
}
default: {
default:
{
sendMessage(plr, C.SCHEMATIC_MISSING_ARG);
break;
}

View File

@ -48,81 +48,95 @@ import com.intellectualcrafters.plot.util.UUIDHandler;
import com.plotsquared.general.commands.CommandDeclaration;
import com.plotsquared.listener.PlotListener;
// TODO Make sub-subcommands
@CommandDeclaration(
command = "set",
description = "Set a plot value",
aliases = {"s"},
usage = "/plot set <biome|alias|home|flag> <value...>",
permission = "plots.set",
category = CommandCategory.ACTIONS,
requiredType = RequiredType.NONE
)
public class Set extends SubCommand {
command = "set",
description = "Set a plot value",
aliases = { "s" },
usage = "/plot set <biome|alias|home|flag> <value...>",
permission = "plots.set",
category = CommandCategory.ACTIONS,
requiredType = RequiredType.NONE)
public class Set extends SubCommand
{
public final static String[] values = new String[] { "biome", "alias", "home", "flag" };
public final static String[] aliases = new String[] { "b", "w", "wf", "f", "a", "h", "fl" };
@Override
public boolean onCommand(final PlotPlayer plr, final String ... args) {
public boolean onCommand(final PlotPlayer plr, final String... args)
{
final Location loc = plr.getLocation();
final Plot plot = MainUtil.getPlot(loc);
if (plot == null) {
return !sendMessage(plr, C.NOT_IN_PLOT);
}
if (!plot.hasOwner()) {
if (plot == null) { return !sendMessage(plr, C.NOT_IN_PLOT); }
if (!plot.hasOwner())
{
sendMessage(plr, C.PLOT_NOT_CLAIMED);
return false;
}
if (!plot.isOwner(plr.getUUID())) {
if (!Permissions.hasPermission(plr, "plots.set.other")) {
if (!plot.isOwner(plr.getUUID()))
{
if (!Permissions.hasPermission(plr, "plots.set.other"))
{
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.set.other");
return false;
}
}
if (args.length < 1) {
PlotManager manager = PS.get().getPlotManager(loc.getWorld());
ArrayList<String> newValues = new ArrayList<String>();
if (args.length < 1)
{
final PlotManager manager = PS.get().getPlotManager(loc.getWorld());
final ArrayList<String> newValues = new ArrayList<String>();
newValues.addAll(Arrays.asList(values));
newValues.addAll(Arrays.asList(manager.getPlotComponents(PS.get().getPlotWorld(loc.getWorld()), plot.id)));
MainUtil.sendMessage(plr, C.SUBCOMMAND_SET_OPTIONS_HEADER.s() + getArgumentList(newValues));
return false;
}
for (int i = 0; i < aliases.length; i++) {
if (aliases[i].equalsIgnoreCase(args[0])) {
for (int i = 0; i < aliases.length; i++)
{
if (aliases[i].equalsIgnoreCase(args[0]))
{
args[0] = values[i];
break;
}
}
if (args[0].equalsIgnoreCase("flag")) {
if (args.length < 2) {
if (args[0].equalsIgnoreCase("flag"))
{
if (args.length < 2)
{
final String message = StringMan.replaceFromMap("$2" + (StringMan.join(FlagManager.getFlags(plr), "$1, $2")), C.replacements);
// final String message = StringMan.join(FlagManager.getFlags(plr), "&c, &6");
MainUtil.sendMessage(plr, C.NEED_KEY.s().replaceAll("%values%", message));
return false;
}
AbstractFlag af;
try {
try
{
af = FlagManager.getFlag(args[1].toLowerCase());
} catch (final Exception e) {
}
catch (final Exception e)
{
af = new AbstractFlag(args[1].toLowerCase());
}
if (!FlagManager.getFlags().contains(af) || FlagManager.isReserved(af.getKey())) {
if (!FlagManager.getFlags().contains(af) || FlagManager.isReserved(af.getKey()))
{
MainUtil.sendMessage(plr, C.NOT_VALID_FLAG);
return false;
}
if (!Permissions.hasPermission(plr, "plots.set.flag." + args[1].toLowerCase())) {
if (!Permissions.hasPermission(plr, "plots.set.flag." + args[1].toLowerCase()))
{
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.set.flag." + args[1].toLowerCase());
return false;
}
if (args.length == 2) {
if (FlagManager.getPlotFlagAbs(plot, args[1].toLowerCase()) == null) {
if (args.length == 2)
{
if (FlagManager.getPlotFlagAbs(plot, args[1].toLowerCase()) == null)
{
MainUtil.sendMessage(plr, C.FLAG_NOT_IN_PLOT);
return false;
}
final boolean result = FlagManager.removePlotFlag(plot, args[1].toLowerCase());
if (!result) {
if (!result)
{
MainUtil.sendMessage(plr, C.FLAG_NOT_REMOVED);
return false;
}
@ -130,34 +144,43 @@ public class Set extends SubCommand {
PlotListener.plotEntry(plr, plot);
return true;
}
try {
try
{
final String value = StringMan.join(Arrays.copyOfRange(args, 2, args.length), " ");
final Object parsed_value = af.parseValueRaw(value);
if (parsed_value == null) {
if (parsed_value == null)
{
MainUtil.sendMessage(plr, af.getValueDesc());
return false;
}
final Flag flag = new Flag(FlagManager.getFlag(args[1].toLowerCase(), true), parsed_value);
final boolean result = FlagManager.addPlotFlag(plot, flag);
if (!result) {
if (!result)
{
MainUtil.sendMessage(plr, C.FLAG_NOT_ADDED);
return false;
}
MainUtil.sendMessage(plr, C.FLAG_ADDED);
PlotListener.plotEntry(plr, plot);
return true;
} catch (final Exception e) {
}
catch (final Exception e)
{
MainUtil.sendMessage(plr, "&c" + e.getMessage());
return false;
}
}
if (args[0].equalsIgnoreCase("home")) {
if (!Permissions.hasPermission(plr, "plots.set.home")) {
if (args[0].equalsIgnoreCase("home"))
{
if (!Permissions.hasPermission(plr, "plots.set.home"))
{
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.set.home");
return false;
}
if (args.length > 1) {
if (args[1].equalsIgnoreCase("none")) {
if (args.length > 1)
{
if (args[1].equalsIgnoreCase("none"))
{
plot.setHome(null);
return true;
}
@ -172,50 +195,62 @@ public class Set extends SubCommand {
plot.setHome(blockloc);
return MainUtil.sendMessage(plr, C.POSITION_SET);
}
if (args[0].equalsIgnoreCase("desc")) {
if (!Permissions.hasPermission(plr, "plots.set.desc")) {
if (args[0].equalsIgnoreCase("desc"))
{
if (!Permissions.hasPermission(plr, "plots.set.desc"))
{
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.set.desc");
return false;
}
if (args.length < 2) {
if (args.length < 2)
{
MainUtil.sendMessage(plr, C.MISSING_DESC);
return false;
}
final StringBuilder desc = new StringBuilder();
for (int i = 1; i < args.length; i++) {
for (int i = 1; i < args.length; i++)
{
desc.append(args[i]).append(" ");
}
String descValue = desc.substring(0, desc.length() - 1);
final String descValue = desc.substring(0, desc.length() - 1);
Flag flag = new Flag(FlagManager.getFlag("description"), descValue);
final Flag flag = new Flag(FlagManager.getFlag("description"), descValue);
final boolean result = FlagManager.addPlotFlag(plot, flag);
if (!result) {
if (!result)
{
MainUtil.sendMessage(plr, C.FLAG_NOT_ADDED);
return false;
}
MainUtil.sendMessage(plr, C.DESC_SET);
return true;
}
if (args[0].equalsIgnoreCase("alias")) {
if (!Permissions.hasPermission(plr, "plots.set.alias")) {
if (args[0].equalsIgnoreCase("alias"))
{
if (!Permissions.hasPermission(plr, "plots.set.alias"))
{
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.set.alias");
return false;
}
if (args.length < 2) {
if (args.length < 2)
{
MainUtil.sendMessage(plr, C.MISSING_ALIAS);
return false;
}
final String alias = args[1];
if (alias.length() >= 50) {
if (alias.length() >= 50)
{
MainUtil.sendMessage(plr, C.ALIAS_TOO_LONG);
return false;
}
for (final Plot p : PS.get().getPlotsInWorld(plr.getLocation().getWorld())) {
if (p.getSettings().getAlias().equalsIgnoreCase(alias)) {
for (final Plot p : PS.get().getPlotsInWorld(plr.getLocation().getWorld()))
{
if (p.getSettings().getAlias().equalsIgnoreCase(alias))
{
MainUtil.sendMessage(plr, C.ALIAS_IS_TAKEN);
return false;
}
if (UUIDHandler.nameExists(new StringWrapper(alias))) {
if (UUIDHandler.nameExists(new StringWrapper(alias)))
{
MainUtil.sendMessage(plr, C.ALIAS_IS_TAKEN);
return false;
}
@ -224,39 +259,48 @@ public class Set extends SubCommand {
MainUtil.sendMessage(plr, C.ALIAS_SET_TO.s().replaceAll("%alias%", alias));
return true;
}
if (args[0].equalsIgnoreCase("biome")) {
if (!Permissions.hasPermission(plr, "plots.set.biome")) {
if (args[0].equalsIgnoreCase("biome"))
{
if (!Permissions.hasPermission(plr, "plots.set.biome"))
{
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.set.biome");
return false;
}
if (args.length < 2) {
if (args.length < 2)
{
MainUtil.sendMessage(plr, C.NEED_BIOME);
return true;
}
if (args[1].length() < 2) {
if (args[1].length() < 2)
{
sendMessage(plr, C.NAME_LITTLE, "Biome", args[1].length() + "", "2");
return true;
}
final int biome = BlockManager.manager.getBiomeFromString(args[1]);
if (biome == -1) {
if (biome == -1)
{
MainUtil.sendMessage(plr, getBiomeList(BlockManager.manager.getBiomeList()));
return true;
}
if (MainUtil.runners.containsKey(plot)) {
if (MainUtil.runners.containsKey(plot))
{
MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER);
return false;
}
MainUtil.runners.put(plot, 1);
plot.setBiome(args[1].toUpperCase(), new Runnable() {
plot.setBiome(args[1].toUpperCase(), new Runnable()
{
@Override
public void run() {
public void run()
{
MainUtil.runners.remove(plot);
MainUtil.sendMessage(plr, C.BIOME_SET_TO.s() + args[1].toLowerCase());
}
});
return true;
}
if (args[0].equalsIgnoreCase("limit")) {
if (args[0].equalsIgnoreCase("limit"))
{
// /plot set limit Empire92 +1
return true;
}
@ -266,69 +310,89 @@ public class Set extends SubCommand {
final PlotManager manager = PS.get().getPlotManager(world);
final String[] components = manager.getPlotComponents(plotworld, plot.id);
boolean allowUnsafe = DebugAllowUnsafe.unsafeAllowed.contains(plr.getUUID());
final boolean allowUnsafe = DebugAllowUnsafe.unsafeAllowed.contains(plr.getUUID());
for (final String component : components) {
if (component.equalsIgnoreCase(args[0])) {
if (!Permissions.hasPermission(plr, "plots.set." + component)) {
for (final String component : components)
{
if (component.equalsIgnoreCase(args[0]))
{
if (!Permissions.hasPermission(plr, "plots.set." + component))
{
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.set." + component);
return false;
}
PlotBlock[] blocks;
try {
if (args.length < 2) {
try
{
if (args.length < 2)
{
MainUtil.sendMessage(plr, C.NEED_BLOCK);
return true;
}
String[] split = args[1].split(",");
final String[] split = args[1].split(",");
blocks = Configuration.BLOCKLIST.parseString(args[1]);
for (int i = 0; i < blocks.length; i++) {
PlotBlock block = blocks[i];
if (block == null) {
for (int i = 0; i < blocks.length; i++)
{
final PlotBlock block = blocks[i];
if (block == null)
{
MainUtil.sendMessage(plr, C.NOT_VALID_BLOCK, split[i]);
String name;
if (split[i].contains("%")) {
if (split[i].contains("%"))
{
name = split[i].split("%")[1];
}
else {
else
{
name = split[i];
}
StringComparison<PlotBlock>.ComparisonResult match = BlockManager.manager.getClosestBlock(name);
if (match != null) {
final StringComparison<PlotBlock>.ComparisonResult match = BlockManager.manager.getClosestBlock(name);
if (match != null)
{
name = BlockManager.manager.getClosestMatchingName(match.best);
if (name != null) {
if (name != null)
{
MainUtil.sendMessage(plr, C.DID_YOU_MEAN, name.toLowerCase());
}
}
return false;
}
else if (!allowUnsafe && !BlockManager.manager.isBlockSolid(block)) {
else if (!allowUnsafe && !BlockManager.manager.isBlockSolid(block))
{
MainUtil.sendMessage(plr, C.NOT_ALLOWED_BLOCK, block.toString());
return false;
}
}
if (!allowUnsafe) {
for (PlotBlock block : blocks) {
if (!BlockManager.manager.isBlockSolid(block)) {
if (!allowUnsafe)
{
for (final PlotBlock block : blocks)
{
if (!BlockManager.manager.isBlockSolid(block))
{
MainUtil.sendMessage(plr, C.NOT_ALLOWED_BLOCK, block.toString());
return false;
}
}
}
} catch (final Exception e2) {
}
catch (final Exception e2)
{
MainUtil.sendMessage(plr, C.NOT_VALID_BLOCK, args[1]);
return false;
}
if (MainUtil.runners.containsKey(plot)) {
if (MainUtil.runners.containsKey(plot))
{
MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER);
return false;
}
MainUtil.runners.put(plot, 1);
manager.setComponent(plotworld, plot.id, component, blocks);
MainUtil.sendMessage(plr, C.GENERATING_COMPONENT);
SetBlockQueue.addNotify(new Runnable() {
SetBlockQueue.addNotify(new Runnable()
{
@Override
public void run() {
public void run()
{
MainUtil.runners.remove(plot);
}
});
@ -337,15 +401,21 @@ public class Set extends SubCommand {
}
{
AbstractFlag af;
try {
try
{
af = new AbstractFlag(args[0].toLowerCase());
} catch (final Exception e) {
}
catch (final Exception e)
{
af = new AbstractFlag("");
}
if (FlagManager.getFlags().contains(af)) {
if (FlagManager.getFlags().contains(af))
{
final StringBuilder a = new StringBuilder();
if (args.length > 1) {
for (int x = 1; x < args.length; x++) {
if (args.length > 1)
{
for (int x = 1; x < args.length; x++)
{
a.append(" ").append(args[x]);
}
}
@ -353,29 +423,34 @@ public class Set extends SubCommand {
return true;
}
}
ArrayList<String> newValues = new ArrayList<String>();
final ArrayList<String> newValues = new ArrayList<String>();
newValues.addAll(Arrays.asList(values));
newValues.addAll(Arrays.asList(manager.getPlotComponents(PS.get().getPlotWorld(loc.getWorld()), plot.id)));
MainUtil.sendMessage(plr, C.SUBCOMMAND_SET_OPTIONS_HEADER.s() + getArgumentList(newValues));
return false;
}
private String getString(final String s) {
private String getString(final String s)
{
return StringMan.replaceAll(C.BLOCK_LIST_ITEM.s(), "%mat%", s);
}
private String getArgumentList(final List<String> newValues) {
private String getArgumentList(final List<String> newValues)
{
final StringBuilder builder = new StringBuilder();
for (final String s : newValues) {
for (final String s : newValues)
{
builder.append(getString(s));
}
return builder.toString().substring(1, builder.toString().length() - 1);
}
private String getBiomeList(final String[] biomes) {
private String getBiomeList(final String[] biomes)
{
final StringBuilder builder = new StringBuilder();
builder.append(C.NEED_BIOME.s());
for (final String b : biomes) {
for (final String b : biomes)
{
builder.append(getString(b));
}
return builder.toString().substring(1, builder.toString().length() - 1);

View File

@ -38,82 +38,98 @@ import com.plotsquared.general.commands.Argument;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "setowner",
permission = "plots.set.owner",
description = "Set the plot owner",
usage = "/plot setowner <player>",
aliases = {"so"},
category = CommandCategory.ACTIONS,
requiredType = RequiredType.NONE
)
public class SetOwner extends SubCommand {
command = "setowner",
permission = "plots.set.owner",
description = "Set the plot owner",
usage = "/plot setowner <player>",
aliases = { "so" },
category = CommandCategory.ACTIONS,
requiredType = RequiredType.NONE)
public class SetOwner extends SubCommand
{
public SetOwner() {
public SetOwner()
{
requiredArguments = new Argument[] {
Argument.PlayerName
Argument.PlayerName
};
}
private UUID getUUID(final String string) {
private UUID getUUID(final String string)
{
return UUIDHandler.getUUID(string, null);
}
@Override
public boolean onCommand(final PlotPlayer plr, final String[] args) {
public boolean onCommand(final PlotPlayer plr, final String[] args)
{
final Location loc = plr.getLocation();
final Plot plot = MainUtil.getPlot(loc);
if ((plot == null) || (plot.owner == null && !Permissions.hasPermission(plr, "plots.admin.command.setowner"))) {
if ((plot == null) || ((plot.owner == null) && !Permissions.hasPermission(plr, "plots.admin.command.setowner")))
{
MainUtil.sendMessage(plr, C.NOT_IN_PLOT);
return false;
}
if (args.length < 1) {
if (args.length < 1)
{
MainUtil.sendMessage(plr, C.NEED_USER);
return false;
}
final PlotId bot = MainUtil.getBottomPlot(plot).id;
final PlotId top = MainUtil.getTopPlot(plot).id;
final ArrayList<PlotId> plots = MainUtil.getPlotSelectionIds(bot, top);
PlotPlayer other = UUIDHandler.getPlayer(args[0]);
if (other == null) {
if (!Permissions.hasPermission(plr, "plots.admin.command.setowner")) {
MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[0]);
return false;
}
final PlotPlayer other = UUIDHandler.getPlayer(args[0]);
if (other == null)
{
if (!Permissions.hasPermission(plr, "plots.admin.command.setowner"))
{
MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[0]);
return false;
}
}
else {
if (!Permissions.hasPermission(plr, "plots.admin.command.setowner")) {
int size = plots.size();
else
{
if (!Permissions.hasPermission(plr, "plots.admin.command.setowner"))
{
final int size = plots.size();
final int currentPlots = (Settings.GLOBAL_LIMIT ? MainUtil.getPlayerPlotCount(other) : MainUtil.getPlayerPlotCount(loc.getWorld(), other)) + size;
if (currentPlots > MainUtil.getAllowedPlots(other)) {
if (currentPlots > MainUtil.getAllowedPlots(other))
{
sendMessage(plr, C.CANT_TRANSFER_MORE_PLOTS);
return false;
}
}
}
}
if (!plot.isOwner(plr.getUUID())) {
if (!Permissions.hasPermission(plr, "plots.admin.command.setowner")) {
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.admin.command.setowner");
return false;
}
if (!plot.isOwner(plr.getUUID()))
{
if (!Permissions.hasPermission(plr, "plots.admin.command.setowner"))
{
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.admin.command.setowner");
return false;
}
}
final String world = loc.getWorld();
final UUID uuid = getUUID(args[0]);
if (uuid == null) {
if (uuid == null)
{
MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[0]);
return false;
}
for (final PlotId id : plots) {
for (final PlotId id : plots)
{
Plot current = PS.get().getPlot(world, id);
if (current == null) {
if (current == null)
{
current = MainUtil.getPlot(world, id);
current.owner = uuid;
current.create();
}
else {
else
{
current.owner = uuid;
DBFunc.setOwner(current, current.owner);
}
@ -121,8 +137,9 @@ public class SetOwner extends SubCommand {
}
MainUtil.setSign(args[0], plot);
MainUtil.sendMessage(plr, C.SET_OWNER);
if (other != null) {
MainUtil.sendMessage(other, C.NOW_OWNER, plot.world + ";" + plot.id);
if (other != null)
{
MainUtil.sendMessage(other, C.NOW_OWNER, plot.world + ";" + plot.id);
}
return true;
}

View File

@ -39,26 +39,31 @@ import com.intellectualcrafters.plot.util.StringMan;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "setup",
permission = "plots.admin.command.setup",
description = "Setup wizard for plot worlds",
usage = "/plot setup",
aliases = {"create"},
category = CommandCategory.ACTIONS
)
public class Setup extends SubCommand {
command = "setup",
permission = "plots.admin.command.setup",
description = "Setup wizard for plot worlds",
usage = "/plot setup",
aliases = { "create" },
category = CommandCategory.ACTIONS)
public class Setup extends SubCommand
{
public void displayGenerators(PlotPlayer plr) {
StringBuffer message = new StringBuffer();
public void displayGenerators(final PlotPlayer plr)
{
final StringBuffer message = new StringBuffer();
message.append("&6What generator do you want?");
for (Entry<String, PlotGenerator<?>> entry : SetupUtils.generators.entrySet()) {
if (entry.getKey().equals("PlotSquared")) {
for (final Entry<String, PlotGenerator<?>> entry : SetupUtils.generators.entrySet())
{
if (entry.getKey().equals("PlotSquared"))
{
message.append("\n&8 - &2" + entry.getKey() + " (Default Generator)");
}
else if (entry.getValue().isFull()) {
else if (entry.getValue().isFull())
{
message.append("\n&8 - &7" + entry.getKey() + " (Plot Generator)");
}
else {
else
{
message.append("\n&8 - &7" + entry.getKey() + " (Unknown structure)");
}
}
@ -66,10 +71,12 @@ public class Setup extends SubCommand {
}
@Override
public boolean onCommand(final PlotPlayer plr, final String[] args) {
public boolean onCommand(final PlotPlayer plr, final String[] args)
{
// going through setup
String name = plr.getName();
if (!SetupUtils.setupMap.containsKey(name)) {
final String name = plr.getName();
if (!SetupUtils.setupMap.containsKey(name))
{
final SetupObject object = new SetupObject();
SetupUtils.setupMap.put(name, object);
SetupUtils.manager.updateGenerators();
@ -77,29 +84,38 @@ public class Setup extends SubCommand {
displayGenerators(plr);
return false;
}
if (args.length == 1) {
if (args[0].equalsIgnoreCase("cancel")) {
if (args.length == 1)
{
if (args[0].equalsIgnoreCase("cancel"))
{
SetupUtils.setupMap.remove(name);
MainUtil.sendMessage(plr, "&aCancelled setup");
return false;
}
if (args[0].equalsIgnoreCase("back")) {
if (args[0].equalsIgnoreCase("back"))
{
final SetupObject object = SetupUtils.setupMap.get(name);
if (object.setup_index > 0) {
if (object.setup_index > 0)
{
object.setup_index--;
final ConfigurationNode node = object.step[object.setup_index];
sendMessage(plr, C.SETUP_STEP, object.setup_index + 1 + "", node.getDescription(), node.getType().getType(), node.getDefaultValue() + "");
return false;
} else if (object.current > 0) {
}
else if (object.current > 0)
{
object.current--;
}
}
}
final SetupObject object = SetupUtils.setupMap.get(name);
final int index = object.current;
switch (index) {
case 0: { // choose generator
if ((args.length != 1) || !SetupUtils.generators.containsKey(args[0])) {
switch (index)
{
case 0:
{ // choose generator
if ((args.length != 1) || !SetupUtils.generators.containsKey(args[0]))
{
final String prefix = "\n&8 - &7";
MainUtil.sendMessage(plr, "&cYou must choose a generator!" + prefix + StringMan.join(SetupUtils.generators.keySet(), prefix).replaceAll("PlotSquared", "&2PlotSquared"));
sendMessage(plr, C.SETUP_INIT);
@ -111,40 +127,50 @@ public class Setup extends SubCommand {
MainUtil.sendMessage(plr, "&6What world type do you want?" + "\n&8 - &2DEFAULT&8 - &7Standard plot generation" + "\n&8 - &7AUGMENTED&8 - &7Plot generation with terrain" + partial);
break;
}
case 1: { // choose world type
List<String> allTypes = Arrays.asList(new String[] { "default", "augmented", "partial"});
List<String> allDesc = Arrays.asList(new String[] { "Standard plot generation", "Plot generation with vanilla terrain", "Vanilla with clusters of plots"});
ArrayList<String> types = new ArrayList<>();
if (SetupUtils.generators.get(object.setupGenerator).isFull()) {
case 1:
{ // choose world type
final List<String> allTypes = Arrays.asList(new String[] { "default", "augmented", "partial" });
final List<String> allDesc = Arrays.asList(new String[] { "Standard plot generation", "Plot generation with vanilla terrain", "Vanilla with clusters of plots" });
final ArrayList<String> types = new ArrayList<>();
if (SetupUtils.generators.get(object.setupGenerator).isFull())
{
types.add("default");
}
types.add("augmented");
if (Settings.ENABLE_CLUSTERS) {
if (Settings.ENABLE_CLUSTERS)
{
types.add("partial");
}
if ((args.length != 1) || !types.contains(args[0].toLowerCase())) {
if ((args.length != 1) || !types.contains(args[0].toLowerCase()))
{
MainUtil.sendMessage(plr, "&cYou must choose a world type!");
for (String type : types) {
int i = allTypes.indexOf(type);
if (type.equals("default")) {
for (final String type : types)
{
final int i = allTypes.indexOf(type);
if (type.equals("default"))
{
MainUtil.sendMessage(plr, "&8 - &2" + type + " &8-&7 " + allDesc.get(i));
}
else {
else
{
MainUtil.sendMessage(plr, "&8 - &7" + type + " &8-&7 " + allDesc.get(i));
}
}
return false;
}
object.type = allTypes.indexOf(args[0].toLowerCase());
PlotGenerator<?> gen = SetupUtils.generators.get(object.setupGenerator);
if (object.type == 0) {
final PlotGenerator<?> gen = SetupUtils.generators.get(object.setupGenerator);
if (object.type == 0)
{
object.current++;
if (object.step == null) {
if (object.step == null)
{
object.plotManager = object.setupGenerator;
object.step = SetupUtils.generators.get(object.plotManager).getNewPlotWorld(null).getSettingNodes();
SetupUtils.generators.get(object.plotManager).processSetup(object);
}
if (object.step.length == 0) {
if (object.step.length == 0)
{
object.current = 4;
MainUtil.sendMessage(plr, "&6What do you want your world to be called?");
object.setup_index = 0;
@ -152,93 +178,125 @@ public class Setup extends SubCommand {
}
final ConfigurationNode step = object.step[object.setup_index];
sendMessage(plr, C.SETUP_STEP, object.setup_index + 1 + "", step.getDescription(), step.getType().getType(), step.getDefaultValue() + "");
} else {
if (gen.isFull()) {
}
else
{
if (gen.isFull())
{
object.plotManager = object.setupGenerator;
object.setupGenerator = null;
object.step = SetupUtils.generators.get(object.plotManager).getNewPlotWorld(null).getSettingNodes();
SetupUtils.generators.get(object.plotManager).processSetup(object);
}
else {
else
{
object.plotManager = "PlotSquared";
MainUtil.sendMessage(plr, "&c[WARNING] The specified generator does not identify as BukkitPlotGenerator");
MainUtil.sendMessage(plr, "&7 - You may need to manually configure the other plugin");
object.step = SetupUtils.generators.get(object.plotManager).getNewPlotWorld(null).getSettingNodes();
}
MainUtil.sendMessage(plr, "&6What terrain would you like in plots?" + "\n&8 - &2NONE&8 - &7No terrain at all" + "\n&8 - &7ORE&8 - &7Just some ore veins and trees" + "\n&8 - &7ROAD&8 - &7Terrain seperated by roads" + "\n&8 - &7ALL&8 - &7Entirely vanilla generation");
MainUtil.sendMessage(plr, "&6What terrain would you like in plots?"
+ "\n&8 - &2NONE&8 - &7No terrain at all"
+ "\n&8 - &7ORE&8 - &7Just some ore veins and trees"
+ "\n&8 - &7ROAD&8 - &7Terrain seperated by roads"
+ "\n&8 - &7ALL&8 - &7Entirely vanilla generation");
}
object.current++;
break;
}
case 2: { // Choose terrain
case 2:
{ // Choose terrain
final List<String> terrain = Arrays.asList(new String[] { "none", "ore", "road", "all" });
if ((args.length != 1) || !terrain.contains(args[0].toLowerCase())) {
MainUtil.sendMessage(plr, "&cYou must choose the terrain!" + "\n&8 - &2NONE&8 - &7No terrain at all" + "\n&8 - &7ORE&8 - &7Just some ore veins and trees" + "\n&8 - &7ROAD&8 - &7Terrain seperated by roads" + "\n&8 - &7ALL&8 - &7Entirely vanilla generation");
if ((args.length != 1) || !terrain.contains(args[0].toLowerCase()))
{
MainUtil.sendMessage(plr, "&cYou must choose the terrain!"
+ "\n&8 - &2NONE&8 - &7No terrain at all"
+ "\n&8 - &7ORE&8 - &7Just some ore veins and trees"
+ "\n&8 - &7ROAD&8 - &7Terrain seperated by roads"
+ "\n&8 - &7ALL&8 - &7Entirely vanilla generation");
return false;
}
object.terrain = terrain.indexOf(args[0].toLowerCase());
object.current++;
if (object.step == null) {
if (object.step == null)
{
object.step = SetupUtils.generators.get(object.plotManager).getNewPlotWorld(null).getSettingNodes();
}
final ConfigurationNode step = object.step[object.setup_index];
sendMessage(plr, C.SETUP_STEP, object.setup_index + 1 + "", step.getDescription(), step.getType().getType(), step.getDefaultValue() + "");
break;
}
case 3: { // world setup
if (object.setup_index == object.step.length) {
case 3:
{ // world setup
if (object.setup_index == object.step.length)
{
MainUtil.sendMessage(plr, "&6What do you want your world to be called?");
object.setup_index = 0;
object.current++;
return true;
}
ConfigurationNode step = object.step[object.setup_index];
if (args.length < 1) {
if (args.length < 1)
{
sendMessage(plr, C.SETUP_STEP, object.setup_index + 1 + "", step.getDescription(), step.getType().getType(), step.getDefaultValue() + "");
return false;
}
final boolean valid = step.isValid(args[0]);
if (valid) {
if (valid)
{
sendMessage(plr, C.SETUP_VALID_ARG, step.getConstant(), args[0]);
step.setValue(args[0]);
object.setup_index++;
if (object.setup_index == object.step.length) {
if (object.setup_index == object.step.length)
{
onCommand(plr, args);
return false;
}
step = object.step[object.setup_index];
sendMessage(plr, C.SETUP_STEP, object.setup_index + 1 + "", step.getDescription(), step.getType().getType(), step.getDefaultValue() + "");
return false;
} else {
}
else
{
sendMessage(plr, C.SETUP_INVALID_ARG, args[0], step.getConstant());
sendMessage(plr, C.SETUP_STEP, object.setup_index + 1 + "", step.getDescription(), step.getType().getType(), step.getDefaultValue() + "");
return false;
}
}
case 4: {
if (args.length != 1) {
case 4:
{
if (args.length != 1)
{
MainUtil.sendMessage(plr, "&cYou need to choose a world name!");
return false;
}
if (BlockManager.manager.isWorld(args[0])) {
if (PS.get().isPlotWorld(args[0])) {
if (BlockManager.manager.isWorld(args[0]))
{
if (PS.get().isPlotWorld(args[0]))
{
MainUtil.sendMessage(plr, "&cThat world name is already taken!");
return false;
}
MainUtil.sendMessage(plr, "&cThe world you specified already exists. After restarting, new terrain will use PlotSquared, however you may need to reset the world for it to generate correctly!");
MainUtil.sendMessage(plr,
"&cThe world you specified already exists. After restarting, new terrain will use PlotSquared, however you may need to reset the world for it to generate correctly!");
}
object.world = args[0];
SetupUtils.setupMap.remove(name);
final String world;
if (object.setupManager == null) {
if (object.setupManager == null)
{
world = SetupUtils.manager.setupWorld(object);
}
else {
else
{
world = object.setupManager.setupWorld(object);
}
try {
try
{
plr.teleport(BlockManager.manager.getSpawn(world));
} catch (final Exception e) {
}
catch (final Exception e)
{
plr.sendMessage("&cAn error occured. See console for more information");
e.printStackTrace();
}

View File

@ -1,52 +1,53 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
// PlotSquared - A plot manager and world generator for the Bukkit API /
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
// /
// This program is free software; you can redistribute it and/or modify /
// it under the terms of the GNU General Public License as published by /
// the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.commands;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.object.PlotPlayer;
/**
* SubCommand class
*
* @author Citymonstret
*/
@SuppressWarnings({ "deprecation", "unused" })
public abstract class SubCommand extends com.plotsquared.general.commands.Command<PlotPlayer> {
/**
* The category
*/
public CommandCategory category;
/**
* Send a message
*
* @param plr Player who will receive the mssage
* @param c Caption
* @param args Arguments (%s's)
*
* @see com.intellectualcrafters.plot.util.MainUtil#sendMessage(PlotPlayer, C, String...)
*/
public boolean sendMessage(PlotPlayer plr, final C c, final String... args) {
c.send(plr, args);
return true;
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////
// PlotSquared - A plot manager and world generator for the Bukkit API /
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
// /
// This program is free software; you can redistribute it and/or modify /
// it under the terms of the GNU General Public License as published by /
// the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.commands;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.object.PlotPlayer;
/**
* SubCommand class
*
*/
@SuppressWarnings({ "deprecation", "unused" })
public abstract class SubCommand extends com.plotsquared.general.commands.Command<PlotPlayer>
{
/**
* The category
*/
public CommandCategory category;
/**
* Send a message
*
* @param plr Player who will receive the mssage
* @param c Caption
* @param args Arguments (%s's)
*
* @see com.intellectualcrafters.plot.util.MainUtil#sendMessage(PlotPlayer, C, String...)
*/
public boolean sendMessage(final PlotPlayer plr, final C c, final String... args)
{
c.send(plr, args);
return true;
}

View File

@ -36,95 +36,104 @@ import com.intellectualcrafters.plot.util.Permissions;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "swap",
description = "Swap two plots",
aliases = {"switch"},
category = CommandCategory.ACTIONS,
requiredType = RequiredType.NONE
)
public class Swap extends SubCommand {
command = "swap",
description = "Swap two plots",
aliases = { "switch" },
category = CommandCategory.ACTIONS,
requiredType = RequiredType.NONE)
public class Swap extends SubCommand
{
@Override
public boolean onCommand(final PlotPlayer plr, final String[] args) {
public boolean onCommand(final PlotPlayer plr, final String[] args)
{
MainUtil.sendMessage(plr, "&cThis command has not been optimized for large selections yet. Please bug me if this becomes an issue.");
if (args.length < 1) {
if (args.length < 1)
{
MainUtil.sendMessage(plr, C.NEED_PLOT_ID);
MainUtil.sendMessage(plr, C.SWAP_SYNTAX);
return false;
}
final Location loc = plr.getLocation();
final Plot plot = MainUtil.getPlot(loc);
if (plot == null) {
return !sendMessage(plr, C.NOT_IN_PLOT);
}
if ((!plot.hasOwner() || !plot.isOwner(plr.getUUID())) && !Permissions.hasPermission(plr, "plots.admin.command.swap")) {
if (plot == null) { return !sendMessage(plr, C.NOT_IN_PLOT); }
if ((!plot.hasOwner() || !plot.isOwner(plr.getUUID())) && !Permissions.hasPermission(plr, "plots.admin.command.swap"))
{
MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
return false;
}
Plot bot1 = MainUtil.getBottomPlot(plot);
Plot top1 = MainUtil.getTopPlot(plot);
PlotId id2 = PlotId.fromString(args[0]);
if (id2 == null) {
final Plot bot1 = MainUtil.getBottomPlot(plot);
final Plot top1 = MainUtil.getTopPlot(plot);
final PlotId id2 = PlotId.fromString(args[0]);
if (id2 == null)
{
MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_ID);
MainUtil.sendMessage(plr, C.SWAP_SYNTAX);
return false;
}
final String world = loc.getWorld();
Plot plot2 = MainUtil.getPlot(world, id2);
PlotId id3 = new PlotId(id2.x + top1.id.x - bot1.id.x, id2.y + top1.id.y - bot1.id.y);
Plot plot3 = MainUtil.getPlot(world, id3);
final Plot plot2 = MainUtil.getPlot(world, id2);
final PlotId id3 = new PlotId((id2.x + top1.id.x) - bot1.id.x, (id2.y + top1.id.y) - bot1.id.y);
final Plot plot3 = MainUtil.getPlot(world, id3);
// Getting secon selection
Plot bot2 = MainUtil.getBottomPlot(plot2);
Plot top2 = MainUtil.getTopPlot(plot3);
final Plot bot2 = MainUtil.getBottomPlot(plot2);
final Plot top2 = MainUtil.getTopPlot(plot3);
// cancel swap if intersection
PlotCluster cluster1 = new PlotCluster(world, bot1.id, top1.id, null);
PlotClusterId cluster2id = new PlotClusterId(bot2.id, top2.id);
if (ClusterManager.intersects(cluster1, cluster2id)) {
final PlotCluster cluster1 = new PlotCluster(world, bot1.id, top1.id, null);
final PlotClusterId cluster2id = new PlotClusterId(bot2.id, top2.id);
if (ClusterManager.intersects(cluster1, cluster2id))
{
MainUtil.sendMessage(plr, C.SWAP_OVERLAP);
return false;
}
// Check dimensions
if (top1.id.x - bot1.id.x != top2.id.x - bot2.id.x || top1.id.y - bot1.id.y != top2.id.y - bot2.id.y ) {
if (((top1.id.x - bot1.id.x) != (top2.id.x - bot2.id.x)) || ((top1.id.y - bot1.id.y) != (top2.id.y - bot2.id.y)))
{
MainUtil.sendMessage(plr, C.SWAP_DIMENSIONS, "1");
MainUtil.sendMessage(plr, C.SWAP_SYNTAX);
return false;
}
// Getting selections as ids
final ArrayList<PlotId> selection1 = MainUtil.getPlotSelectionIds(bot1.id, top1.id);
final ArrayList<PlotId> selection2 = MainUtil.getPlotSelectionIds(bot2.id, top2.id);
// Getting selections as location coordinates
Location pos1 = MainUtil.getPlotBottomLocAbs(world, bot1.id);
Location pos2 = MainUtil.getPlotTopLocAbs(world, top1.id).subtract(1, 0, 1);
Location pos3 = MainUtil.getPlotBottomLocAbs(world, bot2.id);
Location pos4 = MainUtil.getPlotTopLocAbs(world, top2.id).subtract(1, 0, 1);
if (MainUtil.getPlot(pos2) != null) {
final Location pos1 = MainUtil.getPlotBottomLocAbs(world, bot1.id);
final Location pos2 = MainUtil.getPlotTopLocAbs(world, top1.id).subtract(1, 0, 1);
final Location pos3 = MainUtil.getPlotBottomLocAbs(world, bot2.id);
final Location pos4 = MainUtil.getPlotTopLocAbs(world, top2.id).subtract(1, 0, 1);
if (MainUtil.getPlot(pos2) != null)
{
pos1.add(1, 0, 1);
pos2.add(1, 0, 1);
pos3.add(1, 0, 1);
pos4.add(1, 0, 1);
}
// Swapping the blocks, states and entites
ChunkManager.manager.swap(world, pos1, pos2, pos3, pos4);
// Swapping the plot data
for (int i = 0; i < selection1.size(); i++) {
final boolean last = i == selection1.size() - 1;
PlotId swaper = selection1.get(i);
PlotId swapee = selection2.get(i);
MainUtil.swapData(world, swaper, swapee, new Runnable() {
for (int i = 0; i < selection1.size(); i++)
{
final boolean last = i == (selection1.size() - 1);
final PlotId swaper = selection1.get(i);
final PlotId swapee = selection2.get(i);
MainUtil.swapData(world, swaper, swapee, new Runnable()
{
@Override
public void run() {
if (last) {
public void run()
{
if (last)
{
MainUtil.sendMessage(plr, C.SWAP_SUCCESS);
}
}

View File

@ -34,74 +34,84 @@ import com.plotsquared.general.commands.Argument;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "tp",
description = "Teleport to a plot",
permission = "plots.tp",
usage = "/plot tp <alias|id>",
requiredType = RequiredType.NONE,
category = CommandCategory.TELEPORT
)
public class TP extends SubCommand {
command = "tp",
description = "Teleport to a plot",
permission = "plots.tp",
usage = "/plot tp <alias|id>",
requiredType = RequiredType.NONE,
category = CommandCategory.TELEPORT)
public class TP extends SubCommand
{
public TP() {
public TP()
{
requiredArguments = new Argument[] {
Argument.String
Argument.String
};
}
@Override
public boolean onCommand(final PlotPlayer plr, final String[] args) {
public boolean onCommand(final PlotPlayer plr, final String[] args)
{
final String id = args[0];
PlotId plotid;
final Location loc = plr.getLocation();
final String pworld = loc.getWorld();
String world = pworld;
if (args.length == 2) {
if (BlockManager.manager.isWorld(args[1])) {
if (args.length == 2)
{
if (BlockManager.manager.isWorld(args[1]))
{
world = args[1];
}
}
if (!PS.get().isPlotWorld(world)) {
if (!PS.get().isPlotWorld(world))
{
MainUtil.sendMessage(plr, C.NOT_IN_PLOT_WORLD);
return false;
}
Plot temp;
if ((temp = isAlias(world, id)) != null) {
if ((temp = isAlias(world, id)) != null)
{
MainUtil.teleportPlayer(plr, plr.getLocation(), temp);
return true;
}
try {
try
{
plotid = new PlotId(Integer.parseInt(id.split(";")[0]), Integer.parseInt(id.split(";")[1]));
MainUtil.teleportPlayer(plr, plr.getLocation(), MainUtil.getPlot(world, plotid));
return true;
} catch (final Exception e) {
}
catch (final Exception e)
{
MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_ID);
}
return false;
}
private Plot isAlias(final String world, String a) {
private Plot isAlias(final String world, String a)
{
int index = 0;
if (a.contains(";")) {
if (a.contains(";"))
{
final String[] split = a.split(";");
if ((split[1].length() > 0) && MathMan.isInteger(split[1])) {
if ((split[1].length() > 0) && MathMan.isInteger(split[1]))
{
index = Integer.parseInt(split[1]);
}
a = split[0];
}
final PlotPlayer player = UUIDHandler.getPlayer(a);
if (player != null) {
if (player != null)
{
final java.util.Set<Plot> plotMainPlots = PS.get().getPlots(world, player);
final Plot[] plots = plotMainPlots.toArray(new Plot[plotMainPlots.size()]);
if (plots.length > index) {
return plots[index];
}
if (plots.length > index) { return plots[index]; }
return null;
}
for (final Plot p : PS.get().getPlotsInWorld(world)) {
if ((p.getSettings().getAlias().length() > 0) && p.getSettings().getAlias().equalsIgnoreCase(a)) {
return p;
}
for (final Plot p : PS.get().getPlotsInWorld(world))
{
if ((p.getSettings().getAlias().length() > 0) && p.getSettings().getAlias().equalsIgnoreCase(a)) { return p; }
}
return null;
}

View File

@ -28,41 +28,47 @@ import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.StringMan;
import com.plotsquared.general.commands.Argument;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "target",
usage = "/plot target <X;Z|nearest>",
description = "Target a plot with your compass",
permission = "plots.target",
requiredType = RequiredType.NONE,
category = CommandCategory.ACTIONS
)
public class Target extends SubCommand {
command = "target",
usage = "/plot target <X;Z|nearest>",
description = "Target a plot with your compass",
permission = "plots.target",
requiredType = RequiredType.NONE,
category = CommandCategory.ACTIONS)
public class Target extends SubCommand
{
@Override
public boolean onCommand(final PlotPlayer plr, final String[] args) {
public boolean onCommand(final PlotPlayer plr, final String[] args)
{
final Location ploc = plr.getLocation();
if (!PS.get().isPlotWorld(ploc.getWorld())) {
if (!PS.get().isPlotWorld(ploc.getWorld()))
{
MainUtil.sendMessage(plr, C.NOT_IN_PLOT_WORLD);
return false;
}
PlotId id = MainUtil.parseId(args[0]);
if (id == null) {
if (StringMan.isEqualIgnoreCaseToAny(args[0], "near", "nearest")) {
if (id == null)
{
if (StringMan.isEqualIgnoreCaseToAny(args[0], "near", "nearest"))
{
Plot closest = null;
int distance = Integer.MAX_VALUE;
for (Plot plot : PS.get().getPlotsInWorld(ploc.getWorld())) {
double current = plot.getBottom().getEuclideanDistanceSquared(ploc);
if (current < distance) {
for (final Plot plot : PS.get().getPlotsInWorld(ploc.getWorld()))
{
final double current = plot.getBottom().getEuclideanDistanceSquared(ploc);
if (current < distance)
{
distance = (int) current;
closest = plot;
}
}
id = closest.id;
}
else {
else
{
MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_ID);
return false;
}

View File

@ -47,35 +47,38 @@ import com.intellectualcrafters.plot.util.TaskManager;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "template",
permission = "plots.admin",
description = "Create or use a world template",
usage = "/plot template [import|export] <world> <template>",
category = CommandCategory.DEBUG
)
public class Template extends SubCommand {
command = "template",
permission = "plots.admin",
description = "Create or use a world template",
usage = "/plot template [import|export] <world> <template>",
category = CommandCategory.DEBUG)
public class Template extends SubCommand
{
public static boolean extractAllFiles(String world, String template) {
byte[] buffer = new byte[2048];
try {
File folder = new File(PS.get().IMP.getDirectory() + File.separator + "templates");
if (!folder.exists()) {
return false;
}
File input = new File(folder + File.separator + template + ".template");
File output = PS.get().IMP.getDirectory();
if (!output.exists()) {
public static boolean extractAllFiles(final String world, final String template)
{
final byte[] buffer = new byte[2048];
try
{
final File folder = new File(PS.get().IMP.getDirectory() + File.separator + "templates");
if (!folder.exists()) { return false; }
final File input = new File(folder + File.separator + template + ".template");
final File output = PS.get().IMP.getDirectory();
if (!output.exists())
{
output.mkdirs();
}
ZipInputStream zis = new ZipInputStream(new FileInputStream(input));
final ZipInputStream zis = new ZipInputStream(new FileInputStream(input));
ZipEntry ze = zis.getNextEntry();
while (ze != null) {
String name = ze.getName();
File newFile = new File((output + File.separator + name).replaceAll("__TEMP_DIR__", world));
while (ze != null)
{
final String name = ze.getName();
final File newFile = new File((output + File.separator + name).replaceAll("__TEMP_DIR__", world));
new File(newFile.getParent()).mkdirs();
FileOutputStream fos = new FileOutputStream(newFile);
final FileOutputStream fos = new FileOutputStream(newFile);
int len;
while ((len = zis.read(buffer)) > 0) {
while ((len = zis.read(buffer)) > 0)
{
fos.write(buffer, 0, len);
}
fos.close();
@ -84,33 +87,40 @@ public class Template extends SubCommand {
zis.closeEntry();
zis.close();
return true;
} catch (Exception e) {
}
catch (final Exception e)
{
e.printStackTrace();
return false;
}
}
public static byte[] getBytes(PlotWorld plotworld) {
ConfigurationSection section = PS.get().config.getConfigurationSection("worlds." + plotworld.worldname);
YamlConfiguration config = new YamlConfiguration();
String generator = SetupUtils.manager.getGenerator(plotworld);
if (generator != null) {
public static byte[] getBytes(final PlotWorld plotworld)
{
final ConfigurationSection section = PS.get().config.getConfigurationSection("worlds." + plotworld.worldname);
final YamlConfiguration config = new YamlConfiguration();
final String generator = SetupUtils.manager.getGenerator(plotworld);
if (generator != null)
{
config.set("generator.plugin", generator);
}
for (String key : section.getKeys(true)) {
for (final String key : section.getKeys(true))
{
config.set(key, section.get(key));
}
return config.saveToString().getBytes();
}
public static void zipAll(final String world, Set<FileBytes> files) throws IOException {
File output = new File(PS.get().IMP.getDirectory() + File.separator + "templates");
public static void zipAll(final String world, final Set<FileBytes> files) throws IOException
{
final File output = new File(PS.get().IMP.getDirectory() + File.separator + "templates");
output.mkdirs();
FileOutputStream fos = new FileOutputStream(output + File.separator + world + ".template");
ZipOutputStream zos = new ZipOutputStream(fos);
final FileOutputStream fos = new FileOutputStream(output + File.separator + world + ".template");
final ZipOutputStream zos = new ZipOutputStream(fos);
for (FileBytes file : files) {
ZipEntry ze = new ZipEntry(file.path);
for (final FileBytes file : files)
{
final ZipEntry ze = new ZipEntry(file.path);
zos.putNextEntry(ze);
zos.write(file.data);
}
@ -119,14 +129,19 @@ public class Template extends SubCommand {
}
@Override
public boolean onCommand(final PlotPlayer plr, final String[] args) {
if (args.length != 2 && args.length != 3) {
if (args.length == 1) {
if (args[0].equalsIgnoreCase("export")) {
public boolean onCommand(final PlotPlayer plr, final String[] args)
{
if ((args.length != 2) && (args.length != 3))
{
if (args.length == 1)
{
if (args[0].equalsIgnoreCase("export"))
{
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot template export <world>");
return true;
}
else if (args[0].equalsIgnoreCase("import")) {
else if (args[0].equalsIgnoreCase("import"))
{
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot template import <world> <template>");
return true;
}
@ -135,43 +150,53 @@ public class Template extends SubCommand {
return true;
}
final String world = args[1];
switch (args[0].toLowerCase()) {
case "import": {
if (args.length != 3) {
switch (args[0].toLowerCase())
{
case "import":
{
if (args.length != 3)
{
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot template import <world> <template>");
return false;
}
if (PS.get().isPlotWorld(world)) {
if (PS.get().isPlotWorld(world))
{
MainUtil.sendMessage(plr, C.SETUP_WORLD_TAKEN, world);
return false;
}
boolean result = extractAllFiles(world, args[2]);
if (!result) {
MainUtil.sendMessage(plr, "&cInvalid template file: " + args[2] +".template");
final boolean result = extractAllFiles(world, args[2]);
if (!result)
{
MainUtil.sendMessage(plr, "&cInvalid template file: " + args[2] + ".template");
return false;
}
File worldFile = new File(PS.get().IMP.getDirectory() + File.separator + "templates" + File.separator + "tmp-data.yml");
YamlConfiguration worldConfig = YamlConfiguration.loadConfiguration(worldFile);
final File worldFile = new File(PS.get().IMP.getDirectory() + File.separator + "templates" + File.separator + "tmp-data.yml");
final YamlConfiguration worldConfig = YamlConfiguration.loadConfiguration(worldFile);
PS.get().config.set("worlds." + world, worldConfig.get(""));
try {
try
{
PS.get().config.save(PS.get().configFile);
PS.get().config.load(PS.get().configFile);
} catch (Exception e) {
}
catch (final Exception e)
{
e.printStackTrace();
}
String manager = worldConfig.getString("generator.plugin");
if (manager == null) {
if (manager == null)
{
manager = "PlotSquared";
}
String generator = worldConfig.getString("generator.init");
if (generator == null) {
if (generator == null)
{
generator = manager;
}
int type = worldConfig.getInt("generator.type");
int terrain = worldConfig.getInt("generator.terrain");
final int type = worldConfig.getInt("generator.type");
final int terrain = worldConfig.getInt("generator.terrain");
SetupObject setup = new SetupObject();
final SetupObject setup = new SetupObject();
setup.plotManager = manager;
setup.setupGenerator = generator;
setup.type = type;
@ -179,34 +204,43 @@ public class Template extends SubCommand {
setup.step = new ConfigurationNode[0];
setup.world = world;
SetupUtils.manager.setupWorld(setup);
SetBlockQueue.addNotify(new Runnable() {
SetBlockQueue.addNotify(new Runnable()
{
@Override
public void run() {
public void run()
{
MainUtil.sendMessage(plr, "Done!");
plr.teleport(BlockManager.manager.getSpawn(world));
}
});
return true;
}
case "export": {
if (args.length != 2) {
case "export":
{
if (args.length != 2)
{
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot template export <world>");
return false;
}
final PlotWorld plotworld = PS.get().getPlotWorld(world);
if (!BlockManager.manager.isWorld(world) || (plotworld == null)) {
if (!BlockManager.manager.isWorld(world) || (plotworld == null))
{
MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_WORLD);
return false;
}
final PlotManager manager = PS.get().getPlotManager(world);
final PlotPlayer finalPlr = plr;
TaskManager.runTaskAsync(new Runnable() {
TaskManager.runTaskAsync(new Runnable()
{
@Override
public void run() {
try {
public void run()
{
try
{
manager.exportTemplate(plotworld);
}
catch (Exception e) {
catch (final Exception e)
{
e.printStackTrace();
MainUtil.sendMessage(finalPlr, "Failed: " + e.getMessage());
return;
@ -216,8 +250,9 @@ public class Template extends SubCommand {
});
return true;
}
default: {
C.COMMAND_SYNTAX.send(plr, this.getUsage());
default:
{
C.COMMAND_SYNTAX.send(plr, getUsage());
}
}
return false;

View File

@ -31,124 +31,151 @@ import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.StringMan;
import com.plotsquared.bukkit.BukkitMain;
import com.plotsquared.general.commands.Command;
import com.plotsquared.general.commands.CommandCaller;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "toggle",
aliases = {"attribute"},
permission = "plots.use",
description = "Toggle per user settings",
usage = "/plot toggle <setting>",
requiredType = RequiredType.NONE,
category = CommandCategory.ACTIONS
)
public class Toggle extends SubCommand {
command = "toggle",
aliases = { "attribute" },
permission = "plots.use",
description = "Toggle per user settings",
usage = "/plot toggle <setting>",
requiredType = RequiredType.NONE,
category = CommandCategory.ACTIONS)
public class Toggle extends SubCommand
{
public void noArgs(PlotPlayer plr) {
public void noArgs(final PlotPlayer plr)
{
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot toggle <setting>");
ArrayList<String> options = new ArrayList<>();
for (Entry<String, Command<PlotPlayer>> entry : toggles.entrySet()) {
if (Permissions.hasPermission(plr, entry.getValue().getPermission())) {
final ArrayList<String> options = new ArrayList<>();
for (final Entry<String, Command<PlotPlayer>> entry : toggles.entrySet())
{
if (Permissions.hasPermission(plr, entry.getValue().getPermission()))
{
options.add(entry.getKey());
}
}
if (options.size() > 0) {
if (options.size() > 0)
{
MainUtil.sendMessage(plr, C.SUBCOMMAND_SET_OPTIONS_HEADER.s() + StringMan.join(options, ","));
}
}
private HashMap<String, Command<PlotPlayer>> toggles;
public Toggle() {
public Toggle()
{
toggles = new HashMap<>();
toggles.put("titles",
new Command<PlotPlayer>("titles", "/plot toggle titles", "Toggle titles for yourself", C.PERMISSION_PLOT_TOGGLE_TITLES.s()) {
@Override
public boolean onCommand(PlotPlayer player, String[] args) {
if (toggle(player, "disabletitles")) {
MainUtil.sendMessage(player, C.TOGGLE_ENABLED, getCommand());
}
else {
MainUtil.sendMessage(player, C.TOGGLE_DISABLED, getCommand());
}
return true;
}
});
toggles.put("chatspy",
new Command<PlotPlayer>("chatspy", "/plot toggle chatspy", "Toggle chat spying", C.PERMISSION_COMMANDS_CHAT.s()) {
@Override
public boolean onCommand(PlotPlayer player, String[] args) {
if (toggle(player, "chatspy")) {
MainUtil.sendMessage(player, C.TOGGLE_DISABLED, getCommand());
}
else {
MainUtil.sendMessage(player, C.TOGGLE_ENABLED, getCommand());
}
return true;
}
});
toggles.put("chat",
new Command<PlotPlayer>("chat", "/plot toggle chat", "Toggle plot chat for yourself", C.PERMISSION_PLOT_TOGGLE_CHAT.s()) {
toggles.put("titles",
new Command<PlotPlayer>("titles", "/plot toggle titles", "Toggle titles for yourself", C.PERMISSION_PLOT_TOGGLE_TITLES.s())
{
@Override
public boolean onCommand(PlotPlayer player, String[] args) {
if (toggle(player, "chat")) {
public boolean onCommand(final PlotPlayer player, final String[] args)
{
if (toggle(player, "disabletitles"))
{
MainUtil.sendMessage(player, C.TOGGLE_ENABLED, getCommand());
}
else
{
MainUtil.sendMessage(player, C.TOGGLE_DISABLED, getCommand());
}
return true;
}
});
toggles.put("chatspy",
new Command<PlotPlayer>("chatspy", "/plot toggle chatspy", "Toggle chat spying", C.PERMISSION_COMMANDS_CHAT.s())
{
@Override
public boolean onCommand(final PlotPlayer player, final String[] args)
{
if (toggle(player, "chatspy"))
{
MainUtil.sendMessage(player, C.TOGGLE_DISABLED, getCommand());
}
else
{
MainUtil.sendMessage(player, C.TOGGLE_ENABLED, getCommand());
}
return true;
}
});
toggles.put("chat",
new Command<PlotPlayer>("chat", "/plot toggle chat", "Toggle plot chat for yourself", C.PERMISSION_PLOT_TOGGLE_CHAT.s())
{
@Override
public boolean onCommand(final PlotPlayer player, final String[] args)
{
if (toggle(player, "chat"))
{
MainUtil.sendMessage(player, C.PLOT_CHAT_OFF);
}
else {
else
{
MainUtil.sendMessage(player, C.PLOT_CHAT_ON);
}
return true;
}
});
if (PS.get().worldedit != null) {
toggles.put("worldedit",
new Command<PlotPlayer>("worldedit", "/plot toggle worldedit", "Toggle worldedit bypass", C.PERMISSION_WORLDEDIT_BYPASS.s()) {
if (PS.get().worldedit != null)
{
toggles.put("worldedit",
new Command<PlotPlayer>("worldedit", "/plot toggle worldedit", "Toggle worldedit bypass", C.PERMISSION_WORLDEDIT_BYPASS.s())
{
@Override
public boolean onCommand(PlotPlayer player, String[] args) {
if (toggle(player, "worldedit")) {
public boolean onCommand(final PlotPlayer player, final String[] args)
{
if (toggle(player, "worldedit"))
{
MainUtil.sendMessage(player, C.WORLDEDIT_RESTRICTED);
}
else {
else
{
MainUtil.sendMessage(player, C.WORLDEDIT_UNMASKED);
}
return true;
}
});
}
}
@Override
public boolean onCommand(final PlotPlayer player, final String[] args) {
if (args.length == 0) {
public boolean onCommand(final PlotPlayer player, final String[] args)
{
if (args.length == 0)
{
noArgs(player);
return false;
}
Command<PlotPlayer> cmd = toggles.get(args[0].toLowerCase());
if (cmd == null) {
final Command<PlotPlayer> cmd = toggles.get(args[0].toLowerCase());
if (cmd == null)
{
noArgs(player);
return false;
}
if (!Permissions.hasPermission(player, cmd.getPermission())) {
if (!Permissions.hasPermission(player, cmd.getPermission()))
{
C.NO_PERMISSION.send(player, cmd.getPermission());
return false;
}
return cmd.onCommand(player, Arrays.copyOfRange(args, 1, args.length));
}
public boolean toggle(PlotPlayer player, String key) {
if (player.getAttribute(key)) {
public boolean toggle(final PlotPlayer player, final String key)
{
if (player.getAttribute(key))
{
player.removeAttribute(key);
return true;
}
else {
else
{
player.setAttribute(key);
return false;
}

View File

@ -42,62 +42,77 @@ import com.intellectualcrafters.plot.util.TaskManager;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "trim",
permission = "plots.admin",
description = "Delete unmodified portions of your plotworld",
usage = "/plot trim",
requiredType = RequiredType.CONSOLE,
category = CommandCategory.DEBUG
)
public class Trim extends SubCommand {
command = "trim",
permission = "plots.admin",
description = "Delete unmodified portions of your plotworld",
usage = "/plot trim",
requiredType = RequiredType.CONSOLE,
category = CommandCategory.DEBUG)
public class Trim extends SubCommand
{
public static boolean TASK = false;
public static ArrayList<Plot> expired = null;
private static int TASK_ID = 0;
public static boolean getBulkRegions(final ArrayList<ChunkLoc> empty, final String world, final Runnable whenDone) {
if (Trim.TASK) {
return false;
}
TaskManager.runTaskAsync(new Runnable() {
public static boolean getBulkRegions(final ArrayList<ChunkLoc> empty, final String world, final Runnable whenDone)
{
if (Trim.TASK) { return false; }
TaskManager.runTaskAsync(new Runnable()
{
@Override
public void run() {
public void run()
{
final String directory = world + File.separator + "region";
final File folder = new File(directory);
final File[] regionFiles = folder.listFiles();
for (final File file : regionFiles) {
for (final File file : regionFiles)
{
final String name = file.getName();
if (name.endsWith("mca")) {
if (file.getTotalSpace() <= 8192) {
try {
if (name.endsWith("mca"))
{
if (file.getTotalSpace() <= 8192)
{
try
{
final String[] split = name.split("\\.");
final int x = Integer.parseInt(split[1]);
final int z = Integer.parseInt(split[2]);
final ChunkLoc loc = new ChunkLoc(x, z);
empty.add(loc);
} catch (final Exception e) {
}
catch (final Exception e)
{
PS.debug("INVALID MCA: " + name);
}
} else {
}
else
{
final Path path = Paths.get(file.getPath());
try {
try
{
final BasicFileAttributes attr = Files.readAttributes(path, BasicFileAttributes.class);
final long creation = attr.creationTime().toMillis();
final long modification = file.lastModified();
final long diff = Math.abs(creation - modification);
if (diff < 10000) {
try {
if (diff < 10000)
{
try
{
final String[] split = name.split("\\.");
final int x = Integer.parseInt(split[1]);
final int z = Integer.parseInt(split[2]);
final ChunkLoc loc = new ChunkLoc(x, z);
empty.add(loc);
} catch (final Exception e) {
}
catch (final Exception e)
{
PS.debug("INVALID MCA: " + name);
}
}
} catch (final Exception e) {
}
catch (final Exception e)
{}
}
}
}
@ -109,10 +124,9 @@ public class Trim extends SubCommand {
return true;
}
public static boolean getTrimRegions(final ArrayList<ChunkLoc> empty, final String world, final Runnable whenDone) {
if (Trim.TASK) {
return false;
}
public static boolean getTrimRegions(final ArrayList<ChunkLoc> empty, final String world, final Runnable whenDone)
{
if (Trim.TASK) { return false; }
System.currentTimeMillis();
sendMessage("Collecting region data...");
final ArrayList<Plot> plots = new ArrayList<>();
@ -121,12 +135,16 @@ public class Trim extends SubCommand {
sendMessage(" - MCA #: " + chunks.size());
sendMessage(" - CHUNKS: " + (chunks.size() * 1024) + " (max)");
sendMessage(" - TIME ESTIMATE: " + (chunks.size() / 1200) + " minutes");
Trim.TASK_ID = TaskManager.runTaskRepeat(new Runnable() {
Trim.TASK_ID = TaskManager.runTaskRepeat(new Runnable()
{
@Override
public void run() {
public void run()
{
final long start = System.currentTimeMillis();
while ((System.currentTimeMillis() - start) < 50) {
if (plots.size() == 0) {
while ((System.currentTimeMillis() - start) < 50)
{
if (plots.size() == 0)
{
empty.addAll(chunks);
Trim.TASK = false;
TaskManager.runTaskAsync(whenDone);
@ -137,14 +155,16 @@ public class Trim extends SubCommand {
final Location pos1 = MainUtil.getPlotBottomLoc(world, plot.id);
final Location pos2 = MainUtil.getPlotTopLoc(world, plot.id);
int ccx1 = (pos1.getX() >> 9);
int ccz1 = (pos1.getZ() >> 9);
int ccx2 = (pos2.getX() >> 9);
int ccz2 = (pos2.getZ() >> 9);
for(int x = ccx1; x <= ccx2; x++) {
for(int z = ccz1; z <= ccz2; z++) {
final int ccx1 = (pos1.getX() >> 9);
final int ccz1 = (pos1.getZ() >> 9);
final int ccx2 = (pos2.getX() >> 9);
final int ccz2 = (pos2.getZ() >> 9);
for (int x = ccx1; x <= ccx2; x++)
{
for (int z = ccz1; z <= ccz2; z++)
{
chunks.remove(new ChunkLoc(x, z));
}
}
@ -155,62 +175,78 @@ public class Trim extends SubCommand {
return true;
}
public static void deleteChunks(final String world, final ArrayList<ChunkLoc> chunks) {
public static void deleteChunks(final String world, final ArrayList<ChunkLoc> chunks)
{
ChunkManager.manager.deleteRegionFiles(world, chunks);
}
public static void sendMessage(final String message) {
public static void sendMessage(final String message)
{
PS.debug("&3PlotSquared -> World trim&8: &7" + message);
}
public PlotId getId(final String id) {
try {
public PlotId getId(final String id)
{
try
{
final String[] split = id.split(";");
return new PlotId(Integer.parseInt(split[0]), Integer.parseInt(split[1]));
} catch (final Exception e) {
}
catch (final Exception e)
{
return null;
}
}
@Override
public boolean onCommand(final PlotPlayer plr, final String[] args) {
if (args.length == 1) {
public boolean onCommand(final PlotPlayer plr, final String[] args)
{
if (args.length == 1)
{
final String arg = args[0].toLowerCase();
final PlotId id = getId(arg);
if (id != null) {
if (id != null)
{
MainUtil.sendMessage(plr, "/plot trim x;z &l<world>");
return false;
}
if (arg.equals("all")) {
if (arg.equals("all"))
{
MainUtil.sendMessage(plr, "/plot trim all &l<world>");
return false;
}
MainUtil.sendMessage(plr, C.TRIM_SYNTAX);
return false;
}
if (args.length != 2) {
if (args.length != 2)
{
MainUtil.sendMessage(plr, C.TRIM_SYNTAX);
return false;
}
final String arg = args[0].toLowerCase();
if (!arg.equals("all")) {
if (!arg.equals("all"))
{
MainUtil.sendMessage(plr, C.TRIM_SYNTAX);
return false;
}
final String world = args[1];
if (!BlockManager.manager.isWorld(world) || (PS.get().getPlotWorld(world) == null)) {
if (!BlockManager.manager.isWorld(world) || (PS.get().getPlotWorld(world) == null))
{
MainUtil.sendMessage(plr, C.NOT_VALID_WORLD);
return false;
}
if (Trim.TASK) {
if (Trim.TASK)
{
sendMessage(C.TRIM_IN_PROGRESS.s());
return false;
}
sendMessage(C.TRIM_START.s());
final ArrayList<ChunkLoc> empty = new ArrayList<>();
getTrimRegions(empty, world, new Runnable() {
getTrimRegions(empty, world, new Runnable()
{
@Override
public void run() {
public void run()
{
deleteChunks(world, empty);
PS.log("$1Trim task complete!");
}

View File

@ -37,69 +37,84 @@ import com.plotsquared.general.commands.Argument;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "trust",
aliases = {"t"},
requiredType = RequiredType.NONE,
usage = "/plot trust <player>",
description = "Allow a player to build in a plot",
category = CommandCategory.ACTIONS
)
public class Trust extends SubCommand {
command = "trust",
aliases = { "t" },
requiredType = RequiredType.NONE,
usage = "/plot trust <player>",
description = "Allow a player to build in a plot",
category = CommandCategory.ACTIONS)
public class Trust extends SubCommand
{
public Trust() {
public Trust()
{
requiredArguments = new Argument[] {
Argument.PlayerName
Argument.PlayerName
};
}
@Override
public boolean onCommand(final PlotPlayer plr, final String[] args) {
public boolean onCommand(final PlotPlayer plr, final String[] args)
{
final Location loc = plr.getLocation();
final Plot plot = MainUtil.getPlot(loc);
if (plot == null) {
return !sendMessage(plr, C.NOT_IN_PLOT);
}
if (!plot.hasOwner()) {
if (plot == null) { return !sendMessage(plr, C.NOT_IN_PLOT); }
if (!plot.hasOwner())
{
MainUtil.sendMessage(plr, C.PLOT_UNOWNED);
return false;
}
if (!plot.isOwner(plr.getUUID()) && !Permissions.hasPermission(plr, "plots.admin.command.trust")) {
if (!plot.isOwner(plr.getUUID()) && !Permissions.hasPermission(plr, "plots.admin.command.trust"))
{
MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
return true;
}
UUID uuid;
if (args[0].equalsIgnoreCase("*")) {
if (args[0].equalsIgnoreCase("*"))
{
uuid = DBFunc.everyone;
} else {
}
else
{
uuid = UUIDHandler.getUUID(args[0], null);
}
if (uuid == null) {
if (UUIDHandler.implementation instanceof SQLUUIDHandler) {
if (uuid == null)
{
if (UUIDHandler.implementation instanceof SQLUUIDHandler)
{
MainUtil.sendMessage(plr, C.INVALID_PLAYER_WAIT, args[0]);
} else {
}
else
{
MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[0]);
}
return false;
}
if (plot.isOwner(uuid)) {
if (plot.isOwner(uuid))
{
MainUtil.sendMessage(plr, C.ALREADY_OWNER);
return false;
}
if (plot.getTrusted().contains(uuid)) {
if (plot.getTrusted().contains(uuid))
{
MainUtil.sendMessage(plr, C.ALREADY_ADDED);
return false;
}
if (plot.removeMember(uuid)) {
if (plot.removeMember(uuid))
{
plot.addTrusted(uuid);
}
else {
if (plot.getMembers().size() + plot.getTrusted().size() >= PS.get().getPlotWorld(plot.world).MAX_PLOT_MEMBERS) {
else
{
if ((plot.getMembers().size() + plot.getTrusted().size()) >= PS.get().getPlotWorld(plot.world).MAX_PLOT_MEMBERS)
{
MainUtil.sendMessage(plr, C.PLOT_MAX_MEMBERS);
return false;
}
if (plot.getDenied().contains(uuid)) {
if (plot.getDenied().contains(uuid))
{
plot.removeDenied(uuid);
}
plot.addTrusted(uuid);

View File

@ -32,42 +32,39 @@ import com.intellectualcrafters.plot.util.Permissions;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "unclaim",
usage = "/plot unclaim",
requiredType = RequiredType.NONE,
description = "Unclaim a plot",
category = CommandCategory.ACTIONS
)
public class Unclaim extends SubCommand {
command = "unclaim",
usage = "/plot unclaim",
requiredType = RequiredType.NONE,
description = "Unclaim a plot",
category = CommandCategory.ACTIONS)
public class Unclaim extends SubCommand
{
@Override
public boolean onCommand(final PlotPlayer plr, final String[] args) {
public boolean onCommand(final PlotPlayer plr, final String[] args)
{
final Location loc = plr.getLocation();
final Plot plot = MainUtil.getPlot(loc);
if (plot == null) {
return !sendMessage(plr, C.NOT_IN_PLOT);
}
if (!plot.hasOwner()) {
return !sendMessage(plr, C.PLOT_NOT_CLAIMED);
}
if (!MainUtil.getTopPlot(plot).equals(MainUtil.getBottomPlot(plot))) {
return !sendMessage(plr, C.UNLINK_REQUIRED);
}
if (((!plot.hasOwner() || !plot.isOwner(plr.getUUID()))) && !Permissions.hasPermission(plr, "plots.admin.command.unclaim")) {
return !sendMessage(plr, C.NO_PLOT_PERMS);
}
if (plot == null) { return !sendMessage(plr, C.NOT_IN_PLOT); }
if (!plot.hasOwner()) { return !sendMessage(plr, C.PLOT_NOT_CLAIMED); }
if (!MainUtil.getTopPlot(plot).equals(MainUtil.getBottomPlot(plot))) { return !sendMessage(plr, C.UNLINK_REQUIRED); }
if (((!plot.hasOwner() || !plot.isOwner(plr.getUUID()))) && !Permissions.hasPermission(plr, "plots.admin.command.unclaim")) { return !sendMessage(plr, C.NO_PLOT_PERMS); }
final PlotWorld pWorld = PS.get().getPlotWorld(plot.world);
if ((EconHandler.manager != null) && pWorld.USE_ECONOMY) {
if ((EconHandler.manager != null) && pWorld.USE_ECONOMY)
{
final double c = pWorld.SELL_PRICE;
if (c > 0d) {
if (c > 0d)
{
EconHandler.manager.depositMoney(plr, c);
sendMessage(plr, C.ADDED_BALANCE, c + "");
}
}
if (plot.unclaim()) {
if (plot.unclaim())
{
MainUtil.sendMessage(plr, C.UNCLAIM_SUCCESS);
}
else {
else
{
MainUtil.sendMessage(plr, C.UNCLAIM_FAILED);
}
return true;

View File

@ -35,75 +35,89 @@ import com.plotsquared.general.commands.Argument;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "undeny",
aliases = {"ud"},
description = "Remove a denied user from a plot",
usage = "/plot undeny <player>",
requiredType = RequiredType.NONE,
category = CommandCategory.ACTIONS
)
public class Undeny extends SubCommand {
command = "undeny",
aliases = { "ud" },
description = "Remove a denied user from a plot",
usage = "/plot undeny <player>",
requiredType = RequiredType.NONE,
category = CommandCategory.ACTIONS)
public class Undeny extends SubCommand
{
public Undeny() {
public Undeny()
{
requiredArguments = new Argument[] {
Argument.PlayerName
Argument.PlayerName
};
}
@Override
public boolean onCommand(final PlotPlayer plr, final String ... args) {
public boolean onCommand(final PlotPlayer plr, final String... args)
{
final Location loc = plr.getLocation();
final Plot plot = MainUtil.getPlot(loc);
if (plot == null) {
return !sendMessage(plr, C.NOT_IN_PLOT);
}
if (!plot.hasOwner()) {
if (plot == null) { return !sendMessage(plr, C.NOT_IN_PLOT); }
if (!plot.hasOwner())
{
MainUtil.sendMessage(plr, C.PLOT_UNOWNED);
return false;
}
if (!plot.isOwner(plr.getUUID()) && !Permissions.hasPermission(plr, "plots.admin.command.undeny")) {
if (!plot.isOwner(plr.getUUID()) && !Permissions.hasPermission(plr, "plots.admin.command.undeny"))
{
MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
return true;
}
int count = 0;
switch (args[0]) {
switch (args[0])
{
case "unknown":
ArrayList<UUID> toRemove = new ArrayList<>();
for (UUID uuid : plot.getDenied()) {
if (UUIDHandler.getName(uuid) == null) {
final ArrayList<UUID> toRemove = new ArrayList<>();
for (final UUID uuid : plot.getDenied())
{
if (UUIDHandler.getName(uuid) == null)
{
toRemove.add(uuid);
}
}
for (UUID uuid : toRemove) {
for (final UUID uuid : toRemove)
{
plot.removeDenied(uuid);
count++;
}
break;
case "*":
for (UUID uuid : new ArrayList<>(plot.getDenied())) {
for (final UUID uuid : new ArrayList<>(plot.getDenied()))
{
plot.removeDenied(uuid);
count++;
}
break;
default:
UUID uuid = UUIDHandler.getUUID(args[0], null);
if (uuid != null) {
if (plot.removeDenied(uuid)) {
final UUID uuid = UUIDHandler.getUUID(args[0], null);
if (uuid != null)
{
if (plot.removeDenied(uuid))
{
count++;
}
}
break;
}
if (count == 0) {
if (UUIDHandler.implementation instanceof SQLUUIDHandler) {
if (count == 0)
{
if (UUIDHandler.implementation instanceof SQLUUIDHandler)
{
MainUtil.sendMessage(plr, C.INVALID_PLAYER_WAIT, args[0]);
} else {
}
else
{
MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[0]);
}
return false;
}
else {
else
{
MainUtil.sendMessage(plr, C.REMOVED_PLAYERS, count + "");
}
return true;

View File

@ -32,44 +32,43 @@ import com.intellectualcrafters.plot.util.TaskManager;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "unlink",
aliases = {"u", "unmerge"},
description = "Unlink a mega-plot",
usage = "/plot unlink",
requiredType = RequiredType.NONE,
category = CommandCategory.ACTIONS
)
public class Unlink extends SubCommand {
command = "unlink",
aliases = { "u", "unmerge" },
description = "Unlink a mega-plot",
usage = "/plot unlink",
requiredType = RequiredType.NONE,
category = CommandCategory.ACTIONS)
public class Unlink extends SubCommand
{
@Override
public boolean onCommand(final PlotPlayer plr, final String[] args) {
public boolean onCommand(final PlotPlayer plr, final String[] args)
{
final Location loc = plr.getLocation();
final Plot plot = MainUtil.getPlot(loc);
if (plot == null) {
return !sendMessage(plr, C.NOT_IN_PLOT);
}
if ((!plot.hasOwner() || !plot.isOwner(plr.getUUID())) && !Permissions.hasPermission(plr, "plots.admin.command.unlink")) {
return sendMessage(plr, C.NO_PLOT_PERMS);
}
if (MainUtil.getTopPlot(plot).equals(MainUtil.getBottomPlot(plot))) {
return sendMessage(plr, C.UNLINK_IMPOSSIBLE);
}
Runnable runnable = new Runnable() {
if (plot == null) { return !sendMessage(plr, C.NOT_IN_PLOT); }
if ((!plot.hasOwner() || !plot.isOwner(plr.getUUID())) && !Permissions.hasPermission(plr, "plots.admin.command.unlink")) { return sendMessage(plr, C.NO_PLOT_PERMS); }
if (MainUtil.getTopPlot(plot).equals(MainUtil.getBottomPlot(plot))) { return sendMessage(plr, C.UNLINK_IMPOSSIBLE); }
final Runnable runnable = new Runnable()
{
@Override
public void run() {
if (!MainUtil.unlinkPlot(plot, true)) {
public void run()
{
if (!MainUtil.unlinkPlot(plot, true))
{
MainUtil.sendMessage(plr, "&cUnlink has been cancelled");
return;
}
MainUtil.sendMessage(plr, C.UNLINK_SUCCESS);
}
};
if (Settings.CONFIRM_UNLINK && !(Permissions.hasPermission(plr, "plots.confirm.bypass"))) {
if (Settings.CONFIRM_UNLINK && !(Permissions.hasPermission(plr, "plots.confirm.bypass")))
{
CmdConfirm.addPending(plr, "/plot unlink " + plot.id, runnable);
}
else {
else
{
TaskManager.runTask(runnable);
}
return true;

View File

@ -36,71 +36,82 @@ import com.plotsquared.general.commands.CommandDeclaration;
// UNTRUST("untrust", "ut"),
@CommandDeclaration(
command = "untrust",
aliases = {"ut"},
permission = "plots.untrust",
description = "Remove a trusted user from a plot",
usage = "/plot untrust <player>",
requiredType = RequiredType.NONE,
category = CommandCategory.ACTIONS
)
public class Untrust extends SubCommand {
command = "untrust",
aliases = { "ut" },
permission = "plots.untrust",
description = "Remove a trusted user from a plot",
usage = "/plot untrust <player>",
requiredType = RequiredType.NONE,
category = CommandCategory.ACTIONS)
public class Untrust extends SubCommand
{
public Untrust() {
public Untrust()
{
requiredArguments = new Argument[] {
Argument.PlayerName
Argument.PlayerName
};
}
@Override
public boolean onCommand(final PlotPlayer plr, final String[] args) {
public boolean onCommand(final PlotPlayer plr, final String[] args)
{
final Location loc = plr.getLocation();
final Plot plot = MainUtil.getPlot(loc);
if (plot == null) {
return !sendMessage(plr, C.NOT_IN_PLOT);
}
if (!plot.hasOwner()) {
if (plot == null) { return !sendMessage(plr, C.NOT_IN_PLOT); }
if (!plot.hasOwner())
{
MainUtil.sendMessage(plr, C.PLOT_UNOWNED);
return false;
}
if (!plot.isOwner(plr.getUUID()) && !Permissions.hasPermission(plr, "plots.admin.command.untrust")) {
if (!plot.isOwner(plr.getUUID()) && !Permissions.hasPermission(plr, "plots.admin.command.untrust"))
{
MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
return true;
}
int count = 0;
switch (args[0]) {
switch (args[0])
{
case "unknown":
ArrayList<UUID> toRemove = new ArrayList<>();
for (UUID uuid : plot.getTrusted()) {
if (UUIDHandler.getName(uuid) == null) {
final ArrayList<UUID> toRemove = new ArrayList<>();
for (final UUID uuid : plot.getTrusted())
{
if (UUIDHandler.getName(uuid) == null)
{
toRemove.add(uuid);
}
}
for (UUID uuid : toRemove) {
for (final UUID uuid : toRemove)
{
plot.removeTrusted(uuid);
count++;
}
break;
case "*":
for (UUID uuid : new ArrayList<>(plot.getTrusted())) {
for (final UUID uuid : new ArrayList<>(plot.getTrusted()))
{
plot.removeTrusted(uuid);
count++;
}
break;
default:
UUID uuid = UUIDHandler.getUUID(args[0], null);
if (uuid != null) {
if (plot.removeTrusted(uuid)) {
final UUID uuid = UUIDHandler.getUUID(args[0], null);
if (uuid != null)
{
if (plot.removeTrusted(uuid))
{
count++;
}
}
break;
}
if (count == 0) {
if (count == 0)
{
MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[0]);
return false;
}
else {
else
{
MainUtil.sendMessage(plr, C.REMOVED_PLAYERS, count + "");
}
return true;

View File

@ -30,43 +30,52 @@ import com.intellectualcrafters.plot.util.MainUtil;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "update",
permission = "plots.admin",
description = "Update PlotSquared",
usage = "/plot update",
requiredType = RequiredType.NONE,
aliases = {"updateplugin"},
category = CommandCategory.DEBUG
)
public class Update extends SubCommand {
command = "update",
permission = "plots.admin",
description = "Update PlotSquared",
usage = "/plot update",
requiredType = RequiredType.NONE,
aliases = { "updateplugin" },
category = CommandCategory.DEBUG)
public class Update extends SubCommand
{
public static String version;
@Override
public boolean onCommand(PlotPlayer plr, String[] args) {
public boolean onCommand(final PlotPlayer plr, final String[] args)
{
URL url;
if (args.length == 0) {
if (args.length == 0)
{
url = PS.get().update;
}
else if (args.length == 1) {
try {
else if (args.length == 1)
{
try
{
url = new URL(args[0]);
} catch (MalformedURLException e) {
}
catch (final MalformedURLException e)
{
MainUtil.sendConsoleMessage("&cInvalid url: " + args[0]);
MainUtil.sendConsoleMessage(C.COMMAND_SYNTAX, "/plot update [url]");
return false;
}
}
else {
else
{
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, getUsage().replaceAll("\\{label\\}", "plot"));
return false;
}
if (url == null) {
if (url == null)
{
MainUtil.sendMessage(plr, "&cNo update found!");
MainUtil.sendMessage(plr, "&cTo manually specify an update URL: /plot update <url>");
return false;
}
if (PS.get().update(null, url) && url == PS.get().update) {
if (PS.get().update(null, url) && (url == PS.get().update))
{
PS.get().update = null;
}
return true;

View File

@ -36,26 +36,30 @@ import com.plotsquared.general.commands.Argument;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "visit",
permission = "plots.visit",
description = "Visit someones plot",
usage = "/plot visit <player|aliases|world|id> [#]",
aliases = {"v"},
requiredType = RequiredType.NONE,
category = CommandCategory.TELEPORT
)
public class Visit extends SubCommand {
command = "visit",
permission = "plots.visit",
description = "Visit someones plot",
usage = "/plot visit <player|aliases|world|id> [#]",
aliases = { "v" },
requiredType = RequiredType.NONE,
category = CommandCategory.TELEPORT)
public class Visit extends SubCommand
{
public Visit() {
public Visit()
{
requiredArguments = new Argument[] {
Argument.String
Argument.String
};
}
public List<Plot> getPlots(final UUID uuid) {
public List<Plot> getPlots(final UUID uuid)
{
final List<Plot> plots = new ArrayList<>();
for (final Plot p : PS.get().getPlots()) {
if (p.hasOwner() && p.isOwner(uuid)) {
for (final Plot p : PS.get().getPlots())
{
if (p.hasOwner() && p.isOwner(uuid))
{
plots.add(p);
}
}
@ -63,65 +67,81 @@ public class Visit extends SubCommand {
}
@Override
public boolean onCommand(PlotPlayer plr, String[] args) {
public boolean onCommand(final PlotPlayer plr, final String[] args)
{
ArrayList<Plot> plots = new ArrayList<>();
UUID user = UUIDHandler.getCachedUUID(args[0], null);
if (user != null ) {
final UUID user = UUIDHandler.getCachedUUID(args[0], null);
if (user != null)
{
// do plots by username
plots = PS.get().sortPlotsByTemp(PS.get().getPlots(user));
} else if (PS.get().isPlotWorld(args[0])) {
}
else if (PS.get().isPlotWorld(args[0]))
{
// do plots by world
plots = PS.get().sortPlots(PS.get().getPlotsInWorld(args[0]), SortType.DISTANCE_FROM_ORIGIN, null);
}
else {
Plot plot = MainUtil.getPlotFromString(plr, args[0], true);
if (plot == null) {
return false;
}
else
{
final Plot plot = MainUtil.getPlotFromString(plr, args[0], true);
if (plot == null) { return false; }
plots.add(plot);
}
if (plots.size() == 0) {
if (plots.size() == 0)
{
sendMessage(plr, C.FOUND_NO_PLOTS);
return false;
}
int index = 0;
if (args.length == 2) {
try {
if (args.length == 2)
{
try
{
index = Integer.parseInt(args[1]) - 1;
if (index < 0 || index >= plots.size()) {
if ((index < 0) || (index >= plots.size()))
{
sendMessage(plr, C.NOT_VALID_NUMBER, "(1, " + plots.size() + ")");
sendMessage(plr, C.COMMAND_SYNTAX, "/plot visit " + args[0] + " [#]");
return false;
}
}
catch (Exception e) {
catch (final Exception e)
{
sendMessage(plr, C.NOT_VALID_NUMBER, "(1, " + plots.size() + ")");
sendMessage(plr, C.COMMAND_SYNTAX, "/plot visit " + args[0] + " [#]");
return false;
}
}
Plot plot = plots.get(index);
if (!plot.hasOwner()) {
if (!Permissions.hasPermission(plr, "plots.visit.unowned")) {
final Plot plot = plots.get(index);
if (!plot.hasOwner())
{
if (!Permissions.hasPermission(plr, "plots.visit.unowned"))
{
sendMessage(plr, C.NO_PERMISSION, "plots.visit.unowned");
return false;
}
}
else if (plot.isOwner(plr.getUUID())) {
if (!Permissions.hasPermission(plr, "plots.visit.owned") && !Permissions.hasPermission(plr, "plots.home")) {
else if (plot.isOwner(plr.getUUID()))
{
if (!Permissions.hasPermission(plr, "plots.visit.owned") && !Permissions.hasPermission(plr, "plots.home"))
{
sendMessage(plr, C.NO_PERMISSION, "plots.visit.owned, plots.home");
return false;
}
}
else if (plot.isAdded(plr.getUUID())) {
if (!Permissions.hasPermission(plr, "plots.visit.shared")) {
else if (plot.isAdded(plr.getUUID()))
{
if (!Permissions.hasPermission(plr, "plots.visit.shared"))
{
sendMessage(plr, C.NO_PERMISSION, "plots.visit.shared");
return false;
}
}
else {
if (!Permissions.hasPermission(plr, "plots.visit.other")) {
else
{
if (!Permissions.hasPermission(plr, "plots.visit.other"))
{
sendMessage(plr, C.NO_PERMISSION, "plots.visit.other");
return false;
}

View File

@ -20,30 +20,25 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.commands;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.Permissions;
import com.plotsquared.bukkit.BukkitMain;
import com.plotsquared.general.commands.CommandDeclaration;
import com.plotsquared.listener.WEManager;
@CommandDeclaration(
command = "weanywhere",
permission = "plots.worldedit.bypass",
description = "Force bypass of WorldEdit",
aliases = {"wea"},
usage = "/plot weanywhere",
requiredType = RequiredType.NONE,
category = CommandCategory.DEBUG
)
command = "weanywhere",
permission = "plots.worldedit.bypass",
description = "Force bypass of WorldEdit",
aliases = { "wea" },
usage = "/plot weanywhere",
requiredType = RequiredType.NONE,
category = CommandCategory.DEBUG)
@Deprecated
public class WE_Anywhere extends SubCommand {
public class WE_Anywhere extends SubCommand
{
@Override
public boolean onCommand(PlotPlayer player, String[] arguments) {
return MainCommand.onCommand(player, "plot", new String[] {"toggle", "worldedit"});
public boolean onCommand(final PlotPlayer player, final String[] arguments)
{
return MainCommand.onCommand(player, "plot", new String[] { "toggle", "worldedit" });
}
}

View File

@ -25,18 +25,13 @@ import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map.Entry;
import java.util.Set;
import java.util.UUID;
import org.bukkit.ChatColor;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.PS.SortType;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.flag.Flag;
import com.intellectualcrafters.plot.flag.FlagManager;
import com.intellectualcrafters.plot.object.ConsolePlayer;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotMessage;
import com.intellectualcrafters.plot.object.PlotPlayer;
@ -48,98 +43,109 @@ import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.StringComparison;
import com.intellectualcrafters.plot.util.StringMan;
import com.intellectualcrafters.plot.util.UUIDHandler;
import com.plotsquared.bukkit.object.BukkitPlayer;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "list",
aliases = {"l"},
description = "List plots",
permission = "plots.list",
category = CommandCategory.INFO
)
public class list extends SubCommand {
command = "list",
aliases = { "l" },
description = "List plots",
permission = "plots.list",
category = CommandCategory.INFO)
public class list extends SubCommand
{
private static String getName(final UUID id) {
if (id == null) {
return "none";
}
final String name = UUIDHandler.getName(id);
if (name == null) {
return "unknown";
}
return name;
}
private String[] getArgumentList(PlotPlayer player) {
List<String> args = new ArrayList<>();
if (EconHandler.manager != null && Permissions.hasPermission(player, "plots.list.forsale")) {
private String[] getArgumentList(final PlotPlayer player)
{
final List<String> args = new ArrayList<>();
if ((EconHandler.manager != null) && Permissions.hasPermission(player, "plots.list.forsale"))
{
args.add("forsale");
}
if (Permissions.hasPermission(player, "plots.list.mine")) {
if (Permissions.hasPermission(player, "plots.list.mine"))
{
args.add("mine");
}
if (Permissions.hasPermission(player, "plots.list.shared")) {
if (Permissions.hasPermission(player, "plots.list.shared"))
{
args.add("shared");
}
if (Permissions.hasPermission(player, "plots.list.world")) {
if (Permissions.hasPermission(player, "plots.list.world"))
{
args.add("world");
}
if (Permissions.hasPermission(player, "plots.list.top")) {
if (Permissions.hasPermission(player, "plots.list.top"))
{
args.add("top");
}
if (Permissions.hasPermission(player, "plots.list.all")) {
if (Permissions.hasPermission(player, "plots.list.all"))
{
args.add("all");
}
if (Permissions.hasPermission(player, "plots.list.unowned")) {
if (Permissions.hasPermission(player, "plots.list.unowned"))
{
args.add("unowned");
}
if (Permissions.hasPermission(player, "plots.list.unknown")) {
if (Permissions.hasPermission(player, "plots.list.unknown"))
{
args.add("unknown");
}
if (Permissions.hasPermission(player, "plots.list.player")) {
if (Permissions.hasPermission(player, "plots.list.player"))
{
args.add("<player>");
}
if (Permissions.hasPermission(player, "plots.list.world")) {
if (Permissions.hasPermission(player, "plots.list.world"))
{
args.add("<world>");
}
if (Permissions.hasPermission(player, "plots.list.done")) {
if (Permissions.hasPermission(player, "plots.list.done"))
{
args.add("done");
}
return args.toArray(new String[args.size()]);
}
public void noArgs(PlotPlayer plr) {
public void noArgs(final PlotPlayer plr)
{
MainUtil.sendMessage(plr, C.SUBCOMMAND_SET_OPTIONS_HEADER.s() + getArgumentList(getArgumentList(plr)));
}
@Override
public boolean onCommand(final PlotPlayer plr, final String[] args) {
if (args.length < 1) {
public boolean onCommand(final PlotPlayer plr, final String[] args)
{
if (args.length < 1)
{
noArgs(plr);
return false;
}
int page = 0;
if (args.length > 1) {
try {
if (args.length > 1)
{
try
{
page = Integer.parseInt(args[1]);
--page;
if (page < 0) {
if (page < 0)
{
page = 0;
}
} catch (final Exception e) {
}
catch (final Exception e)
{
page = 0;
}
}
List<Plot> plots = null;
String world = plr.getLocation().getWorld();
String arg = args[0].toLowerCase();
final String world = plr.getLocation().getWorld();
final String arg = args[0].toLowerCase();
boolean sort = true;
switch (arg) {
case "mine": {
if (!Permissions.hasPermission(plr, "plots.list.mine")) {
switch (arg)
{
case "mine":
{
if (!Permissions.hasPermission(plr, "plots.list.mine"))
{
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.list.mine");
return false;
}
@ -147,79 +153,102 @@ public class list extends SubCommand {
plots = PS.get().sortPlotsByTemp(PS.get().getPlots(plr));
break;
}
case "shared": {
if (!Permissions.hasPermission(plr, "plots.list.shared")) {
case "shared":
{
if (!Permissions.hasPermission(plr, "plots.list.shared"))
{
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.list.shared");
return false;
}
plots = new ArrayList<Plot>();
for (Plot plot : PS.get().getPlots()) {
if (plot.getTrusted().contains(plr.getUUID()) || plot.getMembers().contains(plr.getUUID())) {
for (final Plot plot : PS.get().getPlots())
{
if (plot.getTrusted().contains(plr.getUUID()) || plot.getMembers().contains(plr.getUUID()))
{
plots.add(plot);
}
}
break;
}
case "world": {
if (!Permissions.hasPermission(plr, "plots.list.world")) {
case "world":
{
if (!Permissions.hasPermission(plr, "plots.list.world"))
{
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.list.world");
return false;
}
if (!Permissions.hasPermission(plr, "plots.list.world." + world)) {
if (!Permissions.hasPermission(plr, "plots.list.world." + world))
{
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.list.world." + world);
return false;
}
plots = new ArrayList<>(PS.get().getPlotsInWorld(world));
break;
}
case "all": {
if (!Permissions.hasPermission(plr, "plots.list.all")) {
case "all":
{
if (!Permissions.hasPermission(plr, "plots.list.all"))
{
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.list.all");
return false;
}
plots = new ArrayList<>(PS.get().getPlots());
break;
}
case "done": {
if (!Permissions.hasPermission(plr, "plots.list.done")) {
case "done":
{
if (!Permissions.hasPermission(plr, "plots.list.done"))
{
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.list.done");
return false;
}
plots = new ArrayList<>();
String match;
if (args.length == 2) {
if (args.length == 2)
{
match = args[1];
}
else {
else
{
match = null;
}
for (Plot plot : PS.get().getPlots()) {
Flag flag = plot.getSettings().flags.get("done");
if (flag == null) {
for (final Plot plot : PS.get().getPlots())
{
final Flag flag = plot.getSettings().flags.get("done");
if (flag == null)
{
continue;
}
if (match != null) {
try {
if (flag.getValueString().matches(match)) {
if (match != null)
{
try
{
if (flag.getValueString().matches(match))
{
plots.add(plot);
}
}
catch (Exception e) {
catch (final Exception e)
{
break;
}
}
else {
else
{
plots.add(plot);
}
}
Collections.sort(plots, new Comparator<Plot>() {
Collections.sort(plots, new Comparator<Plot>()
{
@Override
public int compare(Plot a, Plot b) {
String va = a.getSettings().flags.get("done").getValueString();
String vb = b.getSettings().flags.get("done").getValueString();
if (MathMan.isInteger(va)) {
public int compare(final Plot a, final Plot b)
{
final String va = a.getSettings().flags.get("done").getValueString();
final String vb = b.getSettings().flags.get("done").getValueString();
if (MathMan.isInteger(va))
{
if (MathMan.isInteger(vb)) {
return Integer.parseInt(vb) - Integer.parseInt(va);
return Integer.parseInt(vb) - Integer.parseInt(va);
}
return -1;
}
@ -229,37 +258,45 @@ public class list extends SubCommand {
sort = false;
break;
}
case "top": {
if (!Permissions.hasPermission(plr, "plots.list.top")) {
case "top":
{
if (!Permissions.hasPermission(plr, "plots.list.top"))
{
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.list.top");
return false;
}
plots = new ArrayList<>(PS.get().getPlots());
Collections.sort(plots, new Comparator<Plot>() {
Collections.sort(plots, new Comparator<Plot>()
{
@Override
public int compare(Plot p1, Plot p2) {
public int compare(final Plot p1, final Plot p2)
{
double v1 = 0;
double v2 = 0;
int p1s = p1.getSettings().ratings != null ? p1.getSettings().ratings.size() : 0;
int p2s = p2.getSettings().ratings != null ? p2.getSettings().ratings.size() : 0;
if (p1.getSettings().ratings != null && p1s > 0) {
for (Entry<UUID, Rating> entry : p1.getRatings().entrySet()) {
double av = entry.getValue().getAverageRating();
final int p1s = p1.getSettings().ratings != null ? p1.getSettings().ratings.size() : 0;
final int p2s = p2.getSettings().ratings != null ? p2.getSettings().ratings.size() : 0;
if ((p1.getSettings().ratings != null) && (p1s > 0))
{
for (final Entry<UUID, Rating> entry : p1.getRatings().entrySet())
{
final double av = entry.getValue().getAverageRating();
v1 += av * av;
}
v1 /= p1s;
v1 += p1s;
}
if (p2.getSettings().ratings != null && p2s > 0) {
for (Entry<UUID, Rating> entry : p2.getRatings().entrySet()) {
double av = entry.getValue().getAverageRating();
if ((p2.getSettings().ratings != null) && (p2s > 0))
{
for (final Entry<UUID, Rating> entry : p2.getRatings().entrySet())
{
final double av = entry.getValue().getAverageRating();
v2 += av * av;
}
v2 /= p2s;
v2 += p2s;
}
if (v2 == v1 && v2 != 0) {
return p2s - p1s;
if ((v2 == v1) && (v2 != 0)) {
return p2s - p1s;
}
return (int) Math.signum(v2 - v1);
}
@ -267,59 +304,77 @@ public class list extends SubCommand {
sort = false;
break;
}
case "forsale": {
if (!Permissions.hasPermission(plr, "plots.list.forsale")) {
case "forsale":
{
if (!Permissions.hasPermission(plr, "plots.list.forsale"))
{
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.list.forsale");
return false;
}
if (EconHandler.manager == null) {
if (EconHandler.manager == null)
{
break;
}
plots = new ArrayList<>();
for (Plot plot : PS.get().getPlots()) {
for (final Plot plot : PS.get().getPlots())
{
final Flag price = FlagManager.getPlotFlag(plot, "price");
if (price != null) {
if (price != null)
{
plots.add(plot);
}
}
break;
}
case "unowned": {
if (!Permissions.hasPermission(plr, "plots.list.unowned")) {
case "unowned":
{
if (!Permissions.hasPermission(plr, "plots.list.unowned"))
{
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.list.unowned");
return false;
}
plots = new ArrayList<>();
for (Plot plot : PS.get().getPlots()) {
if (plot.owner == null) {
for (final Plot plot : PS.get().getPlots())
{
if (plot.owner == null)
{
plots.add(plot);
}
}
break;
}
case "unknown": {
if (!Permissions.hasPermission(plr, "plots.list.unknown")) {
case "unknown":
{
if (!Permissions.hasPermission(plr, "plots.list.unknown"))
{
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.list.unknown");
return false;
}
plots = new ArrayList<>();
for (Plot plot : PS.get().getPlots()) {
if (plot.owner == null) {
for (final Plot plot : PS.get().getPlots())
{
if (plot.owner == null)
{
continue;
}
if (UUIDHandler.getName(plot.owner) == null) {
if (UUIDHandler.getName(plot.owner) == null)
{
plots.add(plot);
}
}
break;
}
default: {
if (PS.get().isPlotWorld(args[0])) {
if (!Permissions.hasPermission(plr, "plots.list.world")) {
default:
{
if (PS.get().isPlotWorld(args[0]))
{
if (!Permissions.hasPermission(plr, "plots.list.world"))
{
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.list.world");
return false;
}
if (!Permissions.hasPermission(plr, "plots.list.world." + args[0])) {
if (!Permissions.hasPermission(plr, "plots.list.world." + args[0]))
{
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.list.world." + args[0]);
return false;
}
@ -327,14 +382,19 @@ public class list extends SubCommand {
break;
}
UUID uuid = UUIDHandler.getUUID(args[0], null);
if (uuid == null) {
try {
if (uuid == null)
{
try
{
uuid = UUID.fromString(args[0]);
}
catch (Exception e) {}
catch (final Exception e)
{}
}
if (uuid != null) {
if (!Permissions.hasPermission(plr, "plots.list.player")) {
if (uuid != null)
{
if (!Permissions.hasPermission(plr, "plots.list.player"))
{
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.list.player");
return false;
}
@ -344,91 +404,107 @@ public class list extends SubCommand {
}
}
}
if (plots == null) {
if (plots == null)
{
sendMessage(plr, C.DID_YOU_MEAN, new StringComparison<String>(args[0], new String[] { "mine", "shared", "world", "all" }).getBestMatch());
return false;
}
if (plots.size() == 0) {
if (plots.size() == 0)
{
MainUtil.sendMessage(plr, C.FOUND_NO_PLOTS);
return false;
}
displayPlots(plr, plots, 12, page, world, args, sort);
return true;
}
public void displayPlots(PlotPlayer player, List<Plot> plots, int pageSize, int page, String world, String[] args, boolean sort) {
if (sort) {
public void displayPlots(final PlotPlayer player, List<Plot> plots, final int pageSize, int page, final String world, final String[] args, final boolean sort)
{
if (sort)
{
plots = PS.get().sortPlots(plots, SortType.DISTANCE_FROM_ORIGIN, world);
}
if (page < 0) {
if (page < 0)
{
page = 0;
}
final int totalPages = (int) Math.ceil(plots.size() / pageSize);
if (page > totalPages) {
if (page > totalPages)
{
page = totalPages;
}
// Only display pageSize!
int max = (page * pageSize) + pageSize;
if (max > plots.size()) {
if (max > plots.size())
{
max = plots.size();
}
List<Plot> subList = plots.subList(page * pageSize, max);
final List<Plot> subList = plots.subList(page * pageSize, max);
// Header
String header = C.PLOT_LIST_HEADER_PAGED.s()
.replaceAll("%cur", page + 1 + "")
.replaceAll("%max", totalPages + 1 + "")
.replaceAll("%amount%", plots.size() + "")
.replaceAll("%word%", "all");
final String header = C.PLOT_LIST_HEADER_PAGED.s()
.replaceAll("%cur", page + 1 + "")
.replaceAll("%max", totalPages + 1 + "")
.replaceAll("%amount%", plots.size() + "")
.replaceAll("%word%", "all");
MainUtil.sendMessage(player, header);
int i = page * pageSize;
for (Plot plot : subList) {
if (plot.getSettings().isMerged()) {
if (!MainUtil.getBottomPlot(plot).equals(plot)) {
for (final Plot plot : subList)
{
if (plot.getSettings().isMerged())
{
if (!MainUtil.getBottomPlot(plot).equals(plot))
{
continue;
}
}
i++;
String color;
if (plot.owner == null) {
if (plot.owner == null)
{
color = "$3";
}
else if (plot.isOwner(player.getUUID())) {
else if (plot.isOwner(player.getUUID()))
{
color = "$1";
}
else if (plot.isAdded(player.getUUID())) {
else if (plot.isAdded(player.getUUID()))
{
color = "$4";
}
else if (plot.isDenied(player.getUUID())) {
else if (plot.isDenied(player.getUUID()))
{
color = "$2";
}
else {
else
{
color = "$1";
}
PlotMessage trusted =
new PlotMessage()
.text(C.color(C.PLOT_INFO_TRUSTED.s().replaceAll("%trusted%", Info.getPlayerList(plot.getTrusted()))))
.color("$1");
PlotMessage members =
new PlotMessage()
.text(C.color(C.PLOT_INFO_MEMBERS.s().replaceAll("%members%", Info.getPlayerList(plot.getMembers()))))
.color("$1");
final PlotMessage trusted =
new PlotMessage()
.text(C.color(C.PLOT_INFO_TRUSTED.s().replaceAll("%trusted%", Info.getPlayerList(plot.getTrusted()))))
.color("$1");
final PlotMessage members =
new PlotMessage()
.text(C.color(C.PLOT_INFO_MEMBERS.s().replaceAll("%members%", Info.getPlayerList(plot.getMembers()))))
.color("$1");
String strFlags = StringMan.join(plot.getSettings().flags.values(), ",");
if (strFlags.length() == 0) {
if (strFlags.length() == 0)
{
strFlags = C.NONE.s();
}
PlotMessage flags =
new PlotMessage()
.text(C.color(C.PLOT_INFO_FLAGS.s().replaceAll("%flags%", strFlags)))
.color("$1");
final PlotMessage flags =
new PlotMessage()
.text(C.color(C.PLOT_INFO_FLAGS.s().replaceAll("%flags%", strFlags)))
.color("$1");
PlotMessage message = new PlotMessage()
.text("[")
.color("$3")
@ -439,48 +515,54 @@ public class list extends SubCommand {
.text("]")
.color("$3")
.text(" " + plot.toString())
.tooltip(trusted, members, flags)
.command("/plot info " + plot.world + ";" + plot.id)
.color(color)
.text(" - ")
.color("$2");
String prefix = "";
for (UUID uuid : plot.getOwners()) {
String name = UUIDHandler.getName(uuid);
if (name == null) {
for (final UUID uuid : plot.getOwners())
{
final String name = UUIDHandler.getName(uuid);
if (name == null)
{
message = message
.text(prefix)
.color("$4")
.text("unknown")
.color("$2")
.tooltip(uuid.toString())
.suggest(uuid.toString());
.text(prefix)
.color("$4")
.text("unknown")
.color("$2")
.tooltip(uuid.toString())
.suggest(uuid.toString());
}
else {
PlotPlayer pp = UUIDHandler.getPlayer(uuid);
if (pp != null) {
else
{
final PlotPlayer pp = UUIDHandler.getPlayer(uuid);
if (pp != null)
{
message = message
.text(prefix)
.color("$4")
.text(name).color("$1")
.tooltip(new PlotMessage("Online").color("$4"));
.text(prefix)
.color("$4")
.text(name).color("$1")
.tooltip(new PlotMessage("Online").color("$4"));
}
else {
else
{
message = message
.text(prefix)
.color("$4")
.text(name).color("$1")
.tooltip(new PlotMessage("Offline").color("$3"));
.text(prefix)
.color("$4")
.text(name).color("$1")
.tooltip(new PlotMessage("Offline").color("$3"));
}
}
prefix = ", ";
}
message.send(player);
}
if (page < totalPages && page > 0) {
// back | next
if ((page < totalPages) && (page > 0))
{
// back | next
new PlotMessage()
.text("<-")
.color("$1")
@ -495,7 +577,8 @@ public class list extends SubCommand {
.send(player);
return;
}
if (page == 0 && totalPages != 0) {
if ((page == 0) && (totalPages != 0))
{
// next
new PlotMessage()
.text("<-")
@ -510,7 +593,8 @@ public class list extends SubCommand {
.send(player);
return;
}
if (page == totalPages && totalPages != 0) {
if ((page == totalPages) && (totalPages != 0))
{
// back
new PlotMessage()
.text("<-")
@ -526,11 +610,13 @@ public class list extends SubCommand {
return;
}
}
private String getArgumentList(final String[] strings) {
private String getArgumentList(final String[] strings)
{
final StringBuilder builder = new StringBuilder();
String prefix = "";
for (final String s : strings) {
for (final String s : strings)
{
builder.append(prefix + s);
prefix = " | ";
}

View File

@ -27,16 +27,17 @@ import com.intellectualcrafters.plot.util.StringMan;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "plugin",
permission = "plots.use",
description = "Show plugin information",
aliases = {"version"},
category = CommandCategory.INFO
)
public class plugin extends SubCommand {
command = "plugin",
permission = "plots.use",
description = "Show plugin information",
aliases = { "version" },
category = CommandCategory.INFO)
public class plugin extends SubCommand
{
@Override
public boolean onCommand(final PlotPlayer plr, final String[] args) {
public boolean onCommand(final PlotPlayer plr, final String[] args)
{
MainUtil.sendMessage(plr, String.format("$2>> $1&lPlotSquared $2($1Version$2: $1%s$2)", StringMan.join(PS.get().IMP.getPluginVersion(), ".")));
MainUtil.sendMessage(plr, String.format("$2>> $1&lAuthors$2: $1Citymonstret $2& $1Empire92"));
MainUtil.sendMessage(plr, String.format("$2>> $1&lWiki$2: $1https://github.com/IntellectualCrafters/PlotSquared/wiki"));

View File

@ -38,49 +38,50 @@ import com.plotsquared.general.commands.CommandCaller;
/**
* Captions class.
*
* @author Citymonstret
*/
public enum C {
public enum C
{
/*
* Static flags
*/
FLAG_USE("use","static.flags"),
FLAG_PLACE("place","static.flags"),
FLAG_PVP("pvp","static.flags"),
FLAG_HANGING_PLACE("hanging-place","static.flags"),
FLAG_HANGING_BREAK("hanging-break","static.flags"),
FLAG_HOSTILE_INTERACT("hostile-interact","static.flags"),
FLAG_ANIMAL_INTERACT("animal-interact","static.flags"),
FLAG_VEHICLE_USE("vehicle-use","static.flags"),
FLAG_PLAYER_INTERACT("player-interact","static.flags"),
FLAG_TAMED_INTERACT("tamed-interact","static.flags"),
FLAG_DISABLE_PHYSICS("disable-physics","static.flags"),
FLAG_USE("use", "static.flags"),
FLAG_PLACE("place", "static.flags"),
FLAG_PVP("pvp", "static.flags"),
FLAG_HANGING_PLACE("hanging-place", "static.flags"),
FLAG_HANGING_BREAK("hanging-break", "static.flags"),
FLAG_HOSTILE_INTERACT("hostile-interact", "static.flags"),
FLAG_ANIMAL_INTERACT("animal-interact", "static.flags"),
FLAG_VEHICLE_USE("vehicle-use", "static.flags"),
FLAG_PLAYER_INTERACT("player-interact", "static.flags"),
FLAG_TAMED_INTERACT("tamed-interact", "static.flags"),
FLAG_DISABLE_PHYSICS("disable-physics", "static.flags"),
/*
* Static permission
*/
PERMISSION_STAR("*","static.permissions"),
PERMISSION_ADMIN("plots.admin","static.permissions"),
PERMISSION_PROJECTILE_UNOWNED("plots.projectile.unowned","static.permissions"),
PERMISSION_PROJECTILE_OTHER("plots.projectile.other","static.permissions"),
PERMISSION_ADMIN_INTERACT_BLOCKED_CMDS("plots.admin.interact.blockedcommands","static.permissions"),
PERMISSION_WORLDEDIT_BYPASS("plots.worldedit.bypass","static.permissions"),
PERMISSION_PLOT_TOGGLE_TITLES("plots.toggle.titles","static.permissions"),
PERMISSION_PLOT_TOGGLE_CHAT("plots.toggle.chat","static.permissions"),
PERMISSION_ADMIN_EXIT_DENIED("plots.admin.exit.denied","static.permissions"),
PERMISSION_ADMIN_ENTRY_DENIED("plots.admin.entry.denied","static.permissions"),
PERMISSION_COMMANDS_CHAT("plots.admin.command.chat","static.permissions"),
PERMISSION_MERGE_OTHER("plots.merge.other","static.permissions"),
PERMISSION_ADMIN_DESTROY_UNOWNED("plots.admin.destroy.unowned","static.permissions"),
PERMISSION_ADMIN_DESTROY_OTHER( "plots.admin.destroy.other","static.permissions"),
PERMISSION_ADMIN_DESTROY_ROAD("plots.admin.destroy.road","static.permissions"),
PERMISSION_ADMIN_BUILD_ROAD("plots.admin.build.road","static.permissions"),
PERMISSION_ADMIN_BUILD_UNOWNED("plots.admin.build.unowned","static.permissions"),
PERMISSION_ADMIN_BUILD_OTHER("plots.admin.build.other","static.permissions"),
PERMISSION_ADMIN_INTERACT_ROAD("plots.admin.interact.road","static.permissions"),
PERMISSION_ADMIN_INTERACT_UNOWNED("plots.admin.interact.unowned","static.permissions"),
PERMISSION_ADMIN_INTERACT_OTHER("plots.admin.interact.other","static.permissions"),
PERMISSION_ADMIN_BUILD_HEIGHTLIMIT("plots.admin.build.heightlimit","static.permissions"),
PERMISSION_STAR("*", "static.permissions"),
PERMISSION_ADMIN("plots.admin", "static.permissions"),
PERMISSION_PROJECTILE_UNOWNED("plots.projectile.unowned", "static.permissions"),
PERMISSION_PROJECTILE_OTHER("plots.projectile.other", "static.permissions"),
PERMISSION_ADMIN_INTERACT_BLOCKED_CMDS("plots.admin.interact.blockedcommands", "static.permissions"),
PERMISSION_WORLDEDIT_BYPASS("plots.worldedit.bypass", "static.permissions"),
PERMISSION_PLOT_TOGGLE_TITLES("plots.toggle.titles", "static.permissions"),
PERMISSION_PLOT_TOGGLE_CHAT("plots.toggle.chat", "static.permissions"),
PERMISSION_ADMIN_EXIT_DENIED("plots.admin.exit.denied", "static.permissions"),
PERMISSION_ADMIN_ENTRY_DENIED("plots.admin.entry.denied", "static.permissions"),
PERMISSION_COMMANDS_CHAT("plots.admin.command.chat", "static.permissions"),
PERMISSION_MERGE_OTHER("plots.merge.other", "static.permissions"),
PERMISSION_ADMIN_DESTROY_UNOWNED("plots.admin.destroy.unowned", "static.permissions"),
PERMISSION_ADMIN_DESTROY_OTHER("plots.admin.destroy.other", "static.permissions"),
PERMISSION_ADMIN_DESTROY_ROAD("plots.admin.destroy.road", "static.permissions"),
PERMISSION_ADMIN_BUILD_ROAD("plots.admin.build.road", "static.permissions"),
PERMISSION_ADMIN_BUILD_UNOWNED("plots.admin.build.unowned", "static.permissions"),
PERMISSION_ADMIN_BUILD_OTHER("plots.admin.build.other", "static.permissions"),
PERMISSION_ADMIN_INTERACT_ROAD("plots.admin.interact.road", "static.permissions"),
PERMISSION_ADMIN_INTERACT_UNOWNED("plots.admin.interact.unowned", "static.permissions"),
PERMISSION_ADMIN_INTERACT_OTHER("plots.admin.interact.other", "static.permissions"),
PERMISSION_ADMIN_BUILD_HEIGHTLIMIT("plots.admin.build.heightlimit", "static.permissions"),
/*
* Confirm
*/
@ -109,7 +110,9 @@ public enum C {
/*
* Cluster
*/
CLUSTER_AVAILABLE_ARGS("$1The following sub commands are available: $4list$2, $4create$2, $4delete$2, $4resize$2, $4invite$2, $4kick$2, $4leave$2, $4members$2, $4info$2, $4tp$2, $4sethome", "Cluster"),
CLUSTER_AVAILABLE_ARGS(
"$1The following sub commands are available: $4list$2, $4create$2, $4delete$2, $4resize$2, $4invite$2, $4kick$2, $4leave$2, $4members$2, $4info$2, $4tp$2, $4sethome",
"Cluster"),
CLUSTER_LIST_HEADING("$2There are $1%s$2 clusters in this world", "Cluster"),
CLUSTER_LIST_ELEMENT("$2 - $1%s&-", "Cluster"),
CLUSTER_INTERSECTION("$2The proposed area overlaps with $1%s$2 existing cluster/s", "Cluster"),
@ -183,7 +186,7 @@ public enum C {
COMMENT_REMOVED("$4Successfully deleted comment/s:n$2 - '$3%s$2'", "Comment"),
COMMENT_ADDED("$4A comment has been left", "Comment"),
COMMENT_HEADER("$2&m---------&r $1Comments $2&m---------&r", "Comment"),
INBOX_EMPTY("$2No comments","Comment"),
INBOX_EMPTY("$2No comments", "Comment"),
/*
* Console
*/
@ -206,7 +209,7 @@ public enum C {
NO_CLIPBOARD("$2You don't have a selection in your clipboard", "Clipboard"),
CLIPBOARD_INFO("$2Current Selection - Plot ID: $1%id$2, Width: $1%width$2, Total Blocks: $1%total$2", "Clipboard"),
/*
*
*
*/
TOGGLE_ENABLED("$2Enabled setting: %s", "Toggle"),
TOGGLE_DISABLED("$2Disabled setting: %s", "Toggle"),
@ -215,11 +218,11 @@ public enum C {
/*
* Done
*/
DONE_ALREADY_DONE("$2This plot is already marked as done","Done"),
DONE_NOT_DONE("$2This plot is not marked as done.","Done"),
DONE_INSUFFICIENT_COMPLEXITY("$2This plot is too simple. Please add more detail before using this command.","Done"),
DONE_SUCCESS("$1Successfully marked this plot as done.","Done"),
DONE_REMOVED("$1You may now continue building in this plot.","Done"),
DONE_ALREADY_DONE("$2This plot is already marked as done", "Done"),
DONE_NOT_DONE("$2This plot is not marked as done.", "Done"),
DONE_INSUFFICIENT_COMPLEXITY("$2This plot is too simple. Please add more detail before using this command.", "Done"),
DONE_SUCCESS("$1Successfully marked this plot as done.", "Done"),
DONE_REMOVED("$1You may now continue building in this plot.", "Done"),
/*
* Ratings
*/
@ -252,10 +255,16 @@ public enum C {
SETUP_STEP("$3[$1Step %s0$3] $1%s1 $2- $1Expecting: $2%s2 $1Default: $2%s3", "Setup"),
SETUP_INVALID_ARG("$2%s0 is not a valid argument for step %s1. To cancel setup use: $1/plot setup cancel", "Setup"),
SETUP_VALID_ARG("$2Value $1%s0 $2set to %s1", "Setup"),
SETUP_FINISHED("$4You should have been teleported to the created world. Otherwise you will need to set the generator manually using the bukkit.yml or your chosen world management plugin.", "Setup"),
SETUP_FINISHED(
"$4You should have been teleported to the created world. Otherwise you will need to set the generator manually using the bukkit.yml or your chosen world management plugin.",
"Setup"),
SETUP_WORLD_TAKEN("$2%s is already a registered plotworld", "Setup"),
SETUP_MISSING_WORLD("$2You need to specify a world name ($1/plot setup &l<world>$1 <generator>$2)&-$1Additional commands:&-$2 - $1/plot setup <value>&-$2 - $1/plot setup back&-$2 - $1/plot setup cancel", "Setup"),
SETUP_MISSING_GENERATOR("$2You need to specify a generator ($1/plot setup <world> &l<generator>&r$2)&-$1Additional commands:&-$2 - $1/plot setup <value>&-$2 - $1/plot setup back&-$2 - $1/plot setup cancel", "Setup"),
SETUP_MISSING_WORLD(
"$2You need to specify a world name ($1/plot setup &l<world>$1 <generator>$2)&-$1Additional commands:&-$2 - $1/plot setup <value>&-$2 - $1/plot setup back&-$2 - $1/plot setup cancel",
"Setup"),
SETUP_MISSING_GENERATOR(
"$2You need to specify a generator ($1/plot setup <world> &l<generator>&r$2)&-$1Additional commands:&-$2 - $1/plot setup <value>&-$2 - $1/plot setup back&-$2 - $1/plot setup cancel",
"Setup"),
SETUP_INVALID_GENERATOR("$2Invalid generator. Possible options: %s", "Setup"),
/*
* Schematic Stuff
@ -441,7 +450,16 @@ public enum C {
PLOT_UNOWNED("$2The current plot must have an owner to perform this action", "Info"),
PLOT_INFO_UNCLAIMED("$2Plot $1%s$2 is not yet claimed", "Info"),
PLOT_INFO_HEADER("$3&m---------&r $1INFO $3&m---------", false, "Info"),
PLOT_INFO("$1ID: $2%id%$1&-" + "$1Alias: $2%alias%$1&-" + "$1Owner: $2%owner%$1&-" + "$1Biome: $2%biome%$1&-" + "$1Can Build: $2%build%$1&-" + "$1Rating: $2%rating%&-" + "$1Trusted: $2%trusted%$1&-" + "$1Members: $2%members%$1&-" + "$1Denied: $2%denied%$1&-" + "$1Flags: $2%flags%", "Info"),
PLOT_INFO("$1ID: $2%id%$1&-"
+ "$1Alias: $2%alias%$1&-"
+ "$1Owner: $2%owner%$1&-"
+ "$1Biome: $2%biome%$1&-"
+ "$1Can Build: $2%build%$1&-"
+ "$1Rating: $2%rating%&-"
+ "$1Trusted: $2%trusted%$1&-"
+ "$1Members: $2%members%$1&-"
+ "$1Denied: $2%denied%$1&-"
+ "$1Flags: $2%flags%", "Info"),
PLOT_INFO_FOOTER("$3&m---------&r $1INFO $3&m---------", false, "Info"),
PLOT_INFO_TRUSTED("$1Trusted:$2 %trusted%", "Info"),
PLOT_INFO_MEMBERS("$1Members:$2 %members%", "Info"),
@ -593,7 +611,8 @@ public enum C {
/**
* Constructor for custom strings.
*/
C() {
C()
{
/*
* use setCustomString();
*/
@ -605,10 +624,12 @@ public enum C {
* @param d default
* @param prefix use prefix
*/
C(final String d, final boolean prefix, String cat) {
C(final String d, final boolean prefix, final String cat)
{
this.d = d;
if (this.s == null) {
this.s = d;
if (s == null)
{
s = d;
}
this.prefix = prefix;
this.cat = cat.toLowerCase();
@ -619,23 +640,27 @@ public enum C {
*
* @param d default
*/
C(final String d, String cat) {
C(final String d, final String cat)
{
this(d, true, cat.toLowerCase());
}
@Override
public String toString() {
public String toString()
{
return s;
}
public static String format(String m, Object... args) {
if (args.length == 0) {
return m;
}
Map<String, String> map = new LinkedHashMap<String, String>();
if (args.length > 0) {
for (int i = args.length - 1 ; i >= 0; i--) {
if (args[i] == null) {
public static String format(String m, final Object... args)
{
if (args.length == 0) { return m; }
final Map<String, String> map = new LinkedHashMap<String, String>();
if (args.length > 0)
{
for (int i = args.length - 1; i >= 0; i--)
{
if (args[i] == null)
{
args[i] = "";
}
map.put("%s" + i, args[i].toString());
@ -647,49 +672,60 @@ public enum C {
return m;
}
public static String format(C c, Object... args) {
public static String format(final C c, final Object... args)
{
return format(c.s, args);
}
public static String color(String string) {
public static String color(final String string)
{
return StringMan.replaceFromMap(string, replacements);
}
public static void load(File file) {
try {
if (!file.exists()) {
public static void load(final File file)
{
try
{
if (!file.exists())
{
file.getParentFile().mkdirs();
file.createNewFile();
}
YamlConfiguration yml = YamlConfiguration.loadConfiguration(file);
Set<String> keys = yml.getKeys(true);
EnumSet<C> all = EnumSet.allOf(C.class);
HashSet<String> allNames = new HashSet<>();
HashSet<String> allCats = new HashSet<>();
HashSet<String> toRemove = new HashSet<>();
for (C c: all) {
final YamlConfiguration yml = YamlConfiguration.loadConfiguration(file);
final Set<String> keys = yml.getKeys(true);
final EnumSet<C> all = EnumSet.allOf(C.class);
final HashSet<String> allNames = new HashSet<>();
final HashSet<String> allCats = new HashSet<>();
final HashSet<String> toRemove = new HashSet<>();
for (final C c : all)
{
allNames.add(c.name());
allCats.add(c.cat.toLowerCase());
}
HashSet<C> captions = new HashSet<>();
final HashSet<C> captions = new HashSet<>();
boolean changed = false;
for (String key : keys) {
if (!yml.isString(key)) {
if (!allCats.contains(key)) {
for (final String key : keys)
{
if (!yml.isString(key))
{
if (!allCats.contains(key))
{
toRemove.add(key);
}
continue;
}
String[] split = key.split("\\.");
String node = split[split.length - 1].toUpperCase();
C caption = allNames.contains(node) ? valueOf(node) : null;
if (caption != null) {
if (caption.cat.startsWith("static")) {
final String[] split = key.split("\\.");
final String node = split[split.length - 1].toUpperCase();
final C caption = allNames.contains(node) ? valueOf(node) : null;
if (caption != null)
{
if (caption.cat.startsWith("static"))
{
continue;
}
String value = yml.getString(key);
if (!split[0].equalsIgnoreCase(caption.cat)) {
final String value = yml.getString(key);
if (!split[0].equalsIgnoreCase(caption.cat))
{
changed = true;
yml.set(key, null);
yml.set(caption.cat + "." + caption.name().toLowerCase(), value);
@ -697,30 +733,37 @@ public enum C {
captions.add(caption);
caption.s = value;
}
else {
else
{
toRemove.add(key);
}
}
for (String remove : toRemove) {
for (final String remove : toRemove)
{
changed = true;
yml.set(remove, null);
}
ConfigurationSection config = PS.get().style.getConfigurationSection("color");
Set<String> styles = config.getKeys(false);
final ConfigurationSection config = PS.get().style.getConfigurationSection("color");
final Set<String> styles = config.getKeys(false);
// HashMap<String, String> replacements = new HashMap<>();
replacements.clear();
for (String style : styles) {
for (final String style : styles)
{
replacements.put("$" + style, "\u00a7" + config.getString(style));
}
for (char letter : "1234567890abcdefklmnor".toCharArray()) {
for (final char letter : "1234567890abcdefklmnor".toCharArray())
{
replacements.put("&" + letter, "\u00a7" + letter);
}
replacements.put("\\\\n", "\n");
replacements.put("\\n", "\n");
replacements.put("&-", "\n");
for (C caption : all) {
if (!captions.contains(caption)) {
if (caption.cat.startsWith("static")) {
for (final C caption : all)
{
if (!captions.contains(caption))
{
if (caption.cat.startsWith("static"))
{
continue;
}
changed = true;
@ -728,36 +771,45 @@ public enum C {
}
caption.s = StringMan.replaceFromMap(caption.s, replacements);
}
if (changed) {
if (changed)
{
yml.save(file);
}
}
catch (Exception e) {
catch (final Exception e)
{
e.printStackTrace();
}
}
public String s() {
return this.s;
public String s()
{
return s;
}
public boolean usePrefix() {
return this.prefix;
public boolean usePrefix()
{
return prefix;
}
public String formatted() {
public String formatted()
{
return StringMan.replaceFromMap(s(), replacements);
}
public String getCat() {
public String getCat()
{
return cat;
}
public void send(CommandCaller plr, String... args) {
if (plr == null) {
public void send(final CommandCaller plr, final String... args)
{
if (plr == null)
{
MainUtil.sendConsoleMessage(this, args);
}
else {
else
{
plr.sendMessage(this, args);
}
}

View File

@ -1,248 +1,313 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
// PlotSquared - A plot manager and world generator for the Bukkit API /
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
// /
// This program is free software; you can redistribute it and/or modify /
// it under the terms of the GNU General Public License as published by /
// the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.config;
import java.util.ArrayList;
import com.intellectualcrafters.plot.object.PlotBlock;
import com.intellectualcrafters.plot.util.BlockManager;
import com.intellectualcrafters.plot.util.StringComparison;
/**
* Main Configuration Utility
*
* @author Empire92
*/
@SuppressWarnings("unused")
public class Configuration {
public static final SettingValue<String> STRING = new SettingValue<String>("STRING") {
@Override
public boolean validateValue(final String string) {
return true;
}
@Override
public String parseString(final String string) {
return string;
}
};
public static final SettingValue<String[]> STRINGLIST = new SettingValue<String[]>("STRINGLIST") {
@Override
public boolean validateValue(final String string) {
return true;
}
@Override
public String[] parseString(final String string) {
return string.split(",");
}
};
public static final SettingValue<Integer> INTEGER = new SettingValue<Integer>("INTEGER") {
@Override
public boolean validateValue(final String string) {
try {
Integer.parseInt(string);
return true;
} catch (final Exception e) {
return false;
}
}
@Override
public Integer parseString(final String string) {
return Integer.parseInt(string);
}
};
public static final SettingValue<Boolean> BOOLEAN = new SettingValue<Boolean>("BOOLEAN") {
@Override
public boolean validateValue(final String string) {
try {
Boolean.parseBoolean(string);
return true;
} catch (final Exception e) {
return false;
}
}
@Override
public Boolean parseString(final String string) {
return Boolean.parseBoolean(string);
}
};
public static final SettingValue<Double> DOUBLE = new SettingValue<Double>("DOUBLE") {
@Override
public boolean validateValue(final String string) {
try {
Double.parseDouble(string);
return true;
} catch (final Exception e) {
return false;
}
}
@Override
public Double parseString(final String string) {
return Double.parseDouble(string);
}
};
public static final SettingValue<String> BIOME = new SettingValue<String>("BIOME") {
@Override
public boolean validateValue(final String string) {
try {
final int biome = BlockManager.manager.getBiomeFromString(string.toUpperCase());
return biome != -1;
} catch (final Exception e) {
return false;
}
}
@Override
public String parseString(final String string) {
if (validateValue(string)) {
return string.toUpperCase();
}
return "FOREST";
}
};
public static final SettingValue<PlotBlock> BLOCK = new SettingValue<PlotBlock>("BLOCK") {
@Override
public boolean validateValue(final String string) {
try {
if (string.contains(":")) {
final String[] split = string.split(":");
Short.parseShort(split[0]);
Short.parseShort(split[1]);
} else {
Short.parseShort(string);
}
return true;
} catch (final Exception e) {
return false;
}
}
@Override
public PlotBlock parseString(final String string) {
if (string.contains(":")) {
final String[] split = string.split(":");
return new PlotBlock(Short.parseShort(split[0]), Byte.parseByte(split[1]));
} else {
return new PlotBlock(Short.parseShort(string), (byte) 0);
}
}
};
public static final SettingValue<PlotBlock[]> BLOCKLIST = new SettingValue<PlotBlock[]>("BLOCKLIST") {
@Override
public boolean validateValue(final String string) {
try {
for (String block : string.split(",")) {
if (block.contains("%")) {
final String[] split = block.split("%");
Integer.parseInt(split[0]);
block = split[1];
}
StringComparison<PlotBlock>.ComparisonResult value = BlockManager.manager.getClosestBlock(block);
if (value == null || value.match > 1) {
return false;
}
}
return true;
} catch (final Exception e) {
return false;
}
}
@Override
public PlotBlock[] parseString(final String string) {
final String[] blocks = string.split(",");
final ArrayList<PlotBlock> parsedvalues = new ArrayList<>();
final PlotBlock[] values = new PlotBlock[blocks.length];
final int[] counts = new int[blocks.length];
int min = 100;
for (int i = 0; i < blocks.length; i++) {
try {
if (blocks[i].contains("%")) {
final String[] split = blocks[i].split("%");
blocks[i] = split[1];
final int value = Integer.parseInt(split[0]);
counts[i] = value;
if (value < min) {
min = value;
}
} else {
counts[i] = 1;
if (1 < min) {
min = 1;
}
}
StringComparison<PlotBlock>.ComparisonResult result = BlockManager.manager.getClosestBlock(blocks[i]);
if (result != null && result.match < 2) {
values[i] = result.best;
}
}
catch (Exception e) {}
}
final int gcd = gcd(counts);
for (int i = 0; i < counts.length; i++) {
final int num = counts[i];
for (int j = 0; j < (num / gcd); j++) {
parsedvalues.add(values[i]);
}
}
return parsedvalues.toArray(new PlotBlock[parsedvalues.size()]);
}
};
public static int gcd(final int a, final int b) {
if (b == 0) {
return a;
}
return gcd(b, a % b);
}
private static int gcd(final int[] a) {
int result = a[0];
for (int i = 1; i < a.length; i++) {
result = gcd(result, a[i]);
}
return result;
}
/**
* Create your own SettingValue object to make the management of plotworld configuration easier
*/
public static abstract class SettingValue<T> {
private final String type;
public SettingValue(final String type) {
this.type = type;
}
public String getType() {
return this.type;
}
public abstract T parseString(final String string);
public abstract boolean validateValue(final String string);
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////
// PlotSquared - A plot manager and world generator for the Bukkit API /
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
// /
// This program is free software; you can redistribute it and/or modify /
// it under the terms of the GNU General Public License as published by /
// the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.config;
import java.util.ArrayList;
import com.intellectualcrafters.plot.object.PlotBlock;
import com.intellectualcrafters.plot.util.BlockManager;
import com.intellectualcrafters.plot.util.StringComparison;
/**
* Main Configuration Utility
*
*/
@SuppressWarnings("unused")
public class Configuration
{
public static final SettingValue<String> STRING = new SettingValue<String>("STRING")
{
@Override
public boolean validateValue(final String string)
{
return true;
}
@Override
public String parseString(final String string)
{
return string;
}
};
public static final SettingValue<String[]> STRINGLIST = new SettingValue<String[]>("STRINGLIST")
{
@Override
public boolean validateValue(final String string)
{
return true;
}
@Override
public String[] parseString(final String string)
{
return string.split(",");
}
};
public static final SettingValue<Integer> INTEGER = new SettingValue<Integer>("INTEGER")
{
@Override
public boolean validateValue(final String string)
{
try
{
Integer.parseInt(string);
return true;
}
catch (final Exception e)
{
return false;
}
}
@Override
public Integer parseString(final String string)
{
return Integer.parseInt(string);
}
};
public static final SettingValue<Boolean> BOOLEAN = new SettingValue<Boolean>("BOOLEAN")
{
@Override
public boolean validateValue(final String string)
{
try
{
Boolean.parseBoolean(string);
return true;
}
catch (final Exception e)
{
return false;
}
}
@Override
public Boolean parseString(final String string)
{
return Boolean.parseBoolean(string);
}
};
public static final SettingValue<Double> DOUBLE = new SettingValue<Double>("DOUBLE")
{
@Override
public boolean validateValue(final String string)
{
try
{
Double.parseDouble(string);
return true;
}
catch (final Exception e)
{
return false;
}
}
@Override
public Double parseString(final String string)
{
return Double.parseDouble(string);
}
};
public static final SettingValue<String> BIOME = new SettingValue<String>("BIOME")
{
@Override
public boolean validateValue(final String string)
{
try
{
final int biome = BlockManager.manager.getBiomeFromString(string.toUpperCase());
return biome != -1;
}
catch (final Exception e)
{
return false;
}
}
@Override
public String parseString(final String string)
{
if (validateValue(string)) {
return string.toUpperCase();
}
return "FOREST";
}
};
public static final SettingValue<PlotBlock> BLOCK = new SettingValue<PlotBlock>("BLOCK")
{
@Override
public boolean validateValue(final String string)
{
try
{
if (string.contains(":"))
{
final String[] split = string.split(":");
Short.parseShort(split[0]);
Short.parseShort(split[1]);
}
else
{
Short.parseShort(string);
}
return true;
}
catch (final Exception e)
{
return false;
}
}
@Override
public PlotBlock parseString(final String string)
{
if (string.contains(":"))
{
final String[] split = string.split(":");
return new PlotBlock(Short.parseShort(split[0]), Byte.parseByte(split[1]));
}
else
{
return new PlotBlock(Short.parseShort(string), (byte) 0);
}
}
};
public static final SettingValue<PlotBlock[]> BLOCKLIST = new SettingValue<PlotBlock[]>("BLOCKLIST")
{
@Override
public boolean validateValue(final String string)
{
try
{
for (String block : string.split(","))
{
if (block.contains("%"))
{
final String[] split = block.split("%");
Integer.parseInt(split[0]);
block = split[1];
}
final StringComparison<PlotBlock>.ComparisonResult value = BlockManager.manager.getClosestBlock(block);
if ((value == null) || (value.match > 1)) {
return false;
}
}
return true;
}
catch (final Exception e)
{
return false;
}
}
@Override
public PlotBlock[] parseString(final String string)
{
final String[] blocks = string.split(",");
final ArrayList<PlotBlock> parsedvalues = new ArrayList<>();
final PlotBlock[] values = new PlotBlock[blocks.length];
final int[] counts = new int[blocks.length];
int min = 100;
for (int i = 0; i < blocks.length; i++)
{
try
{
if (blocks[i].contains("%"))
{
final String[] split = blocks[i].split("%");
blocks[i] = split[1];
final int value = Integer.parseInt(split[0]);
counts[i] = value;
if (value < min)
{
min = value;
}
}
else
{
counts[i] = 1;
if (1 < min)
{
min = 1;
}
}
final StringComparison<PlotBlock>.ComparisonResult result = BlockManager.manager.getClosestBlock(blocks[i]);
if ((result != null) && (result.match < 2))
{
values[i] = result.best;
}
}
catch (final Exception e)
{}
}
final int gcd = gcd(counts);
for (int i = 0; i < counts.length; i++)
{
final int num = counts[i];
for (int j = 0; j < (num / gcd); j++)
{
parsedvalues.add(values[i]);
}
}
return parsedvalues.toArray(new PlotBlock[parsedvalues.size()]);
}
};
public static int gcd(final int a, final int b)
{
if (b == 0) { return a; }
return gcd(b, a % b);
}
private static int gcd(final int[] a)
{
int result = a[0];
for (int i = 1; i < a.length; i++)
{
result = gcd(result, a[i]);
}
return result;
}
/**
* Create your own SettingValue object to make the management of plotworld configuration easier
*/
public static abstract class SettingValue<T>
{
private final String type;
public SettingValue(final String type)
{
this.type = type;
}
public String getType()
{
return this.type;
}
public abstract T parseString(final String string);
public abstract boolean validateValue(final String string);
}

View File

@ -1,101 +1,111 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
// PlotSquared - A plot manager and world generator for the Bukkit API /
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
// /
// This program is free software; you can redistribute it and/or modify /
// it under the terms of the GNU General Public License as published by /
// the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.config;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import com.intellectualcrafters.plot.config.Configuration.SettingValue;
import com.intellectualcrafters.plot.object.PlotBlock;
import com.intellectualcrafters.plot.util.StringMan;
/**
* Configuration Node
*
* @author Empire92
*/
public class ConfigurationNode {
private final String constant;
private final Object default_value;
private final String description;
private final SettingValue type;
private Object value;
public ConfigurationNode(final String constant, final Object default_value, final String description, final SettingValue type, final boolean required) {
this.constant = constant;
this.default_value = default_value;
this.description = description;
this.value = default_value;
this.type = type;
}
public SettingValue getType() {
return this.type;
}
public boolean isValid(final String string) {
try {
final Object result = this.type.parseString(string);
return result != null;
} catch (final Exception e) {
return false;
}
}
public boolean setValue(final String string) {
if (!this.type.validateValue(string)) {
return false;
}
this.value = this.type.parseString(string);
return true;
}
public Object getValue() {
if (this.value instanceof String[]) {
return Arrays.asList((String[]) this.value);
} else if (this.value instanceof Object[]) {
final List<String> values = new ArrayList<String>();
for (final Object value : (Object[]) this.value) {
values.add(value.toString());
}
return values;
} else if (this.value instanceof PlotBlock) {
return this.value.toString();
}
return this.value;
}
public String getConstant() {
return this.constant;
}
public Object getDefaultValue() {
if (this.default_value instanceof Object[]) {
return StringMan.join((Object[]) this.default_value, ",");
}
return this.default_value;
}
public String getDescription() {
return this.description;
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////
// PlotSquared - A plot manager and world generator for the Bukkit API /
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
// /
// This program is free software; you can redistribute it and/or modify /
// it under the terms of the GNU General Public License as published by /
// the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.config;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import com.intellectualcrafters.plot.config.Configuration.SettingValue;
import com.intellectualcrafters.plot.object.PlotBlock;
import com.intellectualcrafters.plot.util.StringMan;
/**
* Configuration Node
*
*/
public class ConfigurationNode
{
private final String constant;
private final Object default_value;
private final String description;
private final SettingValue type;
private Object value;
public ConfigurationNode(final String constant, final Object default_value, final String description, final SettingValue type, final boolean required)
{
this.constant = constant;
this.default_value = default_value;
this.description = description;
value = default_value;
this.type = type;
}
public SettingValue getType()
{
return type;
}
public boolean isValid(final String string)
{
try
{
final Object result = type.parseString(string);
return result != null;
}
catch (final Exception e)
{
return false;
}
}
public boolean setValue(final String string)
{
if (!type.validateValue(string)) { return false; }
value = type.parseString(string);
return true;
}
public Object getValue()
{
if (value instanceof String[])
{
return Arrays.asList((String[]) value);
}
else if (value instanceof Object[])
{
final List<String> values = new ArrayList<String>();
for (final Object value : (Object[]) this.value)
{
values.add(value.toString());
}
return values;
}
else if (value instanceof PlotBlock) { return value.toString(); }
return value;
}
public String getConstant()
{
return constant;
}
public Object getDefaultValue()
{
if (default_value instanceof Object[]) { return StringMan.join((Object[]) default_value, ","); }
return default_value;
}
public String getDescription()
{
return description;
}

View File

@ -1,259 +1,258 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
// PlotSquared - A plot manager and world generator for the Bukkit API /
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
// /
// This program is free software; you can redistribute it and/or modify /
// it under the terms of the GNU General Public License as published by /
// the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.config;
import java.util.ArrayList;
import java.util.List;
/**
* Updater and DB settings
*
* @author Citymonstret
* @author Empire92
*/
public class Settings {
public static boolean USE_SQLUUIDHANDLER = false;
public static boolean ENABLE_CLUSTERS = false;
public static boolean FAST_CLEAR = false;
/**
* Default UUID_FECTHING: false
*/
public static boolean PERMISSION_CACHING = false;
public static boolean CACHE_RATINGS = true;
public static boolean UUID_FROM_DISK = false;
/**
* Web
*/
public static String WEB_URL = "http://empcraft.com/plots/";
public static String WEB_IP = "your.ip.here";
public static boolean DOWNLOAD_REQUIRES_DONE = false;
/**
* Ratings
*/
public static List<String> RATING_CATEGORIES = null;
public static boolean REQUIRE_DONE = false;
public static boolean DONE_COUNTS_TOWARDS_LIMIT = false;
public static boolean DONE_RESTRICTS_BUILDING = false;
/**
* PlotMe settings
*/
public static boolean CONVERT_PLOTME = true;
public static boolean CACHE_PLOTME = false;
public static boolean USE_PLOTME_ALIAS = false;
/**
* Comment system
*/
public static boolean COMMENT_NOTIFICATIONS = false;
/**
* Chunk processor
*/
public static boolean CHUNK_PROCESSOR = false;
public static boolean EXPERIMENTAL_FAST_ASYNC_WORLDEDIT = false;
public static boolean CHUNK_PROCESSOR_TRIM_ON_SAVE = false;
public static boolean CHUNK_PROCESSOR_GC = false;
public static int CHUNK_PROCESSOR_MAX_BLOCKSTATES = 4096;
public static int CHUNK_PROCESSOR_MAX_ENTITIES = 512;
public static boolean CHUNK_PROCESSOR_DISABLE_PHYSICS = false;
/**
* TNT listener
*/
public static boolean TNT_LISTENER = false;
/**
* Redstone disabler
*/
public static boolean REDSTONE_DISABLER = false;
public static boolean REDSTONE_DISABLER_UNOCCUPIED = false;
/**
* Check for falling blocks when pistons extend?
*/
public static boolean PISTON_FALLING_BLOCK_CHECK = true;
/**
* Max auto claiming size
*/
public static int MAX_AUTO_SIZE = 4;
/**
* Default worldedit-require-selection-in-mask: false
*/
public static boolean REQUIRE_SELECTION = true;
public static boolean QUEUE_COMMANDS = false;
public static boolean WE_ALLOW_HELPER = false;
public static long WE_MAX_VOLUME = 500000;
public static long WE_MAX_ITERATIONS = 1000;
public static List<String> WE_BLACKLIST = new ArrayList<>();
/**
* Default kill road mobs: true
*/
public final static boolean KILL_ROAD_MOBS_DEFAULT = false;
public final static boolean KILL_ROAD_VEHICLES_DEFAULT = false;
/**
* Default mob pathfinding: true
*/
public final static boolean MOB_PATHFINDING_DEFAULT = true;
/**
* Teleport to path on login
*/
public static boolean TELEPORT_ON_LOGIN = false;
/**
* Display titles
*/
public static boolean TITLES = true;
/**
* Schematic Save Path
*/
public static String SCHEMATIC_SAVE_PATH = "plugins/PlotSquared/schematics";
/**
* BO3 Save Path
*/
public static String BO3_SAVE_PATH = "BO3";
/**
* Max allowed plots
*/
public static int MAX_PLOTS = 127;
/**
* WorldGuard region on claimed plots
*/
public static boolean WORLDGUARD = false;
/**
* metrics
*/
public static boolean METRICS = true;
/**
* plot specific resource pack
*/
public static String PLOT_SPECIFIC_RESOURCE_PACK = "";
/**
* Kill road mobs?
*/
public static boolean KILL_ROAD_MOBS;
public static boolean KILL_ROAD_VEHICLES;
/**
* mob pathfinding?
*/
public static boolean MOB_PATHFINDING;
/**
* Delete plots on ban?
*/
public static boolean DELETE_PLOTS_ON_BAN = false;
/**
* Verbose?
*/
public static boolean DEBUG = true;
/**
* Have colored console messages?
*/
public static boolean CONSOLE_COLOR = true;
/**
* Fancy chat e.g. for /plot list
*/
public static boolean FANCY_CHAT = true;
/**
* The delay (in seconds) before teleportation commences
*/
public static int TELEPORT_DELAY;
/**
* Auto clear enabled
*/
public static boolean AUTO_CLEAR = false;
/**
* Days until a plot gets cleared
*/
public static int AUTO_CLEAR_DAYS = 360;
public static int CLEAR_THRESHOLD = 1;
public static int CLEAR_INTERVAL = 120;
/**
* API Location
*/
public static String API_URL = "http://www.intellectualsites.com/minecraft.php";
/**
* Use the custom API
*/
public static boolean CUSTOM_API = true;
/**
* Use offline mode storage
*/
public static boolean TWIN_MODE_UUID = false;
public static boolean OFFLINE_MODE = false;
public static boolean UUID_LOWERCASE = false;
/**
* Command confirmation
*/
public static boolean CONFIRM_CLEAR = true;
public static boolean CONFIRM_DELETE = true;
public static boolean CONFIRM_UNLINK = true;
/**
* Use global plot limit?
*/
public static boolean GLOBAL_LIMIT = false;
/**
* Database settings
*
* @author Citymonstret
*/
public static class DB {
/**
* MongoDB enabled?
*/
public static boolean USE_MONGO = false; /*
* TODO: Implement Mongo
* @Brandon
*/
/**
* SQLite enabled?
*/
public static boolean USE_SQLITE = false;
/**
* MySQL Enabled?
*/
public static boolean USE_MYSQL = true; /* NOTE: Fixed connector */
/**
* SQLite Database name
*/
public static String SQLITE_DB = "storage";
/**
* MySQL Host name
*/
public static String HOST_NAME = "localhost";
/**
* MySQL Port
*/
public static String PORT = "3306";
/**
* MySQL DB
*/
public static String DATABASE = "plot_db";
/**
* MySQL User
*/
public static String USER = "root";
/**
* MySQL Password
*/
public static String PASSWORD = "password";
/**
* MySQL Prefix
*/
public static String PREFIX = "";
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////
// PlotSquared - A plot manager and world generator for the Bukkit API /
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
// /
// This program is free software; you can redistribute it and/or modify /
// it under the terms of the GNU General Public License as published by /
// the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.config;
import java.util.ArrayList;
import java.util.List;
/**
* Updater and DB settings
*
*/
public class Settings
{
public static boolean USE_SQLUUIDHANDLER = false;
public static boolean ENABLE_CLUSTERS = false;
public static boolean FAST_CLEAR = false;
/**
* Default UUID_FECTHING: false
*/
public static boolean PERMISSION_CACHING = false;
public static boolean CACHE_RATINGS = true;
public static boolean UUID_FROM_DISK = false;
/**
* Web
*/
public static String WEB_URL = "http://empcraft.com/plots/";
public static String WEB_IP = "your.ip.here";
public static boolean DOWNLOAD_REQUIRES_DONE = false;
/**
* Ratings
*/
public static List<String> RATING_CATEGORIES = null;
public static boolean REQUIRE_DONE = false;
public static boolean DONE_COUNTS_TOWARDS_LIMIT = false;
public static boolean DONE_RESTRICTS_BUILDING = false;
/**
* PlotMe settings
*/
public static boolean CONVERT_PLOTME = true;
public static boolean CACHE_PLOTME = false;
public static boolean USE_PLOTME_ALIAS = false;
/**
* Comment system
*/
public static boolean COMMENT_NOTIFICATIONS = false;
/**
* Chunk processor
*/
public static boolean CHUNK_PROCESSOR = false;
public static boolean EXPERIMENTAL_FAST_ASYNC_WORLDEDIT = false;
public static boolean CHUNK_PROCESSOR_TRIM_ON_SAVE = false;
public static boolean CHUNK_PROCESSOR_GC = false;
public static int CHUNK_PROCESSOR_MAX_BLOCKSTATES = 4096;
public static int CHUNK_PROCESSOR_MAX_ENTITIES = 512;
public static boolean CHUNK_PROCESSOR_DISABLE_PHYSICS = false;
/**
* TNT listener
*/
public static boolean TNT_LISTENER = false;
/**
* Redstone disabler
*/
public static boolean REDSTONE_DISABLER = false;
public static boolean REDSTONE_DISABLER_UNOCCUPIED = false;
/**
* Check for falling blocks when pistons extend?
*/
public static boolean PISTON_FALLING_BLOCK_CHECK = true;
/**
* Max auto claiming size
*/
public static int MAX_AUTO_SIZE = 4;
/**
* Default worldedit-require-selection-in-mask: false
*/
public static boolean REQUIRE_SELECTION = true;
public static boolean QUEUE_COMMANDS = false;
public static boolean WE_ALLOW_HELPER = false;
public static long WE_MAX_VOLUME = 500000;
public static long WE_MAX_ITERATIONS = 1000;
public static List<String> WE_BLACKLIST = new ArrayList<>();
/**
* Default kill road mobs: true
*/
public final static boolean KILL_ROAD_MOBS_DEFAULT = false;
public final static boolean KILL_ROAD_VEHICLES_DEFAULT = false;
/**
* Default mob pathfinding: true
*/
public final static boolean MOB_PATHFINDING_DEFAULT = true;
/**
* Teleport to path on login
*/
public static boolean TELEPORT_ON_LOGIN = false;
/**
* Display titles
*/
public static boolean TITLES = true;
/**
* Schematic Save Path
*/
public static String SCHEMATIC_SAVE_PATH = "plugins/PlotSquared/schematics";
/**
* BO3 Save Path
*/
public static String BO3_SAVE_PATH = "BO3";
/**
* Max allowed plots
*/
public static int MAX_PLOTS = 127;
/**
* WorldGuard region on claimed plots
*/
public static boolean WORLDGUARD = false;
/**
* metrics
*/
public static boolean METRICS = true;
/**
* plot specific resource pack
*/
public static String PLOT_SPECIFIC_RESOURCE_PACK = "";
/**
* Kill road mobs?
*/
public static boolean KILL_ROAD_MOBS;
public static boolean KILL_ROAD_VEHICLES;
/**
* mob pathfinding?
*/
public static boolean MOB_PATHFINDING;
/**
* Delete plots on ban?
*/
public static boolean DELETE_PLOTS_ON_BAN = false;
/**
* Verbose?
*/
public static boolean DEBUG = true;
/**
* Have colored console messages?
*/
public static boolean CONSOLE_COLOR = true;
/**
* Fancy chat e.g. for /plot list
*/
public static boolean FANCY_CHAT = true;
/**
* The delay (in seconds) before teleportation commences
*/
public static int TELEPORT_DELAY;
/**
* Auto clear enabled
*/
public static boolean AUTO_CLEAR = false;
/**
* Days until a plot gets cleared
*/
public static int AUTO_CLEAR_DAYS = 360;
public static int CLEAR_THRESHOLD = 1;
public static int CLEAR_INTERVAL = 120;
/**
* API Location
*/
public static String API_URL = "http://www.intellectualsites.com/minecraft.php";
/**
* Use the custom API
*/
public static boolean CUSTOM_API = true;
/**
* Use offline mode storage
*/
public static boolean TWIN_MODE_UUID = false;
public static boolean OFFLINE_MODE = false;
public static boolean UUID_LOWERCASE = false;
/**
* Command confirmation
*/
public static boolean CONFIRM_CLEAR = true;
public static boolean CONFIRM_DELETE = true;
public static boolean CONFIRM_UNLINK = true;
/**
* Use global plot limit?
*/
public static boolean GLOBAL_LIMIT = false;
/**
* Database settings
*
*/
public static class DB
{
/**
* MongoDB enabled?
*/
public static boolean USE_MONGO = false; /*
* TODO: Implement Mongo
* @Brandon
*/
/**
* SQLite enabled?
*/
public static boolean USE_SQLITE = false;
/**
* MySQL Enabled?
*/
public static boolean USE_MYSQL = true; /* NOTE: Fixed connector */
/**
* SQLite Database name
*/
public static String SQLITE_DB = "storage";
/**
* MySQL Host name
*/
public static String HOST_NAME = "localhost";
/**
* MySQL Port
*/
public static String PORT = "3306";
/**
* MySQL DB
*/
public static String DATABASE = "plot_db";
/**
* MySQL User
*/
public static String USER = "root";
/**
* MySQL Password
*/
public static String PASSWORD = "password";
/**
* MySQL Prefix
*/

View File

@ -1,349 +1,348 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
// PlotSquared - A plot manager and world generator for the Bukkit API /
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
// /
// This program is free software; you can redistribute it and/or modify /
// it under the terms of the GNU General Public License as published by /
// the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.database;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import com.intellectualcrafters.plot.flag.Flag;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotCluster;
import com.intellectualcrafters.plot.object.PlotClusterId;
import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.object.comment.PlotComment;
/**
* @author Citymonstret
* @author Empire92
*/
public interface AbstractDB {
/**
* The UUID that will count as everyone
*/
UUID everyone = UUID.fromString("1-1-3-3-7");
/**
* Set Plot owner
*
* @param plot Plot in which the owner should be set
* @param uuid The uuid of the new owner
*/
void setOwner(final Plot plot, final UUID uuid);
/**
* Create all settings, and create default helpers, trusted + denied lists
*
* @param plots Plots for which the default table entries should be created
*/
void createPlotsAndData(final ArrayList<Plot> plots, Runnable whenDone);
/**
* Create a plot
*
* @param plot That should be created
*/
void createPlot(final Plot plot);
/**
* Create tables
*
* @param database Database in which the tables will be created
*
* @throws SQLException If the database manager is unable to create the tables
*/
void createTables() throws Exception;
/**
* Delete a plot
*
* @param plot Plot that should be deleted
*/
void delete(final Plot plot);
void delete(final PlotCluster cluster);
/**
* Create plot settings
*
* @param id Plot Entry ID
* @param plot Plot Object
*/
void createPlotSettings(final int id, final Plot plot);
/**
* Get the table entry ID
*
* @param world Which the plot is located in
* @param id2 Plot ID
*
* @return Integer = Plot Entry Id
*/
int getId(final Plot plot);
/**
* Get the id of a given plot cluster
*
* @param world Which the plot is located in
* @param id cluster id
*
* @return Integer = Cluster Entry Id
*/
int getClusterId(final String world, final PlotClusterId id);
/**
* @return A linked hashmap containing all plots
*/
ConcurrentHashMap<String, ConcurrentHashMap<PlotId, Plot>> getPlots();
/**
*
*/
void validateAllPlots(Set<Plot> toValidate);
/**
* @return A hashmap containing all plot clusters
*/
HashMap<String, HashSet<PlotCluster>> getClusters();
/**
* Set the merged status for a plot
*
* @param world World in which the plot is located
* @param plot Plot Object
* @param merged boolean[]
*/
void setMerged(final Plot plot, final boolean[] merged);
/**
* Swap the settings, helpers etc. of two plots
* @param p1 Plot1
* @param p2 Plot2
*/
void swapPlots(final Plot p1, final Plot p2);
/**
* Set plot flags
*
* @param world World in which the plot is located
* @param plot Plot Object
* @param flags flags to set (flag[])
*/
void setFlags(final Plot plot, final Collection<Flag> flags);
/**
* Set cluster flags
*
* @param cluster PlotCluster Object
* @param flags flags to set (flag[])
*/
void setFlags(final PlotCluster cluster, final Collection<Flag> flags);
/**
* Rename a cluster
*/
void setClusterName(final PlotCluster cluster, final String name);
/**
* Set the plot alias
*
* @param plot Plot for which the alias should be set
* @param alias Plot Alias
*/
void setAlias(final Plot plot, final String alias);
/**
* Purgle a plot
*
* @param world World in which the plot is located
* @param uniqueIds list of plot id (db) to be purged
*/
void purgeIds(final String world, final Set<Integer> uniqueIds);
/**
* Purge a whole world
*
* @param world World in which the plots should be purged
*/
void purge(final String world, final Set<PlotId> plotIds);
/**
* Set Plot Home Position
*
* @param plot Plot Object
* @param position Plot Home Position
*/
void setPosition(final Plot plot, final String position);
/**
*
* @param cluster
* @param position
*/
void setPosition(final PlotCluster cluster, final String position);
/**
* @param plot Plot Object
* @param uuid Player that should be removed
*/
void removeTrusted(final Plot plot, final UUID uuid);
/**
* @param cluster PlotCluster Object
* @param uuid Player that should be removed
*/
void removeHelper(final PlotCluster cluster, final UUID uuid);
/**
* @param plot Plot Object
* @param uuid Player that should be removed
*/
void removeMember(final Plot plot, final UUID uuid);
/**
*
* @param cluster
* @param uuid
*/
void removeInvited(final PlotCluster cluster, final UUID uuid);
/**
* @param plot Plot Object
* @param uuid Player that should be removed
*/
void setTrusted(final Plot plot, final UUID uuid);
/**
* @param cluster PlotCluster Object
* @param uuid Player that should be removed
*/
void setHelper(final PlotCluster cluster, final UUID uuid);
/**
* @param plot Plot Object
* @param uuid Player that should be added
*/
void setMember(final Plot plot, final UUID uuid);
/**
*
* @param world
* @param cluster
* @param uuid
*/
void setInvited(final PlotCluster cluster, final UUID uuid);
/**
* @param plot Plot Object
* @param uuid Player uuid
*/
void removeDenied(final Plot plot, final UUID uuid);
/**
* @param plot Plot Object
* @param uuid Player uuid that should be added
*/
void setDenied(final Plot plot, final UUID uuid);
/**
* Get Plots ratings
*
* @param plot Plot Object
*
* @return Plot Ratings (pre-calculated)
*/
HashMap<UUID, Integer> getRatings(final Plot plot);
/**
* Set a rating for a plot
* @param plot
* @param rater
* @param value
*/
void setRating(final Plot plot, UUID rater, int value);
/**
* Remove a plot comment
*
* @param world World in which the plot is located
* @param plot Plot Object
* @param comment Comment to remove
*/
void removeComment(final Plot plot, final PlotComment comment);
/**
* Clear an inbox
* @param plot
* @param inbox
*/
void clearInbox(Plot plot, String inbox);
/**
* Set a plot comment
*
* @param world World in which the plot is located
* @param plot Plot Object
* @param comment Comment to add
*/
void setComment(final Plot plot, final PlotComment comment);
/**
* Get Plot Comments
*
* @param world World in which the plot is located
* @param plot Plot Object
* @param tier Comment Tier
*
* @return Plot Comments within the specified tier
*/
void getComments(final Plot plot, final String inbox, RunnableVal whenDone);
void createPlotAndSettings(Plot plot, Runnable whenDone);
void createCluster(PlotCluster cluster);
void resizeCluster(PlotCluster current, PlotClusterId resize);
void movePlot(Plot originalPlot, Plot newPlot);
/**
* Replace a old uuid with a new one in the database<br>
* - Useful for replacing a few uuids (not the entire database)<br>
* - For entire conversion, the uuidconvert command scales better
* @param old
* @param now
*/
void replaceUUID(UUID old, UUID now);
/**
* Don't fuck with this one, unless you enjoy it rough
*/
boolean deleteTables();
void close();
}
////////////////////////////////////////////////////////////////////////////////////////////////////
// PlotSquared - A plot manager and world generator for the Bukkit API /
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
// /
// This program is free software; you can redistribute it and/or modify /
// it under the terms of the GNU General Public License as published by /
// the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.database;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import com.intellectualcrafters.plot.flag.Flag;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotCluster;
import com.intellectualcrafters.plot.object.PlotClusterId;
import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.object.comment.PlotComment;
/**
*/
public interface AbstractDB
{
/**
* The UUID that will count as everyone
*/
UUID everyone = UUID.fromString("1-1-3-3-7");
/**
* Set Plot owner
*
* @param plot Plot in which the owner should be set
* @param uuid The uuid of the new owner
*/
void setOwner(final Plot plot, final UUID uuid);
/**
* Create all settings, and create default helpers, trusted + denied lists
*
* @param plots Plots for which the default table entries should be created
*/
void createPlotsAndData(final ArrayList<Plot> plots, final Runnable whenDone);
/**
* Create a plot
*
* @param plot That should be created
*/
void createPlot(final Plot plot);
/**
* Create tables
*
* @param database Database in which the tables will be created
*
* @throws SQLException If the database manager is unable to create the tables
*/
void createTables() throws Exception;
/**
* Delete a plot
*
* @param plot Plot that should be deleted
*/
void delete(final Plot plot);
void delete(final PlotCluster cluster);
/**
* Create plot settings
*
* @param id Plot Entry ID
* @param plot Plot Object
*/
void createPlotSettings(final int id, final Plot plot);
/**
* Get the table entry ID
*
* @param world Which the plot is located in
* @param id2 Plot ID
*
* @return Integer = Plot Entry Id
*/
int getId(final Plot plot);
/**
* Get the id of a given plot cluster
*
* @param world Which the plot is located in
* @param id cluster id
*
* @return Integer = Cluster Entry Id
*/
int getClusterId(final String world, final PlotClusterId id);
/**
* @return A linked hashmap containing all plots
*/
ConcurrentHashMap<String, ConcurrentHashMap<PlotId, Plot>> getPlots();
/**
*
*/
void validateAllPlots(final Set<Plot> toValidate);
/**
* @return A hashmap containing all plot clusters
*/
HashMap<String, HashSet<PlotCluster>> getClusters();
/**
* Set the merged status for a plot
*
* @param world World in which the plot is located
* @param plot Plot Object
* @param merged boolean[]
*/
void setMerged(final Plot plot, final boolean[] merged);
/**
* Swap the settings, helpers etc. of two plots
* @param p1 Plot1
* @param p2 Plot2
*/
void swapPlots(final Plot p1, final Plot p2);
/**
* Set plot flags
*
* @param world World in which the plot is located
* @param plot Plot Object
* @param flags flags to set (flag[])
*/
void setFlags(final Plot plot, final Collection<Flag> flags);
/**
* Set cluster flags
*
* @param cluster PlotCluster Object
* @param flags flags to set (flag[])
*/
void setFlags(final PlotCluster cluster, final Collection<Flag> flags);
/**
* Rename a cluster
*/
void setClusterName(final PlotCluster cluster, final String name);
/**
* Set the plot alias
*
* @param plot Plot for which the alias should be set
* @param alias Plot Alias
*/
void setAlias(final Plot plot, final String alias);
/**
* Purgle a plot
*
* @param world World in which the plot is located
* @param uniqueIds list of plot id (db) to be purged
*/
void purgeIds(final String world, final Set<Integer> uniqueIds);
/**
* Purge a whole world
*
* @param world World in which the plots should be purged
*/
void purge(final String world, final Set<PlotId> plotIds);
/**
* Set Plot Home Position
*
* @param plot Plot Object
* @param position Plot Home Position
*/
void setPosition(final Plot plot, final String position);
/**
*
* @param cluster
* @param position
*/
void setPosition(final PlotCluster cluster, final String position);
/**
* @param plot Plot Object
* @param uuid Player that should be removed
*/
void removeTrusted(final Plot plot, final UUID uuid);
/**
* @param cluster PlotCluster Object
* @param uuid Player that should be removed
*/
void removeHelper(final PlotCluster cluster, final UUID uuid);
/**
* @param plot Plot Object
* @param uuid Player that should be removed
*/
void removeMember(final Plot plot, final UUID uuid);
/**
*
* @param cluster
* @param uuid
*/
void removeInvited(final PlotCluster cluster, final UUID uuid);
/**
* @param plot Plot Object
* @param uuid Player that should be removed
*/
void setTrusted(final Plot plot, final UUID uuid);
/**
* @param cluster PlotCluster Object
* @param uuid Player that should be removed
*/
void setHelper(final PlotCluster cluster, final UUID uuid);
/**
* @param plot Plot Object
* @param uuid Player that should be added
*/
void setMember(final Plot plot, final UUID uuid);
/**
*
* @param world
* @param cluster
* @param uuid
*/
void setInvited(final PlotCluster cluster, final UUID uuid);
/**
* @param plot Plot Object
* @param uuid Player uuid
*/
void removeDenied(final Plot plot, final UUID uuid);
/**
* @param plot Plot Object
* @param uuid Player uuid that should be added
*/
void setDenied(final Plot plot, final UUID uuid);
/**
* Get Plots ratings
*
* @param plot Plot Object
*
* @return Plot Ratings (pre-calculated)
*/
HashMap<UUID, Integer> getRatings(final Plot plot);
/**
* Set a rating for a plot
* @param plot
* @param rater
* @param value
*/
void setRating(final Plot plot, final UUID rater, final int value);
/**
* Remove a plot comment
*
* @param world World in which the plot is located
* @param plot Plot Object
* @param comment Comment to remove
*/
void removeComment(final Plot plot, final PlotComment comment);
/**
* Clear an inbox
* @param plot
* @param inbox
*/
void clearInbox(final Plot plot, final String inbox);
/**
* Set a plot comment
*
* @param world World in which the plot is located
* @param plot Plot Object
* @param comment Comment to add
*/
void setComment(final Plot plot, final PlotComment comment);
/**
* Get Plot Comments
*
* @param world World in which the plot is located
* @param plot Plot Object
* @param tier Comment Tier
*
* @return Plot Comments within the specified tier
*/
void getComments(final Plot plot, final String inbox, final RunnableVal whenDone);
void createPlotAndSettings(final Plot plot, final Runnable whenDone);
void createCluster(final PlotCluster cluster);
void resizeCluster(final PlotCluster current, final PlotClusterId resize);
void movePlot(final Plot originalPlot, final Plot newPlot);
/**
* Replace a old uuid with a new one in the database<br>
* - Useful for replacing a few uuids (not the entire database)<br>
* - For entire conversion, the uuidconvert command scales better
* @param old
* @param now
*/
void replaceUUID(final UUID old, final UUID now);
/**
* Don't fuck with this one, unless you enjoy it rough
*/
boolean deleteTables();

View File

@ -1,436 +1,435 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
// PlotSquared - A plot manager and world generator for the Bukkit API /
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
// /
// This program is free software; you can redistribute it and/or modify /
// it under the terms of the GNU General Public License as published by /
// the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.database;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import com.intellectualcrafters.plot.flag.Flag;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotCluster;
import com.intellectualcrafters.plot.object.PlotClusterId;
import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.object.comment.PlotComment;
/**
* DB Functions
*
* @author Empire92
* @author Citymonstret
*/
public class DBFunc {
/**
* The "global" uuid
*/
public static final UUID everyone = UUID.fromString("1-1-3-3-7");
/**
* Abstract Database Manager
*/
public static AbstractDB dbManager;
public static void movePlot(final Plot originalPlot, final Plot newPlot) {
if (originalPlot.temp == -1 || newPlot.temp == -1) {
return;
}
dbManager.movePlot(originalPlot, newPlot);
}
public static void validatePlots(Set<Plot> plots) {
dbManager.validateAllPlots(plots);
}
/**
* Check if a resultset contains a column
* @param rs
* @param columnName
* @return
* @throws SQLException
*/
public static boolean hasColumn(ResultSet r, String name) {
try {
ResultSetMetaData meta = r.getMetaData();
int count = meta.getColumnCount();
for (int x = 1; x <= count; x++) {
if (name.equals(meta.getColumnName(x))) {
return true;
}
}
return false;
}
catch (SQLException e) {
return false;
}
}
/**
* Set the owner of a plot
*
* @param plot Plot Object
* @param uuid New Owner
*/
public static void setOwner(final Plot plot, final UUID uuid) {
if (plot.temp == -1) {
return;
}
dbManager.setOwner(plot, uuid);
}
/**
* Create all settings + (trusted, denied, members)
*
* @param plots List containing all plot objects
*/
public static void createPlotsAndData(final ArrayList<Plot> plots, Runnable whenDone) {
dbManager.createPlotsAndData(plots, whenDone);
}
/**
* Create a plot
*
* @param plot Plot to create
*/
public static void createPlot(final Plot plot) {
if (plot.temp == -1) {
return;
}
dbManager.createPlot(plot);
}
/**
* Create a plot
*
* @param plot Plot to create
*/
public static void createPlotAndSettings(final Plot plot, Runnable whenDone) {
if (plot.temp == -1) {
return;
}
dbManager.createPlotAndSettings(plot, whenDone);
}
/**
* Create tables
*
* @throws Exception
*/
public static void createTables(final String database) throws Exception {
dbManager.createTables();
}
/**
* Delete a plot
*
* @param plot Plot to delete
*/
public static void delete(final Plot plot) {
if (plot.temp == -1) {
return;
}
dbManager.delete(plot);
}
public static void delete(final PlotCluster toDelete) {
dbManager.delete(toDelete);
}
/**
* Create plot settings
*
* @param id Plot ID
* @param plot Plot Object
*/
public static void createPlotSettings(final int id, final Plot plot) {
if (plot.temp == -1) {
return;
}
dbManager.createPlotSettings(id, plot);
}
/**
* Get a plot id
*
* @param world World
* @param id2 Plot ID
*
* @return ID
*/
/*
* public static int getId(String plotId id2) { Statement stmt =
* null; try { stmt = connection.createStatement(); ResultSet r =
* stmt.executeQuery("SELECT `id` FROM `plot` WHERE `plot_id_x` = '" + id2.x
* + "' AND `plot_id_z` = '" + id2.y + "' AND `world` = '" + world +
* "' ORDER BY `timestamp` ASC"); int id = Integer.MAX_VALUE;
* while(r.next()) { id = r.getInt("id"); } stmt.close(); return id; }
* catch(SQLException e) { e.printStackTrace(); } return Integer.MAX_VALUE;
* }
*/
public static int getId(final Plot plot) {
return dbManager.getId(plot);
}
/**
* @return Plots
*/
public static ConcurrentHashMap<String, ConcurrentHashMap<PlotId, Plot>> getPlots() {
return dbManager.getPlots();
}
public static void setMerged(final Plot plot, final boolean[] merged) {
if (plot.temp == -1) {
return;
}
dbManager.setMerged(plot, merged);
}
public static void setFlags(final Plot plot, final Collection<Flag> flags) {
if (plot.temp == -1) {
return;
}
dbManager.setFlags(plot, flags);
}
public static void setFlags(final PlotCluster cluster, final Collection<Flag> flags) {
dbManager.setFlags(cluster, flags);
}
/**
* @param plot
* @param alias
*/
public static void setAlias(final Plot plot, final String alias) {
if (plot.temp == -1) {
return;
}
dbManager.setAlias(plot, alias);
}
public static void purgeIds(final String world, final Set<Integer> uniqueIds) {
dbManager.purgeIds(world, uniqueIds);
}
public static void purge(final String world, final Set<PlotId> plotIds) {
dbManager.purge(world, plotIds);
}
/**
* @param plot
* @param position
*/
public static void setPosition(final Plot plot, final String position) {
if (plot.temp == -1) {
return;
}
dbManager.setPosition(plot, position);
}
/**
* @param plot
* @param comment
*/
public static void removeComment(final Plot plot, final PlotComment comment) {
if (plot != null && plot.temp == -1) {
return;
}
dbManager.removeComment(plot, comment);
}
public static void clearInbox(final Plot plot, final String inbox) {
if (plot != null && plot.temp == -1) {
return;
}
dbManager.clearInbox(plot, inbox);
}
/**
* @param plot
* @param comment
*/
public static void setComment(final Plot plot, final PlotComment comment) {
if (plot != null && plot.temp == -1) {
return;
}
dbManager.setComment(plot, comment);
}
/**
* @param plot
*/
public static void getComments(final Plot plot, final String inbox, RunnableVal whenDone) {
if (plot != null && plot.temp == -1) {
return;
}
dbManager.getComments(plot, inbox, whenDone);
}
/**
* @param plot
* @param uuid
*/
public static void removeTrusted(final Plot plot, final UUID uuid) {
if (plot.temp == -1) {
return;
}
dbManager.removeTrusted(plot, uuid);
}
/**
* @param cluster
* @param uuid
*/
public static void removeHelper(final PlotCluster cluster, final UUID uuid) {
dbManager.removeHelper(cluster, uuid);
}
/**
* @param world
* @param cluster
*/
public static void createCluster(final String world, final PlotCluster cluster) {
dbManager.createCluster(cluster);
}
/**
* @param current
* @param resize
*/
public static void resizeCluster(final PlotCluster current, final PlotClusterId resize) {
dbManager.resizeCluster(current, resize);
}
/**
* @param plot
* @param uuid
*/
public static void removeMember(final Plot plot, final UUID uuid) {
if (plot.temp == -1) {
return;
}
dbManager.removeMember(plot, uuid);
}
/**
*
* @param cluster
* @param uuid
*/
public static void removeInvited(final PlotCluster cluster, final UUID uuid) {
dbManager.removeInvited(cluster, uuid);
}
/**
* @param world
* @param plot
* @param uuid
*/
public static void setTrusted(final Plot plot, final UUID uuid) {
if (plot.temp == -1) {
return;
}
dbManager.setTrusted(plot, uuid);
}
public static void setHelper(final PlotCluster cluster, final UUID uuid) {
dbManager.setHelper(cluster, uuid);
}
/**
* @param world
* @param plot
* @param uuid
*/
public static void setMember(final Plot plot, final UUID uuid) {
if (plot.temp == -1) {
return;
}
dbManager.setMember(plot, uuid);
}
public static void setInvited(final String world, final PlotCluster cluster, final UUID uuid) {
dbManager.setInvited(cluster, uuid);
}
/**
* @param world
* @param plot
* @param uuid
*/
public static void removeDenied(final Plot plot, final UUID uuid) {
if (plot.temp == -1) {
return;
}
dbManager.removeDenied(plot, uuid);
}
/**
* @param world
* @param plot
* @param uuid
*/
public static void setDenied(final Plot plot, final UUID uuid) {
if (plot.temp == -1) {
return;
}
dbManager.setDenied(plot, uuid);
}
public static HashMap<UUID, Integer> getRatings(final Plot plot) {
if (plot.temp == -1) {
return new HashMap<>();
}
return dbManager.getRatings(plot);
}
public static void setRating(Plot plot, UUID rater, int value) {
if (plot.temp == -1) {
return;
}
dbManager.setRating(plot, rater, value);
}
public static HashMap<String, HashSet<PlotCluster>> getClusters() {
return dbManager.getClusters();
}
public static void setPosition(final PlotCluster cluster, final String position) {
dbManager.setPosition(cluster, position);
}
/**
* Replace all occurances of a uuid in the database with another one
* @param old
* @param now
*/
public static void replaceUUID(UUID old, UUID now) {
dbManager.replaceUUID(old, now);
}
public static void close() {
dbManager.close();
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////
// PlotSquared - A plot manager and world generator for the Bukkit API /
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
// /
// This program is free software; you can redistribute it and/or modify /
// it under the terms of the GNU General Public License as published by /
// the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.database;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import com.intellectualcrafters.plot.flag.Flag;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotCluster;
import com.intellectualcrafters.plot.object.PlotClusterId;
import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.object.comment.PlotComment;
/**
* DB Functions
*
*/
public class DBFunc
{
/**
* The "global" uuid
*/
public static final UUID everyone = UUID.fromString("1-1-3-3-7");
/**
* Abstract Database Manager
*/
public static AbstractDB dbManager;
public static void movePlot(final Plot originalPlot, final Plot newPlot)
{
if ((originalPlot.temp == -1) || (newPlot.temp == -1)) { return; }
dbManager.movePlot(originalPlot, newPlot);
}
public static void validatePlots(final Set<Plot> plots)
{
dbManager.validateAllPlots(plots);
}
/**
* Check if a resultset contains a column
* @param rs
* @param columnName
* @return
* @throws SQLException
*/
public static boolean hasColumn(final ResultSet r, final String name)
{
try
{
final ResultSetMetaData meta = r.getMetaData();
final int count = meta.getColumnCount();
for (int x = 1; x <= count; x++)
{
if (name.equals(meta.getColumnName(x))) { return true; }
}
return false;
}
catch (final SQLException e)
{
return false;
}
}
/**
* Set the owner of a plot
*
* @param plot Plot Object
* @param uuid New Owner
*/
public static void setOwner(final Plot plot, final UUID uuid)
{
if (plot.temp == -1) { return; }
dbManager.setOwner(plot, uuid);
}
/**
* Create all settings + (trusted, denied, members)
*
* @param plots List containing all plot objects
*/
public static void createPlotsAndData(final ArrayList<Plot> plots, final Runnable whenDone)
{
dbManager.createPlotsAndData(plots, whenDone);
}
/**
* Create a plot
*
* @param plot Plot to create
*/
public static void createPlot(final Plot plot)
{
if (plot.temp == -1) { return; }
dbManager.createPlot(plot);
}
/**
* Create a plot
*
* @param plot Plot to create
*/
public static void createPlotAndSettings(final Plot plot, final Runnable whenDone)
{
if (plot.temp == -1) { return; }
dbManager.createPlotAndSettings(plot, whenDone);
}
/**
* Create tables
*
* @throws Exception
*/
public static void createTables(final String database) throws Exception
{
dbManager.createTables();
}
/**
* Delete a plot
*
* @param plot Plot to delete
*/
public static void delete(final Plot plot)
{
if (plot.temp == -1) { return; }
dbManager.delete(plot);
}
public static void delete(final PlotCluster toDelete)
{
dbManager.delete(toDelete);
}
/**
* Create plot settings
*
* @param id Plot ID
* @param plot Plot Object
*/
public static void createPlotSettings(final int id, final Plot plot)
{
if (plot.temp == -1) { return; }
dbManager.createPlotSettings(id, plot);
}
/**
* Get a plot id
*
* @param world World
* @param id2 Plot ID
*
* @return ID
*/
/*
* public static int getId(String plotId id2) { Statement stmt =
* null; try { stmt = connection.createStatement(); ResultSet r =
* stmt.executeQuery("SELECT `id` FROM `plot` WHERE `plot_id_x` = '" + id2.x
* + "' AND `plot_id_z` = '" + id2.y + "' AND `world` = '" + world +
* "' ORDER BY `timestamp` ASC"); int id = Integer.MAX_VALUE;
* while(r.next()) { id = r.getInt("id"); } stmt.close(); return id; }
* catch(SQLException e) { e.printStackTrace(); } return Integer.MAX_VALUE;
* }
*/
public static int getId(final Plot plot)
{
return dbManager.getId(plot);
}
/**
* @return Plots
*/
public static ConcurrentHashMap<String, ConcurrentHashMap<PlotId, Plot>> getPlots()
{
return dbManager.getPlots();
}
public static void setMerged(final Plot plot, final boolean[] merged)
{
if (plot.temp == -1) { return; }
dbManager.setMerged(plot, merged);
}
public static void setFlags(final Plot plot, final Collection<Flag> flags)
{
if (plot.temp == -1) { return; }
dbManager.setFlags(plot, flags);
}
public static void setFlags(final PlotCluster cluster, final Collection<Flag> flags)
{
dbManager.setFlags(cluster, flags);
}
/**
* @param plot
* @param alias
*/
public static void setAlias(final Plot plot, final String alias)
{
if (plot.temp == -1) { return; }
dbManager.setAlias(plot, alias);
}
public static void purgeIds(final String world, final Set<Integer> uniqueIds)
{
dbManager.purgeIds(world, uniqueIds);
}
public static void purge(final String world, final Set<PlotId> plotIds)
{
dbManager.purge(world, plotIds);
}
/**
* @param plot
* @param position
*/
public static void setPosition(final Plot plot, final String position)
{
if (plot.temp == -1) { return; }
dbManager.setPosition(plot, position);
}
/**
* @param plot
* @param comment
*/
public static void removeComment(final Plot plot, final PlotComment comment)
{
if ((plot != null) && (plot.temp == -1)) { return; }
dbManager.removeComment(plot, comment);
}
public static void clearInbox(final Plot plot, final String inbox)
{
if ((plot != null) && (plot.temp == -1)) { return; }
dbManager.clearInbox(plot, inbox);
}
/**
* @param plot
* @param comment
*/
public static void setComment(final Plot plot, final PlotComment comment)
{
if ((plot != null) && (plot.temp == -1)) { return; }
dbManager.setComment(plot, comment);
}
/**
* @param plot
*/
public static void getComments(final Plot plot, final String inbox, final RunnableVal whenDone)
{
if ((plot != null) && (plot.temp == -1)) { return; }
dbManager.getComments(plot, inbox, whenDone);
}
/**
* @param plot
* @param uuid
*/
public static void removeTrusted(final Plot plot, final UUID uuid)
{
if (plot.temp == -1) { return; }
dbManager.removeTrusted(plot, uuid);
}
/**
* @param cluster
* @param uuid
*/
public static void removeHelper(final PlotCluster cluster, final UUID uuid)
{
dbManager.removeHelper(cluster, uuid);
}
/**
* @param world
* @param cluster
*/
public static void createCluster(final String world, final PlotCluster cluster)
{
dbManager.createCluster(cluster);
}
/**
* @param current
* @param resize
*/
public static void resizeCluster(final PlotCluster current, final PlotClusterId resize)
{
dbManager.resizeCluster(current, resize);
}
/**
* @param plot
* @param uuid
*/
public static void removeMember(final Plot plot, final UUID uuid)
{
if (plot.temp == -1) { return; }
dbManager.removeMember(plot, uuid);
}
/**
*
* @param cluster
* @param uuid
*/
public static void removeInvited(final PlotCluster cluster, final UUID uuid)
{
dbManager.removeInvited(cluster, uuid);
}
/**
* @param world
* @param plot
* @param uuid
*/
public static void setTrusted(final Plot plot, final UUID uuid)
{
if (plot.temp == -1) { return; }
dbManager.setTrusted(plot, uuid);
}
public static void setHelper(final PlotCluster cluster, final UUID uuid)
{
dbManager.setHelper(cluster, uuid);
}
/**
* @param world
* @param plot
* @param uuid
*/
public static void setMember(final Plot plot, final UUID uuid)
{
if (plot.temp == -1) { return; }
dbManager.setMember(plot, uuid);
}
public static void setInvited(final String world, final PlotCluster cluster, final UUID uuid)
{
dbManager.setInvited(cluster, uuid);
}
/**
* @param world
* @param plot
* @param uuid
*/
public static void removeDenied(final Plot plot, final UUID uuid)
{
if (plot.temp == -1) { return; }
dbManager.removeDenied(plot, uuid);
}
/**
* @param world
* @param plot
* @param uuid
*/
public static void setDenied(final Plot plot, final UUID uuid)
{
if (plot.temp == -1) { return; }
dbManager.setDenied(plot, uuid);
}
public static HashMap<UUID, Integer> getRatings(final Plot plot)
{
if (plot.temp == -1) { return new HashMap<>(); }
return dbManager.getRatings(plot);
}
public static void setRating(final Plot plot, final UUID rater, final int value)
{
if (plot.temp == -1) { return; }
dbManager.setRating(plot, rater, value);
}
public static HashMap<String, HashSet<PlotCluster>> getClusters()
{
return dbManager.getClusters();
}
public static void setPosition(final PlotCluster cluster, final String position)
{
dbManager.setPosition(cluster, position);
}
/**
* Replace all occurances of a uuid in the database with another one
* @param old
* @param now
*/
public static void replaceUUID(final UUID old, final UUID now)
{
dbManager.replaceUUID(old, now);
}
public static void close()
{
dbManager.close();

View File

@ -30,9 +30,10 @@ import java.sql.SQLException;
* @author -_Husky_-
* @author tips48
*/
public abstract class Database {
public abstract Connection forceConnection() throws SQLException, ClassNotFoundException ;
public abstract class Database
{
public abstract Connection forceConnection() throws SQLException, ClassNotFoundException;
/**
* Opens a connection with the database

View File

@ -32,7 +32,8 @@ import java.sql.Statement;
* @author -_Husky_-
* @author tips48
*/
public class MySQL extends Database {
public class MySQL extends Database
{
private final String user;
private final String database;
private final String password;
@ -49,66 +50,73 @@ public class MySQL extends Database {
* @param username Username
* @param password Password
*/
public MySQL(final String hostname, final String port, final String database, final String username, final String password) {
public MySQL(final String hostname, final String port, final String database, final String username, final String password)
{
this.hostname = hostname;
this.port = port;
this.database = database;
this.user = username;
user = username;
this.password = password;
this.connection = null;
connection = null;
}
public Connection forceConnection() throws SQLException, ClassNotFoundException {
@Override
public Connection forceConnection() throws SQLException, ClassNotFoundException
{
Class.forName("com.mysql.jdbc.Driver");
this.connection = DriverManager.getConnection("jdbc:mysql://" + this.hostname + ":" + this.port + "/" + this.database, this.user, this.password);
return this.connection;
connection = DriverManager.getConnection("jdbc:mysql://" + hostname + ":" + port + "/" + database, user, password);
return connection;
}
@Override
public Connection openConnection() throws SQLException, ClassNotFoundException {
if (checkConnection()) {
return this.connection;
}
public Connection openConnection() throws SQLException, ClassNotFoundException
{
if (checkConnection()) { return connection; }
Class.forName("com.mysql.jdbc.Driver");
this.connection = DriverManager.getConnection("jdbc:mysql://" + this.hostname + ":" + this.port + "/" + this.database, this.user, this.password);
return this.connection;
connection = DriverManager.getConnection("jdbc:mysql://" + hostname + ":" + port + "/" + database, user, password);
return connection;
}
@Override
public boolean checkConnection() throws SQLException {
return (this.connection != null) && !this.connection.isClosed();
public boolean checkConnection() throws SQLException
{
return (connection != null) && !connection.isClosed();
}
@Override
public Connection getConnection() {
return this.connection;
public Connection getConnection()
{
return connection;
}
@Override
public boolean closeConnection() throws SQLException {
if (this.connection == null) {
return false;
}
this.connection.close();
this.connection = null;
public boolean closeConnection() throws SQLException
{
if (connection == null) { return false; }
connection.close();
connection = null;
return true;
}
@Override
public ResultSet querySQL(final String query) throws SQLException, ClassNotFoundException {
if (checkConnection()) {
public ResultSet querySQL(final String query) throws SQLException, ClassNotFoundException
{
if (checkConnection())
{
openConnection();
}
final Statement statement = this.connection.createStatement();
final Statement statement = connection.createStatement();
return statement.executeQuery(query);
}
@Override
public int updateSQL(final String query) throws SQLException, ClassNotFoundException {
if (checkConnection()) {
public int updateSQL(final String query) throws SQLException, ClassNotFoundException
{
if (checkConnection())
{
openConnection();
}
final Statement statement = this.connection.createStatement();
final Statement statement = connection.createStatement();
return statement.executeUpdate(query);
}
}

View File

@ -1,117 +1,128 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
// PlotSquared - A plot manager and world generator for the Bukkit API /
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
// /
// This program is free software; you can redistribute it and/or modify /
// it under the terms of the GNU General Public License as published by /
// the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.database;
import java.io.File;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import com.intellectualcrafters.plot.PS;
/**
* Connects to and uses a SQLite database
*
* @author Citymonstret
* @author tips48
*/
public class SQLite extends Database {
private final String dbLocation;
private Connection connection;
/**
* Creates a new SQLite instance
*
* @param dbLocation Location of the Database (Must end in .db)
*/
public SQLite(final String dbLocation) {
this.dbLocation = dbLocation;
}
@Override
public Connection openConnection() throws SQLException, ClassNotFoundException {
if (checkConnection()) {
return this.connection;
}
if (!PS.get().IMP.getDirectory().exists()) {
PS.get().IMP.getDirectory().mkdirs();
}
final File file = new File(this.dbLocation);
if (!(file.exists())) {
try {
file.createNewFile();
} catch (final IOException e) {
PS.debug("&cUnable to create database!");
}
}
Class.forName("org.sqlite.JDBC");
this.connection = DriverManager.getConnection("jdbc:sqlite:" + this.dbLocation);
return this.connection;
}
@Override
public boolean checkConnection() throws SQLException {
return (this.connection != null) && !this.connection.isClosed();
}
@Override
public Connection getConnection() {
return this.connection;
}
@Override
public boolean closeConnection() throws SQLException {
if (this.connection == null) {
return false;
}
this.connection.close();
this.connection = null;
return true;
}
@Override
public ResultSet querySQL(final String query) throws SQLException, ClassNotFoundException {
if (checkConnection()) {
openConnection();
}
final Statement statement = this.connection.createStatement();
return statement.executeQuery(query);
}
@Override
public int updateSQL(final String query) throws SQLException, ClassNotFoundException {
if (checkConnection()) {
openConnection();
}
final Statement statement = this.connection.createStatement();
return statement.executeUpdate(query);
}
@Override
public Connection forceConnection() throws SQLException, ClassNotFoundException {
Class.forName("org.sqlite.JDBC");
this.connection = DriverManager.getConnection("jdbc:sqlite:" + this.dbLocation);
return this.connection;
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////
// PlotSquared - A plot manager and world generator for the Bukkit API /
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
// /
// This program is free software; you can redistribute it and/or modify /
// it under the terms of the GNU General Public License as published by /
// the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.database;
import java.io.File;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import com.intellectualcrafters.plot.PS;
/**
* Connects to and uses a SQLite database
*
* @author tips48
*/
public class SQLite extends Database
{
private final String dbLocation;
private Connection connection;
/**
* Creates a new SQLite instance
*
* @param dbLocation Location of the Database (Must end in .db)
*/
public SQLite(final String dbLocation)
{
this.dbLocation = dbLocation;
}
@Override
public Connection openConnection() throws SQLException, ClassNotFoundException
{
if (checkConnection()) { return connection; }
if (!PS.get().IMP.getDirectory().exists())
{
PS.get().IMP.getDirectory().mkdirs();
}
final File file = new File(dbLocation);
if (!(file.exists()))
{
try
{
file.createNewFile();
}
catch (final IOException e)
{
PS.debug("&cUnable to create database!");
}
}
Class.forName("org.sqlite.JDBC");
connection = DriverManager.getConnection("jdbc:sqlite:" + dbLocation);
return connection;
}
@Override
public boolean checkConnection() throws SQLException
{
return (connection != null) && !connection.isClosed();
}
@Override
public Connection getConnection()
{
return connection;
}
@Override
public boolean closeConnection() throws SQLException
{
if (connection == null) { return false; }
connection.close();
connection = null;
return true;
}
@Override
public ResultSet querySQL(final String query) throws SQLException, ClassNotFoundException
{
if (checkConnection())
{
openConnection();
}
final Statement statement = connection.createStatement();
return statement.executeQuery(query);
}
@Override
public int updateSQL(final String query) throws SQLException, ClassNotFoundException
{
if (checkConnection())
{
openConnection();
}
final Statement statement = connection.createStatement();
return statement.executeUpdate(query);
}
@Override
public Connection forceConnection() throws SQLException, ClassNotFoundException
{
Class.forName("org.sqlite.JDBC");
connection = DriverManager.getConnection("jdbc:sqlite:" + dbLocation);
return connection;
}

View File

@ -5,31 +5,39 @@ import java.sql.SQLException;
import com.intellectualcrafters.plot.util.StringMan;
public abstract class StmtMod<T> {
public abstract String getCreateMySQL(int size);
public String getCreateMySQL(int size, String query, int params) {
final StringBuilder statement = new StringBuilder(query);
for (int i = 0; i < size - 1; i++) {
public abstract class StmtMod<T>
{
public abstract String getCreateMySQL(final int size);
public String getCreateMySQL(final int size, final String query, final int params)
{
final StringBuilder statement = new StringBuilder(query);
for (int i = 0; i < (size - 1); i++)
{
statement.append("(" + StringMan.repeat(",(?)", params).substring(1) + "),");
}
statement.append("(" + StringMan.repeat(",(?)", params).substring(1) + ")");
return statement.toString();
}
public String getCreateSQLite(int size, String query, int params) {
StringBuilder statement = new StringBuilder(query);
String modParams = StringMan.repeat(",?", params).substring(1);
for (int i = 0; i < (size - 1); i++) {
}
public String getCreateSQLite(final int size, final String query, final int params)
{
final StringBuilder statement = new StringBuilder(query);
final String modParams = StringMan.repeat(",?", params).substring(1);
for (int i = 0; i < (size - 1); i++)
{
statement.append("UNION SELECT " + modParams + " ");
}
return statement.toString();
}
public abstract String getCreateSQLite(int size);
public abstract String getCreateSQL();
public abstract void setMySQL(PreparedStatement stmt, int i, T obj) throws SQLException;
public abstract void setSQLite(PreparedStatement stmt, int i, T obj) throws SQLException;
public abstract void setSQL(PreparedStatement stmt, T obj) throws SQLException;
return statement.toString();
}
public abstract String getCreateSQLite(final int size);
public abstract String getCreateSQL();
public abstract void setMySQL(final PreparedStatement stmt, final int i, final T obj) throws SQLException;
public abstract void setSQLite(final PreparedStatement stmt, final int i, final T obj) throws SQLException;
public abstract void setSQL(final PreparedStatement stmt, final T obj) throws SQLException;
}

View File

@ -1,112 +1,117 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
// PlotSquared - A plot manager and world generator for the Bukkit API /
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
// /
// This program is free software; you can redistribute it and/or modify /
// it under the terms of the GNU General Public License as published by /
// the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.flag;
import com.intellectualcrafters.plot.util.StringMan;
/**
* Created 2014-09-23 for PlotSquared
*
* @author Citymonstret
* @author Empire92
*/
public class AbstractFlag {
public final String key;
public final FlagValue<?> value;
public AbstractFlag(final String key) {
this(key, new FlagValue.StringValue());
}
/**
* AbstractFlag is a parameter used in creating a new Flag<br>
* The key must be alphabetical characters and &lt;= 16 characters in length
* @param key
*/
public AbstractFlag(final String key, final FlagValue<?> value) {
if (!StringMan.isAlpha(key.replaceAll("_", "").replaceAll("-", ""))) {
throw new IllegalArgumentException("Flag must be alphabetic characters");
}
if (key.length() > 16) {
throw new IllegalArgumentException("Key must be <= 16 characters");
}
this.key = key.toLowerCase();
if (value == null) {
this.value = new FlagValue.StringValue();
} else {
this.value = value;
}
}
public boolean isList() {
return this.value instanceof FlagValue.ListValue;
}
public Object parseValueRaw(final String value) {
try {
return this.value.parse(value);
} catch (final Exception e) {
return null;
}
}
public String toString(final Object t) {
return this.value.toString(t);
}
public String getValueDesc() {
return this.value.getDescription();
}
/**
* AbstractFlag key
*
* @return String
*/
public String getKey() {
return this.key;
}
@Override
public String toString() {
return this.key;
}
@Override
public int hashCode() {
return this.key.hashCode();
}
@Override
public boolean equals(final Object other) {
if (other == null) {
return false;
}
if (other == this) {
return true;
}
if (!(other instanceof AbstractFlag)) {
return false;
}
final AbstractFlag otherObj = (AbstractFlag) other;
return (otherObj.key.equals(this.key));
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////
// PlotSquared - A plot manager and world generator for the Bukkit API /
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
// /
// This program is free software; you can redistribute it and/or modify /
// it under the terms of the GNU General Public License as published by /
// the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.flag;
import com.intellectualcrafters.plot.util.StringMan;
/**
* Created 2014-09-23 for PlotSquared
*
*/
public class AbstractFlag
{
public final String key;
public final FlagValue<?> value;
public AbstractFlag(final String key)
{
this(key, new FlagValue.StringValue());
}
/**
* AbstractFlag is a parameter used in creating a new Flag<br>
* The key must be alphabetical characters and &lt;= 16 characters in length
* @param key
*/
public AbstractFlag(final String key, final FlagValue<?> value)
{
if (!StringMan.isAlpha(key.replaceAll("_", "").replaceAll("-", ""))) { throw new IllegalArgumentException("Flag must be alphabetic characters"); }
if (key.length() > 16) { throw new IllegalArgumentException("Key must be <= 16 characters"); }
this.key = key.toLowerCase();
if (value == null)
{
this.value = new FlagValue.StringValue();
}
else
{
this.value = value;
}
}
public boolean isList()
{
return value instanceof FlagValue.ListValue;
}
public Object parseValueRaw(final String value)
{
try
{
return this.value.parse(value);
}
catch (final Exception e)
{
return null;
}
}
public String toString(final Object t)
{
return value.toString(t);
}
public String getValueDesc()
{
return value.getDescription();
}
/**
* AbstractFlag key
*
* @return String
*/
public String getKey()
{
return key;
}
@Override
public String toString()
{
return key;
}
@Override
public int hashCode()
{
return key.hashCode();
}
@Override
public boolean equals(final Object other)
{
if (other == null) { return false; }
if (other == this) { return true; }
if (!(other instanceof AbstractFlag)) { return false; }
final AbstractFlag otherObj = (AbstractFlag) other;
return (otherObj.key.equals(key));

View File

@ -22,7 +22,8 @@ package com.intellectualcrafters.plot.flag;
import com.intellectualcrafters.plot.util.StringMan;
public class Flag {
public class Flag
{
private AbstractFlag key;
private Object value;
@ -35,31 +36,29 @@ public class Flag {
*
* @throws IllegalArgumentException if you provide inadequate inputs
*/
public Flag(final AbstractFlag key, final String value) {
if (!StringMan.isAsciiPrintable(value)) {
throw new IllegalArgumentException("Flag must be ascii");
}
if (value.length() > 128) {
throw new IllegalArgumentException("Value must be <= 128 characters");
}
public Flag(final AbstractFlag key, final String value)
{
if (!StringMan.isAsciiPrintable(value)) { throw new IllegalArgumentException("Flag must be ascii"); }
if (value.length() > 128) { throw new IllegalArgumentException("Value must be <= 128 characters"); }
this.key = key;
this.value = key.parseValueRaw(value);
if (this.value == null) {
throw new IllegalArgumentException(key.getValueDesc() + " (" + value + ")");
}
if (this.value == null) { throw new IllegalArgumentException(key.getValueDesc() + " (" + value + ")"); }
}
public void setKey(final AbstractFlag key) {
public void setKey(final AbstractFlag key)
{
this.key = key;
if (this.value instanceof String) {
this.value = key.parseValueRaw((String) this.value);
if (value instanceof String)
{
value = key.parseValueRaw((String) value);
}
}
/**
* Warning: Unchecked
*/
public Flag(final AbstractFlag key, final Object value) {
public Flag(final AbstractFlag key, final Object value)
{
this.key = key;
this.value = value;
}
@ -69,8 +68,9 @@ public class Flag {
*
* @return AbstractFlag
*/
public AbstractFlag getAbstractFlag() {
return this.key;
public AbstractFlag getAbstractFlag()
{
return key;
}
/**
@ -78,8 +78,9 @@ public class Flag {
*
* @return String
*/
public String getKey() {
return this.key.getKey();
public String getKey()
{
return key.getKey();
}
/**
@ -87,39 +88,36 @@ public class Flag {
*
* @return String
*/
public Object getValue() {
return this.value;
public Object getValue()
{
return value;
}
public String getValueString() {
return this.key.toString(this.value);
public String getValueString()
{
return key.toString(value);
}
@Override
public String toString() {
if (this.value.equals("")) {
return this.key.getKey();
}
return this.key + ":" + getValueString();
public String toString()
{
if (value.equals("")) { return key.getKey(); }
return key + ":" + getValueString();
}
@Override
public boolean equals(final Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
public boolean equals(final Object obj)
{
if (this == obj) { return true; }
if (obj == null) { return false; }
if (getClass() != obj.getClass()) { return false; }
final Flag other = (Flag) obj;
return (this.key.getKey().equals(other.key.getKey()) && this.value.equals(other.value));
return (key.getKey().equals(other.key.getKey()) && value.equals(other.value));
}
@Override
public int hashCode() {
return this.key.getKey().hashCode();
public int hashCode()
{
return key.getKey().hashCode();
}
}

View File

@ -1,443 +1,484 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
// PlotSquared - A plot manager and world generator for the Bukkit API /
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
// /
// This program is free software; you can redistribute it and/or modify /
// it under the terms of the GNU General Public License as published by /
// the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.flag;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotCluster;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.PlotSettings;
import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.util.EventUtil;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.Permissions;
/**
* Flag Manager Utility
*
* @author Citymonstret
* @author Empire92
*/
@SuppressWarnings("unused")
public class FlagManager {
// TODO add some flags
// - Plot clear interval
// - Mob cap
// - customized plot composition
private final static HashSet<String> reserved = new HashSet<>();
private final static HashSet<AbstractFlag> flags = new HashSet<>();
/**
* Reserve a flag so that it cannot be set by players
* @param flag
*/
public static void reserveFlag(String flag) {
reserved.add(flag);
}
/**
* Get if a flag is reserved
* @param flag
* @return
*/
public static boolean isReserved(String flag) {
return reserved.contains(flag);
}
/**
* Get the reserved flags
* @return
*/
public static HashSet<String> getReservedFlags() {
return (HashSet<String>) reserved.clone();
}
/**
* Unreserve a flag
* @param flag
*/
public static void unreserveFlag(String flag) {
reserved.remove(flag);
}
/**
* Register an AbstractFlag with PlotSquared
*
* @param af Flag to register
*
* @return boolean success
*/
public static boolean addFlag(AbstractFlag af) {
return addFlag(af, false);
}
public static boolean addFlag(AbstractFlag af, boolean reserved) {
PS.debug(C.PREFIX.s() + "&8 - Adding flag: &7" + af);
for (PlotWorld plotworld : PS.get().getPlotWorldObjects()) {
Flag flag = ((HashMap<String, Flag>) plotworld.DEFAULT_FLAGS.clone()).get(af.getKey());
if (flag != null) {
flag.setKey(af);
}
}
if (PS.get().getAllPlotsRaw() != null) {
for (final Plot plot : PS.get().getPlotsRaw()) {
Flag flag = plot.getSettings().flags.get(af.getKey());
if (flag != null) {
flag.setKey(af);
}
}
}
if ((getFlag(af.getKey()) == null) && flags.add(af)) {
if (reserved) reserveFlag(af.getKey());
return true;
}
return false;
}
public static Flag getSettingFlag(final String world, final PlotSettings settings, final String id) {
Flag flag;
if (settings.flags.size() == 0 || (flag = settings.flags.get(id)) == null) {
PlotWorld plotworld = PS.get().getPlotWorld(world);
if (plotworld == null) {
return null;
}
if (plotworld.DEFAULT_FLAGS.size() == 0) {
return null;
}
return ((HashMap<String, Flag>) plotworld.DEFAULT_FLAGS.clone()).get(id);
}
return flag;
}
public static boolean isBooleanFlag(final Plot plot, final String key, final boolean defaultValue) {
final Flag flag = FlagManager.getPlotFlag(plot, key);
if (flag == null) {
return defaultValue;
}
final Object value = flag.getValue();
if (value instanceof Boolean) {
return (boolean) value;
}
return defaultValue;
}
/**
* Get the value of a flag for a plot (respects flag defaults)
* @param plot
* @param flag
* @return Flag
*/
public static Flag getPlotFlag(final Plot plot, final String flag) {
if (!plot.hasOwner()) {
return null;
}
return getSettingFlag(plot.world, plot.getSettings(), flag);
}
public static boolean isPlotFlagTrue(final Plot plot, final String strFlag) {
if (plot.owner == null) {
return false;
}
final Flag flag = getPlotFlag(plot, strFlag);
return !(flag == null || !((Boolean) flag.getValue()));
}
public static boolean isPlotFlagFalse(final Plot plot, final String strFlag) {
if (plot.owner == null) {
return false;
}
final Flag flag = getPlotFlag(plot, strFlag);
if (flag == null || ((Boolean) flag.getValue())) {
return false;
}
return false;
}
/**
* Get the value of a flag for a plot (ignores flag defaults)
* @param plot
* @param flag
* @return Flag
*/
public static Flag getPlotFlagAbs(final Plot plot, final String flag) {
return getSettingFlagAbs(plot.getSettings(), flag);
}
public static Flag getSettingFlagAbs(final PlotSettings settings, final String flag) {
if ((settings.flags == null) || (settings.flags.size() == 0)) {
return null;
}
return settings.flags.get(flag);
}
/**
* Add a flag to a plot
* @param plot
* @param flag
*/
public static boolean addPlotFlag(final Plot plot, final Flag flag) {
final boolean result = EventUtil.manager.callFlagAdd(flag, plot);
if (!result) {
return false;
}
plot.getSettings().flags.put(flag.getKey(), flag);
MainUtil.reEnterPlot(plot);
DBFunc.setFlags(plot, plot.getSettings().flags.values());
return true;
}
public static boolean addPlotFlagAbs(final Plot plot, final Flag flag) {
final boolean result = EventUtil.manager.callFlagAdd(flag, plot);
if (!result) {
return false;
}
plot.getSettings().flags.put(flag.getKey(), flag);
return true;
}
public static boolean addClusterFlag(final PlotCluster cluster, final Flag flag) {
//TODO plot cluster flag event
final Flag hasFlag = getSettingFlag(cluster.world, cluster.settings, flag.getKey());
cluster.settings.flags.put(flag.getKey(), flag);
DBFunc.setFlags(cluster, cluster.settings.flags.values());
return true;
}
/**
*
* @param plot
* @return set of flags
*/
public static HashMap<String, Flag> getPlotFlags(final Plot plot) {
if (!plot.hasOwner()) {
return null;
}
return getSettingFlags(plot.world, plot.getSettings());
}
public static HashMap<String, Flag> getPlotFlags(final String world, final PlotSettings settings, final boolean ignorePluginflags) {
HashMap<String, Flag> flags = new HashMap<>();
PlotWorld plotWorld = PS.get().getPlotWorld(world);
if (plotWorld != null && plotWorld.DEFAULT_FLAGS.size() != 0) {
flags.putAll(plotWorld.DEFAULT_FLAGS);
}
if (ignorePluginflags) {
for (final Map.Entry<String, Flag> flag : settings.flags.entrySet()) {
if (isReserved(flag.getValue().getAbstractFlag().getKey())) continue;
flags.put(flag.getKey(), flag.getValue());
}
} else {
flags.putAll(settings.flags);
}
return flags;
}
public static HashMap<String, Flag> getSettingFlags(final String world, final PlotSettings settings) {
return getPlotFlags(world, settings, false);
}
public static boolean removePlotFlag(final Plot plot, final String id) {
Flag flag = plot.getSettings().flags.remove(id);
if (flag == null) {
return false;
}
final boolean result = EventUtil.manager.callFlagRemove(flag, plot);
if (!result) {
plot.getSettings().flags.put(id, flag);
return false;
}
MainUtil.reEnterPlot(plot);
DBFunc.setFlags(plot, plot.getSettings().flags.values());
return true;
}
public static boolean removeClusterFlag(final PlotCluster cluster, final String id) {
Flag flag = cluster.settings.flags.remove(id);
if (flag == null) {
return false;
}
final boolean result = EventUtil.manager.callFlagRemove(flag, cluster);
if (!result) {
cluster.settings.flags.put(id, flag);
return false;
}
DBFunc.setFlags(cluster, cluster.settings.flags.values());
return true;
}
public static void setPlotFlags(final Plot plot, final Set<Flag> flags) {
if (flags != null && flags.size() != 0) {
plot.getSettings().flags.clear();
for (Flag flag : flags) {
plot.getSettings().flags.put(flag.getKey(), flag);
}
}
else if (plot.getSettings().flags.size() == 0) {
return;
}
else {
plot.getSettings().flags.clear();
}
MainUtil.reEnterPlot(plot);
DBFunc.setFlags(plot, plot.getSettings().flags.values());
}
public static void setClusterFlags(final PlotCluster cluster, final Set<Flag> flags) {
if (flags != null && flags.size() != 0) {
cluster.settings.flags.clear();
for (Flag flag : flags) {
cluster.settings.flags.put(flag.getKey(), flag);
}
}
else if (cluster.settings.flags.size() == 0) {
return;
}
else {
cluster.settings.flags.clear();
}
DBFunc.setFlags(cluster, cluster.settings.flags.values());
}
public static Flag[] removeFlag(final Flag[] flags, final String r) {
final Flag[] f = new Flag[flags.length - 1];
int index = 0;
for (final Flag flag : flags) {
if (!flag.getKey().equals(r)) {
f[index++] = flag;
}
}
return f;
}
public static Set<Flag> removeFlag(final Set<Flag> flags, final String r) {
final HashSet<Flag> newflags = new HashSet<>();
for (final Flag flag : flags) {
if (!flag.getKey().equalsIgnoreCase(r)) {
newflags.add(flag);
}
}
return newflags;
}
/**
* Get a list of registered AbstractFlag objects
*
* @return List (AbstractFlag)
*/
public static HashSet<AbstractFlag> getFlags() {
return flags;
}
/**
* Get a list of registerd AbstragFlag objects based on player permissions
*
* @param player with permissions
*
* @return List (AbstractFlag)
*/
public static List<AbstractFlag> getFlags(final PlotPlayer player) {
final List<AbstractFlag> returnFlags = new ArrayList<>();
for (final AbstractFlag flag : flags) {
if (Permissions.hasPermission(player, "plots.set.flag." + flag.getKey().toLowerCase())) {
returnFlags.add(flag);
}
}
return returnFlags;
}
/**
* Get an AbstractFlag by a string Returns null if flag does not exist
*
* @param string Flag Key
*
* @return AbstractFlag
*/
public static AbstractFlag getFlag(final String string) {
for (final AbstractFlag flag : flags) {
if (flag.getKey().equalsIgnoreCase(string)) {
return flag;
}
}
return null;
}
/**
* Get an AbstractFlag by a string
*
* @param string Flag Key
* @param create If to create the flag if it does not exist
*
* @return AbstractFlag
*/
public static AbstractFlag getFlag(final String string, final boolean create) {
if ((getFlag(string) == null) && create) {
final AbstractFlag flag = new AbstractFlag(string);
return flag;
}
return getFlag(string);
}
/**
* Remove a registered AbstractFlag
*
* @param flag Flag Key
*
* @return boolean Result of operation
*/
public static boolean removeFlag(final AbstractFlag flag) {
return flags.remove(flag);
}
public static HashMap<String, Flag> parseFlags(final List<String> flagstrings) {
HashMap<String, Flag> map = new HashMap<String, Flag>();
for (String key : flagstrings) {
final String[] split;
if (key.contains(";")) {
split = key.split(";");
}
else {
split = key.split(":");
}
Flag flag;
if (split.length == 1) {
flag = new Flag(getFlag(split[0], true), "");
} else {
flag = new Flag(getFlag(split[0], true), split[1]);
}
map.put(flag.getKey(), flag);
}
return map;
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////
// PlotSquared - A plot manager and world generator for the Bukkit API /
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
// /
// This program is free software; you can redistribute it and/or modify /
// it under the terms of the GNU General Public License as published by /
// the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.flag;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotCluster;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.PlotSettings;
import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.util.EventUtil;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.Permissions;
/**
* Flag Manager Utility
*
*/
@SuppressWarnings("unused")
public class FlagManager
{
// TODO add some flags
// - Plot clear interval
// - Mob cap
// - customized plot composition
private final static HashSet<String> reserved = new HashSet<>();
private final static HashSet<AbstractFlag> flags = new HashSet<>();
/**
* Reserve a flag so that it cannot be set by players
* @param flag
*/
public static void reserveFlag(final String flag)
{
reserved.add(flag);
}
/**
* Get if a flag is reserved
* @param flag
* @return
*/
public static boolean isReserved(final String flag)
{
return reserved.contains(flag);
}
/**
* Get the reserved flags
* @return
*/
public static HashSet<String> getReservedFlags()
{
return (HashSet<String>) reserved.clone();
}
/**
* Unreserve a flag
* @param flag
*/
public static void unreserveFlag(final String flag)
{
reserved.remove(flag);
}
/**
* Register an AbstractFlag with PlotSquared
*
* @param af Flag to register
*
* @return boolean success
*/
public static boolean addFlag(final AbstractFlag af)
{
return addFlag(af, false);
}
public static boolean addFlag(final AbstractFlag af, final boolean reserved)
{
PS.debug(C.PREFIX.s() + "&8 - Adding flag: &7" + af);
for (final PlotWorld plotworld : PS.get().getPlotWorldObjects())
{
final Flag flag = ((HashMap<String, Flag>) plotworld.DEFAULT_FLAGS.clone()).get(af.getKey());
if (flag != null)
{
flag.setKey(af);
}
}
if (PS.get().getAllPlotsRaw() != null)
{
for (final Plot plot : PS.get().getPlotsRaw())
{
final Flag flag = plot.getSettings().flags.get(af.getKey());
if (flag != null)
{
flag.setKey(af);
}
}
}
if ((getFlag(af.getKey()) == null) && flags.add(af))
{
if (reserved)
{
reserveFlag(af.getKey());
}
return true;
}
return false;
}
public static Flag getSettingFlag(final String world, final PlotSettings settings, final String id)
{
Flag flag;
if ((settings.flags.size() == 0) || ((flag = settings.flags.get(id)) == null))
{
final PlotWorld plotworld = PS.get().getPlotWorld(world);
if (plotworld == null) { return null; }
if (plotworld.DEFAULT_FLAGS.size() == 0) { return null; }
return ((HashMap<String, Flag>) plotworld.DEFAULT_FLAGS.clone()).get(id);
}
return flag;
}
public static boolean isBooleanFlag(final Plot plot, final String key, final boolean defaultValue)
{
final Flag flag = FlagManager.getPlotFlag(plot, key);
if (flag == null) { return defaultValue; }
final Object value = flag.getValue();
if (value instanceof Boolean) { return (boolean) value; }
return defaultValue;
}
/**
* Get the value of a flag for a plot (respects flag defaults)
* @param plot
* @param flag
* @return Flag
*/
public static Flag getPlotFlag(final Plot plot, final String flag)
{
if (!plot.hasOwner()) { return null; }
return getSettingFlag(plot.world, plot.getSettings(), flag);
}
public static boolean isPlotFlagTrue(final Plot plot, final String strFlag)
{
if (plot.owner == null) { return false; }
final Flag flag = getPlotFlag(plot, strFlag);
return !((flag == null) || !((Boolean) flag.getValue()));
}
public static boolean isPlotFlagFalse(final Plot plot, final String strFlag)
{
if (plot.owner == null) { return false; }
final Flag flag = getPlotFlag(plot, strFlag);
if ((flag == null) || ((Boolean) flag.getValue())) { return false; }
return false;
}
/**
* Get the value of a flag for a plot (ignores flag defaults)
* @param plot
* @param flag
* @return Flag
*/
public static Flag getPlotFlagAbs(final Plot plot, final String flag)
{
return getSettingFlagAbs(plot.getSettings(), flag);
}
public static Flag getSettingFlagAbs(final PlotSettings settings, final String flag)
{
if ((settings.flags == null) || (settings.flags.size() == 0)) { return null; }
return settings.flags.get(flag);
}
/**
* Add a flag to a plot
* @param plot
* @param flag
*/
public static boolean addPlotFlag(final Plot plot, final Flag flag)
{
final boolean result = EventUtil.manager.callFlagAdd(flag, plot);
if (!result) { return false; }
plot.getSettings().flags.put(flag.getKey(), flag);
MainUtil.reEnterPlot(plot);
DBFunc.setFlags(plot, plot.getSettings().flags.values());
return true;
}
public static boolean addPlotFlagAbs(final Plot plot, final Flag flag)
{
final boolean result = EventUtil.manager.callFlagAdd(flag, plot);
if (!result) { return false; }
plot.getSettings().flags.put(flag.getKey(), flag);
return true;
}
public static boolean addClusterFlag(final PlotCluster cluster, final Flag flag)
{
getSettingFlag(cluster.world, cluster.settings, flag.getKey());
cluster.settings.flags.put(flag.getKey(), flag);
DBFunc.setFlags(cluster, cluster.settings.flags.values());
return true;
}
/**
*
* @param plot
* @return set of flags
*/
public static HashMap<String, Flag> getPlotFlags(final Plot plot)
{
if (!plot.hasOwner()) { return null; }
return getSettingFlags(plot.world, plot.getSettings());
}
public static HashMap<String, Flag> getPlotFlags(final String world, final PlotSettings settings, final boolean ignorePluginflags)
{
final HashMap<String, Flag> flags = new HashMap<>();
final PlotWorld plotWorld = PS.get().getPlotWorld(world);
if ((plotWorld != null) && (plotWorld.DEFAULT_FLAGS.size() != 0))
{
flags.putAll(plotWorld.DEFAULT_FLAGS);
}
if (ignorePluginflags)
{
for (final Map.Entry<String, Flag> flag : settings.flags.entrySet())
{
if (isReserved(flag.getValue().getAbstractFlag().getKey()))
{
continue;
}
flags.put(flag.getKey(), flag.getValue());
}
}
else
{
flags.putAll(settings.flags);
}
return flags;
}
public static HashMap<String, Flag> getSettingFlags(final String world, final PlotSettings settings)
{
return getPlotFlags(world, settings, false);
}
public static boolean removePlotFlag(final Plot plot, final String id)
{
final Flag flag = plot.getSettings().flags.remove(id);
if (flag == null) { return false; }
final boolean result = EventUtil.manager.callFlagRemove(flag, plot);
if (!result)
{
plot.getSettings().flags.put(id, flag);
return false;
}
MainUtil.reEnterPlot(plot);
DBFunc.setFlags(plot, plot.getSettings().flags.values());
return true;
}
public static boolean removeClusterFlag(final PlotCluster cluster, final String id)
{
final Flag flag = cluster.settings.flags.remove(id);
if (flag == null) { return false; }
final boolean result = EventUtil.manager.callFlagRemove(flag, cluster);
if (!result)
{
cluster.settings.flags.put(id, flag);
return false;
}
DBFunc.setFlags(cluster, cluster.settings.flags.values());
return true;
}
public static void setPlotFlags(final Plot plot, final Set<Flag> flags)
{
if ((flags != null) && (flags.size() != 0))
{
plot.getSettings().flags.clear();
for (final Flag flag : flags)
{
plot.getSettings().flags.put(flag.getKey(), flag);
}
}
else if (plot.getSettings().flags.size() == 0)
{
return;
}
else
{
plot.getSettings().flags.clear();
}
MainUtil.reEnterPlot(plot);
DBFunc.setFlags(plot, plot.getSettings().flags.values());
}
public static void setClusterFlags(final PlotCluster cluster, final Set<Flag> flags)
{
if ((flags != null) && (flags.size() != 0))
{
cluster.settings.flags.clear();
for (final Flag flag : flags)
{
cluster.settings.flags.put(flag.getKey(), flag);
}
}
else if (cluster.settings.flags.size() == 0)
{
return;
}
else
{
cluster.settings.flags.clear();
}
DBFunc.setFlags(cluster, cluster.settings.flags.values());
}
public static Flag[] removeFlag(final Flag[] flags, final String r)
{
final Flag[] f = new Flag[flags.length - 1];
int index = 0;
for (final Flag flag : flags)
{
if (!flag.getKey().equals(r))
{
f[index++] = flag;
}
}
return f;
}
public static Set<Flag> removeFlag(final Set<Flag> flags, final String r)
{
final HashSet<Flag> newflags = new HashSet<>();
for (final Flag flag : flags)
{
if (!flag.getKey().equalsIgnoreCase(r))
{
newflags.add(flag);
}
}
return newflags;
}
/**
* Get a list of registered AbstractFlag objects
*
* @return List (AbstractFlag)
*/
public static HashSet<AbstractFlag> getFlags()
{
return flags;
}
/**
* Get a list of registerd AbstragFlag objects based on player permissions
*
* @param player with permissions
*
* @return List (AbstractFlag)
*/
public static List<AbstractFlag> getFlags(final PlotPlayer player)
{
final List<AbstractFlag> returnFlags = new ArrayList<>();
for (final AbstractFlag flag : flags)
{
if (Permissions.hasPermission(player, "plots.set.flag." + flag.getKey().toLowerCase()))
{
returnFlags.add(flag);
}
}
return returnFlags;
}
/**
* Get an AbstractFlag by a string Returns null if flag does not exist
*
* @param string Flag Key
*
* @return AbstractFlag
*/
public static AbstractFlag getFlag(final String string)
{
for (final AbstractFlag flag : flags)
{
if (flag.getKey().equalsIgnoreCase(string)) { return flag; }
}
return null;
}
/**
* Get an AbstractFlag by a string
*
* @param string Flag Key
* @param create If to create the flag if it does not exist
*
* @return AbstractFlag
*/
public static AbstractFlag getFlag(final String string, final boolean create)
{
if ((getFlag(string) == null) && create)
{
final AbstractFlag flag = new AbstractFlag(string);
return flag;
}
return getFlag(string);
}
/**
* Remove a registered AbstractFlag
*
* @param flag Flag Key
*
* @return boolean Result of operation
*/
public static boolean removeFlag(final AbstractFlag flag)
{
return flags.remove(flag);
}
public static HashMap<String, Flag> parseFlags(final List<String> flagstrings)
{
final HashMap<String, Flag> map = new HashMap<String, Flag>();
for (final String key : flagstrings)
{
final String[] split;
if (key.contains(";"))
{
split = key.split(";");
}
else
{
split = key.split(":");
}
Flag flag;
if (split.length == 1)
{
flag = new Flag(getFlag(split[0], true), "");
}
else
{
flag = new Flag(getFlag(split[0], true), split[1]);
}
map.put(flag.getKey(), flag);
}
return map;

File diff suppressed because it is too large Load Diff

View File

@ -14,38 +14,47 @@ import com.intellectualcrafters.plot.util.SetBlockQueue;
/**
* A plot manager with square plots which tesselate on a square grid with the following sections: ROAD, WALL, BORDER (wall), PLOT, FLOOR (plot)
*/
public class ClassicPlotManager extends SquarePlotManager {
public class ClassicPlotManager extends SquarePlotManager
{
@Override
public boolean setComponent(final PlotWorld plotworld, final PlotId plotid, final String component, final PlotBlock[] blocks) {
switch (component) {
case "floor": {
public boolean setComponent(final PlotWorld plotworld, final PlotId plotid, final String component, final PlotBlock[] blocks)
{
switch (component)
{
case "floor":
{
setFloor(plotworld, plotid, blocks);
return true;
}
case "wall": {
case "wall":
{
setWallFilling(plotworld, plotid, blocks);
return true;
}
case "border": {
case "border":
{
setWall(plotworld, plotid, blocks);
return true;
}
}
return false;
}
@Override
public boolean unclaimPlot(PlotWorld plotworld, Plot plot, Runnable whenDone) {
public boolean unclaimPlot(final PlotWorld plotworld, final Plot plot, final Runnable whenDone)
{
final HybridPlotWorld dpw = ((HybridPlotWorld) plotworld);
setWallFilling(dpw, plot.id, new PlotBlock[] { dpw.WALL_FILLING });
if (dpw.WALL_BLOCK.id != 0 || !dpw.WALL_BLOCK.equals(dpw.CLAIMED_WALL_BLOCK)) {
if ((dpw.WALL_BLOCK.id != 0) || !dpw.WALL_BLOCK.equals(dpw.CLAIMED_WALL_BLOCK))
{
setWall(dpw, plot.id, new PlotBlock[] { dpw.WALL_BLOCK });
}
SetBlockQueue.addNotify(whenDone);
return true;
}
public boolean setFloor(final PlotWorld plotworld, final PlotId plotid, final PlotBlock[] blocks) {
public boolean setFloor(final PlotWorld plotworld, final PlotId plotid, final PlotBlock[] blocks)
{
final ClassicPlotWorld dpw = (ClassicPlotWorld) plotworld;
final Location pos1 = MainUtil.getPlotBottomLoc(plotworld.worldname, plotid).add(1, 0, 1);
final Location pos2 = MainUtil.getPlotTopLoc(plotworld.worldname, plotid).add(1, 0, 1);
@ -55,66 +64,76 @@ public class ClassicPlotManager extends SquarePlotManager {
return true;
}
public boolean setWallFilling(final PlotWorld plotworld, final PlotId plotid, final PlotBlock[] blocks) {
public boolean setWallFilling(final PlotWorld plotworld, final PlotId plotid, final PlotBlock[] blocks)
{
final ClassicPlotWorld dpw = (ClassicPlotWorld) plotworld;
if (dpw.ROAD_WIDTH == 0) {
return false;
}
if (dpw.ROAD_WIDTH == 0) { return false; }
final Location bottom = MainUtil.getPlotBottomLoc(plotworld.worldname, plotid);
final Location top = MainUtil.getPlotTopLoc(plotworld.worldname, plotid).add(1, 0, 1);
int x, z;
z = bottom.getZ();
PseudoRandom random = new PseudoRandom();
for (x = bottom.getX(); x <= (top.getX() - 1); x++) {
for (int y = 1; y <= dpw.WALL_HEIGHT; y++) {
final PseudoRandom random = new PseudoRandom();
for (x = bottom.getX(); x <= (top.getX() - 1); x++)
{
for (int y = 1; y <= dpw.WALL_HEIGHT; y++)
{
SetBlockQueue.setBlock(plotworld.worldname, x, y, z, blocks[random.random(blocks.length)]);
}
}
x = top.getX();
for (z = bottom.getZ(); z <= (top.getZ() - 1); z++) {
for (int y = 1; y <= dpw.WALL_HEIGHT; y++) {
for (z = bottom.getZ(); z <= (top.getZ() - 1); z++)
{
for (int y = 1; y <= dpw.WALL_HEIGHT; y++)
{
SetBlockQueue.setBlock(plotworld.worldname, x, y, z, blocks[random.random(blocks.length)]);
}
}
z = top.getZ();
for (x = top.getX(); x >= (bottom.getX() + 1); x--) {
for (int y = 1; y <= dpw.WALL_HEIGHT; y++) {
for (x = top.getX(); x >= (bottom.getX() + 1); x--)
{
for (int y = 1; y <= dpw.WALL_HEIGHT; y++)
{
SetBlockQueue.setBlock(plotworld.worldname, x, y, z, blocks[random.random(blocks.length)]);
}
}
x = bottom.getX();
for (z = top.getZ(); z >= (bottom.getZ() + 1); z--) {
for (int y = 1; y <= dpw.WALL_HEIGHT; y++) {
for (z = top.getZ(); z >= (bottom.getZ() + 1); z--)
{
for (int y = 1; y <= dpw.WALL_HEIGHT; y++)
{
SetBlockQueue.setBlock(plotworld.worldname, x, y, z, blocks[random.random(blocks.length)]);
}
}
return true;
}
public boolean setWall(final PlotWorld plotworld, final PlotId plotid, final PlotBlock[] blocks) {
public boolean setWall(final PlotWorld plotworld, final PlotId plotid, final PlotBlock[] blocks)
{
final ClassicPlotWorld dpw = (ClassicPlotWorld) plotworld;
if (dpw.ROAD_WIDTH == 0) {
return false;
}
if (dpw.ROAD_WIDTH == 0) { return false; }
final Location bottom = MainUtil.getPlotBottomLoc(plotworld.worldname, plotid);
final Location top = MainUtil.getPlotTopLoc(plotworld.worldname, plotid).add(1, 0, 1);
int x, z;
z = bottom.getZ();
PseudoRandom random = new PseudoRandom();
final PseudoRandom random = new PseudoRandom();
final int y = dpw.WALL_HEIGHT + 1;
for (x = bottom.getX(); x <= (top.getX() - 1); x++) {
for (x = bottom.getX(); x <= (top.getX() - 1); x++)
{
SetBlockQueue.setBlock(plotworld.worldname, x, y, z, blocks[random.random(blocks.length)]);
}
x = top.getX();
for (z = bottom.getZ(); z <= (top.getZ() - 1); z++) {
for (z = bottom.getZ(); z <= (top.getZ() - 1); z++)
{
SetBlockQueue.setBlock(plotworld.worldname, x, y, z, blocks[random.random(blocks.length)]);
}
z = top.getZ();
for (x = top.getX(); x >= (bottom.getX() + 1); x--) {
for (x = top.getX(); x >= (bottom.getX() + 1); x--)
{
SetBlockQueue.setBlock(plotworld.worldname, x, y, z, blocks[random.random(blocks.length)]);
}
x = bottom.getX();
for (z = top.getZ(); z >= (bottom.getZ() + 1); z--) {
for (z = top.getZ(); z >= (bottom.getZ() + 1); z--)
{
SetBlockQueue.setBlock(plotworld.worldname, x, y, z, blocks[random.random(blocks.length)]);
}
return true;
@ -124,7 +143,8 @@ public class ClassicPlotManager extends SquarePlotManager {
* PLOT MERGING
*/
@Override
public boolean createRoadEast(final PlotWorld plotworld, final Plot plot) {
public boolean createRoadEast(final PlotWorld plotworld, final Plot plot)
{
final ClassicPlotWorld dpw = (ClassicPlotWorld) plotworld;
final Location pos1 = getPlotBottomLocAbs(plotworld, plot.id);
final Location pos2 = getPlotTopLocAbs(plotworld, plot.id);
@ -132,18 +152,23 @@ public class ClassicPlotManager extends SquarePlotManager {
final int ex = (sx + dpw.ROAD_WIDTH) - 1;
final int sz = pos1.getZ() - 1;
final int ez = pos2.getZ() + 2;
MainUtil.setSimpleCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx, Math.min(dpw.WALL_HEIGHT, dpw.ROAD_HEIGHT) + 1, sz + 1), new Location(plotworld.worldname, ex + 1, 257, ez), new PlotBlock((short) 0, (byte) 0));
MainUtil.setSimpleCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx, 1, sz + 1), new Location(plotworld.worldname, ex + 1, dpw.PLOT_HEIGHT, ez), new PlotBlock((short) 7, (byte) 0));
MainUtil.setSimpleCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx, Math.min(dpw.WALL_HEIGHT, dpw.ROAD_HEIGHT) + 1, sz + 1), new Location(plotworld.worldname, ex + 1,
257, ez), new PlotBlock((short) 0, (byte) 0));
MainUtil.setSimpleCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx, 1, sz + 1), new Location(plotworld.worldname, ex + 1, dpw.PLOT_HEIGHT, ez), new PlotBlock((short) 7,
(byte) 0));
MainUtil.setSimpleCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx, 1, sz + 1), new Location(plotworld.worldname, sx + 1, dpw.WALL_HEIGHT + 1, ez), dpw.WALL_FILLING);
MainUtil.setSimpleCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx, dpw.WALL_HEIGHT + 1, sz + 1), new Location(plotworld.worldname, sx + 1, dpw.WALL_HEIGHT + 2, ez), dpw.WALL_BLOCK);
MainUtil.setSimpleCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx, dpw.WALL_HEIGHT + 1, sz + 1), new Location(plotworld.worldname, sx + 1, dpw.WALL_HEIGHT + 2, ez),
dpw.WALL_BLOCK);
MainUtil.setSimpleCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, ex, 1, sz + 1), new Location(plotworld.worldname, ex + 1, dpw.WALL_HEIGHT + 1, ez), dpw.WALL_FILLING);
MainUtil.setSimpleCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, ex, dpw.WALL_HEIGHT + 1, sz + 1), new Location(plotworld.worldname, ex + 1, dpw.WALL_HEIGHT + 2, ez), dpw.WALL_BLOCK);
MainUtil.setSimpleCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, ex, dpw.WALL_HEIGHT + 1, sz + 1), new Location(plotworld.worldname, ex + 1, dpw.WALL_HEIGHT + 2, ez),
dpw.WALL_BLOCK);
MainUtil.setSimpleCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx + 1, 1, sz + 1), new Location(plotworld.worldname, ex, dpw.ROAD_HEIGHT + 1, ez), dpw.ROAD_BLOCK);
return true;
}
@Override
public boolean createRoadSouth(final PlotWorld plotworld, final Plot plot) {
public boolean createRoadSouth(final PlotWorld plotworld, final Plot plot)
{
final ClassicPlotWorld dpw = (ClassicPlotWorld) plotworld;
final Location pos1 = getPlotBottomLocAbs(plotworld, plot.id);
final Location pos2 = getPlotTopLocAbs(plotworld, plot.id);
@ -151,32 +176,38 @@ public class ClassicPlotManager extends SquarePlotManager {
final int ez = (sz + dpw.ROAD_WIDTH) - 1;
final int sx = pos1.getX() - 1;
final int ex = pos2.getX() + 2;
MainUtil.setSimpleCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx + 1, Math.min(dpw.WALL_HEIGHT, dpw.ROAD_HEIGHT) + 1, sz), new Location(plotworld.worldname, ex, 257, ez + 1), new PlotBlock((short) 0, (byte) 0));
MainUtil.setSimpleCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx + 1, Math.min(dpw.WALL_HEIGHT, dpw.ROAD_HEIGHT) + 1, sz), new Location(plotworld.worldname, ex, 257,
ez + 1), new PlotBlock((short) 0, (byte) 0));
MainUtil.setSimpleCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx + 1, 0, sz), new Location(plotworld.worldname, ex, 1, ez + 1), new PlotBlock((short) 7, (byte) 0));
MainUtil.setSimpleCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx + 1, 1, sz), new Location(plotworld.worldname, ex, dpw.WALL_HEIGHT + 1, sz + 1), dpw.WALL_FILLING);
MainUtil.setSimpleCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx + 1, dpw.WALL_HEIGHT + 1, sz), new Location(plotworld.worldname, ex, dpw.WALL_HEIGHT + 2, sz + 1), dpw.WALL_BLOCK);
MainUtil.setSimpleCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx + 1, dpw.WALL_HEIGHT + 1, sz), new Location(plotworld.worldname, ex, dpw.WALL_HEIGHT + 2, sz + 1),
dpw.WALL_BLOCK);
MainUtil.setSimpleCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx + 1, 1, ez), new Location(plotworld.worldname, ex, dpw.WALL_HEIGHT + 1, ez + 1), dpw.WALL_FILLING);
MainUtil.setSimpleCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx + 1, dpw.WALL_HEIGHT + 1, ez), new Location(plotworld.worldname, ex, dpw.WALL_HEIGHT + 2, ez + 1), dpw.WALL_BLOCK);
MainUtil.setSimpleCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx + 1, dpw.WALL_HEIGHT + 1, ez), new Location(plotworld.worldname, ex, dpw.WALL_HEIGHT + 2, ez + 1),
dpw.WALL_BLOCK);
MainUtil.setSimpleCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx + 1, 1, sz + 1), new Location(plotworld.worldname, ex, dpw.ROAD_HEIGHT + 1, ez), dpw.ROAD_BLOCK);
return true;
}
@Override
public boolean createRoadSouthEast(final PlotWorld plotworld, final Plot plot) {
public boolean createRoadSouthEast(final PlotWorld plotworld, final Plot plot)
{
final ClassicPlotWorld dpw = (ClassicPlotWorld) plotworld;
final Location pos2 = getPlotTopLocAbs(plotworld, plot.id);
final int sx = pos2.getX() + 1;
final int ex = (sx + dpw.ROAD_WIDTH) - 1;
final int sz = pos2.getZ() + 1;
final int ez = (sz + dpw.ROAD_WIDTH) - 1;
MainUtil.setSimpleCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx + 1, dpw.ROAD_HEIGHT + 1, sz + 1), new Location(plotworld.worldname, ex, 257, ez), new PlotBlock((short) 0, (byte) 0));
MainUtil.setSimpleCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx + 1, dpw.ROAD_HEIGHT + 1, sz + 1), new Location(plotworld.worldname, ex, 257, ez), new PlotBlock(
(short) 0, (byte) 0));
MainUtil.setSimpleCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx + 1, 0, sz + 1), new Location(plotworld.worldname, ex, 1, ez), new PlotBlock((short) 7, (byte) 0));
MainUtil.setSimpleCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx + 1, 1, sz + 1), new Location(plotworld.worldname, ex, dpw.ROAD_HEIGHT + 1, ez), dpw.ROAD_BLOCK);
return true;
}
@Override
public boolean removeRoadEast(final PlotWorld plotworld, final Plot plot) {
public boolean removeRoadEast(final PlotWorld plotworld, final Plot plot)
{
final ClassicPlotWorld dpw = (ClassicPlotWorld) plotworld;
final Location pos1 = getPlotBottomLocAbs(plotworld, plot.id);
final Location pos2 = getPlotTopLocAbs(plotworld, plot.id);
@ -184,14 +215,16 @@ public class ClassicPlotManager extends SquarePlotManager {
final int ex = (sx + dpw.ROAD_WIDTH) - 1;
final int sz = pos1.getZ();
final int ez = pos2.getZ() + 1;
MainUtil.setSimpleCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx, Math.min(dpw.PLOT_HEIGHT, dpw.ROAD_HEIGHT) + 1, sz), new Location(plotworld.worldname, ex + 1, 257, ez + 1), new PlotBlock((short) 0, (byte) 0));
MainUtil.setSimpleCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx, Math.min(dpw.PLOT_HEIGHT, dpw.ROAD_HEIGHT) + 1, sz), new Location(plotworld.worldname, ex + 1, 257,
ez + 1), new PlotBlock((short) 0, (byte) 0));
MainUtil.setCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx, 1, sz + 1), new Location(plotworld.worldname, ex + 1, dpw.PLOT_HEIGHT, ez), dpw.MAIN_BLOCK);
MainUtil.setCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx, dpw.PLOT_HEIGHT, sz + 1), new Location(plotworld.worldname, ex + 1, dpw.PLOT_HEIGHT + 1, ez), dpw.TOP_BLOCK);
return true;
}
@Override
public boolean removeRoadSouth(final PlotWorld plotworld, final Plot plot) {
public boolean removeRoadSouth(final PlotWorld plotworld, final Plot plot)
{
final ClassicPlotWorld dpw = (ClassicPlotWorld) plotworld;
final Location pos1 = getPlotBottomLocAbs(plotworld, plot.id);
final Location pos2 = getPlotTopLocAbs(plotworld, plot.id);
@ -199,21 +232,24 @@ public class ClassicPlotManager extends SquarePlotManager {
final int ez = (sz + dpw.ROAD_WIDTH) - 1;
final int sx = pos1.getX();
final int ex = pos2.getX() + 1;
MainUtil.setSimpleCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx, Math.min(dpw.PLOT_HEIGHT, dpw.ROAD_HEIGHT) + 1, sz), new Location(plotworld.worldname, ex + 1, 257, ez + 1), new PlotBlock((short) 0, (byte) 0));
MainUtil.setSimpleCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx, Math.min(dpw.PLOT_HEIGHT, dpw.ROAD_HEIGHT) + 1, sz), new Location(plotworld.worldname, ex + 1, 257,
ez + 1), new PlotBlock((short) 0, (byte) 0));
MainUtil.setCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx + 1, 1, sz), new Location(plotworld.worldname, ex, dpw.PLOT_HEIGHT, ez + 1), dpw.MAIN_BLOCK);
MainUtil.setCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx + 1, dpw.PLOT_HEIGHT, sz), new Location(plotworld.worldname, ex, dpw.PLOT_HEIGHT + 1, ez + 1), dpw.TOP_BLOCK);
return true;
}
@Override
public boolean removeRoadSouthEast(final PlotWorld plotworld, final Plot plot) {
public boolean removeRoadSouthEast(final PlotWorld plotworld, final Plot plot)
{
final ClassicPlotWorld dpw = (ClassicPlotWorld) plotworld;
final Location loc = getPlotTopLocAbs(dpw, plot.id);
final int sx = loc.getX() + 1;
final int ex = (sx + dpw.ROAD_WIDTH) - 1;
final int sz = loc.getZ() + 1;
final int ez = (sz + dpw.ROAD_WIDTH) - 1;
MainUtil.setSimpleCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx, dpw.ROAD_HEIGHT + 1, sz), new Location(plotworld.worldname, ex + 1, 257, ez + 1), new PlotBlock((short) 0, (byte) 0));
MainUtil.setSimpleCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx, dpw.ROAD_HEIGHT + 1, sz), new Location(plotworld.worldname, ex + 1, 257, ez + 1), new PlotBlock(
(short) 0, (byte) 0));
MainUtil.setCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx, 1, sz), new Location(plotworld.worldname, ex + 1, dpw.ROAD_HEIGHT, ez + 1), dpw.MAIN_BLOCK);
MainUtil.setCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx, dpw.ROAD_HEIGHT, sz), new Location(plotworld.worldname, ex + 1, dpw.ROAD_HEIGHT + 1, ez + 1), dpw.TOP_BLOCK);
return true;
@ -223,22 +259,27 @@ public class ClassicPlotManager extends SquarePlotManager {
* Finishing off plot merging by adding in the walls surrounding the plot (OPTIONAL)(UNFINISHED)
*/
@Override
public boolean finishPlotMerge(final PlotWorld plotworld, final ArrayList<PlotId> plotIds) {
public boolean finishPlotMerge(final PlotWorld plotworld, final ArrayList<PlotId> plotIds)
{
final PlotId pos1 = plotIds.get(0);
final PlotBlock block = ((ClassicPlotWorld) plotworld).CLAIMED_WALL_BLOCK;
final PlotBlock unclaim = ((ClassicPlotWorld) plotworld).WALL_BLOCK;
if (block.id != 0 || !block.equals(unclaim)) {
if ((block.id != 0) || !block.equals(unclaim))
{
setWall(plotworld, pos1, new PlotBlock[] { block });
}
return true;
}
@Override
public boolean finishPlotUnlink(final PlotWorld plotworld, final ArrayList<PlotId> plotIds) {
public boolean finishPlotUnlink(final PlotWorld plotworld, final ArrayList<PlotId> plotIds)
{
final PlotBlock block = ((ClassicPlotWorld) plotworld).CLAIMED_WALL_BLOCK;
final PlotBlock unclaim = ((ClassicPlotWorld) plotworld).WALL_BLOCK;
for (final PlotId id : plotIds) {
if (block.id != 0 || !block.equals(unclaim)) {
for (final PlotId id : plotIds)
{
if ((block.id != 0) || !block.equals(unclaim))
{
setWall(plotworld, id, new PlotBlock[] { block });
}
}
@ -246,27 +287,32 @@ public class ClassicPlotManager extends SquarePlotManager {
}
@Override
public boolean startPlotMerge(final PlotWorld plotworld, final ArrayList<PlotId> plotIds) {
public boolean startPlotMerge(final PlotWorld plotworld, final ArrayList<PlotId> plotIds)
{
return true;
}
@Override
public boolean startPlotUnlink(final PlotWorld plotworld, final ArrayList<PlotId> plotIds) {
public boolean startPlotUnlink(final PlotWorld plotworld, final ArrayList<PlotId> plotIds)
{
return true;
}
@Override
public boolean claimPlot(final PlotWorld plotworld, final Plot plot) {
public boolean claimPlot(final PlotWorld plotworld, final Plot plot)
{
final PlotBlock unclaim = ((ClassicPlotWorld) plotworld).WALL_BLOCK;
final PlotBlock claim = ((ClassicPlotWorld) plotworld).CLAIMED_WALL_BLOCK;
if (claim.id != 0 || !claim.equals(unclaim)) {
if ((claim.id != 0) || !claim.equals(unclaim))
{
setWall(plotworld, plot.id, new PlotBlock[] { claim });
}
return true;
}
@Override
public String[] getPlotComponents(final PlotWorld plotworld, final PlotId plotid) {
public String[] getPlotComponents(final PlotWorld plotworld, final PlotId plotid)
{
return new String[] { "floor", "wall", "border" };
}
@ -274,7 +320,8 @@ public class ClassicPlotManager extends SquarePlotManager {
* Remove sign for a plot
*/
@Override
public Location getSignLoc(final PlotWorld plotworld, final Plot plot) {
public Location getSignLoc(final PlotWorld plotworld, final Plot plot)
{
final ClassicPlotWorld dpw = (ClassicPlotWorld) plotworld;
final Location bot = MainUtil.getPlotBottomLoc(plotworld.worldname, plot.id);
return new com.intellectualcrafters.plot.object.Location(plotworld.worldname, bot.getX(), dpw.ROAD_HEIGHT + 1, bot.getZ() - 1);

View File

@ -6,7 +6,8 @@ import com.intellectualcrafters.plot.config.ConfigurationNode;
import com.intellectualcrafters.plot.object.PlotBlock;
import com.intellectualcrafters.plot.util.StringMan;
public abstract class ClassicPlotWorld extends SquarePlotWorld {
public abstract class ClassicPlotWorld extends SquarePlotWorld
{
public static int ROAD_HEIGHT_DEFAULT = 64;
public static int PLOT_HEIGHT_DEFAULT = 64;
public static int WALL_HEIGHT_DEFAULT = 64;
@ -29,15 +30,27 @@ public abstract class ClassicPlotWorld extends SquarePlotWorld {
/**
* CONFIG NODE | DEFAULT VALUE | DESCRIPTION | CONFIGURATION TYPE | REQUIRED FOR INITIAL SETUP
*
*
* Set the last boolean to false if you do not require a specific config node to be set while using the setup
* command - this may be useful if a config value can be changed at a later date, and has no impact on the actual
* world generation
*/
@Override
public ConfigurationNode[] getSettingNodes() {
return new ConfigurationNode[] { new ConfigurationNode("plot.height", ClassicPlotWorld.PLOT_HEIGHT_DEFAULT, "Plot height", Configuration.INTEGER, true), new ConfigurationNode("plot.size", SquarePlotWorld.PLOT_WIDTH_DEFAULT, "Plot width", Configuration.INTEGER, true), new ConfigurationNode("plot.filling", ClassicPlotWorld.MAIN_BLOCK_DEFAULT, "Plot block", Configuration.BLOCKLIST, true), new ConfigurationNode("plot.floor", ClassicPlotWorld.TOP_BLOCK_DEFAULT, "Plot floor block", Configuration.BLOCKLIST, true), new ConfigurationNode("wall.block", ClassicPlotWorld.WALL_BLOCK_DEFAULT, "Top wall block", Configuration.BLOCK, true), new ConfigurationNode("wall.block_claimed", ClassicPlotWorld.CLAIMED_WALL_BLOCK_DEFAULT, "Wall block (claimed)", Configuration.BLOCK, true), new ConfigurationNode("road.width", SquarePlotWorld.ROAD_WIDTH_DEFAULT, "Road width", Configuration.INTEGER, true),
new ConfigurationNode("road.height", ClassicPlotWorld.ROAD_HEIGHT_DEFAULT, "Road height", Configuration.INTEGER, true), new ConfigurationNode("road.block", ClassicPlotWorld.ROAD_BLOCK_DEFAULT, "Road block", Configuration.BLOCK, true), new ConfigurationNode("wall.filling", ClassicPlotWorld.WALL_FILLING_DEFAULT, "Wall filling block", Configuration.BLOCK, true), new ConfigurationNode("wall.height", ClassicPlotWorld.WALL_HEIGHT_DEFAULT, "Wall height", Configuration.INTEGER, true), new ConfigurationNode("plot.bedrock", true, "Plot bedrock generation", Configuration.BOOLEAN, true) };
public ConfigurationNode[] getSettingNodes()
{
return new ConfigurationNode[] {
new ConfigurationNode("plot.height", ClassicPlotWorld.PLOT_HEIGHT_DEFAULT, "Plot height", Configuration.INTEGER, true),
new ConfigurationNode("plot.size", SquarePlotWorld.PLOT_WIDTH_DEFAULT, "Plot width", Configuration.INTEGER, true),
new ConfigurationNode("plot.filling", ClassicPlotWorld.MAIN_BLOCK_DEFAULT, "Plot block", Configuration.BLOCKLIST, true),
new ConfigurationNode("plot.floor", ClassicPlotWorld.TOP_BLOCK_DEFAULT, "Plot floor block", Configuration.BLOCKLIST, true),
new ConfigurationNode("wall.block", ClassicPlotWorld.WALL_BLOCK_DEFAULT, "Top wall block", Configuration.BLOCK, true),
new ConfigurationNode("wall.block_claimed", ClassicPlotWorld.CLAIMED_WALL_BLOCK_DEFAULT, "Wall block (claimed)", Configuration.BLOCK, true),
new ConfigurationNode("road.width", SquarePlotWorld.ROAD_WIDTH_DEFAULT, "Road width", Configuration.INTEGER, true),
new ConfigurationNode("road.height", ClassicPlotWorld.ROAD_HEIGHT_DEFAULT, "Road height", Configuration.INTEGER, true),
new ConfigurationNode("road.block", ClassicPlotWorld.ROAD_BLOCK_DEFAULT, "Road block", Configuration.BLOCK, true),
new ConfigurationNode("wall.filling", ClassicPlotWorld.WALL_FILLING_DEFAULT, "Wall filling block", Configuration.BLOCK, true),
new ConfigurationNode("wall.height", ClassicPlotWorld.WALL_HEIGHT_DEFAULT, "Wall height", Configuration.INTEGER, true),
new ConfigurationNode("plot.bedrock", true, "Plot bedrock generation", Configuration.BOOLEAN, true) };
}
/**
@ -45,21 +58,23 @@ public abstract class ClassicPlotWorld extends SquarePlotWorld {
* configuration section for that specific world.
*/
@Override
public void loadConfiguration(final ConfigurationSection config) {
public void loadConfiguration(final ConfigurationSection config)
{
super.loadConfiguration(config);
this.PLOT_BEDROCK = config.getBoolean("plot.bedrock");
this.PLOT_HEIGHT = Math.min(255, config.getInt("plot.height"));
this.MAIN_BLOCK = (PlotBlock[]) Configuration.BLOCKLIST.parseString(StringMan.join(config.getStringList("plot.filling"), ','));
this.TOP_BLOCK = (PlotBlock[]) Configuration.BLOCKLIST.parseString(StringMan.join(config.getStringList("plot.floor"), ','));
this.WALL_BLOCK = (PlotBlock) Configuration.BLOCK.parseString(config.getString("wall.block"));
this.ROAD_HEIGHT = Math.min(255, config.getInt("road.height"));
this.ROAD_BLOCK = (PlotBlock) Configuration.BLOCK.parseString(config.getString("road.block"));
this.WALL_FILLING = (PlotBlock) Configuration.BLOCK.parseString(config.getString("wall.filling"));
this.WALL_HEIGHT = Math.min(254, config.getInt("wall.height"));
this.CLAIMED_WALL_BLOCK = (PlotBlock) Configuration.BLOCK.parseString(config.getString("wall.block_claimed"));
PLOT_BEDROCK = config.getBoolean("plot.bedrock");
PLOT_HEIGHT = Math.min(255, config.getInt("plot.height"));
MAIN_BLOCK = Configuration.BLOCKLIST.parseString(StringMan.join(config.getStringList("plot.filling"), ','));
TOP_BLOCK = Configuration.BLOCKLIST.parseString(StringMan.join(config.getStringList("plot.floor"), ','));
WALL_BLOCK = Configuration.BLOCK.parseString(config.getString("wall.block"));
ROAD_HEIGHT = Math.min(255, config.getInt("road.height"));
ROAD_BLOCK = Configuration.BLOCK.parseString(config.getString("road.block"));
WALL_FILLING = Configuration.BLOCK.parseString(config.getString("wall.filling"));
WALL_HEIGHT = Math.min(254, config.getInt("wall.height"));
CLAIMED_WALL_BLOCK = Configuration.BLOCK.parseString(config.getString("wall.block_claimed"));
}
public ClassicPlotWorld(final String worldname) {
public ClassicPlotWorld(final String worldname)
{
super(worldname);
}
}

View File

@ -1,5 +1,6 @@
package com.intellectualcrafters.plot.generator;
public abstract class GeneratorManager {
public abstract class GeneratorManager
{
}

View File

@ -5,5 +5,5 @@ import com.intellectualcrafters.plot.object.PlotManager;
/**
* A plot manager where plots tessellate in a grid formation symmetrical about x=z
*/
public abstract class GridPlotManager extends PlotManager {
}
public abstract class GridPlotManager extends PlotManager
{}

View File

@ -2,10 +2,12 @@ package com.intellectualcrafters.plot.generator;
import com.intellectualcrafters.plot.object.PlotWorld;
public abstract class GridPlotWorld extends PlotWorld {
public abstract class GridPlotWorld extends PlotWorld
{
public short SIZE;
public GridPlotWorld(final String worldname) {
public GridPlotWorld(final String worldname)
{
super(worldname);
}
}

View File

@ -43,80 +43,100 @@ import com.intellectualcrafters.plot.util.ChunkManager;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.SetBlockQueue;
public class HybridPlotManager extends ClassicPlotManager {
public class HybridPlotManager extends ClassicPlotManager
{
@Override
public void exportTemplate(final PlotWorld plotworld) throws IOException {
public void exportTemplate(final PlotWorld plotworld) throws IOException
{
final HashSet<FileBytes> files = new HashSet<>(Arrays.asList(new FileBytes("templates/" + "tmp-data.yml", Template.getBytes(plotworld))));
final String psRoot = PS.get().IMP.getDirectory() + File.separator;
final String dir = "schematics" + File.separator + "GEN_ROAD_SCHEMATIC" + File.separator + plotworld.worldname + File.separator;
final String newDir = "schematics" + File.separator + "GEN_ROAD_SCHEMATIC" + File.separator + "__TEMP_DIR__" + File.separator;
try {
final String dir = "schematics" + File.separator + "GEN_ROAD_SCHEMATIC" + File.separator + plotworld.worldname + File.separator;
final String newDir = "schematics" + File.separator + "GEN_ROAD_SCHEMATIC" + File.separator + "__TEMP_DIR__" + File.separator;
try
{
final File sideroad = new File(psRoot + dir + "sideroad.schematic");
if (sideroad.exists()) {
if (sideroad.exists())
{
files.add(new FileBytes(newDir + "sideroad.schematic", Files.readAllBytes(sideroad.toPath())));
}
final File intersection = new File(psRoot + dir + "intersection.schematic");
if (intersection.exists()) {
if (intersection.exists())
{
files.add(new FileBytes(newDir + "intersection.schematic", Files.readAllBytes(intersection.toPath())));
}
final File plot = new File(psRoot + dir + "plot.schematic");
if (plot.exists()) {
if (plot.exists())
{
files.add(new FileBytes(newDir + "plot.schematic", Files.readAllBytes(plot.toPath())));
}
}
catch (final Exception e) {
catch (final Exception e)
{
e.printStackTrace();
}
Template.zipAll(plotworld.worldname, files);
}
@Override
public boolean createRoadEast(PlotWorld plotworld, Plot plot) {
public boolean createRoadEast(final PlotWorld plotworld, final Plot plot)
{
super.createRoadEast(plotworld, plot);
HybridPlotWorld hpw = (HybridPlotWorld) plotworld;
if (!hpw.ROAD_SCHEMATIC_ENABLED) {
return true;
}
PlotId id = plot.id;
PlotId id2 = new PlotId(id.x + 1, id.y);
Location bot = getPlotBottomLocAbs(hpw, id2);
Location top = getPlotTopLocAbs(hpw, id);
Location pos1 = new Location(plot.world, top.getX() + 1, 0, bot.getZ());
Location pos2 = new Location(plot.world, bot.getX(), 255, top.getZ() + 1);
final HybridPlotWorld hpw = (HybridPlotWorld) plotworld;
if (!hpw.ROAD_SCHEMATIC_ENABLED) { return true; }
final PlotId id = plot.id;
final PlotId id2 = new PlotId(id.x + 1, id.y);
final Location bot = getPlotBottomLocAbs(hpw, id2);
final Location top = getPlotTopLocAbs(hpw, id);
final Location pos1 = new Location(plot.world, top.getX() + 1, 0, bot.getZ());
final Location pos2 = new Location(plot.world, bot.getX(), 255, top.getZ() + 1);
createSchemAbs(hpw, pos1, pos2, hpw.ROAD_HEIGHT, true);
return true;
}
public void createSchemAbs(HybridPlotWorld hpw, Location pos1, Location pos2, int height, boolean clear) {
public void createSchemAbs(final HybridPlotWorld hpw, final Location pos1, final Location pos2, final int height, final boolean clear)
{
final int size = hpw.SIZE;
for (int x = pos1.getX(); x <= pos2.getX(); x++) {
for (int x = pos1.getX(); x <= pos2.getX(); x++)
{
short absX = (short) ((x - hpw.ROAD_OFFSET_X) % (size));
if (absX < 0) {
if (absX < 0)
{
absX += size;
}
for (int z = pos1.getZ(); z <= pos2.getZ(); z++) {
for (int z = pos1.getZ(); z <= pos2.getZ(); z++)
{
short absZ = (short) ((z - hpw.ROAD_OFFSET_Z) % (size));
if (absZ < 0) {
if (absZ < 0)
{
absZ += size;
}
final PlotLoc loc = new PlotLoc(absX, absZ);
final HashMap<Short, Short> blocks = hpw.G_SCH.get(loc);
if (clear) {
for (short y = (short) (height); y <= (height + hpw.SCHEMATIC_HEIGHT); y++) {
if (clear)
{
for (short y = (short) (height); y <= (height + hpw.SCHEMATIC_HEIGHT); y++)
{
SetBlockQueue.setBlock(hpw.worldname, x, y + y, z, 0);
}
}
if (blocks != null) {
if (blocks != null)
{
final HashMap<Short, Byte> datas = hpw.G_SCH_DATA.get(loc);
if (datas == null) {
for (final Short y : blocks.keySet()) {
if (datas == null)
{
for (final Short y : blocks.keySet())
{
SetBlockQueue.setBlock(hpw.worldname, x, height + y, z, blocks.get(y));
}
} else {
for (final Short y : blocks.keySet()) {
}
else
{
for (final Short y : blocks.keySet())
{
Byte data = datas.get(y);
if (data == null) {
if (data == null)
{
data = 0;
}
SetBlockQueue.setBlock(hpw.worldname, x, height + y, z, new PlotBlock(blocks.get(y), data));
@ -126,41 +146,39 @@ public class HybridPlotManager extends ClassicPlotManager {
}
}
}
@Override
public boolean createRoadSouth(PlotWorld plotworld, Plot plot) {
public boolean createRoadSouth(final PlotWorld plotworld, final Plot plot)
{
super.createRoadSouth(plotworld, plot);
HybridPlotWorld hpw = (HybridPlotWorld) plotworld;
if (!hpw.ROAD_SCHEMATIC_ENABLED) {
return true;
}
PlotId id = plot.id;
PlotId id2 = new PlotId(id.x, id.y + 1);
Location bot = getPlotBottomLocAbs(hpw, id2);
Location top = getPlotTopLocAbs(hpw, id);
Location pos1 = new Location(plot.world, bot.getX(), 0, top.getZ() + 1);
Location pos2 = new Location(plot.world, top.getX() + 1, 255, bot.getZ());
final HybridPlotWorld hpw = (HybridPlotWorld) plotworld;
if (!hpw.ROAD_SCHEMATIC_ENABLED) { return true; }
final PlotId id = plot.id;
final PlotId id2 = new PlotId(id.x, id.y + 1);
final Location bot = getPlotBottomLocAbs(hpw, id2);
final Location top = getPlotTopLocAbs(hpw, id);
final Location pos1 = new Location(plot.world, bot.getX(), 0, top.getZ() + 1);
final Location pos2 = new Location(plot.world, top.getX() + 1, 255, bot.getZ());
createSchemAbs(hpw, pos1, pos2, hpw.ROAD_HEIGHT, true);
return true;
}
@Override
public boolean createRoadSouthEast(PlotWorld plotworld, Plot plot) {
public boolean createRoadSouthEast(final PlotWorld plotworld, final Plot plot)
{
super.createRoadSouthEast(plotworld, plot);
HybridPlotWorld hpw = (HybridPlotWorld) plotworld;
if (!hpw.ROAD_SCHEMATIC_ENABLED) {
return true;
}
PlotId id = plot.id;
PlotId id2 = new PlotId(id.x + 1, id.y + 1);
Location pos1 = getPlotTopLocAbs(hpw, id).add(1, 0, 1);
Location pos2 = getPlotBottomLocAbs(hpw, id2);
final HybridPlotWorld hpw = (HybridPlotWorld) plotworld;
if (!hpw.ROAD_SCHEMATIC_ENABLED) { return true; }
final PlotId id = plot.id;
final PlotId id2 = new PlotId(id.x + 1, id.y + 1);
final Location pos1 = getPlotTopLocAbs(hpw, id).add(1, 0, 1);
final Location pos2 = getPlotBottomLocAbs(hpw, id2);
pos1.setY(0);
pos2.setY(256);
createSchemAbs(hpw, pos1, pos2, hpw.ROAD_HEIGHT, true);
return true;
}
/**
* Clearing the plot needs to only consider removing the blocks - This implementation has used the setCuboidAsync
* function, as it is fast, and uses NMS code - It also makes use of the fact that deleting chunks is a lot faster
@ -168,25 +186,29 @@ public class HybridPlotManager extends ClassicPlotManager {
* to have 512x512 sized plots
*/
@Override
public boolean clearPlot(final PlotWorld plotworld, final Plot plot, final Runnable whenDone) {
public boolean clearPlot(final PlotWorld plotworld, final Plot plot, final Runnable whenDone)
{
final String world = plotworld.worldname;
final HybridPlotWorld dpw = ((HybridPlotWorld) plotworld);
final Location pos1 = MainUtil.getPlotBottomLoc(world, plot.id).add(1, 0, 1);
final Location pos2 = MainUtil.getPlotTopLoc(world, plot.id);
// If augmented
final boolean canRegen = plotworld.TYPE == 0 && plotworld.TERRAIN == 0;
final boolean canRegen = (plotworld.TYPE == 0) && (plotworld.TERRAIN == 0);
// The component blocks
final PlotBlock[] plotfloor = dpw.TOP_BLOCK;
final PlotBlock[] filling = dpw.MAIN_BLOCK;
final PlotBlock[] bedrock = (dpw.PLOT_BEDROCK ? new PlotBlock[] { new PlotBlock((short) 7, (byte) 0) } : filling);
final PlotBlock air = new PlotBlock((short) 0, (byte) 0);
ChunkManager.chunkTask(pos1, pos2, new RunnableVal<int[]>() {
ChunkManager.chunkTask(pos1, pos2, new RunnableVal<int[]>()
{
@Override
public void run() {
public void run()
{
// If the chunk isn't near the edge and it isn't an augmented world we can just regen the whole chunk
if (canRegen && value[6] == 0) {
if (canRegen && (value[6] == 0))
{
ChunkManager.CURRENT_PLOT_CLEAR = new RegionWrapper(value[2], value[4], value[3], value[5]);
ChunkManager.manager.regenerateChunk(world, new ChunkLoc(value[0], value[1]));
ChunkManager.CURRENT_PLOT_CLEAR = null;
@ -198,8 +220,8 @@ public class HybridPlotManager extends ClassicPlotManager {
// Set the biome
MainUtil.setBiome(world, value[2], value[3], value[4], value[5], dpw.PLOT_BIOME);
// These two locations are for each component (e.g. bedrock, main block, floor, air)
Location bot = new Location(world, value[2], 0, value[3]);
Location top = new Location(world, value[4] + 1, 1, value[5] + 1);
final Location bot = new Location(world, value[2], 0, value[3]);
final Location top = new Location(world, value[4] + 1, 1, value[5] + 1);
MainUtil.setCuboidAsync(world, bot, top, bedrock);
// Each component has a different layer
bot.setY(1);
@ -214,21 +236,22 @@ public class HybridPlotManager extends ClassicPlotManager {
// And finally set the schematic, the y value is unimportant for this function
pastePlotSchematic(dpw, bot, top);
}
}, new Runnable() {
}, new Runnable()
{
@Override
public void run() {
public void run()
{
// And notify whatever called this when plot clearing is done
SetBlockQueue.addNotify(whenDone);
}
}, 5);
return true;
}
public void pastePlotSchematic(HybridPlotWorld plotworld, Location l1, Location l2) {
if (!plotworld.PLOT_SCHEMATIC) {
return;
}
public void pastePlotSchematic(final HybridPlotWorld plotworld, final Location l1, final Location l2)
{
if (!plotworld.PLOT_SCHEMATIC) { return; }
createSchemAbs(plotworld, l1, l2, plotworld.PLOT_HEIGHT, false);
}
}

View File

@ -33,7 +33,8 @@ import com.intellectualcrafters.plot.util.SchematicHandler;
import com.intellectualcrafters.plot.util.SchematicHandler.Dimension;
import com.intellectualcrafters.plot.util.SchematicHandler.Schematic;
public class HybridPlotWorld extends ClassicPlotWorld {
public class HybridPlotWorld extends ClassicPlotWorld
{
public boolean ROAD_SCHEMATIC_ENABLED;
public short SCHEMATIC_HEIGHT;
public boolean PLOT_SCHEMATIC = false;
@ -44,7 +45,8 @@ public class HybridPlotWorld extends ClassicPlotWorld {
/*
* Here we are just calling the super method, nothing special
*/
public HybridPlotWorld(final String worldname) {
public HybridPlotWorld(final String worldname)
{
super(worldname);
}
@ -57,95 +59,114 @@ public class HybridPlotWorld extends ClassicPlotWorld {
* configuration section for that specific world.
*/
@Override
public void loadConfiguration(final ConfigurationSection config) {
public void loadConfiguration(final ConfigurationSection config)
{
super.loadConfiguration(config);
if ((this.ROAD_WIDTH & 1) == 0) {
this.PATH_WIDTH_LOWER = (short) (Math.floor(this.ROAD_WIDTH / 2) - 1);
} else {
this.PATH_WIDTH_LOWER = (short) (Math.floor(this.ROAD_WIDTH / 2));
if ((ROAD_WIDTH & 1) == 0)
{
PATH_WIDTH_LOWER = (short) (Math.floor(ROAD_WIDTH / 2) - 1);
}
this.PATH_WIDTH_UPPER = (short) (this.PATH_WIDTH_LOWER + this.PLOT_WIDTH + 1);
try {
else
{
PATH_WIDTH_LOWER = (short) (Math.floor(ROAD_WIDTH / 2));
}
PATH_WIDTH_UPPER = (short) (PATH_WIDTH_LOWER + PLOT_WIDTH + 1);
try
{
setupSchematics();
} catch (final Exception e) {
}
catch (final Exception e)
{
PS.debug("&c - road schematics are disabled for this world.");
}
}
public void setupSchematics() {
this.G_SCH_DATA = new HashMap<>();
this.G_SCH = new HashMap<>();
final String schem1Str = "GEN_ROAD_SCHEMATIC/" + this.worldname + "/sideroad";
final String schem2Str = "GEN_ROAD_SCHEMATIC/" + this.worldname + "/intersection";
final String schem3Str = "GEN_ROAD_SCHEMATIC/" + this.worldname + "/plot";
public void setupSchematics()
{
G_SCH_DATA = new HashMap<>();
G_SCH = new HashMap<>();
final String schem1Str = "GEN_ROAD_SCHEMATIC/" + worldname + "/sideroad";
final String schem2Str = "GEN_ROAD_SCHEMATIC/" + worldname + "/intersection";
final String schem3Str = "GEN_ROAD_SCHEMATIC/" + worldname + "/plot";
final Schematic schem1 = SchematicHandler.manager.getSchematic(schem1Str);
final Schematic schem2 = SchematicHandler.manager.getSchematic(schem2Str);
final Schematic schem3 = SchematicHandler.manager.getSchematic(schem3Str);
final int shift = (int) this.ROAD_WIDTH / 2;
final int shift = ROAD_WIDTH / 2;
int oddshift = 0;
if ((this.ROAD_WIDTH & 1) != 0) {
if ((ROAD_WIDTH & 1) != 0)
{
oddshift = 1;
}
if (schem3 != null) {
this.PLOT_SCHEMATIC = true;
short[] ids = schem3.getIds();
byte[] datas = schem3.getDatas();
if (schem3 != null)
{
PLOT_SCHEMATIC = true;
final short[] ids = schem3.getIds();
final byte[] datas = schem3.getDatas();
final Dimension d3 = schem3.getSchematicDimension();
final short w3 = (short) d3.getX();
final short l3 = (short) d3.getZ();
final short h3 = (short) d3.getY();
int center_shift_x = 0;
int center_shift_z = 0;
if (l3 < this.PLOT_WIDTH) {
center_shift_z = (this.PLOT_WIDTH - l3) / 2;
if (l3 < PLOT_WIDTH)
{
center_shift_z = (PLOT_WIDTH - l3) / 2;
}
if (w3 < this.PLOT_WIDTH) {
center_shift_x = (this.PLOT_WIDTH - w3) / 2;
if (w3 < PLOT_WIDTH)
{
center_shift_x = (PLOT_WIDTH - w3) / 2;
}
for (short x = 0; x < w3; x++) {
for (short z = 0; z < l3; z++) {
for (short y = 0; y < h3; y++) {
for (short x = 0; x < w3; x++)
{
for (short z = 0; z < l3; z++)
{
for (short y = 0; y < h3; y++)
{
final int index = (y * w3 * l3) + (z * w3) + x;
final short id = ids[index];
final byte data = datas[index];
if (id != 0) {
if (id != 0)
{
addOverlayBlock((short) (x + shift + oddshift + center_shift_x), (y), (short) (z + shift + oddshift + center_shift_z), id, data, false);
}
}
}
}
HashSet<PlotItem> items = schem3.getItems();
if (items != null) {
final HashSet<PlotItem> items = schem3.getItems();
if (items != null)
{
G_SCH_STATE = new HashMap<>();
for (PlotItem item : items) {
for (final PlotItem item : items)
{
item.x += shift + oddshift + center_shift_x;
item.z += shift + oddshift + center_shift_z;
item.y += this.PLOT_HEIGHT;
int x = item.x;
int y = item.y;
int z = item.z;
PlotLoc loc = new PlotLoc(x, z);
if (!G_SCH_STATE.containsKey(loc)) {
item.y += PLOT_HEIGHT;
final int x = item.x;
final int z = item.z;
final PlotLoc loc = new PlotLoc(x, z);
if (!G_SCH_STATE.containsKey(loc))
{
G_SCH_STATE.put(loc, new HashSet<PlotItem>());
}
G_SCH_STATE.get(loc).add(item);
}
}
}
if ((schem1 == null) || (schem2 == null) || (this.ROAD_WIDTH == 0)) {
if ((schem1 == null) || (schem2 == null) || (ROAD_WIDTH == 0))
{
PS.debug(C.PREFIX.s() + "&3 - schematic: &7false");
return;
}
this.ROAD_SCHEMATIC_ENABLED = true;
ROAD_SCHEMATIC_ENABLED = true;
// Do not populate road if using schematic population
this.ROAD_BLOCK = new PlotBlock(this.ROAD_BLOCK.id, (byte) 0);
short[] ids1 = schem1.getIds();
byte[] datas1 = schem1.getDatas();
short[] ids2 = schem2.getIds();
byte[] datas2 = schem2.getDatas();
ROAD_BLOCK = new PlotBlock(ROAD_BLOCK.id, (byte) 0);
final short[] ids1 = schem1.getIds();
final byte[] datas1 = schem1.getDatas();
final short[] ids2 = schem2.getIds();
final byte[] datas2 = schem2.getDatas();
final Dimension d1 = schem1.getSchematicDimension();
final short w1 = (short) d1.getX();
final short l1 = (short) d1.getZ();
@ -154,43 +175,55 @@ public class HybridPlotWorld extends ClassicPlotWorld {
final short w2 = (short) d2.getX();
final short l2 = (short) d2.getZ();
final short h2 = (short) d2.getY();
this.SCHEMATIC_HEIGHT = (short) Math.max(h2, h1);
for (short x = 0; x < w1; x++) {
for (short z = 0; z < l1; z++) {
for (short y = 0; y < h1; y++) {
SCHEMATIC_HEIGHT = (short) Math.max(h2, h1);
for (short x = 0; x < w1; x++)
{
for (short z = 0; z < l1; z++)
{
for (short y = 0; y < h1; y++)
{
final int index = (y * w1 * l1) + (z * w1) + x;
final short id = ids1[index];
final byte data = datas1[index];
if (id != 0) {
if (id != 0)
{
addOverlayBlock((short) (x - (shift)), (y), (short) (z + shift + oddshift), id, data, false);
addOverlayBlock((short) (z + shift + oddshift), (y), (short) (x - shift), id, data, true);
}
}
}
}
for (short x = 0; x < w2; x++) {
for (short z = 0; z < l2; z++) {
for (short y = 0; y < h2; y++) {
for (short x = 0; x < w2; x++)
{
for (short z = 0; z < l2; z++)
{
for (short y = 0; y < h2; y++)
{
final int index = (y * w2 * l2) + (z * w2) + x;
final short id = ids2[index];
final byte data = datas2[index];
if (id != 0) {
if (id != 0)
{
addOverlayBlock((short) (x - shift), (y), (short) (z - shift), id, data, false);
}
}
}
}
}
public static byte wrap(byte data, int start) {
if (data >= start && data < start + 4) {
public static byte wrap(byte data, final int start)
{
if ((data >= start) && (data < (start + 4)))
{
data = (byte) ((((data - start) + 2) & 3) + start);
}
return data;
}
public static byte wrap2(byte data, int start) {
if (data >= start && data < start + 2) {
public static byte wrap2(byte data, final int start)
{
if ((data >= start) && (data < (start + 2)))
{
data = (byte) ((((data - start) + 1) & 1) + start);
}
return data;
@ -198,14 +231,16 @@ public class HybridPlotWorld extends ClassicPlotWorld {
// FIXME depends on block ids
// Possibly make abstract?
public static byte rotate(final short id, byte data) {
switch (id) {
public static byte rotate(final short id, byte data)
{
switch (id)
{
case 162:
case 17: {
if (data >= 4 && data < 12) {
if (data >= 8) {
return (byte) (data - 4);
}
case 17:
{
if ((data >= 4) && (data < 12))
{
if (data >= 8) { return (byte) (data - 4); }
return (byte) (data + 4);
}
return data;
@ -228,14 +263,16 @@ public class HybridPlotWorld extends ClassicPlotWorld {
case 156:
case 163:
case 164:
case 180: {
case 180:
{
data = wrap(data, 0);
data = wrap(data, 4);
return data;
}
case 26:
case 86: {
case 86:
{
data = wrap(data, 0);
return data;
}
@ -253,7 +290,8 @@ public class HybridPlotWorld extends ClassicPlotWorld {
case 149:
case 150:
case 96:
case 167: {
case 167:
{
data = wrap(data, 0);
data = wrap(data, 4);
data = wrap(data, 8);
@ -263,18 +301,21 @@ public class HybridPlotWorld extends ClassicPlotWorld {
case 28:
case 66:
case 157:
case 27: {
case 27:
{
data = wrap2(data, 0);
data = wrap2(data, 3);
if (data == 2) {
if (data == 2)
{
data = 5;
}
else if (data == 5) {
else if (data == 5)
{
data = 2;
}
return data;
}
case 23:
case 29:
case 33:
@ -286,12 +327,14 @@ public class HybridPlotWorld extends ClassicPlotWorld {
case 62:
case 65:
case 68:
case 144: {
case 144:
{
data = wrap(data, 2);
return data;
}
case 143:
case 77: {
case 77:
{
data = wrap(data, 1);
return data;
}
@ -300,28 +343,32 @@ public class HybridPlotWorld extends ClassicPlotWorld {
}
}
public void addOverlayBlock(short x, final short y, short z, final short id, byte data, final boolean rotate) {
if (z < 0) {
z += this.SIZE;
public void addOverlayBlock(short x, final short y, short z, final short id, byte data, final boolean rotate)
{
if (z < 0)
{
z += SIZE;
}
if (x < 0) {
x += this.SIZE;
if (x < 0)
{
x += SIZE;
}
final PlotLoc loc = new PlotLoc(x, z);
if (!this.G_SCH.containsKey(loc)) {
this.G_SCH.put(loc, new HashMap<Short, Short>());
if (!G_SCH.containsKey(loc))
{
G_SCH.put(loc, new HashMap<Short, Short>());
}
this.G_SCH.get(loc).put(y, id);
if (rotate) {
byte newdata = rotate(id, data);
if (data == 0 && newdata == 0) {
return;
}
G_SCH.get(loc).put(y, id);
if (rotate)
{
final byte newdata = rotate(id, data);
if ((data == 0) && (newdata == 0)) { return; }
data = newdata;
}
if (!this.G_SCH_DATA.containsKey(loc)) {
this.G_SCH_DATA.put(loc, new HashMap<Short, Byte>());
if (!G_SCH_DATA.containsKey(loc))
{
G_SCH_DATA.put(loc, new HashMap<Short, Byte>());
}
this.G_SCH_DATA.get(loc).put(y, data);
G_SCH_DATA.get(loc).put(y, data);
}
}

View File

@ -25,10 +25,11 @@ import com.intellectualcrafters.plot.util.SchematicHandler;
import com.intellectualcrafters.plot.util.SetBlockQueue;
import com.intellectualcrafters.plot.util.TaskManager;
public abstract class HybridUtils {
public abstract class HybridUtils
{
public static HybridUtils manager;
public abstract void analyzePlot(final Plot plot, final RunnableVal<PlotAnalysis> whenDone);
public abstract int checkModified(final String world, final int x1, final int x2, final int y1, final int y2, final int z1, final int z2, final PlotBlock[] blocks);
@ -37,77 +38,88 @@ public abstract class HybridUtils {
public static List<ChunkLoc> chunks = new ArrayList<>();
public static String world;
public static boolean UPDATE = false;
public final ArrayList<ChunkLoc> getChunks(ChunkLoc region) {
ArrayList<ChunkLoc> chunks = new ArrayList<ChunkLoc>();
public final ArrayList<ChunkLoc> getChunks(final ChunkLoc region)
{
final ArrayList<ChunkLoc> chunks = new ArrayList<ChunkLoc>();
final int sx = region.x << 5;
final int sz = region.z << 5;
for (int x = sx; x < (sx + 32); x++) {
for (int z = sz; z < (sz + 32); z++) {
for (int x = sx; x < (sx + 32); x++)
{
for (int z = sz; z < (sz + 32); z++)
{
chunks.add(new ChunkLoc(x, z));
}
}
return chunks;
}
public void checkModified(final Plot plot, final RunnableVal<Integer> whenDone) {
if (whenDone == null) {
return;
}
public void checkModified(final Plot plot, final RunnableVal<Integer> whenDone)
{
if (whenDone == null) { return; }
final Location pos1 = MainUtil.getPlotBottomLoc(plot.world, plot.id).add(1, 0, 1);
final Location pos2 = MainUtil.getPlotTopLoc(plot.world, plot.id);
final PlotWorld plotworld = PS.get().getPlotWorld(plot.world);
if (!(plotworld instanceof ClassicPlotWorld)) {
if (!(plotworld instanceof ClassicPlotWorld))
{
whenDone.value = -1;
TaskManager.runTask(whenDone);
return;
}
whenDone.value = 0;
final ClassicPlotWorld cpw = (ClassicPlotWorld) plotworld;
ChunkManager.chunkTask(pos1, pos2, new RunnableVal<int[]>() {
ChunkManager.chunkTask(pos1, pos2, new RunnableVal<int[]>()
{
@Override
public void run() {
ChunkLoc loc = new ChunkLoc(value[0], value[1]);
public void run()
{
final ChunkLoc loc = new ChunkLoc(value[0], value[1]);
ChunkManager.manager.loadChunk(plot.world, loc, false);
int bx = value[2];
int bz = value[3];
int ex = value[4];
int ez = value[5];
final int bx = value[2];
final int bz = value[3];
final int ex = value[4];
final int ez = value[5];
whenDone.value += checkModified(plot.world, bx, ex, 1, cpw.PLOT_HEIGHT - 1, bz, ez, cpw.MAIN_BLOCK);
whenDone.value += checkModified(plot.world, bx, ex, cpw.PLOT_HEIGHT, cpw.PLOT_HEIGHT, bz, ez, cpw.TOP_BLOCK);
whenDone.value += checkModified(plot.world, bx, ex, cpw.PLOT_HEIGHT + 1, 255, bz, ez, new PlotBlock[] { new PlotBlock((short) 0, (byte) 0) });
}
}, new Runnable() {
}, new Runnable()
{
@Override
public void run() {
public void run()
{
TaskManager.runTask(whenDone);
}
}, 5);
}
public boolean scheduleRoadUpdate(final String world, int extend) {
if (HybridUtils.UPDATE) {
return false;
}
public boolean scheduleRoadUpdate(final String world, final int extend)
{
if (HybridUtils.UPDATE) { return false; }
HybridUtils.UPDATE = true;
final List<ChunkLoc> regions = ChunkManager.manager.getChunkChunks(world);
return scheduleRoadUpdate(world, regions, extend);
}
public boolean scheduleRoadUpdate(final String world, final List<ChunkLoc> rgs, final int extend) {
public boolean scheduleRoadUpdate(final String world, final List<ChunkLoc> rgs, final int extend)
{
HybridUtils.regions = rgs;
HybridUtils.world = world;
chunks = new ArrayList<ChunkLoc>();
final AtomicInteger count = new AtomicInteger(0);
final long baseTime = System.currentTimeMillis();
final AtomicInteger last = new AtomicInteger();
TaskManager.runTask(new Runnable() {
TaskManager.runTask(new Runnable()
{
@Override
public void run() {
if (UPDATE == false) {
public void run()
{
if (UPDATE == false)
{
last.set(0);
while (chunks.size() > 0) {
ChunkLoc chunk = chunks.get(0);
while (chunks.size() > 0)
{
final ChunkLoc chunk = chunks.get(0);
chunks.remove(0);
regenerateRoad(world, chunk, extend);
ChunkManager.manager.unloadChunk(world, chunk, true, true);
@ -116,25 +128,35 @@ public abstract class HybridUtils {
return;
}
count.incrementAndGet();
if (count.intValue() % 20 == 0) {
if ((count.intValue() % 20) == 0)
{
PS.debug("PROGRESS: " + ((100 * (2048 - chunks.size())) / 2048) + "%");
}
if (regions.size() == 0 && chunks.size() == 0) {
if ((regions.size() == 0) && (chunks.size() == 0))
{
HybridUtils.UPDATE = false;
PS.debug(C.PREFIX.s() + "Finished road conversion");
// CANCEL TASK
return;
} else {
}
else
{
final Runnable task = this;
TaskManager.runTaskAsync(new Runnable() {
TaskManager.runTaskAsync(new Runnable()
{
@Override
public void run() {
try {
if (last.get() == 0) {
public void run()
{
try
{
if (last.get() == 0)
{
last.set((int) (System.currentTimeMillis() - baseTime));
}
if (chunks.size() < 1024) {
if (regions.size() > 0) {
if (chunks.size() < 1024)
{
if (regions.size() > 0)
{
final ChunkLoc loc = regions.get(0);
PS.debug("&3Updating .mcr: " + loc.x + ", " + loc.z + " (aprrox 1024 chunks)");
PS.debug(" - Remaining: " + regions.size());
@ -143,16 +165,20 @@ public abstract class HybridUtils {
System.gc();
}
}
if (chunks.size() > 0) {
long diff = System.currentTimeMillis() + 1;
if (System.currentTimeMillis() - baseTime - last.get() > 2000 && last.get() != 0) {
if (chunks.size() > 0)
{
final long diff = System.currentTimeMillis() + 1;
if (((System.currentTimeMillis() - baseTime - last.get()) > 2000) && (last.get() != 0))
{
last.set(0);
PS.debug(C.PREFIX.s() + "Detected low TPS. Rescheduling in 30s");
final ChunkLoc chunk = chunks.get(0);
chunks.remove(0);
TaskManager.runTask(new Runnable() {
TaskManager.runTask(new Runnable()
{
@Override
public void run() {
public void run()
{
regenerateRoad(world, chunk, extend);
}
});
@ -160,13 +186,17 @@ public abstract class HybridUtils {
TaskManager.runTaskLater(task, 600);
return;
}
if ((System.currentTimeMillis() - baseTime) - last.get() < 1500 && last.get() != 0) {
while (System.currentTimeMillis() < diff && chunks.size() > 0) {
if ((((System.currentTimeMillis() - baseTime) - last.get()) < 1500) && (last.get() != 0))
{
while ((System.currentTimeMillis() < diff) && (chunks.size() > 0))
{
final ChunkLoc chunk = chunks.get(0);
chunks.remove(0);
TaskManager.runTask(new Runnable() {
TaskManager.runTask(new Runnable()
{
@Override
public void run() {
public void run()
{
regenerateRoad(world, chunk, extend);
}
});
@ -174,23 +204,29 @@ public abstract class HybridUtils {
}
last.set((int) (System.currentTimeMillis() - baseTime));
}
} catch (final Exception e) {
}
catch (final Exception e)
{
e.printStackTrace();
final ChunkLoc loc = regions.get(0);
PS.debug("&c[ERROR]&7 Could not update '" + world + "/region/r." + loc.x + "." + loc.z + ".mca' (Corrupt chunk?)");
final int sx = loc.x << 5;
final int sz = loc.z << 5;
for (int x = sx; x < (sx + 32); x++) {
for (int z = sz; z < (sz + 32); z++) {
for (int x = sx; x < (sx + 32); x++)
{
for (int z = sz; z < (sz + 32); z++)
{
ChunkManager.manager.unloadChunk(world, new ChunkLoc(x, z), true, true);
}
}
PS.debug("&d - Potentially skipping 1024 chunks");
PS.debug("&d - TODO: recommend chunkster if corrupt");
}
SetBlockQueue.addNotify(new Runnable() {
SetBlockQueue.addNotify(new Runnable()
{
@Override
public void run() {
public void run()
{
TaskManager.runTaskLater(task, 20);
}
});
@ -201,8 +237,9 @@ public abstract class HybridUtils {
});
return true;
}
public boolean setupRoadSchematic(final Plot plot) {
public boolean setupRoadSchematic(final Plot plot)
{
final String world = plot.world;
final Location bot = MainUtil.getPlotBottomLoc(world, plot.id);
final Location top = MainUtil.getPlotTopLoc(world, plot.id);
@ -224,13 +261,17 @@ public abstract class HybridUtils {
final Location pos3 = new Location(world, bx, by, bz);
final Location pos4 = new Location(world, tx, ty, tz);
final String dir = PS.get().IMP.getDirectory() + File.separator + "schematics" + File.separator + "GEN_ROAD_SCHEMATIC" + File.separator + plot.world + File.separator;
SchematicHandler.manager.getCompoundTag(world, pos1, pos2, new RunnableVal<CompoundTag>() {
SchematicHandler.manager.getCompoundTag(world, pos1, pos2, new RunnableVal<CompoundTag>()
{
@Override
public void run() {
public void run()
{
SchematicHandler.manager.save(value, dir + "sideroad.schematic");
SchematicHandler.manager.getCompoundTag(world, pos3, pos4, new RunnableVal<CompoundTag>() {
SchematicHandler.manager.getCompoundTag(world, pos3, pos4, new RunnableVal<CompoundTag>()
{
@Override
public void run() {
public void run()
{
SchematicHandler.manager.save(value, dir + "intersection.schematic");
plotworld.ROAD_SCHEMATIC_ENABLED = true;
plotworld.setupSchematics();
@ -243,24 +284,26 @@ public abstract class HybridUtils {
public abstract int get_ey(final String world, final int sx, final int ex, final int sz, final int ez, final int sy);
public boolean regenerateRoad(final String world, final ChunkLoc chunk, int extend) {
public boolean regenerateRoad(final String world, final ChunkLoc chunk, int extend)
{
int x = chunk.x << 4;
int z = chunk.z << 4;
final int ex = x + 15;
final int ez = z + 15;
final HybridPlotWorld plotworld = (HybridPlotWorld) PS.get().getPlotWorld(world);
extend = Math.min(extend, 255 - plotworld.ROAD_HEIGHT - plotworld.SCHEMATIC_HEIGHT);
if (!plotworld.ROAD_SCHEMATIC_ENABLED) {
return false;
}
if (!plotworld.ROAD_SCHEMATIC_ENABLED) { return false; }
boolean toCheck = false;
if (plotworld.TYPE == 2) {
boolean c1 = MainUtil.isPlotArea(new Location(plotworld.worldname, x, 1, z));
boolean c2 = MainUtil.isPlotArea(new Location(plotworld.worldname, ex, 1, ez));
if (!c1 && !c2) {
if (plotworld.TYPE == 2)
{
final boolean c1 = MainUtil.isPlotArea(new Location(plotworld.worldname, x, 1, z));
final boolean c2 = MainUtil.isPlotArea(new Location(plotworld.worldname, ex, 1, ez));
if (!c1 && !c2)
{
return false;
}
else {
else
{
toCheck = c1 ^ c2;
}
}
@ -269,60 +312,82 @@ public abstract class HybridUtils {
final PlotId id2 = manager.getPlotId(plotworld, ex, 0, ez);
x -= plotworld.ROAD_OFFSET_X;
z -= plotworld.ROAD_OFFSET_Z;
if ((id1 == null) || (id2 == null) || (id1 != id2)) {
if ((id1 == null) || (id2 == null) || (id1 != id2))
{
final boolean result = ChunkManager.manager.loadChunk(world, chunk, false);
if (result) {
if (id1 != null) {
if (result)
{
if (id1 != null)
{
final Plot p1 = MainUtil.getPlot(world, id1);
if ((p1 != null) && p1.hasOwner() && p1.getSettings().isMerged()) {
if ((p1 != null) && p1.hasOwner() && p1.getSettings().isMerged())
{
toCheck = true;
}
}
if ((id2 != null) && !toCheck) {
if ((id2 != null) && !toCheck)
{
final Plot p2 = MainUtil.getPlot(world, id2);
if ((p2 != null) && p2.hasOwner() && p2.getSettings().isMerged()) {
if ((p2 != null) && p2.hasOwner() && p2.getSettings().isMerged())
{
toCheck = true;
}
}
final int size = plotworld.SIZE;
for (int X = 0; X < 16; X++) {
for (int X = 0; X < 16; X++)
{
short absX = (short) ((x + X) % size);
for (int Z = 0; Z < 16; Z++) {
for (int Z = 0; Z < 16; Z++)
{
short absZ = (short) ((z + Z) % size);
if (absX < 0) {
if (absX < 0)
{
absX += size;
}
if (absZ < 0) {
if (absZ < 0)
{
absZ += size;
}
boolean condition;
if (toCheck) {
if (toCheck)
{
condition = manager.getPlotId(plotworld, x + X + plotworld.ROAD_OFFSET_X, 1, z + Z + plotworld.ROAD_OFFSET_Z) == null;
// condition = MainUtil.isPlotRoad(new Location(plotworld.worldname, x + X, 1, z + Z));
} else {
// condition = MainUtil.isPlotRoad(new Location(plotworld.worldname, x + X, 1, z + Z));
}
else
{
final boolean gx = absX > plotworld.PATH_WIDTH_LOWER;
final boolean gz = absZ > plotworld.PATH_WIDTH_LOWER;
final boolean lx = absX < plotworld.PATH_WIDTH_UPPER;
final boolean lz = absZ < plotworld.PATH_WIDTH_UPPER;
condition = (!gx || !gz || !lx || !lz);
}
if (condition) {
if (condition)
{
final int sy = plotworld.ROAD_HEIGHT;
final PlotLoc loc = new PlotLoc(absX, absZ);
final HashMap<Short, Short> blocks = plotworld.G_SCH.get(loc);
for (short y = (short) (plotworld.ROAD_HEIGHT); y <= (plotworld.ROAD_HEIGHT + plotworld.SCHEMATIC_HEIGHT + extend); y++) {
for (short y = (short) (plotworld.ROAD_HEIGHT); y <= (plotworld.ROAD_HEIGHT + plotworld.SCHEMATIC_HEIGHT + extend); y++)
{
SetBlockQueue.setBlock(world, x + X + plotworld.ROAD_OFFSET_X, y, z + Z + plotworld.ROAD_OFFSET_Z, 0);
}
if (blocks != null) {
if (blocks != null)
{
final HashMap<Short, Byte> datas = plotworld.G_SCH_DATA.get(loc);
if (datas == null) {
for (final Short y : blocks.keySet()) {
if (datas == null)
{
for (final Short y : blocks.keySet())
{
SetBlockQueue.setBlock(world, x + X + plotworld.ROAD_OFFSET_X, sy + y, z + Z + plotworld.ROAD_OFFSET_Z, blocks.get(y));
}
} else {
for (final Short y : blocks.keySet()) {
}
else
{
for (final Short y : blocks.keySet())
{
Byte data = datas.get(y);
if (data == null) {
if (data == null)
{
data = 0;
}
SetBlockQueue.setBlock(world, x + X + plotworld.ROAD_OFFSET_X, sy + y, z + Z + plotworld.ROAD_OFFSET_Z, new PlotBlock(blocks.get(y), data));
@ -332,9 +397,11 @@ public abstract class HybridUtils {
}
}
}
SetBlockQueue.addNotify(new Runnable() {
SetBlockQueue.addNotify(new Runnable()
{
@Override
public void run() {
public void run()
{
ChunkManager.manager.unloadChunk(world, chunk, true, true);
}
});

Some files were not shown because too many files have changed in this diff Show More