From 955fa674d00c1ba5706360a9a31633d24c81802f Mon Sep 17 00:00:00 2001 From: boy0001 Date: Tue, 28 Jul 2015 03:28:39 +1000 Subject: [PATCH] Fixing some stuff after testing --- .../plot/commands/Cluster.java | 6 +- .../plot/commands/MainCommand.java | 85 ++++++++----------- .../plot/commands/Set.java | 2 +- .../intellectualcrafters/plot/config/C.java | 9 +- .../plot/util/ClusterManager.java | 3 + .../plot/util/StringMan.java | 2 - .../plot/util/helpmenu/HelpMenu.java | 8 +- .../plot/util/helpmenu/HelpObject.java | 14 ++- .../plot/util/helpmenu/HelpPage.java | 14 +-- .../intellectualsites/commands/Command.java | 3 + .../commands/CommandDeclaration.java | 2 +- .../com/plotsquared/bukkit/BukkitMain.java | 3 + .../generator/BukkitGeneratorWrapper.java | 3 - .../bukkit/listeners/WorldEvents.java | 3 - .../util/bukkit/BukkitChunkManager.java | 6 +- .../bukkit/util/bukkit/SetGenCB.java | 2 +- 16 files changed, 79 insertions(+), 86 deletions(-) diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Cluster.java b/src/main/java/com/intellectualcrafters/plot/commands/Cluster.java index 6ee2b8579..12545aa42 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Cluster.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Cluster.java @@ -44,6 +44,7 @@ import com.intellectualcrafters.plot.util.StringMan; import com.intellectualcrafters.plot.util.UUIDHandler; import com.intellectualsites.commands.CommandDeclaration; import com.plotsquared.bukkit.generator.AugmentedPopulator; +import com.plotsquared.bukkit.generator.BukkitGeneratorWrapper; import com.plotsquared.bukkit.generator.BukkitPlotGenerator; import com.plotsquared.bukkit.generator.HybridGen; import com.plotsquared.bukkit.util.SetupUtils; @@ -154,7 +155,7 @@ public class Cluster extends SubCommand { PlotWorld plotworld = PS.get().getPlotWorld(world); if (plotworld == null) { PS.get().config.createSection("worlds." + world); - PS.get().loadWorld(world, null); + PS.get().loadWorld(world, PS.get().IMP.getGenerator(world, null)); } else { final String gen_string = PS.get().config.getString("worlds." + world + "." + "generator.plugin"); @@ -302,8 +303,9 @@ public class Cluster extends SubCommand { return false; } } + long start = System.currentTimeMillis(); ClusterManager.regenCluster(cluster); - MainUtil.sendMessage(plr, C.CLUSTER_REGENERATED); + MainUtil.sendMessage(plr, C.CLUSTER_REGENERATED, (System.currentTimeMillis() - start) + ""); return true; } case "add": diff --git a/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java b/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java index 6a07868e0..aface6672 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java @@ -153,47 +153,43 @@ public class MainCommand extends CommandManager { // return help; // } // - public static void displayHelp(PlotPlayer player, String cat, int page) { - if (cat != null && StringMan.isEqualIgnoreCase(cat, "all")) { - cat = null; + public static void displayHelp(PlotPlayer player, String cat, int page, String label) { + CommandCategory catEnum = null; + if (cat != null) { + if (StringMan.isEqualIgnoreCase(cat, "all")) { + catEnum = null; + } + else { + for (CommandCategory c : CommandCategory.values()) { + if (StringMan.isEqualIgnoreCaseToAny(cat, c.name(), c.toString())) { + catEnum = c; + cat = c.name(); + break; + } + } + if (catEnum == null) { + cat = null; + } + } } if (cat == null && page == 0) { final StringBuilder builder = new StringBuilder(); - builder.append(C.HELP_INFO.s()); - for (final CommandCategory category : CommandCategory.values()) { - builder.append("\n").append(C.HELP_INFO_ITEM.s().replaceAll("%category%", category.toString().toLowerCase()).replaceAll("%category_desc%", category.toString())); + builder.append(C.HELP_HEADER.s()); + for (final CommandCategory c : CommandCategory.values()) { + builder.append("\n" + StringMan.replaceAll(C.HELP_INFO_ITEM.s(), "%category%", c.toString().toLowerCase(), "%category_desc%", c.toString())); } builder.append("\n").append(C.HELP_INFO_ITEM.s().replaceAll("%category%", "all").replaceAll("%category_desc%", "Display all commands")); - MainUtil.sendMessage(player, builder.toString()); - return; - } - CommandCategory cato = null; - for (final CommandCategory category : CommandCategory.values()) { - if (cat.equalsIgnoreCase(category.toString())) { - cato = category; - break; - } - } - if ((cato == null) && !cat.equalsIgnoreCase("all")) { - final StringBuilder builder = new StringBuilder(); - builder.append(C.HELP_INFO.s()); - for (final CommandCategory category : CommandCategory.values()) { - builder.append("\n").append(C.HELP_INFO_ITEM.s().replaceAll("%category%", category.toString().toLowerCase()).replaceAll("%category_desc%", category.toString())); - } + builder.append("\n" + C.HELP_FOOTER.s()); MainUtil.sendMessage(player, builder.toString(), false); return; } + page--; new HelpMenu(player) - .setCategory(cato) + .setCategory(catEnum) .getCommands() .generateMaxPages() - .generatePage(page) + .generatePage(page, label) .render(); - // final StringBuilder help = new StringBuilder(); - // for (final String string : helpMenu(player, cato, page)) { - // help.append(string).append("\n"); - // } - // MainUtil.sendMessage(player, help.toString()); } public static boolean onCommand(final PlotPlayer player, final String cmd, final String... args) { @@ -207,44 +203,37 @@ public class MainCommand extends CommandManager { switch (args.length) { case 3: { category = args[1]; + if (MathMan.isInteger(args[2])) { + try { + help_index = Integer.parseInt(args[2]); + } + catch (NumberFormatException e) {} + } + break; } case 2: { - if (MathMan.isInteger(args[args.length - 1])) { + if (MathMan.isInteger(args[1])) { category = null; try { - help_index = Integer.parseInt(args[1]) - 1; + help_index = Integer.parseInt(args[1]); } catch (NumberFormatException e) {} } if (category == null) { category = args[1]; } - } - case 1: { break; } } - if (args.length == 3) { - if (MathMan.isInteger(args[args.length - 1])) { - category = null; - try { - help_index = Integer.parseInt(args[1]) - 1; - } - catch (NumberFormatException e) {} - } - else { - category = args[1]; - } - } } - else if (MathMan.isInteger(args[args.length - 1])) { + else if (args.length == 1 && MathMan.isInteger(args[args.length - 1])) { try { - help_index = Integer.parseInt(args[args.length - 1]) - 1; + help_index = Integer.parseInt(args[args.length - 1]); } catch (NumberFormatException e) {} } if (help_index != -1) { - displayHelp(player, category, help_index); + displayHelp(player, category, help_index, cmd); return true; } StringBuilder builder = new StringBuilder(cmd).append(" "); diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Set.java b/src/main/java/com/intellectualcrafters/plot/commands/Set.java index c75589637..f85098bd1 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Set.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Set.java @@ -361,7 +361,7 @@ public class Set extends SubCommand { a.append(" ").append(args[x]); } } - MainCommand.onCommand(plr, world, ("flag set " + args[0] + a.toString()).split(" ")); + MainCommand.onCommand(plr, "flag", ("set " + args[0] + a.toString()).split(" ")); return true; } } diff --git a/src/main/java/com/intellectualcrafters/plot/config/C.java b/src/main/java/com/intellectualcrafters/plot/config/C.java index eacabc27d..24721edb1 100644 --- a/src/main/java/com/intellectualcrafters/plot/config/C.java +++ b/src/main/java/com/intellectualcrafters/plot/config/C.java @@ -143,7 +143,7 @@ public enum C { NO_PLOT_INBOX("$2You must stand in or supply a plot argument", "Comment"), COMMENT_REMOVED("$4Successfully deleted comment/s:n$2 - '$3%s$2'", "Comment"), COMMENT_ADDED("$4A comment has been left", "Comment"), - COMMENT_HEADER("$2====== Comments ======", "Comment"), + COMMENT_HEADER("$2&m---------&r $1Comments $2&m---------&r", "Comment"), INBOX_EMPTY("$2No comments","Comment"), /* * Console @@ -388,7 +388,7 @@ public enum C { NONE("None", "Info"), 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====== $1INFO $3======", false, "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_TRUSTED("$1Trusted:$2 %trusted%", "Info"), PLOT_INFO_MEMBERS("$1Members:$2 %members%", "Info"), @@ -505,11 +505,10 @@ public enum C { /* * Help */ - HELP_HEADER("$3====== $1Plot\u00B2 Help $3======", "Help"), + HELP_HEADER("$3&m---------&r $1Plot\u00B2 Help $3&m---------", "Help"), HELP_PAGE_HEADER("$1Category: $2%category%$2,$1 Page: $2%current%$3/$2%max%$2", "Help"), - HELP_FOOTER("$3====== $1Plot\u00B2 Help $3======", "Help"), + HELP_FOOTER("$3&m---------&r $1Plot\u00B2 Help $3&m---------", "Help"), - HELP_INFO("$3====== $1Choose a Category $3======", false, "Help"), HELP_INFO_ITEM("$1/plots help %category% $3- $2%category_desc%", "Help"), HELP_ITEM("$1%usage% [%alias%]&- $3- $2%desc%&-", "Help"), /* diff --git a/src/main/java/com/intellectualcrafters/plot/util/ClusterManager.java b/src/main/java/com/intellectualcrafters/plot/util/ClusterManager.java index 4f63e6310..86c920037 100644 --- a/src/main/java/com/intellectualcrafters/plot/util/ClusterManager.java +++ b/src/main/java/com/intellectualcrafters/plot/util/ClusterManager.java @@ -158,6 +158,9 @@ public class ClusterManager { public static PlotCluster getCluster(final Location loc) { final String world = loc.getWorld(); PlotManager manager = PS.get().getPlotManager(world); + if (manager == null) { + return null; + } PlotId id = manager.getPlotIdAbs(PS.get().getPlotWorld(world), loc.getX(), loc.getY(), loc.getZ()); if (id != null) { return getCluster(world, id); diff --git a/src/main/java/com/intellectualcrafters/plot/util/StringMan.java b/src/main/java/com/intellectualcrafters/plot/util/StringMan.java index cae3ed36d..98d2b3f78 100644 --- a/src/main/java/com/intellectualcrafters/plot/util/StringMan.java +++ b/src/main/java/com/intellectualcrafters/plot/util/StringMan.java @@ -152,12 +152,10 @@ public class StringMan { public static String join(Object[] array, String delimiter) { StringBuilder result = new StringBuilder(); - System.out.print(array.getClass().getName()); for (int i = 0, j = array.length; i < j; i++) { if (i > 0) { result.append(delimiter); } - System.out.print(array[i].getClass().getName()); result.append(array[i]); } return result.toString(); diff --git a/src/main/java/com/intellectualcrafters/plot/util/helpmenu/HelpMenu.java b/src/main/java/com/intellectualcrafters/plot/util/helpmenu/HelpMenu.java index 4a7a86f3f..fe9e25262 100644 --- a/src/main/java/com/intellectualcrafters/plot/util/helpmenu/HelpMenu.java +++ b/src/main/java/com/intellectualcrafters/plot/util/helpmenu/HelpMenu.java @@ -33,18 +33,18 @@ public class HelpMenu { } public HelpMenu generateMaxPages() { - this._maxPage = Math.min(_commands.size() / PER_PAGE, 1); + this._maxPage = Math.max(_commands.size() - 1 / PER_PAGE, 1); return this; } - public HelpMenu generatePage(int currentPage) { + public HelpMenu generatePage(int currentPage, String label) { if (currentPage > _maxPage) { currentPage = _maxPage; } _page = new HelpPage(_commandCategory, currentPage, _maxPage); - int max = Math.min((currentPage * PER_PAGE) + PER_PAGE, _commands.size()); + int max = Math.min((currentPage * PER_PAGE) + (PER_PAGE - 1), _commands.size()); for (int i = currentPage * PER_PAGE; i < max; i++) { - _page.addHelpItem(new HelpObject(_commands.get(i))); + _page.addHelpItem(new HelpObject(_commands.get(i), label)); } return this; } diff --git a/src/main/java/com/intellectualcrafters/plot/util/helpmenu/HelpObject.java b/src/main/java/com/intellectualcrafters/plot/util/helpmenu/HelpObject.java index 15390b0a6..15229feac 100644 --- a/src/main/java/com/intellectualcrafters/plot/util/helpmenu/HelpObject.java +++ b/src/main/java/com/intellectualcrafters/plot/util/helpmenu/HelpObject.java @@ -10,14 +10,9 @@ public class HelpObject { private final Command _command; private final String _rendered; - public HelpObject(final Command command) { + public HelpObject(final Command command, String label) { this._command = command; - String rendered = C.HELP_ITEM.s(); - this._rendered = rendered - .replace("%usage%", _command.getUsage()) - .replace("%alias%", _command.getAliases().size() > 0 ? StringMan.join(_command.getAliases(), "|") : "") - .replace("%desc%", _command.getDescription()) - .replace("%arguments%", buildArgumentList(_command.getRequiredArguments())); // TODO Make configurable + this._rendered = StringMan.replaceAll(C.HELP_ITEM.s(), "%usage%", _command.getUsage(), "[%alias%]", _command.getAliases().size() > 0 ? "(" + StringMan.join(_command.getAliases(), "|") + ")" : "","%desc%", _command.getDescription(),"%arguments%", buildArgumentList(_command.getRequiredArguments()), "{label}", label); } @Override @@ -26,8 +21,11 @@ public class HelpObject { } private String buildArgumentList(Argument[] arguments) { + if (arguments == null) { + return ""; + } StringBuilder builder = new StringBuilder(); - for (final Argument argument : arguments) { + for (final Argument argument : arguments) { builder.append("[").append(argument.getName()).append(" (").append(argument.getExample()).append(")],"); } return arguments.length > 0 ? builder.substring(0, builder.length() - 1) : ""; diff --git a/src/main/java/com/intellectualcrafters/plot/util/helpmenu/HelpPage.java b/src/main/java/com/intellectualcrafters/plot/util/helpmenu/HelpPage.java index d2e3e2b19..eec456da7 100644 --- a/src/main/java/com/intellectualcrafters/plot/util/helpmenu/HelpPage.java +++ b/src/main/java/com/intellectualcrafters/plot/util/helpmenu/HelpPage.java @@ -5,25 +5,27 @@ import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.util.MainUtil; +import java.util.ArrayList; import java.util.HashSet; +import java.util.List; import java.util.Set; public class HelpPage { - private final Set _helpObjecs; + private final List _helpObjecs; private final String _header; public HelpPage(CommandCategory category, int currentPage, int maxPages) { - _helpObjecs = new HashSet<>(); + _helpObjecs = new ArrayList<>(); _header = C.HELP_PAGE_HEADER.s() .replace("%category%", category == null ? "ALL" : category.toString()) - .replace("%current%", currentPage + "") - .replace("%max%", maxPages + ""); + .replace("%current%", (currentPage + 1) + "") + .replace("%max%", (maxPages + 1) + ""); } public void render(final PlotPlayer player) { - if (_helpObjecs.size() < 2) { - MainUtil.sendMessage(player, C.NO_COMMANDS.s(), false); + if (_helpObjecs.size() < 1) { + MainUtil.sendMessage(player, C.NOT_VALID_NUMBER, "(0)"); } else { MainUtil.sendMessage(player, C.HELP_HEADER.s(), false); MainUtil.sendMessage(player, _header, false); diff --git a/src/main/java/com/intellectualsites/commands/Command.java b/src/main/java/com/intellectualsites/commands/Command.java index 8508a9ac1..691e9540d 100644 --- a/src/main/java/com/intellectualsites/commands/Command.java +++ b/src/main/java/com/intellectualsites/commands/Command.java @@ -114,6 +114,9 @@ public abstract class Command extends CommandManager { } final public String getUsage() { + if (this.usage.length() == 0) { + return "/{label} " + command; + } return this.usage; } diff --git a/src/main/java/com/intellectualsites/commands/CommandDeclaration.java b/src/main/java/com/intellectualsites/commands/CommandDeclaration.java index b079c30c9..ffb87cc0b 100644 --- a/src/main/java/com/intellectualsites/commands/CommandDeclaration.java +++ b/src/main/java/com/intellectualsites/commands/CommandDeclaration.java @@ -14,7 +14,7 @@ public @interface CommandDeclaration { String command(); - String[] aliases() default ""; + String[] aliases() default {}; String permission() default ""; diff --git a/src/main/java/com/plotsquared/bukkit/BukkitMain.java b/src/main/java/com/plotsquared/bukkit/BukkitMain.java index 7d31cc096..fde229d3a 100644 --- a/src/main/java/com/plotsquared/bukkit/BukkitMain.java +++ b/src/main/java/com/plotsquared/bukkit/BukkitMain.java @@ -408,6 +408,9 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain { @Override public BukkitGeneratorWrapper getGenerator(final String world, final String name) { + if (name == null) { + return new BukkitGeneratorWrapper(world, null); + } final Plugin gen_plugin = Bukkit.getPluginManager().getPlugin(name); ChunkGenerator gen; if ((gen_plugin != null) && gen_plugin.isEnabled()) { diff --git a/src/main/java/com/plotsquared/bukkit/generator/BukkitGeneratorWrapper.java b/src/main/java/com/plotsquared/bukkit/generator/BukkitGeneratorWrapper.java index 64c5072f6..6d2330a47 100644 --- a/src/main/java/com/plotsquared/bukkit/generator/BukkitGeneratorWrapper.java +++ b/src/main/java/com/plotsquared/bukkit/generator/BukkitGeneratorWrapper.java @@ -46,9 +46,6 @@ public class BukkitGeneratorWrapper extends PlotGenerator { if (gen_wrapper != null) { generator = gen_wrapper.generator; } - else { - System.out.print("INVALID GENERATOR: " + gen_string); - } } } diff --git a/src/main/java/com/plotsquared/bukkit/listeners/WorldEvents.java b/src/main/java/com/plotsquared/bukkit/listeners/WorldEvents.java index 79742994b..77d5fc3f5 100644 --- a/src/main/java/com/plotsquared/bukkit/listeners/WorldEvents.java +++ b/src/main/java/com/plotsquared/bukkit/listeners/WorldEvents.java @@ -38,9 +38,6 @@ public class WorldEvents implements Listener { if (PS.get().config.contains("worlds." + name)) { PS.get().loadWorld(name, new BukkitGeneratorWrapper(name, null)); } - else if (gen != null) { - System.out.print("NOT INSTANCE OF BukkitGeneratorWrapper: " + gen.getClass().getName()); - } } lastWorld = null; } diff --git a/src/main/java/com/plotsquared/bukkit/util/bukkit/BukkitChunkManager.java b/src/main/java/com/plotsquared/bukkit/util/bukkit/BukkitChunkManager.java index fb650667a..37d71b6e8 100644 --- a/src/main/java/com/plotsquared/bukkit/util/bukkit/BukkitChunkManager.java +++ b/src/main/java/com/plotsquared/bukkit/util/bukkit/BukkitChunkManager.java @@ -63,6 +63,7 @@ import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; import java.util.List; +import java.util.Random; import java.util.concurrent.atomic.AtomicInteger; public class BukkitChunkManager extends ChunkManager { @@ -359,6 +360,7 @@ public class BukkitChunkManager extends ChunkManager { } } } + final Random r = new Random(System.currentTimeMillis()); final AugmentedPopulator ap = augpop; TaskManager.runTask(new Runnable() { @Override @@ -380,7 +382,7 @@ public class BukkitChunkManager extends ChunkManager { CURRENT_PLOT_CLEAR = new RegionWrapper(pos1.getX(), pos2.getX(), pos1.getZ(), pos2.getZ()); if (xxb >= p1x && xxt <= p2x && zzb >= p1z && zzt <= p2z) { if (canRegen && ap != null) { - ap.populate(worldObj, null, chunkObj); + ap.populate(worldObj, r, chunkObj); } else { regenerateChunk(world, chunk); @@ -452,7 +454,7 @@ public class BukkitChunkManager extends ChunkManager { } saveEntitiesOut(chunkObj, CURRENT_PLOT_CLEAR); if (canRegen && ap != null) { - ap.populate(worldObj, null, chunkObj); + ap.populate(worldObj, r, chunkObj); } else { regenerateChunk(world, chunk); diff --git a/src/main/java/com/plotsquared/bukkit/util/bukkit/SetGenCB.java b/src/main/java/com/plotsquared/bukkit/util/bukkit/SetGenCB.java index 2c3d75253..77ff9d854 100644 --- a/src/main/java/com/plotsquared/bukkit/util/bukkit/SetGenCB.java +++ b/src/main/java/com/plotsquared/bukkit/util/bukkit/SetGenCB.java @@ -50,6 +50,6 @@ public class SetGenCB { } } } - PS.get().loadWorld(world.getName(), null); + PS.get().loadWorld(world.getName(), PS.get().IMP.getGenerator(world.getName(), null)); } }