From 056f77a3baa24cbf57d1c2482c3b2d6c5014ca4d Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Sun, 27 Mar 2016 03:34:55 +1100 Subject: [PATCH] 3.3.2 --- .../plot/commands/Help.java | 4 +- .../plot/commands/MainCommand.java | 2 +- .../plot/commands/Merge.java | 2 +- .../plotsquared/general/commands/Command.java | 52 +++++++++++-------- .../sponge/util/SpongeCommand.java | 4 +- build.gradle | 2 +- pom.xml | 2 +- 7 files changed, 39 insertions(+), 29 deletions(-) diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/Help.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/Help.java index 16b1c2fa7..f8b3e24a1 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/Help.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/Help.java @@ -13,7 +13,7 @@ import com.plotsquared.general.commands.CommandDeclaration; @CommandDeclaration(command = "help", description = "Get this help menu", - aliases = {"he", "h", "?"}, + aliases = {"he", "?"}, category = CommandCategory.INFO, usage="help [category|#]", permission="plots.use") @@ -23,7 +23,7 @@ public class Help extends Command { } @Override - public boolean canExecute(PlotPlayer player) { + public boolean canExecute(PlotPlayer player, boolean message) { return true; } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java index 94aa6d307..f4f423000 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java @@ -240,7 +240,7 @@ public class MainCommand extends Command { } @Override - public boolean canExecute(PlotPlayer player) { + public boolean canExecute(PlotPlayer player, boolean message) { return true; } } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/Merge.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/Merge.java index 0eb69791c..7a3dd3ef0 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/Merge.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/Merge.java @@ -92,7 +92,7 @@ public class Merge extends SubCommand { } } final PlotArea plotworld = plot.getArea(); - final double price = plotworld.PRICES.get("merge"); + final double price = plotworld.PRICES.containsKey("merge") ? plotworld.PRICES.get("merge") : 0; if (EconHandler.manager != null && plotworld.USE_ECONOMY && price > 0d && EconHandler.manager.getMoney(plr) < price) { sendMessage(plr, C.CANNOT_AFFORD_MERGE, price + ""); return false; diff --git a/Core/src/main/java/com/plotsquared/general/commands/Command.java b/Core/src/main/java/com/plotsquared/general/commands/Command.java index e64367a35..a17f1d04b 100644 --- a/Core/src/main/java/com/plotsquared/general/commands/Command.java +++ b/Core/src/main/java/com/plotsquared/general/commands/Command.java @@ -62,7 +62,7 @@ public abstract class Command { public List getCommands(PlotPlayer player) { List commands = new ArrayList<>(); for (Command cmd : allCommands) { - if (cmd.canExecute(player)) { + if (cmd.canExecute(player, false)) { commands.add(cmd); } } @@ -322,23 +322,22 @@ public abstract class Command { } return; } - if (!cmd.canExecute(player)) { - Argument[] reqArgs = cmd.getRequiredArguments(); - if ((reqArgs != null) && (reqArgs.length > 0)) { - boolean failed = args.length > reqArgs.length; - String[] baseSplit = getCommandString().split(" "); - String[] fullSplit = getUsage().split(" "); - String base = getCommandString(); - for (int i = 0; i < reqArgs.length; i++) { - fullSplit[i + baseSplit.length] = reqArgs[i].getExample().toString(); - failed = failed || reqArgs[i].parse(args[i]) == null; - } - if (failed) { - C.COMMAND_SYNTAX.send(player, StringMan.join(fullSplit, " ")); - return; - } + Argument[] reqArgs = cmd.getRequiredArguments(); + if ((reqArgs != null) && (reqArgs.length > 0)) { + boolean failed = args.length > reqArgs.length; + String[] baseSplit = getCommandString().split(" "); + String[] fullSplit = getUsage().split(" "); + String base = getCommandString(); + for (int i = 0; i < reqArgs.length; i++) { + fullSplit[i + baseSplit.length] = reqArgs[i].getExample().toString(); + failed = failed || reqArgs[i].parse(args[i]) == null; } - C.NO_PERMISSION.send(player, cmd.getPermission()); + if (failed) { + C.COMMAND_SYNTAX.send(player, StringMan.join(fullSplit, " ")); + return; + } + } + if (!cmd.canExecute(player, true)) { return; } cmd.execute(player, Arrays.copyOfRange(args, 1, args.length), confirm, whenDone); @@ -395,8 +394,19 @@ public abstract class Command { return cmd; } - public boolean canExecute(PlotPlayer player) { - return required.allows(player) && Permissions.hasPermission(player, getPermission()); + public boolean canExecute(PlotPlayer player, boolean message) { + if (!required.allows(player)) { + if (message) { + MainUtil.sendMessage(player, required == RequiredType.PLAYER ? C.IS_CONSOLE : C.NOT_CONSOLE); + } + } else if (!Permissions.hasPermission(player, getPermission())) { + if (message) { + C.NO_PERMISSION.send(player, getPermission()); + } + } else { + return true; + } + return false; } public boolean matches(String arg) { @@ -440,11 +450,11 @@ public abstract class Command { String arg = args[0].toLowerCase(); if (space) { Command cmd = getCommand(arg); - return (cmd != null && cmd.canExecute(player)) ? (cmd.tab(player, Arrays.copyOfRange(args, 1, args.length), space)) : null; + return (cmd != null && cmd.canExecute(player, false)) ? (cmd.tab(player, Arrays.copyOfRange(args, 1, args.length), space)) : null; } else { Set commands = new HashSet(); for (Map.Entry entry : staticCommands.entrySet()) { - if (entry.getKey().startsWith(arg) && entry.getValue().canExecute(player)) { + if (entry.getKey().startsWith(arg) && entry.getValue().canExecute(player, false)) { commands.add(entry.getValue()); } } diff --git a/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeCommand.java b/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeCommand.java index 3f7059197..d3f877f3c 100644 --- a/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeCommand.java +++ b/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeCommand.java @@ -55,8 +55,8 @@ public class SpongeCommand implements CommandCallable { final Set tabOptions = new HashSet<>(); final String arg = split[0].toLowerCase(); ArrayList labels = new ArrayList<>(); - for (final Command cmd : MainCommand.getInstance().getCommands()) { - final String label = cmd.getCommand(); + for (final Command cmd : MainCommand.getInstance().getCommands()) { + final String label = cmd.toS(); HashSet aliases = new HashSet<>(cmd.getAliases()); aliases.add(label); for (String alias : aliases) { diff --git a/build.gradle b/build.gradle index abe188e6e..dc4af778e 100644 --- a/build.gradle +++ b/build.gradle @@ -10,7 +10,7 @@ buildscript { } group = 'com.intellectualcrafters' -version = '3.3.1' +version = '3.3.2' description = """PlotSquared""" subprojects { diff --git a/pom.xml b/pom.xml index 81f3500cc..4984e93ab 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ UTF-8 PlotSquared - 3.3.1 + 3.3.2 PlotSquared jar