Commits

md_5 authored 459c38af307
Update to Minecraft 1.21.2
No tags

nms-patches/net/minecraft/commands/CommandDispatcher.patch

Modified
1 1 --- a/net/minecraft/commands/CommandDispatcher.java
2 2 +++ b/net/minecraft/commands/CommandDispatcher.java
3 -@@ -135,6 +135,14 @@
3 +@@ -139,6 +139,14 @@
4 4 import net.minecraft.world.level.GameRules;
5 5 import org.slf4j.Logger;
6 6
7 7 +// CraftBukkit start
8 8 +import com.google.common.base.Joiner;
9 9 +import java.util.Collection;
10 10 +import java.util.LinkedHashSet;
11 11 +import org.bukkit.event.player.PlayerCommandSendEvent;
12 12 +import org.bukkit.event.server.ServerCommandEvent;
13 13 +// CraftBukkit end
14 14 +
15 15 public class CommandDispatcher {
16 16
17 17 private static final ThreadLocal<ExecutionContext<CommandListenerWrapper>> CURRENT_EXECUTION_CONTEXT = new ThreadLocal();
18 -@@ -147,6 +155,7 @@
18 +@@ -151,6 +159,7 @@
19 19 private final com.mojang.brigadier.CommandDispatcher<CommandListenerWrapper> dispatcher = new com.mojang.brigadier.CommandDispatcher();
20 20
21 21 public CommandDispatcher(CommandDispatcher.ServerType commanddispatcher_servertype, CommandBuildContext commandbuildcontext) {
22 22 + this(); // CraftBukkit
23 23 CommandAdvancement.register(this.dispatcher);
24 24 CommandAttribute.register(this.dispatcher, commandbuildcontext);
25 25 CommandExecute.register(this.dispatcher, commandbuildcontext);
26 -@@ -247,6 +256,11 @@
26 +@@ -252,6 +261,11 @@
27 27 CommandPublish.register(this.dispatcher);
28 28 }
29 29
30 30 + // CraftBukkit start
31 31 + }
32 32 +
33 33 + public CommandDispatcher() {
34 34 + // CraftBukkkit end
35 35 this.dispatcher.setConsumer(ExecutionCommandSource.resultConsumer());
36 36 }
37 37
38 -@@ -257,18 +271,65 @@
38 +@@ -262,18 +276,65 @@
39 39 return new ParseResults(commandcontextbuilder1, parseresults.getReader(), parseresults.getExceptions());
40 40 }
41 41
42 42 + // CraftBukkit start
43 43 + public void dispatchServerCommand(CommandListenerWrapper sender, String command) {
44 44 + Joiner joiner = Joiner.on(" ");
45 45 + if (command.startsWith("/")) {
46 46 + command = command.substring(1);
47 47 + }
48 48 +
88 88 + // CraftBukkit end
89 89 }
90 90
91 91 public void performCommand(ParseResults<CommandListenerWrapper> parseresults, String s) {
92 92 + this.performCommand(parseresults, s, s);
93 93 + }
94 94 +
95 95 + public void performCommand(ParseResults<CommandListenerWrapper> parseresults, String s, String label) { // CraftBukkit
96 96 CommandListenerWrapper commandlistenerwrapper = (CommandListenerWrapper) parseresults.getContext().getSource();
97 97
98 - commandlistenerwrapper.getServer().getProfiler().push(() -> {
98 + Profiler.get().push(() -> {
99 99 return "/" + s;
100 100 });
101 101 - ContextChain<CommandListenerWrapper> contextchain = finishParsing(parseresults, s, commandlistenerwrapper);
102 102 + ContextChain<CommandListenerWrapper> contextchain = finishParsing(parseresults, s, commandlistenerwrapper, label); // CraftBukkit
103 103
104 104 try {
105 105 if (contextchain != null) {
106 -@@ -302,7 +363,7 @@
106 +@@ -307,7 +368,7 @@
107 107 }
108 108
109 109 @Nullable
110 110 - private static ContextChain<CommandListenerWrapper> finishParsing(ParseResults<CommandListenerWrapper> parseresults, String s, CommandListenerWrapper commandlistenerwrapper) {
111 111 + private static ContextChain<CommandListenerWrapper> finishParsing(ParseResults<CommandListenerWrapper> parseresults, String s, CommandListenerWrapper commandlistenerwrapper, String label) { // CraftBukkit
112 112 try {
113 113 validateParseResults(parseresults);
114 114 return (ContextChain) ContextChain.tryFlatten(parseresults.getContext().build(s)).orElseThrow(() -> {
115 -@@ -313,7 +374,7 @@
115 +@@ -318,7 +379,7 @@
116 116 if (commandsyntaxexception.getInput() != null && commandsyntaxexception.getCursor() >= 0) {
117 117 int i = Math.min(commandsyntaxexception.getInput().length(), commandsyntaxexception.getCursor());
118 118 IChatMutableComponent ichatmutablecomponent = IChatBaseComponent.empty().withStyle(EnumChatFormat.GRAY).withStyle((chatmodifier) -> {
119 119 - return chatmodifier.withClickEvent(new ChatClickable(ChatClickable.EnumClickAction.SUGGEST_COMMAND, "/" + s));
120 120 + return chatmodifier.withClickEvent(new ChatClickable(ChatClickable.EnumClickAction.SUGGEST_COMMAND, label)); // CraftBukkit
121 121 });
122 122
123 123 if (i > 10) {
124 -@@ -363,7 +424,7 @@
124 +@@ -368,7 +429,7 @@
125 125
126 126 executioncontext1.close();
127 127 } finally {
128 128 - CommandDispatcher.CURRENT_EXECUTION_CONTEXT.set((Object) null);
129 129 + CommandDispatcher.CURRENT_EXECUTION_CONTEXT.set(null); // CraftBukkit - decompile error
130 130 }
131 131 } else {
132 132 consumer.accept(executioncontext);
133 -@@ -372,11 +433,36 @@
133 +@@ -377,11 +438,36 @@
134 134 }
135 135
136 136 public void sendCommands(EntityPlayer entityplayer) {
137 137 - Map<CommandNode<CommandListenerWrapper>, CommandNode<ICompletionProvider>> map = Maps.newHashMap();
138 138 + // CraftBukkit start
139 139 + // Register Vanilla commands into builtRoot as before
140 140 + Map<CommandNode<CommandListenerWrapper>, CommandNode<ICompletionProvider>> map = Maps.newIdentityHashMap(); // Use identity to prevent aliasing issues
141 141 + RootCommandNode vanillaRoot = new RootCommandNode();
142 142 +
143 143 + RootCommandNode<CommandListenerWrapper> vanilla = entityplayer.server.vanillaCommandDispatcher.getDispatcher().getRoot();
161 161 + // Remove labels that were removed during the event
162 162 + for (String orig : bukkit) {
163 163 + if (!event.getCommands().contains(orig)) {
164 164 + rootcommandnode.removeCommand(orig);
165 165 + }
166 166 + }
167 167 + // CraftBukkit end
168 168 entityplayer.connection.send(new PacketPlayOutCommands(rootcommandnode));
169 169 }
170 170
171 -@@ -387,7 +473,7 @@
171 +@@ -392,7 +478,7 @@
172 172 CommandNode<CommandListenerWrapper> commandnode2 = (CommandNode) iterator.next();
173 173
174 174 if (commandnode2.canUse(commandlistenerwrapper)) {
175 175 - ArgumentBuilder<ICompletionProvider, ?> argumentbuilder = commandnode2.createBuilder();
176 176 + ArgumentBuilder argumentbuilder = commandnode2.createBuilder(); // CraftBukkit - decompile error
177 177
178 178 argumentbuilder.requires((icompletionprovider) -> {
179 179 return true;
180 -@@ -410,7 +496,7 @@
180 +@@ -415,7 +501,7 @@
181 181 argumentbuilder.redirect((CommandNode) map.get(argumentbuilder.getRedirect()));
182 182 }
183 183
184 184 - CommandNode<ICompletionProvider> commandnode3 = argumentbuilder.build();
185 185 + CommandNode commandnode3 = argumentbuilder.build(); // CraftBukkit - decompile error
186 186
187 187 map.put(commandnode2, commandnode3);
188 188 commandnode1.addChild(commandnode3);
189 -@@ -471,7 +557,7 @@
189 +@@ -481,7 +567,7 @@
190 190 }
191 191
192 192 private <T> HolderLookup.b.a<T> createLookup(final HolderLookup.b<T> holderlookup_b) {
193 193 - return new HolderLookup.b.a<T>(this) {
194 194 + return new HolderLookup.b.a<T>() { // CraftBukkit - decompile error
195 195 @Override
196 196 public HolderLookup.b<T> parent() {
197 197 return holderlookup_b;

Everything looks good. We'll let you know here if there's anything you should know about.

Add shortcut