diff --git a/PlotSquared/pom.xml b/PlotSquared/pom.xml index 8e5115cfc..f55f498e0 100644 --- a/PlotSquared/pom.xml +++ b/PlotSquared/pom.xml @@ -8,7 +8,7 @@ UTF-8 PlotSquared - 2.7.3 + 2.7.4 PlotSquared jar diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Condense.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Condense.java index bc9378024..36bc2d409 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Condense.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Condense.java @@ -27,9 +27,11 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.nio.file.attribute.BasicFileAttributes; import java.util.ArrayList; +import java.util.Collection; import java.util.HashSet; import java.util.Set; +import org.apache.commons.lang3.StringUtils; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.World; @@ -57,19 +59,72 @@ public class Condense extends SubCommand { super("condense", "plots.admin", "Condense a plotworld", "condense", "", CommandCategory.DEBUG, false); } - public PlotId getId(String id) { - try { - String[] split = id.split(";"); - return new PlotId(Integer.parseInt(split[0]), Integer.parseInt(split[1])); - } - catch (Exception e) { - return null; - } - } - @Override public boolean execute(final Player plr, final String... args) { - return true; + if (plr != null) { + PlayerFunctions.sendMessage(plr, (C.NOT_CONSOLE)); + return false; + } + if (args.length != 2 && args.length != 3) { + PlayerFunctions.sendMessage(plr, "/plot condense [radius]"); + return false; + } + String worldname = args[0]; + World world = Bukkit.getWorld(worldname); + if (world == null || !PlotMain.isPlotWorld(worldname)) { + PlayerFunctions.sendMessage(plr, "INVALID WORLD"); + return false; + } + switch (args[1].toLowerCase()) { + case "start": { + if (args.length == 2) { + PlayerFunctions.sendMessage(plr, "/plot condense " + worldname + " start "); + return false; + } + PlayerFunctions.sendMessage(plr, "NOT IMPLEMENTED"); + return true; + } + case "stop": { + PlayerFunctions.sendMessage(plr, "NOT IMPLEMENTED"); + return true; + } + case "info": { + if (args.length == 2) { + PlayerFunctions.sendMessage(plr, "/plot condense " + worldname + " info "); + return false; + } + if (!StringUtils.isNumeric(args[2])) { + PlayerFunctions.sendMessage(plr, "INVALID RADIUS"); + return false; + } + int radius = Integer.parseInt(args[2]); + Collection plots = PlotMain.getPlots(worldname).values(); + int size = plots.size(); + int minimum_radius = (int) Math.ceil((Math.sqrt(size)/2) + 1); + int max_move = getPlots(plots, minimum_radius).size(); + int user_move = getPlots(plots, radius).size(); + PlayerFunctions.sendMessage(plr, "=== DEFAULT EVAL ==="); + PlayerFunctions.sendMessage(plr, "MINIMUM RADIUS: " + minimum_radius); + PlayerFunctions.sendMessage(plr, "MAXIMUM MOVES: " + max_move); + PlayerFunctions.sendMessage(plr, "=== INPUT EVAL ==="); + PlayerFunctions.sendMessage(plr, "INPUT RADIUS: " + radius); + PlayerFunctions.sendMessage(plr, "ESTIMATED MOVES: " + user_move); + PlayerFunctions.sendMessage(plr, "&e - Radius is measured in plot width"); + return true; + } + } + PlayerFunctions.sendMessage(plr, "/plot condense " + worldname + " start "); + return false; + } + + public Set getPlots(Collection plots, int radius) { + HashSet outside = new HashSet<>(); + for (Plot plot : plots) { + if (plot.id.x > radius || plot.id.x < -radius || plot.id.y > radius || plot.id.y < -radius) { + outside.add(plot); + } + } + return outside; } public static void sendMessage(final String message) { diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java index 433aa1bb5..1b5f7b55d 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java @@ -49,7 +49,7 @@ public class MainCommand implements CommandExecutor, TabCompleter { */ public static final String MAIN_PERMISSION = "plots.use"; - private final static SubCommand[] _subCommands = new SubCommand[]{new Setup(), new DebugSaveTest(), new DebugLoadTest(), new CreateRoadSchematic(), new RegenAllRoads(), new DebugClear(), new Ban(), new Unban(), new OP(), new DEOP(), new Claim(), new Paste(), new Copy(), new Clipboard(), new Auto(), new Home(), new Visit(), new TP(), new Set(), new Clear(), new Delete(), new SetOwner(), new Denied(), new Helpers(), new Trusted(), new Info(), new list(), new Help(), new Debug(), new Schematic(), new plugin(), new Inventory(), new Purge(), new Reload(), new Merge(), new Unlink(), new Kick(), new Rate(), new DebugClaimTest(), new Inbox(), new Comment(), new Database(), new Unclaim(), new Swap(), new MusicSubcommand(), new DebugRoadRegen(), new Trim(), new DebugExec(), new FlagCmd(), new Target(), new DebugFixFlags(), new Move() }; + private final static SubCommand[] _subCommands = new SubCommand[]{new Setup(), new DebugSaveTest(), new DebugLoadTest(), new CreateRoadSchematic(), new RegenAllRoads(), new DebugClear(), new Ban(), new Unban(), new OP(), new DEOP(), new Claim(), new Paste(), new Copy(), new Clipboard(), new Auto(), new Home(), new Visit(), new TP(), new Set(), new Clear(), new Delete(), new SetOwner(), new Denied(), new Helpers(), new Trusted(), new Info(), new list(), new Help(), new Debug(), new Schematic(), new plugin(), new Inventory(), new Purge(), new Reload(), new Merge(), new Unlink(), new Kick(), new Rate(), new DebugClaimTest(), new Inbox(), new Comment(), new Database(), new Unclaim(), new Swap(), new MusicSubcommand(), new DebugRoadRegen(), new Trim(), new DebugExec(), new FlagCmd(), new Target(), new DebugFixFlags(), new Move(), new Condense() }; public final static ArrayList subCommands = new ArrayList() { { diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Move.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Move.java index 06eb8dda0..baf5ee4c4 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Move.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Move.java @@ -45,7 +45,7 @@ import com.intellectualcrafters.plot.util.TaskManager; public class Move extends SubCommand { public Move() { - super("move", "plots.admin", "plot moving debug test", "move", "condense", CommandCategory.DEBUG, true); + super("debugmove", "plots.admin", "plot moving debug test", "debugmove", "move", CommandCategory.DEBUG, true); } @Override diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java index 70a3650eb..12d7c865b 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java @@ -161,6 +161,7 @@ public class SQLManager implements AbstractDB { } stored.get(world).put(new PlotId(idx, idz), id); } + stmt.close(); } catch (final SQLException e) { e.printStackTrace(); }