SteamWar/SpigotCore
Archiviert
13
0

Add SWCommand.enabled for enabling and disabling commands

Dieser Commit ist enthalten in:
yoyosource 2021-03-26 09:16:01 +01:00
Ursprung d0186a43d1
Commit 54c3c8e203

Datei anzeigen

@ -33,6 +33,7 @@ import static de.steamwar.command.SWCommandUtils.getAnnotation;
public abstract class SWCommand { public abstract class SWCommand {
private boolean enabled = true;
private final Set<SubCommand> commandSet = new HashSet<>(); private final Set<SubCommand> commandSet = new HashSet<>();
private final Set<SubCommand> commandHelpSet = new HashSet<>(); private final Set<SubCommand> commandHelpSet = new HashSet<>();
@ -44,6 +45,7 @@ public abstract class SWCommand {
SWCommandUtils.commandMap.register("steamwar", new Command(command, "", "/" + command, Arrays.asList(aliases)) { SWCommandUtils.commandMap.register("steamwar", new Command(command, "", "/" + command, Arrays.asList(aliases)) {
@Override @Override
public boolean execute(CommandSender sender, String alias, String[] args) { public boolean execute(CommandSender sender, String alias, String[] args) {
if (!enabled) return false;
for (SubCommand subCommand : commandSet) { for (SubCommand subCommand : commandSet) {
if (subCommand.invoke(sender, args)) { if (subCommand.invoke(sender, args)) {
return false; return false;
@ -59,6 +61,7 @@ public abstract class SWCommand {
@Override @Override
public List<String> tabComplete(CommandSender sender, String alias, String[] args) throws IllegalArgumentException { public List<String> tabComplete(CommandSender sender, String alias, String[] args) throws IllegalArgumentException {
if (!enabled) return Collections.emptyList();
List<String> strings = new ArrayList<>(); List<String> strings = new ArrayList<>();
for (SubCommand subCommand : commandSet) { for (SubCommand subCommand : commandSet) {
List<String> tabCompletes = subCommand.tabComplete(sender, args); List<String> tabCompletes = subCommand.tabComplete(sender, args);
@ -132,6 +135,14 @@ public abstract class SWCommand {
consumer.accept(anno, parameters); consumer.accept(anno, parameters);
} }
protected boolean isEnabled() {
return enabled;
}
protected void setEnabled(boolean enabled) {
this.enabled = enabled;
}
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD}) @Target({ElementType.METHOD})
protected @interface Register { protected @interface Register {