[fix] stuff working now

This commit is contained in:
Hiajen Hiajen 2021-05-22 15:46:39 +02:00
parent 6a85ecabc3
commit 116c3142e3
5 changed files with 30 additions and 31 deletions

View file

@ -3,8 +3,6 @@ package net.saltymc.eaa;
import net.fabricmc.api.ModInitializer; import net.fabricmc.api.ModInitializer;
import net.saltymc.eaa.handler.CommandHandler; import net.saltymc.eaa.handler.CommandHandler;
import net.saltymc.eaa.handler.HandlerInterface; 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 net.saltymc.eaa.util.ResponseEntity;
import java.util.ArrayList; import java.util.ArrayList;
@ -12,12 +10,20 @@ import java.util.List;
public class EaaMod implements ModInitializer { public class EaaMod implements ModInitializer {
private static EaaMod instance;
private final List<HandlerInterface> handler; private final List<HandlerInterface> handler;
private final List<MixinInterface> mixins;
public EaaMod(){ public EaaMod(){
handler = new ArrayList<>(); handler = new ArrayList<>();
mixins = new ArrayList<>(); }
public static EaaMod getInstance(){
if (instance == null) {
instance = new EaaMod();
instance.onInitialize();
}
return instance;
} }
@Override @Override
@ -28,10 +34,6 @@ public class EaaMod implements ModInitializer {
System.out.println("EAA Mod initializing..."); System.out.println("EAA Mod initializing...");
//init Mixin
mixins.add(new ExampleMixin().init(this));
//Init CommandHandler //Init CommandHandler
handler.add(new CommandHandler()); handler.add(new CommandHandler());
@ -40,8 +42,9 @@ public class EaaMod implements ModInitializer {
public ResponseEntity onEvent(Object object){ public ResponseEntity onEvent(Object object){
for (HandlerInterface hi : handler) { for (HandlerInterface hi : handler) {
ResponseEntity handlerResponse = hi.handle(object); ResponseEntity handlerResponse = hi.handle(object);
if (handlerResponse.isWasHandled()) if (handlerResponse.isWasHandled()) {
return handlerResponse; // Events are exclusive yet return handlerResponse; // Events are exclusive yet
}
} }
return new ResponseEntity(false); return new ResponseEntity(false);

View file

@ -28,6 +28,7 @@ public class CommandHandler implements HandlerInterface {
public CommandHandler(){ public CommandHandler(){
LOGGER.info("init CommandHandler");
commands = new ArrayList<>(); commands = new ArrayList<>();
CommandHandler.commands.add(new EaaCommand()); CommandHandler.commands.add(new EaaCommand());

View file

@ -2,14 +2,25 @@ package net.saltymc.eaa.handler.commands;
import net.fabricmc.fabric.api.client.command.v1.FabricClientCommandSource; import net.fabricmc.fabric.api.client.command.v1.FabricClientCommandSource;
import net.minecraft.text.Text; 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 { public class EaaCommand implements Command {
private static final String COMMAND = "echo"; private static final String COMMAND = "echo";
private static final boolean INTERCEPT = true; private static final boolean INTERCEPT = true;
private static final Logger LOGGER = LogManager.getLogger();
public EaaCommand(){
LOGGER.info("Init EaaCommand");
}
@Override @Override
public boolean run( final FabricClientCommandSource cs, String[] args) { public boolean run( final FabricClientCommandSource cs, String[] args) {
System.out.println("on Command: " + args[0]);
if (!args[0].equalsIgnoreCase(COMMAND)) { if (!args[0].equalsIgnoreCase(COMMAND)) {
return false; return false;
} }

View file

@ -4,6 +4,8 @@ import net.minecraft.client.network.ClientPlayerEntity;
import net.saltymc.eaa.EaaMod; import net.saltymc.eaa.EaaMod;
import net.saltymc.eaa.handler.CommandHandler; import net.saltymc.eaa.handler.CommandHandler;
import net.saltymc.eaa.util.ResponseEntity; 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.Mixin;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Inject;
@ -18,22 +20,13 @@ public class ExampleMixin {
} }
*/ */
@Mixin(ClientPlayerEntity.class) @Mixin(ClientPlayerEntity.class)
public class ExampleMixin implements MixinInterface { //ClientPlayerEntityMixin public class ExampleMixin { //ClientPlayerEntityMixin
private EaaMod eaaMod;
public MixinInterface init(final EaaMod eaaMod){
this.eaaMod = eaaMod;
return this;
}
private static final Logger LOGGER = LogManager.getLogger();
@Inject(method = "sendChatMessage", at = @At("HEAD"), cancellable = true) @Inject(method = "sendChatMessage", at = @At("HEAD"), cancellable = true)
private void onSendChatMessage(String message, CallbackInfo info) { private void onSendChatMessage(String message, CallbackInfo info) {
System.out.println("in onSendChatMessage"); ResponseEntity responseEntity = EaaMod.getInstance().onEvent(message);
ResponseEntity responseEntity = eaaMod.onEvent(message);
if (responseEntity.isInterceptEvent()) if (responseEntity.isInterceptEvent())
info.cancel(); info.cancel();

View file

@ -1,9 +0,0 @@
package net.saltymc.eaa.mixin;
import net.saltymc.eaa.EaaMod;
public interface MixinInterface {
MixinInterface init(final EaaMod eaaMod);
}