From 8baa0f2a64e0039d0df7d168e30c03a22c60bfb4 Mon Sep 17 00:00:00 2001 From: alemi Date: Sat, 11 Mar 2023 22:53:03 +0100 Subject: chore: moved cmdpatch into cmdpatch class --- src/main/java/ftbsc/bscv/Boscovicino.java | 4 ++-- .../java/ftbsc/bscv/events/CommandsBuiltEvent.java | 19 ------------------- src/main/java/ftbsc/bscv/patches/CommandsPatch.java | 17 ++++++++++++----- 3 files changed, 14 insertions(+), 26 deletions(-) delete mode 100644 src/main/java/ftbsc/bscv/events/CommandsBuiltEvent.java (limited to 'src/main/java') diff --git a/src/main/java/ftbsc/bscv/Boscovicino.java b/src/main/java/ftbsc/bscv/Boscovicino.java index d1f4531..90dc5b4 100644 --- a/src/main/java/ftbsc/bscv/Boscovicino.java +++ b/src/main/java/ftbsc/bscv/Boscovicino.java @@ -5,7 +5,7 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.tree.CommandNode; import ftbsc.bscv.api.IModule; -import ftbsc.bscv.events.CommandsBuiltEvent; +import ftbsc.bscv.patches.CommandsPatch.CommandsBuiltEvent; import ftbsc.bscv.system.Friends; import ftbsc.bscv.system.ModManager; import net.minecraft.client.gui.screen.IngameMenuScreen; @@ -86,7 +86,7 @@ public class Boscovicino implements ICommons { @SubscribeEvent public void onCommandSuggestionsBuilt(CommandsBuiltEvent event) { for (CommandNode child : this.dispatcher.getRoot().getChildren()) { - event.dispatcher().getRoot().addChild(child); + event.dispatcher.getRoot().addChild(child); } } diff --git a/src/main/java/ftbsc/bscv/events/CommandsBuiltEvent.java b/src/main/java/ftbsc/bscv/events/CommandsBuiltEvent.java deleted file mode 100644 index 99a2dde..0000000 --- a/src/main/java/ftbsc/bscv/events/CommandsBuiltEvent.java +++ /dev/null @@ -1,19 +0,0 @@ -package ftbsc.bscv.events; - -import com.mojang.brigadier.CommandDispatcher; - -import net.minecraft.command.CommandSource; -import net.minecraft.command.ISuggestionProvider; -import net.minecraftforge.eventbus.api.Event; - -public class CommandsBuiltEvent extends Event { - private CommandDispatcher dispatcher; - - public CommandDispatcher dispatcher() { - return this.dispatcher; - } - - public CommandsBuiltEvent(CommandDispatcher dispatcher) { - this.dispatcher = dispatcher; - } -} diff --git a/src/main/java/ftbsc/bscv/patches/CommandsPatch.java b/src/main/java/ftbsc/bscv/patches/CommandsPatch.java index 410b660..0e8dd2a 100644 --- a/src/main/java/ftbsc/bscv/patches/CommandsPatch.java +++ b/src/main/java/ftbsc/bscv/patches/CommandsPatch.java @@ -1,6 +1,5 @@ package ftbsc.bscv.patches; -import ftbsc.bscv.events.CommandsBuiltEvent; import ftbsc.lll.processor.annotations.Injector; import ftbsc.lll.processor.annotations.Patch; import ftbsc.lll.processor.annotations.Target; @@ -10,6 +9,8 @@ import net.minecraft.client.network.play.ClientPlayNetHandler; import net.minecraft.command.CommandSource; import net.minecraft.network.play.server.SCommandListPacket; import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.eventbus.api.Event; + import org.objectweb.asm.Opcodes; import org.objectweb.asm.tree.*; @@ -17,12 +18,18 @@ import com.mojang.brigadier.CommandDispatcher; public class CommandsPatch { - public static class CommandsHook { - public static void cmdBuilt(CommandDispatcher dispatcher) { - MinecraftForge.EVENT_BUS.post(new CommandsBuiltEvent(dispatcher)); + public static class CommandsBuiltEvent extends Event { + public final CommandDispatcher dispatcher; + + public CommandsBuiltEvent(CommandDispatcher dispatcher) { + this.dispatcher = dispatcher; } } + public static void cmdBuilt(CommandDispatcher dispatcher) { + MinecraftForge.EVENT_BUS.post(new CommandsBuiltEvent(dispatcher)); + } + @Patch(value = ClientPlayNetHandler.class, reason = "add hook to insert our command suggestions") public abstract static class CommandsDispatcherCatcher implements Opcodes { @Target @@ -44,7 +51,7 @@ public class CommandsPatch { is.add(new InsnNode(DUP)); is.add(new MethodInsnNode( INVOKESTATIC, - "ftbsc/bscv/patches/CommandsPatch$CommandsHook", + "ftbsc/bscv/patches/CommandsPatch", "cmdBuilt", "(Lcom/mojang/brigadier/CommandDispatcher;)V" )); -- cgit v1.2.3-56-ga3b1