From 116c3142e3d98aaeff0aab668150fc16ae890536 Mon Sep 17 00:00:00 2001 From: "Ansgar [Hiajen]" Date: Sat, 22 May 2021 15:46:39 +0200 Subject: [PATCH] [fix] stuff working now --- src/main/java/net/saltymc/eaa/EaaMod.java | 23 +++++++++++-------- .../saltymc/eaa/handler/CommandHandler.java | 1 + .../eaa/handler/commands/EaaCommand.java | 11 +++++++++ .../net/saltymc/eaa/mixin/ExampleMixin.java | 17 ++++---------- .../net/saltymc/eaa/mixin/MixinInterface.java | 9 -------- 5 files changed, 30 insertions(+), 31 deletions(-) delete mode 100644 src/main/java/net/saltymc/eaa/mixin/MixinInterface.java diff --git a/src/main/java/net/saltymc/eaa/EaaMod.java b/src/main/java/net/saltymc/eaa/EaaMod.java index 68045a2..722d304 100644 --- a/src/main/java/net/saltymc/eaa/EaaMod.java +++ b/src/main/java/net/saltymc/eaa/EaaMod.java @@ -3,8 +3,6 @@ package net.saltymc.eaa; import net.fabricmc.api.ModInitializer; import net.saltymc.eaa.handler.CommandHandler; import net.saltymc.eaa.handler.HandlerInterface; -import net.saltymc.eaa.mixin.ExampleMixin; -import net.saltymc.eaa.mixin.MixinInterface; import net.saltymc.eaa.util.ResponseEntity; import java.util.ArrayList; @@ -12,12 +10,20 @@ import java.util.List; public class EaaMod implements ModInitializer { + private static EaaMod instance; private final List handler; - private final List mixins; public EaaMod(){ handler = new ArrayList<>(); - mixins = new ArrayList<>(); + } + + public static EaaMod getInstance(){ + if (instance == null) { + instance = new EaaMod(); + instance.onInitialize(); + } + + return instance; } @Override @@ -28,10 +34,6 @@ public class EaaMod implements ModInitializer { System.out.println("EAA Mod initializing..."); - //init Mixin - mixins.add(new ExampleMixin().init(this)); - - //Init CommandHandler handler.add(new CommandHandler()); @@ -40,8 +42,9 @@ public class EaaMod implements ModInitializer { public ResponseEntity onEvent(Object object){ for (HandlerInterface hi : handler) { ResponseEntity handlerResponse = hi.handle(object); - if (handlerResponse.isWasHandled()) - return handlerResponse; // Events are exclusive yet + if (handlerResponse.isWasHandled()) { + return handlerResponse; // Events are exclusive yet + } } return new ResponseEntity(false); diff --git a/src/main/java/net/saltymc/eaa/handler/CommandHandler.java b/src/main/java/net/saltymc/eaa/handler/CommandHandler.java index 81679d3..89feb82 100644 --- a/src/main/java/net/saltymc/eaa/handler/CommandHandler.java +++ b/src/main/java/net/saltymc/eaa/handler/CommandHandler.java @@ -28,6 +28,7 @@ public class CommandHandler implements HandlerInterface { public CommandHandler(){ + LOGGER.info("init CommandHandler"); commands = new ArrayList<>(); CommandHandler.commands.add(new EaaCommand()); diff --git a/src/main/java/net/saltymc/eaa/handler/commands/EaaCommand.java b/src/main/java/net/saltymc/eaa/handler/commands/EaaCommand.java index 9c3e9eb..54b7db7 100644 --- a/src/main/java/net/saltymc/eaa/handler/commands/EaaCommand.java +++ b/src/main/java/net/saltymc/eaa/handler/commands/EaaCommand.java @@ -2,14 +2,25 @@ package net.saltymc.eaa.handler.commands; import net.fabricmc.fabric.api.client.command.v1.FabricClientCommandSource; import net.minecraft.text.Text; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import java.util.Arrays; public class EaaCommand implements Command { private static final String COMMAND = "echo"; private static final boolean INTERCEPT = true; + private static final Logger LOGGER = LogManager.getLogger(); + + public EaaCommand(){ + LOGGER.info("Init EaaCommand"); + } @Override public boolean run( final FabricClientCommandSource cs, String[] args) { + System.out.println("on Command: " + args[0]); + if (!args[0].equalsIgnoreCase(COMMAND)) { return false; } diff --git a/src/main/java/net/saltymc/eaa/mixin/ExampleMixin.java b/src/main/java/net/saltymc/eaa/mixin/ExampleMixin.java index e68aea6..3236563 100644 --- a/src/main/java/net/saltymc/eaa/mixin/ExampleMixin.java +++ b/src/main/java/net/saltymc/eaa/mixin/ExampleMixin.java @@ -4,6 +4,8 @@ import net.minecraft.client.network.ClientPlayerEntity; import net.saltymc.eaa.EaaMod; import net.saltymc.eaa.handler.CommandHandler; import net.saltymc.eaa.util.ResponseEntity; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -18,22 +20,13 @@ public class ExampleMixin { } */ @Mixin(ClientPlayerEntity.class) -public class ExampleMixin implements MixinInterface { //ClientPlayerEntityMixin - - private EaaMod eaaMod; - - public MixinInterface init(final EaaMod eaaMod){ - this.eaaMod = eaaMod; - - return this; - } +public class ExampleMixin { //ClientPlayerEntityMixin + private static final Logger LOGGER = LogManager.getLogger(); @Inject(method = "sendChatMessage", at = @At("HEAD"), cancellable = true) private void onSendChatMessage(String message, CallbackInfo info) { - System.out.println("in onSendChatMessage"); - - ResponseEntity responseEntity = eaaMod.onEvent(message); + ResponseEntity responseEntity = EaaMod.getInstance().onEvent(message); if (responseEntity.isInterceptEvent()) info.cancel(); diff --git a/src/main/java/net/saltymc/eaa/mixin/MixinInterface.java b/src/main/java/net/saltymc/eaa/mixin/MixinInterface.java deleted file mode 100644 index b9c6f14..0000000 --- a/src/main/java/net/saltymc/eaa/mixin/MixinInterface.java +++ /dev/null @@ -1,9 +0,0 @@ -package net.saltymc.eaa.mixin; - -import net.saltymc.eaa.EaaMod; - -public interface MixinInterface { - - MixinInterface init(final EaaMod eaaMod); - -}