This commit is contained in:
Jesse Boyd 2016-03-27 03:34:55 +11:00
parent d4d9a9e148
commit 056f77a3ba
7 changed files with 39 additions and 29 deletions

View File

@ -13,7 +13,7 @@ import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(command = "help", @CommandDeclaration(command = "help",
description = "Get this help menu", description = "Get this help menu",
aliases = {"he", "h", "?"}, aliases = {"he", "?"},
category = CommandCategory.INFO, category = CommandCategory.INFO,
usage="help [category|#]", usage="help [category|#]",
permission="plots.use") permission="plots.use")
@ -23,7 +23,7 @@ public class Help extends Command {
} }
@Override @Override
public boolean canExecute(PlotPlayer player) { public boolean canExecute(PlotPlayer player, boolean message) {
return true; return true;
} }

View File

@ -240,7 +240,7 @@ public class MainCommand extends Command {
} }
@Override @Override
public boolean canExecute(PlotPlayer player) { public boolean canExecute(PlotPlayer player, boolean message) {
return true; return true;
} }
} }

View File

@ -92,7 +92,7 @@ public class Merge extends SubCommand {
} }
} }
final PlotArea plotworld = plot.getArea(); 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) { if (EconHandler.manager != null && plotworld.USE_ECONOMY && price > 0d && EconHandler.manager.getMoney(plr) < price) {
sendMessage(plr, C.CANNOT_AFFORD_MERGE, price + ""); sendMessage(plr, C.CANNOT_AFFORD_MERGE, price + "");
return false; return false;

View File

@ -62,7 +62,7 @@ public abstract class Command {
public List<Command> getCommands(PlotPlayer player) { public List<Command> getCommands(PlotPlayer player) {
List<Command> commands = new ArrayList<>(); List<Command> commands = new ArrayList<>();
for (Command cmd : allCommands) { for (Command cmd : allCommands) {
if (cmd.canExecute(player)) { if (cmd.canExecute(player, false)) {
commands.add(cmd); commands.add(cmd);
} }
} }
@ -322,7 +322,6 @@ public abstract class Command {
} }
return; return;
} }
if (!cmd.canExecute(player)) {
Argument<?>[] reqArgs = cmd.getRequiredArguments(); Argument<?>[] reqArgs = cmd.getRequiredArguments();
if ((reqArgs != null) && (reqArgs.length > 0)) { if ((reqArgs != null) && (reqArgs.length > 0)) {
boolean failed = args.length > reqArgs.length; boolean failed = args.length > reqArgs.length;
@ -338,7 +337,7 @@ public abstract class Command {
return; return;
} }
} }
C.NO_PERMISSION.send(player, cmd.getPermission()); if (!cmd.canExecute(player, true)) {
return; return;
} }
cmd.execute(player, Arrays.copyOfRange(args, 1, args.length), confirm, whenDone); cmd.execute(player, Arrays.copyOfRange(args, 1, args.length), confirm, whenDone);
@ -395,8 +394,19 @@ public abstract class Command {
return cmd; return cmd;
} }
public boolean canExecute(PlotPlayer player) { public boolean canExecute(PlotPlayer player, boolean message) {
return required.allows(player) && Permissions.hasPermission(player, getPermission()); 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) { public boolean matches(String arg) {
@ -440,11 +450,11 @@ public abstract class Command {
String arg = args[0].toLowerCase(); String arg = args[0].toLowerCase();
if (space) { if (space) {
Command cmd = getCommand(arg); 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 { } else {
Set<Command> commands = new HashSet<Command>(); Set<Command> commands = new HashSet<Command>();
for (Map.Entry<String, Command> entry : staticCommands.entrySet()) { for (Map.Entry<String, Command> 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()); commands.add(entry.getValue());
} }
} }

View File

@ -55,8 +55,8 @@ public class SpongeCommand implements CommandCallable {
final Set<String> tabOptions = new HashSet<>(); final Set<String> tabOptions = new HashSet<>();
final String arg = split[0].toLowerCase(); final String arg = split[0].toLowerCase();
ArrayList<String> labels = new ArrayList<>(); ArrayList<String> labels = new ArrayList<>();
for (final Command<PlotPlayer> cmd : MainCommand.getInstance().getCommands()) { for (final Command cmd : MainCommand.getInstance().getCommands()) {
final String label = cmd.getCommand(); final String label = cmd.toS();
HashSet<String> aliases = new HashSet<>(cmd.getAliases()); HashSet<String> aliases = new HashSet<>(cmd.getAliases());
aliases.add(label); aliases.add(label);
for (String alias : aliases) { for (String alias : aliases) {

View File

@ -10,7 +10,7 @@ buildscript {
} }
group = 'com.intellectualcrafters' group = 'com.intellectualcrafters'
version = '3.3.1' version = '3.3.2'
description = """PlotSquared""" description = """PlotSquared"""
subprojects { subprojects {

View File

@ -6,7 +6,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>3.3.1</version> <version>3.3.2</version>
<name>PlotSquared</name> <name>PlotSquared</name>
<packaging>jar</packaging> <packaging>jar</packaging>
<build> <build>