✨ Improve Bukkit command registration logic
When a new command is registered, if a command with that name already exists, Bukkit will not register the new command, ie the existing command gets priority. However, if the already existing command is an alias, it will replaced by the new command. These changes update cloud to be aware whether or not an existing command is an alias, and that if so, that Bukkit will allow us to have priority for this command.
This commit is contained in:
parent
070a719165
commit
77225274ce
1 changed files with 27 additions and 3 deletions
|
|
@ -99,12 +99,12 @@ public class BukkitPluginRegistrationHandler<C> implements CommandRegistrationHa
|
|||
final String namespacedAlias = this.getNamespacedLabel(alias);
|
||||
|
||||
this.recognizedAliases.add(namespacedAlias);
|
||||
if (!this.bukkitCommands.containsKey(alias)) {
|
||||
if (!this.bukkitCommandOrAliasExists(alias)) {
|
||||
this.recognizedAliases.add(alias);
|
||||
}
|
||||
|
||||
if (this.bukkitCommandManager.getSplitAliases()) {
|
||||
if (this.bukkitCommands.containsKey(alias)) {
|
||||
if (this.bukkitCommandOrAliasExists(alias)) {
|
||||
this.registerExternal(namespacedAlias, command, bukkitCommand);
|
||||
} else {
|
||||
this.registerExternal(namespacedAlias, command, bukkitCommand);
|
||||
|
|
@ -113,7 +113,7 @@ public class BukkitPluginRegistrationHandler<C> implements CommandRegistrationHa
|
|||
}
|
||||
}
|
||||
|
||||
if (!this.bukkitCommands.containsKey(label)) {
|
||||
if (!this.bukkitCommandExists(label)) {
|
||||
this.recognizedAliases.add(label);
|
||||
this.registerExternal(label, command, bukkitCommand);
|
||||
}
|
||||
|
|
@ -151,4 +151,28 @@ public class BukkitPluginRegistrationHandler<C> implements CommandRegistrationHa
|
|||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if a command exists in the Bukkit command map, and is not an alias.
|
||||
*
|
||||
* @param commandLabel label to check
|
||||
* @return whether the command exists and is not an alias
|
||||
*/
|
||||
private boolean bukkitCommandExists(final String commandLabel) {
|
||||
final org.bukkit.command.Command existingCommand = this.bukkitCommands.get(commandLabel);
|
||||
if (existingCommand == null) {
|
||||
return false;
|
||||
}
|
||||
return existingCommand.getLabel().equals(commandLabel);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if a command exists in the Bukkit command map, whether or not it is an alias.
|
||||
*
|
||||
* @param commandLabel label to check
|
||||
* @return whether the command exists
|
||||
*/
|
||||
private boolean bukkitCommandOrAliasExists(final String commandLabel) {
|
||||
return this.bukkitCommands.containsKey(commandLabel);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue