|
| 1 | +package com.chattriggers.ctjs.mixins.commands; |
| 2 | + |
| 3 | +import com.llamalad7.mixinextras.sugar.Local; |
| 4 | +import com.mojang.brigadier.CommandDispatcher; |
| 5 | +import com.mojang.brigadier.ParseResults; |
| 6 | +import com.mojang.brigadier.StringReader; |
| 7 | +import com.mojang.brigadier.context.CommandContextBuilder; |
| 8 | +import com.mojang.brigadier.tree.CommandNode; |
| 9 | +import org.spongepowered.asm.mixin.Mixin; |
| 10 | +import org.spongepowered.asm.mixin.injection.At; |
| 11 | +import org.spongepowered.asm.mixin.injection.Inject; |
| 12 | +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; |
| 13 | + |
| 14 | +@Mixin(value = CommandDispatcher.class, remap = false) |
| 15 | +public class CommandDispatcherMixin { |
| 16 | + @Inject( |
| 17 | + method = "parseNodes", |
| 18 | + at = @At( |
| 19 | + value = "INVOKE", |
| 20 | + target = "Lcom/mojang/brigadier/context/CommandContextBuilder;withCommand(Lcom/mojang/brigadier/Command;)Lcom/mojang/brigadier/context/CommandContextBuilder;", |
| 21 | + shift = At.Shift.AFTER |
| 22 | + ) |
| 23 | + ) |
| 24 | + private <S> void addRedirectCommandToContextIfNecessary( |
| 25 | + CommandNode<S> node, |
| 26 | + StringReader originalReader, |
| 27 | + CommandContextBuilder<S> contextSoFar, |
| 28 | + CallbackInfoReturnable<ParseResults<S>> cir, |
| 29 | + @Local(ordinal = 1) CommandNode<S> child, |
| 30 | + @Local(ordinal = 1) CommandContextBuilder<S> context |
| 31 | + ) { |
| 32 | + // TODO: If there is a redirect modifier, this fix will ignore it. |
| 33 | + |
| 34 | + if (context.getCommand() == null && child.getRedirect() != null && child.getRedirect().getCommand() != null) |
| 35 | + context.withCommand(child.getRedirect().getCommand()); |
| 36 | + } |
| 37 | +} |
0 commit comments