Files
MinecraftForge/patches/minecraft/net/minecraft/commands/Commands.java.patch
T
sciwhiz12 5ef0d667e0 [1.18] Fix command redirects by replacing Commands#fillUsableCommands (#8616)
Commands#fillUsableCommands does not handle redirect nodes properly. It
blindly pulls from the cached node map for a redirect node, which may
have no result because the target node of the redirect has not been
visited yet.

CommandHelper#mergeCommandNode is better in this regard, because it
visits the target node of the redirect instead of blindly pulling from
the node map.

Fixes #7551
2022-06-05 15:47:52 +01:00

49 lines
2.6 KiB
Diff

--- a/net/minecraft/commands/Commands.java
+++ b/net/minecraft/commands/Commands.java
@@ -177,7 +_,7 @@
JfrCommand.m_183645_(this.f_82090_);
}
- if (SharedConstants.f_136183_) {
+ if (net.minecraftforge.gametest.ForgeGameTestHooks.isGametestEnabled()) {
TestCommand.m_127946_(this.f_82090_);
}
@@ -201,6 +_,7 @@
if (p_82093_.f_82144_) {
PublishCommand.m_138184_(this.f_82090_);
}
+ net.minecraftforge.event.ForgeEventFactory.onCommandRegister(this.f_82090_, p_82093_);
this.f_82090_.findAmbiguities((p_82108_, p_82109_, p_82110_, p_82111_) -> {
f_82089_.warn("Ambiguity between arguments {} and {} with inputs: {}", this.f_82090_.getPath(p_82109_), this.f_82090_.getPath(p_82110_), p_82111_);
@@ -220,7 +_,17 @@
try {
try {
- return this.f_82090_.execute(stringreader, p_82118_);
+ ParseResults<CommandSourceStack> parse = this.f_82090_.parse(stringreader, p_82118_);
+ net.minecraftforge.event.CommandEvent event = new net.minecraftforge.event.CommandEvent(parse);
+ if (net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(event)) {
+ if (event.getException() instanceof Exception exception) {
+ throw exception;
+ } else if (event.getException() != null) {
+ com.google.common.base.Throwables.throwIfUnchecked(event.getException());
+ }
+ return 1;
+ }
+ return this.f_82090_.execute(event.getParseResults());
} catch (CommandRuntimeException commandruntimeexception) {
p_82118_.m_81352_(commandruntimeexception.m_79226_());
return 0;
@@ -276,7 +_,8 @@
Map<CommandNode<CommandSourceStack>, CommandNode<SharedSuggestionProvider>> map = Maps.newHashMap();
RootCommandNode<SharedSuggestionProvider> rootcommandnode = new RootCommandNode<>();
map.put(this.f_82090_.getRoot(), rootcommandnode);
- this.m_82112_(this.f_82090_.getRoot(), rootcommandnode, p_82096_.m_20203_(), map);
+ // FORGE: Use our own command node merging method to handle redirect nodes properly, see issue #7551
+ net.minecraftforge.server.command.CommandHelper.mergeCommandNode(this.f_82090_.getRoot(), rootcommandnode, map, p_82096_.m_20203_(), ctx -> 0, suggest -> SuggestionProviders.m_121664_((com.mojang.brigadier.suggestion.SuggestionProvider<SharedSuggestionProvider>) (com.mojang.brigadier.suggestion.SuggestionProvider<?>) suggest));
p_82096_.f_8906_.m_141995_(new ClientboundCommandsPacket(rootcommandnode));
}