Commits
md_5 authored 459c38af307
1 1 | --- a/net/minecraft/commands/CommandDispatcher.java |
2 2 | +++ b/net/minecraft/commands/CommandDispatcher.java |
3 - | |
3 + | |
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 - | |
18 + | |
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 - | |
26 + | |
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 - | |
38 + | |
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 - | |
106 + | |
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 - | |
115 + | |
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 - | |
124 + | |
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 - | |
133 + | |
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 - | |
171 + | |
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 - | |
180 + | |
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 - | |
189 + | |
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; |