Commits
md_5 authored bcedf28a1b6
1 1 | --- a/net/minecraft/commands/CommandDispatcher.java |
2 2 | +++ b/net/minecraft/commands/CommandDispatcher.java |
3 - | |
3 + | |
4 4 | import net.minecraft.util.profiling.jfr.JvmProfiler; |
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 Logger LOGGER = LogUtils.getLogger(); |
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((commandcontext, flag, i) -> { |
36 36 | ((CommandListenerWrapper) commandcontext.getSource()).onCommandComplete(commandcontext, flag, i); |
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 int 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 | + |
89 89 | } |
90 90 | |
91 91 | public int performCommand(ParseResults<CommandListenerWrapper> parseresults, String s) { |
92 92 | + return this.performCommand(parseresults, s, s); |
93 93 | + } |
94 94 | + |
95 95 | + public int performCommand(ParseResults<CommandListenerWrapper> parseresults, String s, String label) { // CraftBukkit |
96 96 | CommandListenerWrapper commandlistenerwrapper = (CommandListenerWrapper) parseresults.getContext().getSource(); |
97 97 | |
98 98 | commandlistenerwrapper.getServer().getProfiler().push(() -> { |
99 - | |
99 + | |
100 100 | if (commandsyntaxexception.getInput() != null && commandsyntaxexception.getCursor() >= 0) { |
101 101 | int j = Math.min(commandsyntaxexception.getInput().length(), commandsyntaxexception.getCursor()); |
102 102 | IChatMutableComponent ichatmutablecomponent = IChatBaseComponent.empty().withStyle(EnumChatFormat.GRAY).withStyle((chatmodifier) -> { |
103 103 | - return chatmodifier.withClickEvent(new ChatClickable(ChatClickable.EnumClickAction.SUGGEST_COMMAND, "/" + s)); |
104 104 | + return chatmodifier.withClickEvent(new ChatClickable(ChatClickable.EnumClickAction.SUGGEST_COMMAND, label)); // CraftBukkit |
105 105 | }); |
106 106 | |
107 107 | if (j > 10) { |
108 - | |
108 + | |
109 109 | } |
110 110 | |
111 111 | public void sendCommands(EntityPlayer entityplayer) { |
112 112 | - Map<CommandNode<CommandListenerWrapper>, CommandNode<ICompletionProvider>> map = Maps.newHashMap(); |
113 113 | + // CraftBukkit start |
114 114 | + // Register Vanilla commands into builtRoot as before |
115 115 | + Map<CommandNode<CommandListenerWrapper>, CommandNode<ICompletionProvider>> map = Maps.newIdentityHashMap(); // Use identity to prevent aliasing issues |
116 116 | + RootCommandNode vanillaRoot = new RootCommandNode(); |
117 117 | + |
118 118 | + RootCommandNode<CommandListenerWrapper> vanilla = entityplayer.server.vanillaCommandDispatcher.getDispatcher().getRoot(); |
136 136 | + // Remove labels that were removed during the event |
137 137 | + for (String orig : bukkit) { |
138 138 | + if (!event.getCommands().contains(orig)) { |
139 139 | + rootcommandnode.removeCommand(orig); |
140 140 | + } |
141 141 | + } |
142 142 | + // CraftBukkit end |
143 143 | entityplayer.connection.send(new PacketPlayOutCommands(rootcommandnode)); |
144 144 | } |
145 145 | |
146 - | |
146 + | |
147 147 | CommandNode<CommandListenerWrapper> commandnode2 = (CommandNode) iterator.next(); |
148 148 | |
149 149 | if (commandnode2.canUse(commandlistenerwrapper)) { |
150 150 | - ArgumentBuilder<ICompletionProvider, ?> argumentbuilder = commandnode2.createBuilder(); |
151 151 | + ArgumentBuilder argumentbuilder = commandnode2.createBuilder(); // CraftBukkit - decompile error |
152 152 | |
153 153 | argumentbuilder.requires((icompletionprovider) -> { |
154 154 | return true; |
155 - | |
155 + | |
156 156 | argumentbuilder.redirect((CommandNode) map.get(argumentbuilder.getRedirect())); |
157 157 | } |
158 158 | |
159 159 | - CommandNode<ICompletionProvider> commandnode3 = argumentbuilder.build(); |
160 160 | + CommandNode commandnode3 = argumentbuilder.build(); // CraftBukkit - decompile error |
161 161 | |
162 162 | map.put(commandnode2, commandnode3); |
163 163 | commandnode1.addChild(commandnode3); |