From 54c3c8e203d99f5680f95183a1c6758c0863bb2b Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 26 Mar 2021 09:16:01 +0100 Subject: [PATCH] Add SWCommand.enabled for enabling and disabling commands --- .../src/de/steamwar/command/SWCommand.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/SpigotCore_Main/src/de/steamwar/command/SWCommand.java b/SpigotCore_Main/src/de/steamwar/command/SWCommand.java index d27e575..5623169 100644 --- a/SpigotCore_Main/src/de/steamwar/command/SWCommand.java +++ b/SpigotCore_Main/src/de/steamwar/command/SWCommand.java @@ -33,6 +33,7 @@ import static de.steamwar.command.SWCommandUtils.getAnnotation; public abstract class SWCommand { + private boolean enabled = true; private final Set commandSet = new HashSet<>(); private final Set commandHelpSet = new HashSet<>(); @@ -44,6 +45,7 @@ public abstract class SWCommand { SWCommandUtils.commandMap.register("steamwar", new Command(command, "", "/" + command, Arrays.asList(aliases)) { @Override public boolean execute(CommandSender sender, String alias, String[] args) { + if (!enabled) return false; for (SubCommand subCommand : commandSet) { if (subCommand.invoke(sender, args)) { return false; @@ -59,6 +61,7 @@ public abstract class SWCommand { @Override public List tabComplete(CommandSender sender, String alias, String[] args) throws IllegalArgumentException { + if (!enabled) return Collections.emptyList(); List strings = new ArrayList<>(); for (SubCommand subCommand : commandSet) { List tabCompletes = subCommand.tabComplete(sender, args); @@ -132,6 +135,14 @@ public abstract class SWCommand { consumer.accept(anno, parameters); } + protected boolean isEnabled() { + return enabled; + } + + protected void setEnabled(boolean enabled) { + this.enabled = enabled; + } + @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.METHOD}) protected @interface Register {