✨ fix-commodore (#27)
This commit is contained in:
parent
8f8f98b189
commit
c3469706ab
14 changed files with 435 additions and 11 deletions
|
|
@ -72,14 +72,16 @@ public class BukkitPluginRegistrationHandler<C> implements CommandRegistrationHa
|
|||
public final boolean registerCommand(final @NonNull Command<?> command) {
|
||||
/* We only care about the root command argument */
|
||||
final CommandArgument<?, ?> commandArgument = command.getArguments().get(0);
|
||||
if (this.registeredCommands.containsKey(commandArgument)) {
|
||||
if (!(this.bukkitCommandManager.getCommandRegistrationHandler() instanceof CloudCommodoreManager)
|
||||
&& this.registeredCommands.containsKey(commandArgument)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final String label;
|
||||
final String prefixedLabel = String.format("%s:%s", this.bukkitCommandManager.getOwningPlugin().getName(),
|
||||
commandArgument.getName()).toLowerCase();
|
||||
if (bukkitCommands.containsKey(commandArgument.getName())) {
|
||||
if (!(this.bukkitCommandManager.getCommandRegistrationHandler() instanceof CloudCommodoreManager)
|
||||
&& bukkitCommands.containsKey(commandArgument.getName())) {
|
||||
label = prefixedLabel;
|
||||
} else {
|
||||
label = commandArgument.getName();
|
||||
|
|
|
|||
|
|
@ -26,11 +26,17 @@ package cloud.commandframework.bukkit;
|
|||
import cloud.commandframework.Command;
|
||||
import cloud.commandframework.brigadier.CloudBrigadierManager;
|
||||
import cloud.commandframework.context.CommandContext;
|
||||
import cloud.commandframework.permission.CommandPermission;
|
||||
import com.mojang.brigadier.tree.CommandNode;
|
||||
import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||
import me.lucko.commodore.Commodore;
|
||||
import me.lucko.commodore.CommodoreProvider;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
@SuppressWarnings("ALL")
|
||||
class CloudCommodoreManager<C> extends BukkitPluginRegistrationHandler<C> {
|
||||
|
|
@ -57,9 +63,28 @@ class CloudCommodoreManager<C> extends BukkitPluginRegistrationHandler<C> {
|
|||
final @NonNull BukkitCommand<C> bukkitCommand) {
|
||||
final com.mojang.brigadier.Command<?> cmd = o -> 1;
|
||||
final LiteralCommandNode<?> literalCommandNode = this.brigadierManager
|
||||
.createLiteralCommandNode(label, command, (o, p) -> true, cmd);
|
||||
this.commodore.register(bukkitCommand, literalCommandNode, p ->
|
||||
this.commandManager.hasPermission(commandManager.getCommandSenderMapper().apply(p),
|
||||
command.getCommandPermission()));
|
||||
.<Object>createLiteralCommandNode(label, command, (o, p) -> {
|
||||
final CommandSender sender = this.commodore.getBukkitSender(o);
|
||||
return this.commandManager.hasPermission(this.commandManager.getCommandSenderMapper().apply(sender),
|
||||
(CommandPermission) p);
|
||||
}, false, cmd);
|
||||
final CommandNode existingNode = this.commodore.getDispatcher().findNode(Collections.singletonList(label));
|
||||
if (existingNode != null) {
|
||||
this.mergeChildren(existingNode, literalCommandNode);
|
||||
} else {
|
||||
this.commodore.register(literalCommandNode);
|
||||
}
|
||||
}
|
||||
|
||||
private void mergeChildren(@Nullable final CommandNode<?> existingNode, @Nullable final CommandNode<?> node) {
|
||||
for (final CommandNode child : node.getChildren()) {
|
||||
final CommandNode<?> existingChild = existingNode.getChild(child.getName());
|
||||
if (existingChild == null) {
|
||||
existingNode.addChild(child);
|
||||
} else {
|
||||
this.mergeChildren(existingChild, child);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -66,4 +66,14 @@ public abstract class EntitySelector {
|
|||
public @NonNull String getSelector() {
|
||||
return this.selector;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether the selector selected at least one entity
|
||||
*
|
||||
* @return {@code true} if at least one entity was selected, else {@code false}
|
||||
*/
|
||||
public boolean hasAny() {
|
||||
return !this.entities.isEmpty();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue