🐛 Fix Commodore registration on Bukkit
This commit is contained in:
parent
ce8060d276
commit
01d36aecd8
3 changed files with 27 additions and 20 deletions
|
|
@ -318,6 +318,7 @@ public class BukkitCommandManager<C> extends CommandManager<C> implements Brigad
|
||||||
final CloudCommodoreManager<C> cloudCommodoreManager = new CloudCommodoreManager<>(this);
|
final CloudCommodoreManager<C> cloudCommodoreManager = new CloudCommodoreManager<>(this);
|
||||||
cloudCommodoreManager.initialize(this);
|
cloudCommodoreManager.initialize(this);
|
||||||
this.setCommandRegistrationHandler(cloudCommodoreManager);
|
this.setCommandRegistrationHandler(cloudCommodoreManager);
|
||||||
|
this.setSplitAliases(true);
|
||||||
} catch (final Throwable e) {
|
} catch (final Throwable e) {
|
||||||
throw new BrigadierFailureException(BrigadierFailureReason.COMMODORE_NOT_PRESENT, e);
|
throw new BrigadierFailureException(BrigadierFailureReason.COMMODORE_NOT_PRESENT, e);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,7 @@ import cloud.commandframework.arguments.StaticArgument;
|
||||||
import cloud.commandframework.internal.CommandRegistrationHandler;
|
import cloud.commandframework.internal.CommandRegistrationHandler;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.CommandMap;
|
import org.bukkit.command.CommandMap;
|
||||||
|
import org.bukkit.command.PluginIdentifiableCommand;
|
||||||
import org.bukkit.command.SimpleCommandMap;
|
import org.bukkit.command.SimpleCommandMap;
|
||||||
import org.bukkit.help.GenericCommandHelpTopic;
|
import org.bukkit.help.GenericCommandHelpTopic;
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
@ -38,6 +39,7 @@ import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
@ -95,30 +97,20 @@ public class BukkitPluginRegistrationHandler<C> implements CommandRegistrationHa
|
||||||
aliases.forEach(alias -> this.bukkitCommands.remove(alias));
|
aliases.forEach(alias -> this.bukkitCommands.remove(alias));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final Set<String> newAliases = new HashSet<>();
|
||||||
|
|
||||||
for (final String alias : aliases) {
|
for (final String alias : aliases) {
|
||||||
final String namespacedAlias = this.getNamespacedLabel(alias);
|
final String namespacedAlias = this.getNamespacedLabel(alias);
|
||||||
|
newAliases.add(namespacedAlias);
|
||||||
this.recognizedAliases.add(namespacedAlias);
|
|
||||||
if (!this.bukkitCommandOrAliasExists(alias)) {
|
if (!this.bukkitCommandOrAliasExists(alias)) {
|
||||||
this.recognizedAliases.add(alias);
|
newAliases.add(alias);
|
||||||
}
|
|
||||||
|
|
||||||
if (this.bukkitCommandManager.getSplitAliases()) {
|
|
||||||
if (this.bukkitCommandOrAliasExists(alias)) {
|
|
||||||
this.registerExternal(namespacedAlias, command, bukkitCommand);
|
|
||||||
} else {
|
|
||||||
this.registerExternal(namespacedAlias, command, bukkitCommand);
|
|
||||||
this.registerExternal(alias, command, bukkitCommand);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.bukkitCommandExists(label)) {
|
if (!this.bukkitCommandExists(label)) {
|
||||||
this.recognizedAliases.add(label);
|
newAliases.add(label);
|
||||||
this.registerExternal(label, command, bukkitCommand);
|
|
||||||
}
|
}
|
||||||
this.recognizedAliases.add(this.getNamespacedLabel(label));
|
newAliases.add(namespacedLabel);
|
||||||
this.registerExternal(namespacedLabel, command, bukkitCommand);
|
|
||||||
|
|
||||||
this.commandMap.register(
|
this.commandMap.register(
|
||||||
label,
|
label,
|
||||||
|
|
@ -126,6 +118,11 @@ public class BukkitPluginRegistrationHandler<C> implements CommandRegistrationHa
|
||||||
bukkitCommand
|
bukkitCommand
|
||||||
);
|
);
|
||||||
|
|
||||||
|
this.recognizedAliases.addAll(newAliases);
|
||||||
|
if (this.bukkitCommandManager.getSplitAliases()) {
|
||||||
|
newAliases.forEach(alias -> this.registerExternal(alias, command, bukkitCommand));
|
||||||
|
}
|
||||||
|
|
||||||
this.registeredCommands.put(commandArgument, bukkitCommand);
|
this.registeredCommands.put(commandArgument, bukkitCommand);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -152,7 +149,7 @@ public class BukkitPluginRegistrationHandler<C> implements CommandRegistrationHa
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if a command exists in the Bukkit command map, and is not an alias.
|
* Returns true if a command exists in the Bukkit command map, is not an alias, and is not owned by us.
|
||||||
*
|
*
|
||||||
* @param commandLabel label to check
|
* @param commandLabel label to check
|
||||||
* @return whether the command exists and is not an alias
|
* @return whether the command exists and is not an alias
|
||||||
|
|
@ -162,17 +159,27 @@ public class BukkitPluginRegistrationHandler<C> implements CommandRegistrationHa
|
||||||
if (existingCommand == null) {
|
if (existingCommand == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (existingCommand instanceof PluginIdentifiableCommand) {
|
||||||
|
return existingCommand.getLabel().equals(commandLabel)
|
||||||
|
&& !((PluginIdentifiableCommand) existingCommand).getPlugin().getName()
|
||||||
|
.equalsIgnoreCase(this.bukkitCommandManager.getOwningPlugin().getName());
|
||||||
|
}
|
||||||
return existingCommand.getLabel().equals(commandLabel);
|
return existingCommand.getLabel().equals(commandLabel);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if a command exists in the Bukkit command map, whether or not it is an alias.
|
* Returns true if a command exists in the Bukkit command map, and it is not owned by us, whether or not it is an alias.
|
||||||
*
|
*
|
||||||
* @param commandLabel label to check
|
* @param commandLabel label to check
|
||||||
* @return whether the command exists
|
* @return whether the command exists
|
||||||
*/
|
*/
|
||||||
private boolean bukkitCommandOrAliasExists(final String commandLabel) {
|
private boolean bukkitCommandOrAliasExists(final String commandLabel) {
|
||||||
return this.bukkitCommands.containsKey(commandLabel);
|
final org.bukkit.command.Command command = this.bukkitCommands.get(commandLabel);
|
||||||
|
if (command instanceof PluginIdentifiableCommand) {
|
||||||
|
return !((PluginIdentifiableCommand) command).getPlugin().getName()
|
||||||
|
.equalsIgnoreCase(this.bukkitCommandManager.getOwningPlugin().getName());
|
||||||
|
}
|
||||||
|
return command != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -106,7 +106,6 @@ public class PaperCommandManager<C> extends BukkitCommandManager<C> {
|
||||||
this.paperBrigadierListener,
|
this.paperBrigadierListener,
|
||||||
this.getOwningPlugin()
|
this.getOwningPlugin()
|
||||||
);
|
);
|
||||||
this.setSplitAliases(true);
|
|
||||||
} catch (final Throwable e) {
|
} catch (final Throwable e) {
|
||||||
throw new BrigadierFailureException(BrigadierFailureReason.PAPER_BRIGADIER_INITIALIZATION_FAILURE, e);
|
throw new BrigadierFailureException(BrigadierFailureReason.PAPER_BRIGADIER_INITIALIZATION_FAILURE, e);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue