Skip to content

Commit

Permalink
Provide compatibilty with #417
Browse files Browse the repository at this point in the history
  • Loading branch information
DerEchtePilz committed Dec 13, 2023
1 parent e4a159f commit 142b598
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,7 @@ void register(CommandMetaData<CommandSender> meta, final Argument[] args,
// partial) command registration. Generate the dispatcher file!
writeDispatcherToFile();

platform.postCommandRegistration(registeredCommandInformation, resultantNode, aliasNodes);
platform.postCommandRegistration(registeredCommandInformation, resultantNode, aliasNodes, namespace);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,9 @@ public interface CommandAPIPlatform<Argument
* @param registeredCommand A {@link RegisteredCommand} instance that holds the CommandAPI information for the command
* @param resultantNode The node that was registered
* @param aliasNodes Any alias nodes that were also registered as a part of this registration process
* @param namespace The command namespace
*/
public abstract void postCommandRegistration(RegisteredCommand registeredCommand, LiteralCommandNode<Source> resultantNode, List<LiteralCommandNode<Source>> aliasNodes);
public abstract void postCommandRegistration(RegisteredCommand registeredCommand, LiteralCommandNode<Source> resultantNode, List<LiteralCommandNode<Source>> aliasNodes, String namespace);

/**
* Registers a Brigadier command node and returns the built node.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ public void preCommandRegistration(String commandName) {
}

@Override
public void postCommandRegistration(RegisteredCommand registeredCommand, LiteralCommandNode<Source> resultantNode, List<LiteralCommandNode<Source>> aliasNodes) {
public void postCommandRegistration(RegisteredCommand registeredCommand, LiteralCommandNode<Source> resultantNode, List<LiteralCommandNode<Source>> aliasNodes, String namespace) {
if(!CommandAPI.canRegister()) {
// Usually, when registering commands during server startup, we can just put our commands into the
// `net.minecraft.server.MinecraftServer#vanillaCommandDispatcher` and leave it. As the server finishes setup,
Expand All @@ -500,24 +500,24 @@ public void postCommandRegistration(RegisteredCommand registeredCommand, Literal
// Wrapping Brigadier nodes into VanillaCommandWrappers and putting them in the CommandMap usually happens
// in `CraftServer#setVanillaCommands`
Command command = wrapToVanillaCommandWrapper(resultantNode);
map.register("minecraft", command);
map.register(namespace, command);

// Adding permissions to these Commands usually happens in `CommandAPIBukkit#onEnable`
command.setPermission(permNode);

// Adding commands to the other (Why bukkit/spigot?!) dispatcher usually happens in `CraftServer#syncCommands`
root.addChild(resultantNode);
root.addChild(namespaceNode(resultantNode));
root.addChild(namespaceNode(resultantNode, namespace));

// Do the same for the aliases
for(LiteralCommandNode<Source> node: aliasNodes) {
command = wrapToVanillaCommandWrapper(node);
map.register("minecraft", command);
map.register(namespace, command);

command.setPermission(permNode);

root.addChild(node);
root.addChild(namespaceNode(node));
root.addChild(namespaceNode(node, namespace));
}

// Adding the command to the help map usually happens in `CommandAPIBukkit#onEnable`
Expand All @@ -530,10 +530,10 @@ public void postCommandRegistration(RegisteredCommand registeredCommand, Literal
}
}

private LiteralCommandNode<Source> namespaceNode(LiteralCommandNode<Source> original) {
private LiteralCommandNode<Source> namespaceNode(LiteralCommandNode<Source> original, String namespace) {
// Adapted from a section of `CraftServer#syncCommands`
LiteralCommandNode<Source> clone = new LiteralCommandNode<>(
"minecraft:" + original.getLiteral(),
namespace + ":" + original.getLiteral(),
original.getCommand(),
original.getRequirement(),
original.getRedirect(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public void preCommandRegistration(String commandName) {
}

@Override
public void postCommandRegistration(RegisteredCommand registeredCommand, LiteralCommandNode<Object> resultantNode, List<LiteralCommandNode<Object>> aliasNodes) {
public void postCommandRegistration(RegisteredCommand registeredCommand, LiteralCommandNode<Object> resultantNode, List<LiteralCommandNode<Object>> aliasNodes, String namespace) {
// Nothing to do?
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public void preCommandRegistration(String commandName) {
}

@Override
public void postCommandRegistration(RegisteredCommand registeredCommand, LiteralCommandNode<CommandSource> resultantNode, List<LiteralCommandNode<CommandSource>> aliasNodes) {
public void postCommandRegistration(RegisteredCommand registeredCommand, LiteralCommandNode<CommandSource> resultantNode, List<LiteralCommandNode<CommandSource>> aliasNodes, String namespace) {
// Nothing to do
}

Expand Down

0 comments on commit 142b598

Please sign in to comment.