Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default minecraft alias to redirect #12146

Merged
merged 2 commits into from
Feb 17, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
--- a/net/minecraft/commands/Commands.java
+++ b/net/minecraft/commands/Commands.java
@@ -251,6 +_,24 @@
@@ -150,6 +_,11 @@
private final CommandDispatcher<CommandSourceStack> dispatcher = new CommandDispatcher<>();

public Commands(Commands.CommandSelection selection, CommandBuildContext context) {
+ // Paper start - Brigadier API - modern minecraft overloads that do not use redirects but are copies instead
+ this(selection, context, false);
+ }
+ public Commands(Commands.CommandSelection selection, CommandBuildContext context, final boolean modern) {
+ // Paper end - Brigadier API - modern minecraft overloads that do not use redirects but are copies instead
AdvancementCommands.register(this.dispatcher);
AttributeCommand.register(this.dispatcher, context);
ExecuteCommand.register(this.dispatcher, context);
@@ -251,6 +_,40 @@
PublishCommand.register(this.dispatcher);
}

Expand All @@ -14,12 +26,28 @@
+ // Paper start - Brigadier Command API
+ // Create legacy minecraft namespace commands
+ for (final CommandNode<CommandSourceStack> node : new java.util.ArrayList<>(this.dispatcher.getRoot().getChildren())) {
+ this.dispatcher.getRoot().addChild(
+ io.papermc.paper.command.brigadier.PaperBrigadier.copyLiteral(
+ "minecraft:" + node.getName(),
+ (com.mojang.brigadier.tree.LiteralCommandNode<CommandSourceStack>) node
+ )
+ );
+ if (modern) {
+ // Modern behaviour that simply creates a full copy of the commands node.
+ // Avoids plenty of issues around registering redirects *to* these nodes from the API
+ this.dispatcher.getRoot().addChild(
+ io.papermc.paper.command.brigadier.PaperBrigadier.copyLiteral(
+ "minecraft:" + node.getName(),
+ (com.mojang.brigadier.tree.LiteralCommandNode<CommandSourceStack>) node
+ )
+ );
+ continue;
+ }
+
+ // Legacy behaviour of creating a flattened redirecting node.
+ // Used by CommandArgumentUpgrader
+ CommandNode<CommandSourceStack> flattenedAliasTarget = node;
+ while (flattenedAliasTarget.getRedirect() != null) flattenedAliasTarget = flattenedAliasTarget.getRedirect();
+
+ this.dispatcher.register(
+ com.mojang.brigadier.builder.LiteralArgumentBuilder.<CommandSourceStack>literal("minecraft:" + node.getName())
+ .executes(flattenedAliasTarget.getCommand())
+ .requires(flattenedAliasTarget.getRequirement())
+ .redirect(flattenedAliasTarget));
+ }
+ // Paper end - Brigadier Command API
this.dispatcher.setConsumer(ExecutionCommandSource.resultConsumer());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
--- a/net/minecraft/server/ReloadableServerResources.java
+++ b/net/minecraft/server/ReloadableServerResources.java
@@ -39,6 +_,7 @@
@@ -38,7 +_,8 @@
this.fullRegistryHolder = new ReloadableServerRegistries.Holder(registryAccess.compositeAccess());
this.postponedTags = postponedTags;
this.recipes = new RecipeManager(registries);
this.commands = new Commands(commandSelection, CommandBuildContext.simple(registries, enabledFeatures));
- this.commands = new Commands(commandSelection, CommandBuildContext.simple(registries, enabledFeatures));
+ this.commands = new Commands(commandSelection, CommandBuildContext.simple(registries, enabledFeatures), true); // Paper - Brigadier Command API - use modern alias registration
+ io.papermc.paper.command.brigadier.PaperCommands.INSTANCE.setDispatcher(this.commands, CommandBuildContext.simple(registries, enabledFeatures)); // Paper - Brigadier Command API
this.advancements = new ServerAdvancementManager(registries);
this.functionLibrary = new ServerFunctionLibrary(functionCompilationLevel, this.commands.getDispatcher());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void test() {
CraftDefaultPermissions.registerCorePermissions();
Set<String> perms = collectMinecraftCommandPerms();

Commands commands = new Commands(Commands.CommandSelection.DEDICATED, CommandBuildContext.simple(RegistryHelper.getRegistry(), FeatureFlags.VANILLA_SET));
Commands commands = new Commands(Commands.CommandSelection.DEDICATED, CommandBuildContext.simple(RegistryHelper.getRegistry(), FeatureFlags.VANILLA_SET), true);
RootCommandNode<CommandSourceStack> root = commands.getDispatcher().getRoot();
Set<String> missing = new LinkedHashSet<>();
Set<String> foundPerms = new HashSet<>();
Expand Down
Loading