Improved commands
This commit is contained in:
@@ -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[])}.
|
||||
|
||||
Reference in New Issue
Block a user