1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
|
--- a/net/minecraft/commands/Commands.java
+++ b/net/minecraft/commands/Commands.java
@@ -1,7 +1,6 @@
package net.minecraft.commands;
import com.google.common.collect.Maps;
-import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.ParseResults;
import com.mojang.brigadier.StringReader;
import com.mojang.brigadier.arguments.ArgumentType;
@@ -135,6 +134,14 @@
import net.minecraft.world.level.GameRules;
import org.slf4j.Logger;
+// CraftBukkit start
+import com.google.common.base.Joiner;
+import java.util.Collection;
+import java.util.LinkedHashSet;
+import org.bukkit.event.player.PlayerCommandSendEvent;
+import org.bukkit.event.server.ServerCommandEvent;
+// CraftBukkit end
+
public class Commands {
private static final ThreadLocal<ExecutionContext<CommandSourceStack>> CURRENT_EXECUTION_CONTEXT = new ThreadLocal();
@@ -144,41 +151,42 @@
public static final int LEVEL_GAMEMASTERS = 2;
public static final int LEVEL_ADMINS = 3;
public static final int LEVEL_OWNERS = 4;
- private final CommandDispatcher<CommandSourceStack> dispatcher = new CommandDispatcher();
+ private final com.mojang.brigadier.CommandDispatcher<CommandSourceStack> dispatcher = new com.mojang.brigadier.CommandDispatcher();
- public Commands(Commands.CommandSelection commands_commandselection, CommandBuildContext commandbuildcontext) {
+ public Commands(Commands.CommandSelection selection, CommandBuildContext context) {
+ this(); // CraftBukkit
AdvancementCommands.register(this.dispatcher);
- AttributeCommand.register(this.dispatcher, commandbuildcontext);
- ExecuteCommand.register(this.dispatcher, commandbuildcontext);
+ AttributeCommand.register(this.dispatcher, context);
+ ExecuteCommand.register(this.dispatcher, context);
BossBarCommands.register(this.dispatcher);
- ClearInventoryCommands.register(this.dispatcher, commandbuildcontext);
- CloneCommands.register(this.dispatcher, commandbuildcontext);
- DamageCommand.register(this.dispatcher, commandbuildcontext);
+ ClearInventoryCommands.register(this.dispatcher, context);
+ CloneCommands.register(this.dispatcher, context);
+ DamageCommand.register(this.dispatcher, context);
DataCommands.register(this.dispatcher);
DataPackCommand.register(this.dispatcher);
DebugCommand.register(this.dispatcher);
DefaultGameModeCommands.register(this.dispatcher);
DifficultyCommand.register(this.dispatcher);
- EffectCommands.register(this.dispatcher, commandbuildcontext);
+ EffectCommands.register(this.dispatcher, context);
EmoteCommands.register(this.dispatcher);
- EnchantCommand.register(this.dispatcher, commandbuildcontext);
+ EnchantCommand.register(this.dispatcher, context);
ExperienceCommand.register(this.dispatcher);
- FillCommand.register(this.dispatcher, commandbuildcontext);
- FillBiomeCommand.register(this.dispatcher, commandbuildcontext);
+ FillCommand.register(this.dispatcher, context);
+ FillBiomeCommand.register(this.dispatcher, context);
ForceLoadCommand.register(this.dispatcher);
FunctionCommand.register(this.dispatcher);
GameModeCommand.register(this.dispatcher);
GameRuleCommand.register(this.dispatcher);
- GiveCommand.register(this.dispatcher, commandbuildcontext);
+ GiveCommand.register(this.dispatcher, context);
HelpCommand.register(this.dispatcher);
- ItemCommands.register(this.dispatcher, commandbuildcontext);
+ ItemCommands.register(this.dispatcher, context);
KickCommand.register(this.dispatcher);
KillCommand.register(this.dispatcher);
ListPlayersCommand.register(this.dispatcher);
- LocateCommand.register(this.dispatcher, commandbuildcontext);
- LootCommand.register(this.dispatcher, commandbuildcontext);
+ LocateCommand.register(this.dispatcher, context);
+ LootCommand.register(this.dispatcher, context);
MsgCommand.register(this.dispatcher);
- ParticleCommand.register(this.dispatcher, commandbuildcontext);
+ ParticleCommand.register(this.dispatcher, context);
PlaceCommand.register(this.dispatcher);
PlaySoundCommand.register(this.dispatcher);
RandomCommand.register(this.dispatcher);
@@ -189,14 +197,14 @@
SayCommand.register(this.dispatcher);
ScheduleCommand.register(this.dispatcher);
ScoreboardCommand.register(this.dispatcher);
- SeedCommand.register(this.dispatcher, commands_commandselection != Commands.CommandSelection.INTEGRATED);
- SetBlockCommand.register(this.dispatcher, commandbuildcontext);
+ SeedCommand.register(this.dispatcher, selection != Commands.CommandSelection.INTEGRATED);
+ SetBlockCommand.register(this.dispatcher, context);
SetSpawnCommand.register(this.dispatcher);
SetWorldSpawnCommand.register(this.dispatcher);
SpectateCommand.register(this.dispatcher);
SpreadPlayersCommand.register(this.dispatcher);
StopSoundCommand.register(this.dispatcher);
- SummonCommand.register(this.dispatcher, commandbuildcontext);
+ SummonCommand.register(this.dispatcher, context);
TagCommand.register(this.dispatcher);
TeamCommand.register(this.dispatcher);
TeamMsgCommand.register(this.dispatcher);
@@ -221,12 +229,12 @@
WardenSpawnTrackerCommand.register(this.dispatcher);
SpawnArmorTrimsCommand.register(this.dispatcher);
ServerPackCommand.register(this.dispatcher);
- if (commands_commandselection.includeDedicated) {
+ if (selection.includeDedicated) {
DebugConfigCommand.register(this.dispatcher);
}
}
- if (commands_commandselection.includeDedicated) {
+ if (selection.includeDedicated) {
BanIpCommands.register(this.dispatcher);
BanListCommands.register(this.dispatcher);
BanPlayerCommands.register(this.dispatcher);
@@ -243,100 +251,152 @@
WhitelistCommand.register(this.dispatcher);
}
- if (commands_commandselection.includeIntegrated) {
+ if (selection.includeIntegrated) {
PublishCommand.register(this.dispatcher);
}
+ // CraftBukkit start
+ }
+
+ public Commands() {
+ // CraftBukkkit end
this.dispatcher.setConsumer(ExecutionCommandSource.resultConsumer());
}
- public static <S> ParseResults<S> mapSource(ParseResults<S> parseresults, UnaryOperator<S> unaryoperator) {
- CommandContextBuilder<S> commandcontextbuilder = parseresults.getContext();
- CommandContextBuilder<S> commandcontextbuilder1 = commandcontextbuilder.withSource(unaryoperator.apply(commandcontextbuilder.getSource()));
+ public static <S> ParseResults<S> mapSource(ParseResults<S> parseResults, UnaryOperator<S> mapper) {
+ CommandContextBuilder<S> commandcontextbuilder = parseResults.getContext();
+ CommandContextBuilder<S> commandcontextbuilder1 = commandcontextbuilder.withSource(mapper.apply(commandcontextbuilder.getSource()));
- return new ParseResults(commandcontextbuilder1, parseresults.getReader(), parseresults.getExceptions());
+ return new ParseResults(commandcontextbuilder1, parseResults.getReader(), parseResults.getExceptions());
}
- public void performPrefixedCommand(CommandSourceStack commandsourcestack, String s) {
+ // CraftBukkit start
+ public void dispatchServerCommand(CommandSourceStack sender, String command) {
+ Joiner joiner = Joiner.on(" ");
+ if (command.startsWith("/")) {
+ command = command.substring(1);
+ }
+
+ ServerCommandEvent event = new ServerCommandEvent(sender.getBukkitSender(), command);
+ org.bukkit.Bukkit.getPluginManager().callEvent(event);
+ if (event.isCancelled()) {
+ return;
+ }
+ command = event.getCommand();
+
+ String[] args = command.split(" ");
+
+ String cmd = args[0];
+ if (cmd.startsWith("minecraft:")) cmd = cmd.substring("minecraft:".length());
+ if (cmd.startsWith("bukkit:")) cmd = cmd.substring("bukkit:".length());
+
+ // Block disallowed commands
+ if (cmd.equalsIgnoreCase("stop") || cmd.equalsIgnoreCase("kick") || cmd.equalsIgnoreCase("op")
+ || cmd.equalsIgnoreCase("deop") || cmd.equalsIgnoreCase("ban") || cmd.equalsIgnoreCase("ban-ip")
+ || cmd.equalsIgnoreCase("pardon") || cmd.equalsIgnoreCase("pardon-ip") || cmd.equalsIgnoreCase("reload")) {
+ return;
+ }
+
+ // Handle vanilla commands;
+ if (sender.getLevel().getCraftServer().getCommandBlockOverride(args[0])) {
+ args[0] = "minecraft:" + args[0];
+ }
+
+ String newCommand = joiner.join(args);
+ this.performPrefixedCommand(sender, newCommand, newCommand);
+ }
+ // CraftBukkit end
+
+ public void performPrefixedCommand(CommandSourceStack commandlistenerwrapper, String s) {
+ // CraftBukkit start
+ this.performPrefixedCommand(commandlistenerwrapper, s, s);
+ }
+
+ public void performPrefixedCommand(CommandSourceStack commandlistenerwrapper, String s, String label) {
s = s.startsWith("/") ? s.substring(1) : s;
- this.performCommand(this.dispatcher.parse(s, commandsourcestack), s);
+ this.performCommand(this.dispatcher.parse(s, commandlistenerwrapper), s, label);
+ // CraftBukkit end
}
public void performCommand(ParseResults<CommandSourceStack> parseresults, String s) {
- CommandSourceStack commandsourcestack = (CommandSourceStack) parseresults.getContext().getSource();
+ this.performCommand(parseresults, s, s);
+ }
- commandsourcestack.getServer().getProfiler().push(() -> {
+ public void performCommand(ParseResults<CommandSourceStack> parseresults, String s, String label) { // CraftBukkit
+ CommandSourceStack commandlistenerwrapper = (CommandSourceStack) parseresults.getContext().getSource();
+
+ commandlistenerwrapper.getServer().getProfiler().push(() -> {
return "/" + s;
});
- ContextChain contextchain = finishParsing(parseresults, s, commandsourcestack);
+ ContextChain contextchain = finishParsing(parseresults, s, commandlistenerwrapper, label); // CraftBukkit
try {
if (contextchain != null) {
- executeCommandInContext(commandsourcestack, (executioncontext) -> {
- ExecutionContext.queueInitialCommandExecution(executioncontext, s, contextchain, commandsourcestack, CommandResultCallback.EMPTY);
+ executeCommandInContext(commandlistenerwrapper, (executioncontext) -> {
+ ExecutionContext.queueInitialCommandExecution(executioncontext, s, contextchain, commandlistenerwrapper, CommandResultCallback.EMPTY);
});
}
} catch (Exception exception) {
- MutableComponent mutablecomponent = Component.literal(exception.getMessage() == null ? exception.getClass().getName() : exception.getMessage());
+ MutableComponent ichatmutablecomponent = Component.literal(exception.getMessage() == null ? exception.getClass().getName() : exception.getMessage());
if (Commands.LOGGER.isDebugEnabled()) {
Commands.LOGGER.error("Command exception: /{}", s, exception);
StackTraceElement[] astacktraceelement = exception.getStackTrace();
for (int i = 0; i < Math.min(astacktraceelement.length, 3); ++i) {
- mutablecomponent.append("\n\n").append(astacktraceelement[i].getMethodName()).append("\n ").append(astacktraceelement[i].getFileName()).append(":").append(String.valueOf(astacktraceelement[i].getLineNumber()));
+ ichatmutablecomponent.append("\n\n").append(astacktraceelement[i].getMethodName()).append("\n ").append(astacktraceelement[i].getFileName()).append(":").append(String.valueOf(astacktraceelement[i].getLineNumber()));
}
}
- commandsourcestack.sendFailure(Component.translatable("command.failed").withStyle((style) -> {
- return style.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, mutablecomponent));
+ commandlistenerwrapper.sendFailure(Component.translatable("command.failed").withStyle((chatmodifier) -> {
+ return chatmodifier.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, ichatmutablecomponent));
}));
if (SharedConstants.IS_RUNNING_IN_IDE) {
- commandsourcestack.sendFailure(Component.literal(Util.describeError(exception)));
+ commandlistenerwrapper.sendFailure(Component.literal(Util.describeError(exception)));
Commands.LOGGER.error("'/{}' threw an exception", s, exception);
}
} finally {
- commandsourcestack.getServer().getProfiler().pop();
+ commandlistenerwrapper.getServer().getProfiler().pop();
}
}
@Nullable
- private static ContextChain<CommandSourceStack> finishParsing(ParseResults<CommandSourceStack> parseresults, String s, CommandSourceStack commandsourcestack) {
+ private static ContextChain<CommandSourceStack> finishParsing(ParseResults<CommandSourceStack> parseresults, String s, CommandSourceStack commandlistenerwrapper, String label) { // CraftBukkit
try {
validateParseResults(parseresults);
return (ContextChain) ContextChain.tryFlatten(parseresults.getContext().build(s)).orElseThrow(() -> {
return CommandSyntaxException.BUILT_IN_EXCEPTIONS.dispatcherUnknownCommand().createWithContext(parseresults.getReader());
});
} catch (CommandSyntaxException commandsyntaxexception) {
- commandsourcestack.sendFailure(ComponentUtils.fromMessage(commandsyntaxexception.getRawMessage()));
+ commandlistenerwrapper.sendFailure(ComponentUtils.fromMessage(commandsyntaxexception.getRawMessage()));
if (commandsyntaxexception.getInput() != null && commandsyntaxexception.getCursor() >= 0) {
int i = Math.min(commandsyntaxexception.getInput().length(), commandsyntaxexception.getCursor());
- MutableComponent mutablecomponent = Component.empty().withStyle(ChatFormatting.GRAY).withStyle((style) -> {
- return style.withClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/" + s));
+ MutableComponent ichatmutablecomponent = Component.empty().withStyle(ChatFormatting.GRAY).withStyle((chatmodifier) -> {
+ return chatmodifier.withClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, label)); // CraftBukkit
});
if (i > 10) {
- mutablecomponent.append(CommonComponents.ELLIPSIS);
+ ichatmutablecomponent.append(CommonComponents.ELLIPSIS);
}
- mutablecomponent.append(commandsyntaxexception.getInput().substring(Math.max(0, i - 10), i));
+ ichatmutablecomponent.append(commandsyntaxexception.getInput().substring(Math.max(0, i - 10), i));
if (i < commandsyntaxexception.getInput().length()) {
- MutableComponent mutablecomponent1 = Component.literal(commandsyntaxexception.getInput().substring(i)).withStyle(ChatFormatting.RED, ChatFormatting.UNDERLINE);
+ MutableComponent ichatmutablecomponent1 = Component.literal(commandsyntaxexception.getInput().substring(i)).withStyle(ChatFormatting.RED, ChatFormatting.UNDERLINE);
- mutablecomponent.append((Component) mutablecomponent1);
+ ichatmutablecomponent.append((Component) ichatmutablecomponent1);
}
- mutablecomponent.append((Component) Component.translatable("command.context.here").withStyle(ChatFormatting.RED, ChatFormatting.ITALIC));
- commandsourcestack.sendFailure(mutablecomponent);
+ ichatmutablecomponent.append((Component) Component.translatable("command.context.here").withStyle(ChatFormatting.RED, ChatFormatting.ITALIC));
+ commandlistenerwrapper.sendFailure(ichatmutablecomponent);
}
return null;
}
}
- public static void executeCommandInContext(CommandSourceStack commandsourcestack, Consumer<ExecutionContext<CommandSourceStack>> consumer) {
- MinecraftServer minecraftserver = commandsourcestack.getServer();
+ public static void executeCommandInContext(CommandSourceStack commandlistenerwrapper, Consumer<ExecutionContext<CommandSourceStack>> consumer) {
+ MinecraftServer minecraftserver = commandlistenerwrapper.getServer();
ExecutionContext<CommandSourceStack> executioncontext = (ExecutionContext) Commands.CURRENT_EXECUTION_CONTEXT.get();
boolean flag = executioncontext == null;
@@ -363,7 +423,7 @@
executioncontext1.close();
} finally {
- Commands.CURRENT_EXECUTION_CONTEXT.set((Object) null);
+ Commands.CURRENT_EXECUTION_CONTEXT.set(null); // CraftBukkit - decompile error
}
} else {
consumer.accept(executioncontext);
@@ -371,25 +431,50 @@
}
- public void sendCommands(ServerPlayer serverplayer) {
- Map<CommandNode<CommandSourceStack>, CommandNode<SharedSuggestionProvider>> map = Maps.newHashMap();
+ public void sendCommands(ServerPlayer player) {
+ // CraftBukkit start
+ // Register Vanilla commands into builtRoot as before
+ Map<CommandNode<CommandSourceStack>, CommandNode<SharedSuggestionProvider>> map = Maps.newIdentityHashMap(); // Use identity to prevent aliasing issues
+ RootCommandNode vanillaRoot = new RootCommandNode();
+
+ RootCommandNode<CommandSourceStack> vanilla = player.server.vanillaCommandDispatcher.getDispatcher().getRoot();
+ map.put(vanilla, vanillaRoot);
+ this.fillUsableCommands(vanilla, vanillaRoot, player.createCommandSourceStack(), (Map) map);
+
+ // Now build the global commands in a second pass
RootCommandNode<SharedSuggestionProvider> rootcommandnode = new RootCommandNode();
map.put(this.dispatcher.getRoot(), rootcommandnode);
- this.fillUsableCommands(this.dispatcher.getRoot(), rootcommandnode, serverplayer.createCommandSourceStack(), map);
- serverplayer.connection.send(new ClientboundCommandsPacket(rootcommandnode));
+ this.fillUsableCommands(this.dispatcher.getRoot(), rootcommandnode, player.createCommandSourceStack(), map);
+
+ Collection<String> bukkit = new LinkedHashSet<>();
+ for (CommandNode node : rootcommandnode.getChildren()) {
+ bukkit.add(node.getName());
+ }
+
+ PlayerCommandSendEvent event = new PlayerCommandSendEvent(player.getBukkitEntity(), new LinkedHashSet<>(bukkit));
+ event.getPlayer().getServer().getPluginManager().callEvent(event);
+
+ // Remove labels that were removed during the event
+ for (String orig : bukkit) {
+ if (!event.getCommands().contains(orig)) {
+ rootcommandnode.removeCommand(orig);
+ }
+ }
+ // CraftBukkit end
+ player.connection.send(new ClientboundCommandsPacket(rootcommandnode));
}
- private void fillUsableCommands(CommandNode<CommandSourceStack> commandnode, CommandNode<SharedSuggestionProvider> commandnode1, CommandSourceStack commandsourcestack, Map<CommandNode<CommandSourceStack>, CommandNode<SharedSuggestionProvider>> map) {
- Iterator iterator = commandnode.getChildren().iterator();
+ private void fillUsableCommands(CommandNode<CommandSourceStack> rootCommandSource, CommandNode<SharedSuggestionProvider> rootSuggestion, CommandSourceStack source, Map<CommandNode<CommandSourceStack>, CommandNode<SharedSuggestionProvider>> commandNodeToSuggestionNode) {
+ Iterator iterator = rootCommandSource.getChildren().iterator();
while (iterator.hasNext()) {
CommandNode<CommandSourceStack> commandnode2 = (CommandNode) iterator.next();
- if (commandnode2.canUse(commandsourcestack)) {
- ArgumentBuilder<SharedSuggestionProvider, ?> argumentbuilder = commandnode2.createBuilder();
+ if (commandnode2.canUse(source)) {
+ ArgumentBuilder argumentbuilder = commandnode2.createBuilder(); // CraftBukkit - decompile error
- argumentbuilder.requires((sharedsuggestionprovider) -> {
+ argumentbuilder.requires((icompletionprovider) -> {
return true;
});
if (argumentbuilder.getCommand() != null) {
@@ -407,33 +492,33 @@
}
if (argumentbuilder.getRedirect() != null) {
- argumentbuilder.redirect((CommandNode) map.get(argumentbuilder.getRedirect()));
+ argumentbuilder.redirect((CommandNode) commandNodeToSuggestionNode.get(argumentbuilder.getRedirect()));
}
- CommandNode<SharedSuggestionProvider> commandnode3 = argumentbuilder.build();
+ CommandNode commandnode3 = argumentbuilder.build(); // CraftBukkit - decompile error
- map.put(commandnode2, commandnode3);
- commandnode1.addChild(commandnode3);
+ commandNodeToSuggestionNode.put(commandnode2, commandnode3);
+ rootSuggestion.addChild(commandnode3);
if (!commandnode2.getChildren().isEmpty()) {
- this.fillUsableCommands(commandnode2, commandnode3, commandsourcestack, map);
+ this.fillUsableCommands(commandnode2, commandnode3, source, commandNodeToSuggestionNode);
}
}
}
}
- public static LiteralArgumentBuilder<CommandSourceStack> literal(String s) {
- return LiteralArgumentBuilder.literal(s);
+ public static LiteralArgumentBuilder<CommandSourceStack> literal(String name) {
+ return LiteralArgumentBuilder.literal(name);
}
- public static <T> RequiredArgumentBuilder<CommandSourceStack, T> argument(String s, ArgumentType<T> argumenttype) {
- return RequiredArgumentBuilder.argument(s, argumenttype);
+ public static <T> RequiredArgumentBuilder<CommandSourceStack, T> argument(String name, ArgumentType<T> type) {
+ return RequiredArgumentBuilder.argument(name, type);
}
- public static Predicate<String> createValidator(Commands.ParseFunction commands_parsefunction) {
+ public static Predicate<String> createValidator(Commands.ParseFunction parser) {
return (s) -> {
try {
- commands_parsefunction.parse(new StringReader(s));
+ parser.parse(new StringReader(s));
return true;
} catch (CommandSyntaxException commandsyntaxexception) {
return false;
@@ -441,7 +526,7 @@
};
}
- public CommandDispatcher<CommandSourceStack> getDispatcher() {
+ public com.mojang.brigadier.CommandDispatcher<CommandSourceStack> getDispatcher() {
return this.dispatcher;
}
@@ -454,31 +539,28 @@
}
@Nullable
- public static <S> CommandSyntaxException getParseException(ParseResults<S> parseresults) {
- return !parseresults.getReader().canRead() ? null : (parseresults.getExceptions().size() == 1 ? (CommandSyntaxException) parseresults.getExceptions().values().iterator().next() : (parseresults.getContext().getRange().isEmpty() ? CommandSyntaxException.BUILT_IN_EXCEPTIONS.dispatcherUnknownCommand().createWithContext(parseresults.getReader()) : CommandSyntaxException.BUILT_IN_EXCEPTIONS.dispatcherUnknownArgument().createWithContext(parseresults.getReader())));
+ public static <S> CommandSyntaxException getParseException(ParseResults<S> result) {
+ return !result.getReader().canRead() ? null : (result.getExceptions().size() == 1 ? (CommandSyntaxException) result.getExceptions().values().iterator().next() : (result.getContext().getRange().isEmpty() ? CommandSyntaxException.BUILT_IN_EXCEPTIONS.dispatcherUnknownCommand().createWithContext(result.getReader()) : CommandSyntaxException.BUILT_IN_EXCEPTIONS.dispatcherUnknownArgument().createWithContext(result.getReader())));
}
- public static CommandBuildContext createValidationContext(final HolderLookup.Provider holderlookup_provider) {
+ public static CommandBuildContext createValidationContext(final HolderLookup.Provider provider) {
return new CommandBuildContext() {
@Override
- @Override
- public <T> HolderLookup<T> holderLookup(ResourceKey<? extends Registry<T>> resourcekey) {
- final HolderLookup.RegistryLookup<T> holderlookup_registrylookup = holderlookup_provider.lookupOrThrow(resourcekey);
+ public <T> HolderLookup<T> holderLookup(ResourceKey<? extends Registry<T>> registryResourceKey) {
+ final HolderLookup.RegistryLookup<T> holderlookup_c = provider.lookupOrThrow(registryResourceKey);
- return new HolderLookup.Delegate<T>(holderlookup_registrylookup) {
+ return new HolderLookup.Delegate<T>(holderlookup_c) {
@Override
- @Override
- public Optional<HolderSet.Named<T>> get(TagKey<T> tagkey) {
- return Optional.of(this.getOrThrow(tagkey));
+ public Optional<HolderSet.Named<T>> get(TagKey<T> tagKey) {
+ return Optional.of(this.getOrThrow(tagKey));
}
@Override
- @Override
- public HolderSet.Named<T> getOrThrow(TagKey<T> tagkey) {
- Optional<HolderSet.Named<T>> optional = holderlookup_registrylookup.get(tagkey);
+ public HolderSet.Named<T> getOrThrow(TagKey<T> tagKey) {
+ Optional<HolderSet.Named<T>> optional = holderlookup_c.get(tagKey);
return (HolderSet.Named) optional.orElseGet(() -> {
- return HolderSet.emptyNamed(holderlookup_registrylookup, tagkey);
+ return HolderSet.emptyNamed(holderlookup_c, tagKey);
});
}
};
@@ -488,11 +570,11 @@
public static void validate() {
CommandBuildContext commandbuildcontext = createValidationContext(VanillaRegistries.createLookup());
- CommandDispatcher<CommandSourceStack> commanddispatcher = (new Commands(Commands.CommandSelection.ALL, commandbuildcontext)).getDispatcher();
- RootCommandNode<CommandSourceStack> rootcommandnode = commanddispatcher.getRoot();
+ com.mojang.brigadier.CommandDispatcher<CommandSourceStack> com_mojang_brigadier_commanddispatcher = (new Commands(Commands.CommandSelection.ALL, commandbuildcontext)).getDispatcher();
+ RootCommandNode<CommandSourceStack> rootcommandnode = com_mojang_brigadier_commanddispatcher.getRoot();
- commanddispatcher.findAmbiguities((commandnode, commandnode1, commandnode2, collection) -> {
- Commands.LOGGER.warn("Ambiguity between arguments {} and {} with inputs: {}", new Object[]{commanddispatcher.getPath(commandnode1), commanddispatcher.getPath(commandnode2), collection});
+ com_mojang_brigadier_commanddispatcher.findAmbiguities((commandnode, commandnode1, commandnode2, collection) -> {
+ Commands.LOGGER.warn("Ambiguity between arguments {} and {} with inputs: {}", new Object[]{com_mojang_brigadier_commanddispatcher.getPath(commandnode1), com_mojang_brigadier_commanddispatcher.getPath(commandnode2), collection});
});
Set<ArgumentType<?>> set = ArgumentUtils.findUsedArgumentTypes(rootcommandnode);
Set<ArgumentType<?>> set1 = (Set) set.stream().filter((argumenttype) -> {
|