Skip to content

Commit

Permalink
Allow bukkit commands in /execute command
Browse files Browse the repository at this point in the history
  • Loading branch information
Machine-Maker committed Aug 26, 2021
1 parent 08f746f commit 3cb536c
Showing 1 changed file with 136 additions and 0 deletions.
136 changes: 136 additions & 0 deletions patches/server/0764-Allow-bukkit-commands-in-execute-command.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Jake Potrebic <[email protected]>
Date: Thu, 26 Aug 2021 16:36:11 -0700
Subject: [PATCH] Allow bukkit commands in /execute command


diff --git a/src/main/java/io/papermc/paper/commands/DelegatingRootCommandNode.java b/src/main/java/io/papermc/paper/commands/DelegatingRootCommandNode.java
new file mode 100644
index 0000000000000000000000000000000000000000..ccf7f4b76764801d99d32e3d950f038cac309b02
--- /dev/null
+++ b/src/main/java/io/papermc/paper/commands/DelegatingRootCommandNode.java
@@ -0,0 +1,99 @@
+package io.papermc.paper.commands;
+
+import com.mojang.brigadier.AmbiguityConsumer;
+import com.mojang.brigadier.Command;
+import com.mojang.brigadier.RedirectModifier;
+import com.mojang.brigadier.StringReader;
+import com.mojang.brigadier.tree.CommandNode;
+import com.mojang.brigadier.tree.RootCommandNode;
+import net.minecraft.server.MinecraftServer;
+
+import java.util.Collection;
+import java.util.function.Predicate;
+import java.util.function.Supplier;
+
+public class DelegatingRootCommandNode<S> extends RootCommandNode<S> {
+
+ public static final DelegatingRootCommandNode<net.minecraft.commands.CommandSourceStack> INSTANCE = new DelegatingRootCommandNode<>(() -> MinecraftServer.getServer().resources.commands.getDispatcher().getRoot());
+
+ private Supplier<RootCommandNode<S>> commandNodeSupplier;
+
+ private DelegatingRootCommandNode(Supplier<RootCommandNode<S>> supplier) {
+ this.commandNodeSupplier = supplier;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ return commandNodeSupplier.get().equals(o);
+ }
+
+ @Override
+ public void removeCommand(String name) {
+ commandNodeSupplier.get().removeCommand(name);
+ }
+
+ @Override
+ public Command<S> getCommand() {
+ return commandNodeSupplier.get().getCommand();
+ }
+
+ @Override
+ public Collection<CommandNode<S>> getChildren() {
+ return commandNodeSupplier.get().getChildren();
+ }
+
+ @Override
+ public CommandNode<S> getChild(String name) {
+ return commandNodeSupplier.get().getChild(name);
+ }
+
+ @Override
+ public CommandNode<S> getRedirect() {
+ return commandNodeSupplier.get().getRedirect();
+ }
+
+ @Override
+ public RedirectModifier<S> getRedirectModifier() {
+ return commandNodeSupplier.get().getRedirectModifier();
+ }
+
+ @Override
+ public synchronized boolean canUse(S source) {
+ return commandNodeSupplier.get().canUse(source);
+ }
+
+ @Override
+ public void addChild(CommandNode<S> node) {
+ commandNodeSupplier.get().addChild(node);
+ }
+
+ @Override
+ public void findAmbiguities(AmbiguityConsumer<S> consumer) {
+ commandNodeSupplier.get().findAmbiguities(consumer);
+ }
+
+ @Override
+ public int hashCode() {
+ return commandNodeSupplier.get().hashCode();
+ }
+
+ @Override
+ public Predicate<S> getRequirement() {
+ return commandNodeSupplier.get().getRequirement();
+ }
+
+ @Override
+ public Collection<? extends CommandNode<S>> getRelevantNodes(StringReader input) {
+ return commandNodeSupplier.get().getRelevantNodes(input);
+ }
+
+ @Override
+ public int compareTo(CommandNode<S> o) {
+ return commandNodeSupplier.get().compareTo(o);
+ }
+
+ @Override
+ public boolean isFork() {
+ return commandNodeSupplier.get().isFork();
+ }
+}
diff --git a/src/main/java/net/minecraft/commands/Commands.java b/src/main/java/net/minecraft/commands/Commands.java
index 6fec6a47538da4c0c5a4505e9bedf492bb3376dd..5c7815f8ffd850078fa11e0b4edcfbfb78b9c51d 100644
--- a/src/main/java/net/minecraft/commands/Commands.java
+++ b/src/main/java/net/minecraft/commands/Commands.java
@@ -368,6 +368,7 @@ public class Commands {
RootCommandNode<SharedSuggestionProvider> rootcommandnode = new RootCommandNode();

map.put(this.dispatcher.getRoot(), rootcommandnode);
+ map.put(io.papermc.paper.commands.DelegatingRootCommandNode.INSTANCE, rootcommandnode); // Paper - replace delegating root command with new root command node
this.fillUsableCommands(this.dispatcher.getRoot(), rootcommandnode, player.createCommandSourceStack(), (Map) map);

Collection<String> bukkit = new LinkedHashSet<>();
diff --git a/src/main/java/net/minecraft/server/commands/ExecuteCommand.java b/src/main/java/net/minecraft/server/commands/ExecuteCommand.java
index f9679bd9b0c1cbde183b5e61daec05b61eda409a..553f052d16a48f94aa4a4728915825faec044871 100644
--- a/src/main/java/net/minecraft/server/commands/ExecuteCommand.java
+++ b/src/main/java/net/minecraft/server/commands/ExecuteCommand.java
@@ -94,7 +94,7 @@ public class ExecuteCommand {
}));
dispatcher.register(Commands.literal("execute").requires((source) -> {
return source.hasPermission(2);
- }).then(Commands.literal("run").redirect(dispatcher.getRoot())).then(addConditionals(literalCommandNode, Commands.literal("if"), true)).then(addConditionals(literalCommandNode, Commands.literal("unless"), false)).then(Commands.literal("as").then(Commands.argument("targets", EntityArgument.entities()).fork(literalCommandNode, (context) -> {
+ }).then(Commands.literal("run").redirect(io.papermc.paper.commands.DelegatingRootCommandNode.INSTANCE)).then(addConditionals(literalCommandNode, Commands.literal("if"), true)).then(addConditionals(literalCommandNode, Commands.literal("unless"), false)).then(Commands.literal("as").then(Commands.argument("targets", EntityArgument.entities()).fork(literalCommandNode, (context) -> { // Paper - use delegating root node
List<CommandSourceStack> list = Lists.newArrayList();

for(Entity entity : EntityArgument.getOptionalEntities(context, "targets")) {

0 comments on commit 3cb536c

Please sign in to comment.