Skip to content

Commit

Permalink
✨ Command unregister feature.
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcusSlover committed Aug 1, 2024
1 parent bc35f66 commit 8ffe17f
Showing 1 changed file with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,28 @@ public boolean execute(@NotNull CommandSender sender, @NotNull String commandLab
return this;
}

/**
* Unregister a command.
* @param command the command
*/
public void unregister(@NotNull ICommand command) {
Command commandAnnotation = this.getCommandAnnotation(command);
if (commandAnnotation == null) {
return;
}
String name = commandAnnotation.name();
CommandMap commandMap = Bukkit.getCommandMap();
List<String> keys = new ArrayList<>();
commandMap.getKnownCommands().forEach((key, value) -> {
if (value.getName().equals(name)) {
keys.add(key);
}
});
for (String key : keys) {
commandMap.getKnownCommands().remove(key);
}
}

@NotNull
public Set<org.bukkit.command.Command> getCommands() {
return this.commandSet;
Expand Down

0 comments on commit 8ffe17f

Please sign in to comment.