From 48b169537af9a2a0d8878f7c6d3c1e6eab182bf2 Mon Sep 17 00:00:00 2001 From: Florian CUNY Date: Thu, 9 Aug 2018 17:09:38 +0200 Subject: [PATCH] Prepared automated showHelp if #execute() was returning false I added the code, however I commented it out: there are a few problems with this for now, because some commands are using "return false;" to fail silently. Also did javadoc'd #onlyPlayer(boolean) --- .../bentobox/api/commands/CompositeCommand.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/main/java/world/bentobox/bentobox/api/commands/CompositeCommand.java b/src/main/java/world/bentobox/bentobox/api/commands/CompositeCommand.java index c4ab0a876..00e5f8c4f 100644 --- a/src/main/java/world/bentobox/bentobox/api/commands/CompositeCommand.java +++ b/src/main/java/world/bentobox/bentobox/api/commands/CompositeCommand.java @@ -223,7 +223,13 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi return false; } // Execute and trim args - return cmd.execute(user, (cmd.subCommandLevel > 0) ? args[cmd.subCommandLevel-1] : label, Arrays.asList(args).subList(cmd.subCommandLevel, args.length)); + if (!cmd.execute(user, (cmd.subCommandLevel > 0) ? args[cmd.subCommandLevel-1] : label, Arrays.asList(args).subList(cmd.subCommandLevel, args.length))) { + // If it returned false, then show help for this command + // showHelp(cmd, user); + return false; // And return false (it basically does nothing, but let's be compliant with Bukkit's javadoc) + } else { + return true; + } } /** @@ -441,8 +447,12 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi } /** - * Set whether this command is only for players - * @param onlyPlayer - true if command only for players + * Sets whether this command should only be run by players. + * If this is set to {@code true}, this command will only be runnable by objects implementing {@link Player}. + *

+ * The default value provided when instantiating this CompositeCommand is {@code false}. + * Therefore, this method should only be used in case you want to explicitly edit the value. + * @param onlyPlayer {@code true} if this command should only be run by players. */ public void setOnlyPlayer(boolean onlyPlayer) { this.onlyPlayer = onlyPlayer;