Improved commands

This commit is contained in:
Auxilor
2022-10-30 15:21:21 +00:00
parent 8c1fde57b0
commit 86b427c95e
5 changed files with 14 additions and 19 deletions

View File

@@ -41,8 +41,6 @@ public abstract class PluginCommand extends HandledCommand implements CommandExe
/**
* Registers the command with the server,
* <p>
* Requires the command name to exist, defined in plugin.yml.
*/
public final void register() {
org.bukkit.command.PluginCommand command = Bukkit.getPluginCommand(this.getName());
@@ -50,12 +48,9 @@ public abstract class PluginCommand extends HandledCommand implements CommandExe
command.setExecutor(this);
command.setTabCompleter(this);
} else {
CommandMap commandMap = getCommandMap();
this.unregister();
Command bukkit = commandMap.getCommand(this.getName());
if (bukkit != null) {
bukkit.unregister(commandMap);
}
CommandMap commandMap = getCommandMap();
commandMap.register(this.getName(), new DelegatedBukkitCommand(this));
@@ -63,6 +58,18 @@ public abstract class PluginCommand extends HandledCommand implements CommandExe
}
}
/**
* Unregisters the command from the server.
*/
public final void unregister() {
CommandMap commandMap = getCommandMap();
Command found = commandMap.getCommand(this.getName());
if (found != null) {
found.unregister(commandMap);
}
}
/**
* Internal implementation used to clean up boilerplate.
* Used for parity with {@link CommandExecutor#onCommand(CommandSender, Command, String, String[])}.