Executes the command, returning its success @param sender Source object which is executing this command @param commandLabel The alias of the command used @param args All arguments passed to the command, split via ' ' @return true if the command was successful, otherwise false
(@NotNull CommandSender sender, @NotNull String commandLabel, @NotNull String[] args)
| 30 | * @return true if the command was successful, otherwise false |
| 31 | */ |
| 32 | @Override |
| 33 | public boolean execute(@NotNull CommandSender sender, @NotNull String commandLabel, @NotNull String[] args) { |
| 34 | boolean success = false; |
| 35 | |
| 36 | if (!owningPlugin.isEnabled()) { |
| 37 | throw new CommandException("Cannot execute command '" + commandLabel + "' in plugin " + owningPlugin.getDescription().getFullName() + " - plugin is disabled."); |
| 38 | } |
| 39 | |
| 40 | if (!testPermission(sender)) { |
| 41 | return true; |
| 42 | } |
| 43 | |
| 44 | try { |
| 45 | success = executor.onCommand(sender, this, commandLabel, args); |
| 46 | } catch (Throwable ex) { |
| 47 | throw new CommandException("Unhandled exception executing command '" + commandLabel + "' in plugin " + owningPlugin.getDescription().getFullName(), ex); |
| 48 | } |
| 49 | |
| 50 | if (!success && usageMessage.length() > 0) { |
| 51 | for (String line : usageMessage.replace("<command>", commandLabel).split("\n")) { |
| 52 | sender.sendMessage(line); |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | return success; |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Sets the {@link CommandExecutor} to run when parsing this command |
nothing calls this directly
no test coverage detected