condense info

This commit is contained in:
boy0001 2015-02-16 14:46:57 +11:00
parent 42a710d885
commit 8585727acb
5 changed files with 70 additions and 14 deletions

View File

@ -8,7 +8,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties> </properties>
<artifactId>PlotSquared</artifactId> <artifactId>PlotSquared</artifactId>
<version>2.7.3</version> <version>2.7.4</version>
<name>PlotSquared</name> <name>PlotSquared</name>
<packaging>jar</packaging> <packaging>jar</packaging>
<build> <build>

View File

@ -27,9 +27,11 @@ import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.nio.file.attribute.BasicFileAttributes; import java.nio.file.attribute.BasicFileAttributes;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
import org.apache.commons.lang3.StringUtils;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.World; import org.bukkit.World;
@ -57,19 +59,72 @@ public class Condense extends SubCommand {
super("condense", "plots.admin", "Condense a plotworld", "condense", "", CommandCategory.DEBUG, false); 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 @Override
public boolean execute(final Player plr, final String... args) { 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 <world> <start|stop|info> [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 <radius>");
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 <radius>");
return false;
}
if (!StringUtils.isNumeric(args[2])) {
PlayerFunctions.sendMessage(plr, "INVALID RADIUS");
return false;
}
int radius = Integer.parseInt(args[2]);
Collection<Plot> 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 <radius>");
return false;
}
public Set<Plot> getPlots(Collection<Plot> plots, int radius) {
HashSet<Plot> 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) { public static void sendMessage(final String message) {

View File

@ -49,7 +49,7 @@ public class MainCommand implements CommandExecutor, TabCompleter {
*/ */
public static final String MAIN_PERMISSION = "plots.use"; 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<SubCommand> subCommands = new ArrayList<SubCommand>() { public final static ArrayList<SubCommand> subCommands = new ArrayList<SubCommand>() {
{ {

View File

@ -45,7 +45,7 @@ import com.intellectualcrafters.plot.util.TaskManager;
public class Move extends SubCommand { public class Move extends SubCommand {
public Move() { 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 @Override

View File

@ -161,6 +161,7 @@ public class SQLManager implements AbstractDB {
} }
stored.get(world).put(new PlotId(idx, idz), id); stored.get(world).put(new PlotId(idx, idz), id);
} }
stmt.close();
} catch (final SQLException e) { } catch (final SQLException e) {
e.printStackTrace(); e.printStackTrace();
} }