From d84c0500b3a2b766e99841669a0698fcf82fd6ff Mon Sep 17 00:00:00 2001 From: _Mads Date: Mon, 16 Dec 2024 18:09:11 +0100 Subject: [PATCH] Skift til labymod events --- .../volder/transporter/TransporterAddon.java | 1 - .../listeners/KeyboardListener.java | 8 +- .../transporter/modules/AutoGetModule.java | 21 +++-- .../transporter/modules/AutoTransporter.java | 52 ++++++++---- .../transporter/modules/BalanceModule.java | 26 +++--- .../transporter/modules/McmmoModule.java | 19 ++--- .../transporter/modules/MessagesModule.java | 13 +-- .../transporter/modules/ServerListModule.java | 11 +-- .../transporter/modules/ServerModule.java | 42 +++++++--- .../transporter/modules/SignToolsModule.java | 9 +- .../modules/TransporterMenuModule.java | 12 +-- .../modules/mcmmomodule/McmmoManager.java | 1 - .../modules/mcmmomodule/McmmoSkill.java | 2 - .../mcmmomodule/skills/AbilitySkill.java | 1 - .../unikapi/api/ApiReferenceStorage.java | 7 -- .../unikapi/api/ApiReferenceStorageLaby4.java | 36 -------- .../ClientKeyPressEvent.java | 60 -------------- .../impl/Laby4KeyPressEvent.java | 29 ------- .../ClientMessageEvent.java | 83 ------------------- .../impl/Laby4MessageEvent.java | 32 ------- .../clienttickevent/ClientTickEvent.java | 59 ------------- .../clienttickevent/impl/Laby4TickEvent.java | 34 -------- .../drawscreenevent/DrawScreenEvent.java | 81 ------------------ .../impl/Laby4DrawScreenEvent.java | 40 --------- .../sendmessageevent/SendMessageEvent.java | 76 ----------------- .../impl/Laby4SendMessageEvent.java | 33 -------- .../Laby4ServerSwitchEvent.java | 43 ---------- .../serverswitchevent/ServerSwitchEvent.java | 74 ----------------- .../unikapi/widgets/GuiModuleRenderer.java | 11 +-- 29 files changed, 133 insertions(+), 783 deletions(-) delete mode 100644 core/src/main/java/ml/volder/unikapi/event/events/clientkeypressevent/ClientKeyPressEvent.java delete mode 100644 core/src/main/java/ml/volder/unikapi/event/events/clientkeypressevent/impl/Laby4KeyPressEvent.java delete mode 100644 core/src/main/java/ml/volder/unikapi/event/events/clientmessageevent/ClientMessageEvent.java delete mode 100644 core/src/main/java/ml/volder/unikapi/event/events/clientmessageevent/impl/Laby4MessageEvent.java delete mode 100644 core/src/main/java/ml/volder/unikapi/event/events/clienttickevent/ClientTickEvent.java delete mode 100644 core/src/main/java/ml/volder/unikapi/event/events/clienttickevent/impl/Laby4TickEvent.java delete mode 100644 core/src/main/java/ml/volder/unikapi/event/events/drawscreenevent/DrawScreenEvent.java delete mode 100644 core/src/main/java/ml/volder/unikapi/event/events/drawscreenevent/impl/Laby4DrawScreenEvent.java delete mode 100644 core/src/main/java/ml/volder/unikapi/event/events/sendmessageevent/SendMessageEvent.java delete mode 100644 core/src/main/java/ml/volder/unikapi/event/events/sendmessageevent/impl/Laby4SendMessageEvent.java delete mode 100644 core/src/main/java/ml/volder/unikapi/event/events/serverswitchevent/Laby4ServerSwitchEvent.java delete mode 100644 core/src/main/java/ml/volder/unikapi/event/events/serverswitchevent/ServerSwitchEvent.java diff --git a/core/src/main/java/ml/volder/transporter/TransporterAddon.java b/core/src/main/java/ml/volder/transporter/TransporterAddon.java index 6e9877b..0b64a64 100644 --- a/core/src/main/java/ml/volder/transporter/TransporterAddon.java +++ b/core/src/main/java/ml/volder/transporter/TransporterAddon.java @@ -98,7 +98,6 @@ public void onEnable() { ModuleManager.getInstance().enableModules(); //Events - EventManager.registerEvents(new KeyboardListener()); EventManager.registerEvents(new MainMenuOpenListener()); //Developer tools diff --git a/core/src/main/java/ml/volder/transporter/listeners/KeyboardListener.java b/core/src/main/java/ml/volder/transporter/listeners/KeyboardListener.java index 2574236..bd986a9 100644 --- a/core/src/main/java/ml/volder/transporter/listeners/KeyboardListener.java +++ b/core/src/main/java/ml/volder/transporter/listeners/KeyboardListener.java @@ -4,14 +4,14 @@ import ml.volder.transporter.gui.TransporterModulesMenu; import ml.volder.unikapi.api.input.InputAPI; import ml.volder.unikapi.api.player.PlayerAPI; -import ml.volder.unikapi.event.EventHandler; import ml.volder.unikapi.event.Listener; -import ml.volder.unikapi.event.events.clientkeypressevent.ClientKeyPressEvent; import ml.volder.unikapi.keysystem.Key; +import net.labymod.api.event.Subscribe; +import net.labymod.api.event.client.input.KeyEvent; public class KeyboardListener implements Listener { - @EventHandler - public void onKeyInput(ClientKeyPressEvent event) { + @Subscribe + public void onKeyPress(KeyEvent event){ if(!TransporterAddon.isEnabled()) return; if(TransporterAddon.getInstance().getSettingsKeybind() == null || TransporterAddon.getInstance().getSettingsKeybind().equals(Key.NONE)) diff --git a/core/src/main/java/ml/volder/transporter/modules/AutoGetModule.java b/core/src/main/java/ml/volder/transporter/modules/AutoGetModule.java index db57310..75b2704 100644 --- a/core/src/main/java/ml/volder/transporter/modules/AutoGetModule.java +++ b/core/src/main/java/ml/volder/transporter/modules/AutoGetModule.java @@ -11,20 +11,23 @@ import ml.volder.unikapi.api.input.InputAPI; import ml.volder.unikapi.api.inventory.InventoryAPI; import ml.volder.unikapi.api.player.PlayerAPI; -import ml.volder.unikapi.event.EventHandler; import ml.volder.unikapi.event.EventManager; import ml.volder.unikapi.event.Listener; -import ml.volder.unikapi.event.events.clientkeypressevent.ClientKeyPressEvent; -import ml.volder.unikapi.event.events.clienttickevent.ClientTickEvent; import ml.volder.unikapi.guisystem.ModTextures; import ml.volder.unikapi.guisystem.elements.*; import ml.volder.unikapi.keysystem.Key; import ml.volder.unikapi.keysystem.impl.Laby4KeyMapper; import ml.volder.unikapi.types.Material; +import net.labymod.api.Laby; import net.labymod.api.client.gui.icon.Icon; import net.labymod.api.client.gui.screen.widget.widgets.input.KeybindWidget; import net.labymod.api.client.gui.screen.widget.widgets.input.SliderWidget; import net.labymod.api.client.gui.screen.widget.widgets.input.SwitchWidget; +import net.labymod.api.event.Phase; +import net.labymod.api.event.Subscribe; +import net.labymod.api.event.client.input.KeyEvent; +import net.labymod.api.event.client.lifecycle.GameTickEvent; +import org.jetbrains.annotations.NotNull; public class AutoGetModule extends SimpleModule implements Listener { @@ -71,7 +74,7 @@ public SimpleModule enable() { selectItemElement.getSubSettings().add(new HeaderElement("")); selectItemElement.setOpenSubSettings(false); AutoGetMenu.addSetting(selectItemElement); - EventManager.registerEvents(this); + Laby.labyAPI().eventBus().registerListener(this); return this; } @@ -82,8 +85,10 @@ public void loadConfig() { selectedItem = addon.getTransporterItemManager().getItemByType(getDataManager().getSettings().getData().has("selectedItem") ? getDataManager().getSettings().getData().get("selectedItem").getAsString() : "dirt"); } - @EventHandler - public void onTick(ClientTickEvent tickEvent) { + @Subscribe + public void onTick(@NotNull GameTickEvent event){ + if(event.phase() == Phase.POST) + return; if(!TransporterAddon.isEnabled() || !this.isEnabled || !this.isFeatureActive) return; if(onlyActiveInLobby && !TransporterAddon.getInstance().getServerList().contains(ModuleManager.getInstance().getModule(ServerModule.class).getCurrentServer())) @@ -99,8 +104,8 @@ public void onTick(ClientTickEvent tickEvent) { } } - @EventHandler - public void onKeyInput(ClientKeyPressEvent event) { + @Subscribe + public void onKeyPress(KeyEvent event){ if(!TransporterAddon.isEnabled() || !this.isFeatureActive) return; if(openKey == null || openKey.equals(Key.NONE)) diff --git a/core/src/main/java/ml/volder/transporter/modules/AutoTransporter.java b/core/src/main/java/ml/volder/transporter/modules/AutoTransporter.java index 57b370a..6325412 100644 --- a/core/src/main/java/ml/volder/transporter/modules/AutoTransporter.java +++ b/core/src/main/java/ml/volder/transporter/modules/AutoTransporter.java @@ -9,13 +9,8 @@ import ml.volder.unikapi.api.input.InputAPI; import ml.volder.unikapi.api.inventory.InventoryAPI; import ml.volder.unikapi.api.player.PlayerAPI; -import ml.volder.unikapi.event.EventHandler; import ml.volder.unikapi.event.EventManager; import ml.volder.unikapi.event.Listener; -import ml.volder.unikapi.event.events.clientkeypressevent.ClientKeyPressEvent; -import ml.volder.unikapi.event.events.clientmessageevent.ClientMessageEvent; -import ml.volder.unikapi.event.events.clienttickevent.ClientTickEvent; -import ml.volder.unikapi.event.events.serverswitchevent.ServerSwitchEvent; import ml.volder.unikapi.guisystem.ModTextures; import ml.volder.unikapi.keysystem.Key; import ml.volder.unikapi.keysystem.impl.Laby4KeyMapper; @@ -25,6 +20,15 @@ import net.labymod.api.client.gui.screen.widget.widgets.input.SliderWidget; import net.labymod.api.client.gui.screen.widget.widgets.input.SwitchWidget; import net.labymod.api.configuration.settings.type.SettingHeader; +import net.labymod.api.event.Phase; +import net.labymod.api.event.Subscribe; +import net.labymod.api.event.client.chat.ChatReceiveEvent; +import net.labymod.api.event.client.input.KeyEvent; +import net.labymod.api.event.client.lifecycle.GameTickEvent; +import net.labymod.api.event.client.network.server.ServerDisconnectEvent; +import net.labymod.api.event.client.network.server.ServerJoinEvent; +import net.labymod.api.event.client.network.server.SubServerSwitchEvent; +import org.jetbrains.annotations.NotNull; import java.util.HashMap; import java.util.Map; @@ -54,7 +58,7 @@ public SimpleModule init() { @Override public SimpleModule enable() { - EventManager.registerEvents(this); + Laby.labyAPI().eventBus().registerListener(this); return this; } @@ -111,8 +115,10 @@ public void loadConfig() { //hasTransporterData = hasConfigEntry("hasTransporterData") ? getConfigEntry("hasTransporterData", Boolean.class) : false; } - @EventHandler - public void onTick(ClientTickEvent tickEvent) { + @Subscribe + public void onTick(@NotNull GameTickEvent event){ + if(event.phase() == Phase.POST) + return; if(!TransporterAddon.isEnabled() || !this.isEnabled || !this.isFeatureActive) return; if(!TransporterAddon.getInstance().getServerList().contains(ModuleManager.getInstance().getModule(ServerModule.class).getCurrentServer())) @@ -164,8 +170,8 @@ private void executeAutoTransporterPutMineMethod() { timer = 0; } - @EventHandler - public void onKeyInput(ClientKeyPressEvent event) { + @Subscribe + public void onKeyPress(KeyEvent event){ if(!TransporterAddon.isEnabled() || !this.isFeatureActive) return; if(!TransporterAddon.getInstance().getServerList().contains(ModuleManager.getInstance().getModule(ServerModule.class).getCurrentServer())) @@ -176,20 +182,34 @@ public void onKeyInput(ClientKeyPressEvent event) { this.toggle(); } - @EventHandler - public void onMessage(ClientMessageEvent event) { - if(event.getCleanMessage().equals("Slår auto-transporter til! (all)") || event.getCleanMessage().equals("Slår auto-transporter til! (mine)")) { + @Subscribe + public void onMessage(ChatReceiveEvent event){ + if(event.chatMessage().getPlainText().equals("Slår auto-transporter til! (all)") || event.chatMessage().getPlainText().equals("Slår auto-transporter til! (mine)")) { isEnabled = true; - } else if (event.getCleanMessage().equals("Slår auto-transporter fra!")) { + } else if (event.chatMessage().getPlainText().equals("Slår auto-transporter fra!")) { isEnabled = false; } } - @EventHandler - public void onServerSwitch(ServerSwitchEvent event) { + public void onServerSwitch() { isEnabled = false; } + @Subscribe + public void onSubServerSwitch(@NotNull SubServerSwitchEvent event){ + onServerSwitch(); + } + + @Subscribe + public void onDisconnect(@NotNull ServerDisconnectEvent event){ + onServerSwitch(); + } + + @Subscribe + public void onJoin(@NotNull ServerJoinEvent event){ + onServerSwitch(); + } + public void toggle(){ isEnabled = !isEnabled; if(useAutoTransporterCommand) diff --git a/core/src/main/java/ml/volder/transporter/modules/BalanceModule.java b/core/src/main/java/ml/volder/transporter/modules/BalanceModule.java index f053db3..34321a6 100644 --- a/core/src/main/java/ml/volder/transporter/modules/BalanceModule.java +++ b/core/src/main/java/ml/volder/transporter/modules/BalanceModule.java @@ -15,22 +15,23 @@ import ml.volder.unikapi.event.EventHandler; import ml.volder.unikapi.event.EventManager; import ml.volder.unikapi.event.Listener; -import ml.volder.unikapi.event.events.clientmessageevent.ClientMessageEvent; -import ml.volder.unikapi.event.events.clienttickevent.ClientTickEvent; -import ml.volder.unikapi.event.events.serverswitchevent.ServerSwitchEvent; import ml.volder.unikapi.guisystem.ModTextures; import ml.volder.unikapi.logger.Logger; +import net.labymod.api.Laby; import net.labymod.api.client.gui.icon.Icon; import net.labymod.api.client.gui.screen.widget.widgets.input.SliderWidget; import net.labymod.api.client.gui.screen.widget.widgets.input.SwitchWidget; +import net.labymod.api.event.Phase; +import net.labymod.api.event.Subscribe; +import net.labymod.api.event.client.chat.ChatReceiveEvent; +import net.labymod.api.event.client.lifecycle.GameTickEvent; +import org.jetbrains.annotations.NotNull; import java.io.*; import java.math.BigDecimal; import java.nio.charset.StandardCharsets; import java.util.HashMap; import java.util.Map; -import java.util.Timer; -import java.util.TimerTask; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -52,6 +53,7 @@ public SimpleModule init() { @Override public SimpleModule enable() { EventManager.registerEvents(this); + Laby.labyAPI().eventBus().registerListener(this); return this; } @@ -159,13 +161,13 @@ public boolean isFeatureActive() { private BigDecimal balance = BigDecimal.valueOf(0); - @EventHandler - public void onMessage(ClientMessageEvent event) { + @Subscribe + public void onMessage(ChatReceiveEvent event) { if (!isFeatureActive() || !TransporterAddon.isEnabled()) return; - if(matchBalCommandMessage(event.getCleanMessage())) + if(matchBalCommandMessage(event.chatMessage().getPlainText())) event.setCancelled(true); - matchMessage(event.getCleanMessage()); + matchMessage(event.chatMessage().getPlainText()); } private void matchMessage(String clean) { @@ -228,8 +230,10 @@ public void onTransporterChannelRegister(TransporterChannelRegisteredEvent event } private int timer = 0; - @EventHandler - public void onTick(ClientTickEvent event) { + @Subscribe + public void onTick(@NotNull GameTickEvent event){ + if(event.phase() == Phase.POST) + return; if (!isFeatureActive() || !updateInterval) return; timer+=1; diff --git a/core/src/main/java/ml/volder/transporter/modules/McmmoModule.java b/core/src/main/java/ml/volder/transporter/modules/McmmoModule.java index 44a1ccf..9356516 100644 --- a/core/src/main/java/ml/volder/transporter/modules/McmmoModule.java +++ b/core/src/main/java/ml/volder/transporter/modules/McmmoModule.java @@ -5,16 +5,16 @@ import ml.volder.transporter.settings.accesors.SettingRegistryAccessor; import ml.volder.unikapi.UnikAPI; import ml.volder.unikapi.api.minecraft.MinecraftAPI; -import ml.volder.unikapi.event.EventHandler; import ml.volder.unikapi.event.EventManager; import ml.volder.unikapi.event.Listener; -import ml.volder.unikapi.event.events.clientmessageevent.ClientMessageEvent; -import ml.volder.unikapi.event.events.sendmessageevent.SendMessageEvent; import ml.volder.unikapi.logger.Logger; import net.labymod.api.Laby; import net.labymod.api.event.Phase; import net.labymod.api.event.Subscribe; import net.labymod.api.event.client.chat.ActionBarReceiveEvent; +import net.labymod.api.event.client.chat.ChatMessageSendEvent; +import net.labymod.api.event.client.chat.ChatReceiveEvent; +import org.jetbrains.annotations.NotNull; import java.util.Map; import java.util.Timer; @@ -37,7 +37,6 @@ public SimpleModule init() { @Override public SimpleModule enable() { mcmmoManager.registerModules(); - EventManager.registerEvents(this); Laby.labyAPI().eventBus().registerListener(this); return this; } @@ -47,11 +46,11 @@ public void fillSettings(SettingRegistryAccessor subSettings) { } - @EventHandler - public void onChatMessage(ClientMessageEvent event) { + @Subscribe + public void onChatMessage(ChatReceiveEvent event) { if(!TransporterAddon.isEnabled() || !this.isFeatureActive) return; - mcmmoManager.onMessageReceive(event.getCleanMessage()); + mcmmoManager.onMessageReceive(event.chatMessage().getPlainText()); } @Subscribe @@ -64,8 +63,8 @@ public void onActionBarMessage(ActionBarReceiveEvent event) { mcmmoManager.onMessageReceive(message); } - @EventHandler - public void onSendMessage(SendMessageEvent event) { + @Subscribe + public void onMessage(@NotNull ChatMessageSendEvent event){ if(!TransporterAddon.isEnabled() || !this.isFeatureActive) return; if(!event.getMessage().equals("/mcstats")) @@ -81,8 +80,6 @@ public void run() { } } }, 1000L); - - } public boolean isFeatureActive() { diff --git a/core/src/main/java/ml/volder/transporter/modules/MessagesModule.java b/core/src/main/java/ml/volder/transporter/modules/MessagesModule.java index c80a829..e15da63 100644 --- a/core/src/main/java/ml/volder/transporter/modules/MessagesModule.java +++ b/core/src/main/java/ml/volder/transporter/modules/MessagesModule.java @@ -8,17 +8,18 @@ import ml.volder.transporter.settings.classes.TransporterWidgetFactory; import ml.volder.transporter.utils.FormatingUtils; import ml.volder.unikapi.UnikAPI; -import ml.volder.unikapi.event.EventHandler; import ml.volder.unikapi.event.EventManager; import ml.volder.unikapi.event.Listener; -import ml.volder.unikapi.event.events.clientmessageevent.ClientMessageEvent; import ml.volder.unikapi.guisystem.ModTextures; import ml.volder.unikapi.logger.Logger; +import net.labymod.api.Laby; import net.labymod.api.client.gui.icon.Icon; import net.labymod.api.client.gui.screen.widget.widgets.input.SwitchWidget; import net.labymod.api.client.gui.screen.widget.widgets.input.TextFieldWidget; import net.labymod.api.client.gui.screen.widget.widgets.input.dropdown.DropdownWidget; import net.labymod.api.configuration.settings.type.SettingElement; +import net.labymod.api.event.Subscribe; +import net.labymod.api.event.client.chat.ChatReceiveEvent; import java.io.*; import java.nio.charset.StandardCharsets; @@ -117,7 +118,7 @@ private void loadMessageRegexFromCsv() { @Override public SimpleModule enable() { - EventManager.registerEvents(this); + Laby.labyAPI().eventBus().registerListener(this); return this; } @@ -239,15 +240,15 @@ private SettingElement createMessageSetting(String id, String defaultValue, Icon .build(); } - @EventHandler - public void onChatMessage(ClientMessageEvent event) { + @Subscribe + public void onChatMessage(ChatReceiveEvent event) { if(!TransporterAddon.isEnabled() || !this.isFeatureActive) return; if(onlyActiveInLobby && !TransporterAddon.getInstance().getServerList().contains(ModuleManager.getInstance().getModule(ServerModule.class).getCurrentServer())) return; AtomicBoolean isCancelled = new AtomicBoolean(false); messageHandlers.forEach(iMessageHandler -> { - boolean result = iMessageHandler.messageReceived(event.getMessage(), event.getCleanMessage()); + boolean result = iMessageHandler.messageReceived(event.chatMessage().getFormattedText(), event.chatMessage().getPlainText()); isCancelled.set(result || isCancelled.get()); }); if(isCancelled.get()) diff --git a/core/src/main/java/ml/volder/transporter/modules/ServerListModule.java b/core/src/main/java/ml/volder/transporter/modules/ServerListModule.java index 3225011..dac4793 100644 --- a/core/src/main/java/ml/volder/transporter/modules/ServerListModule.java +++ b/core/src/main/java/ml/volder/transporter/modules/ServerListModule.java @@ -8,15 +8,16 @@ import ml.volder.transporter.settings.classes.TransporterWidgetFactory; import ml.volder.unikapi.api.input.InputAPI; import ml.volder.unikapi.api.player.PlayerAPI; -import ml.volder.unikapi.event.EventHandler; import ml.volder.unikapi.event.EventManager; import ml.volder.unikapi.event.Listener; -import ml.volder.unikapi.event.events.clientkeypressevent.ClientKeyPressEvent; import ml.volder.unikapi.guisystem.ModTextures; import ml.volder.unikapi.keysystem.Key; import ml.volder.unikapi.keysystem.impl.Laby4KeyMapper; +import net.labymod.api.Laby; import net.labymod.api.client.gui.icon.Icon; import net.labymod.api.client.gui.screen.widget.widgets.input.KeybindWidget; +import net.labymod.api.event.Subscribe; +import net.labymod.api.event.client.input.KeyEvent; public class ServerListModule extends SimpleModule implements Listener { private Key openKey = Key.L; // Default key = L @@ -32,7 +33,7 @@ public SimpleModule init() { @Override public SimpleModule enable() { - EventManager.registerEvents(this); + Laby.labyAPI().eventBus().registerListener(this); return this; } @@ -51,8 +52,8 @@ public void fillSettings(SettingRegistryAccessor subSettings) { ); } - @EventHandler - public void onKeyInput(ClientKeyPressEvent event) { + @Subscribe + public void onKeyPress(KeyEvent event){ if(!TransporterAddon.isEnabled() || !this.isFeatureActive) return; if(openKey == null || openKey.equals(Key.NONE)) diff --git a/core/src/main/java/ml/volder/transporter/modules/ServerModule.java b/core/src/main/java/ml/volder/transporter/modules/ServerModule.java index b766c6c..9a7ff8e 100644 --- a/core/src/main/java/ml/volder/transporter/modules/ServerModule.java +++ b/core/src/main/java/ml/volder/transporter/modules/ServerModule.java @@ -2,13 +2,17 @@ import ml.volder.transporter.settings.accesors.SettingRegistryAccessor; import ml.volder.unikapi.api.player.PlayerAPI; -import ml.volder.unikapi.event.EventHandler; import ml.volder.unikapi.event.EventManager; import ml.volder.unikapi.event.Listener; -import ml.volder.unikapi.event.events.clientmessageevent.ClientMessageEvent; -import ml.volder.unikapi.event.events.serverswitchevent.ServerSwitchEvent; import ml.volder.unikapi.types.Material; import ml.volder.unikapi.widgets.ModuleSystem; +import net.labymod.api.Laby; +import net.labymod.api.event.Subscribe; +import net.labymod.api.event.client.chat.ChatReceiveEvent; +import net.labymod.api.event.client.network.server.ServerDisconnectEvent; +import net.labymod.api.event.client.network.server.ServerJoinEvent; +import net.labymod.api.event.client.network.server.SubServerSwitchEvent; +import org.jetbrains.annotations.NotNull; import java.util.Timer; import java.util.TimerTask; @@ -28,7 +32,7 @@ public SimpleModule init() { @Override public SimpleModule enable() { registerModules(); - EventManager.registerEvents(this); + Laby.labyAPI().eventBus().registerListener(this); return this; } @@ -48,12 +52,12 @@ public boolean isFeatureActive() { private String currentServer; private boolean cancelNextServerCommand = false; - @EventHandler - public void onMessage(ClientMessageEvent event) { + @Subscribe + public void onMessage(ChatReceiveEvent event) { if (!isFeatureActive()) return; final Pattern pattern = Pattern.compile("^Du er lige nu forbundet til ([A-Za-z]+), brug /server for at joine en anden server.$"); - final Matcher matcher = pattern.matcher(event.getCleanMessage()); + final Matcher matcher = pattern.matcher(event.chatMessage().getPlainText()); if (matcher.find()) { currentServer = matcher.group(1); if (cancelNextServerCommand) { @@ -64,14 +68,9 @@ public void onMessage(ClientMessageEvent event) { } - @EventHandler - public void onServerSwitch(ServerSwitchEvent event) { + public void onServerSwitch() { if (!isFeatureActive()) return; - if(event.getSwitchType() == ServerSwitchEvent.SWITCH_TYPE.LEAVE){ - currentServer = null; - return; - } currentServer = null; new Timer("updateServerStatus").schedule(new TimerTask() { @Override @@ -82,6 +81,23 @@ public void run() { }, 100L); } + @Subscribe + public void onDisconnect(@NotNull ServerDisconnectEvent event){ + if (!isFeatureActive()) + return; + currentServer = null; + } + + @Subscribe + public void onSubServerSwitch(@NotNull SubServerSwitchEvent event){ + onServerSwitch(); + } + + @Subscribe + public void onJoin(@NotNull ServerJoinEvent event){ + onServerSwitch(); + } + private void registerModules() { ServerModule instance = ModuleManager.getInstance().getModule(ServerModule.class); ModuleSystem.registerModule("server", "Server", false, GuiModulesModule.getModuleRegistry().getOtherCategory(), Material.PAPER, s -> instance.isFeatureActive ? instance.currentServer == null ? "Opdatere!" : instance.currentServer.substring(0, 1).toUpperCase() + currentServer.substring(1) : "Server Tracker featuren er ikke aktiv!"); diff --git a/core/src/main/java/ml/volder/transporter/modules/SignToolsModule.java b/core/src/main/java/ml/volder/transporter/modules/SignToolsModule.java index b28a859..bf554d1 100644 --- a/core/src/main/java/ml/volder/transporter/modules/SignToolsModule.java +++ b/core/src/main/java/ml/volder/transporter/modules/SignToolsModule.java @@ -12,18 +12,20 @@ import ml.volder.unikapi.event.EventHandler; import ml.volder.unikapi.event.EventManager; import ml.volder.unikapi.event.Listener; -import ml.volder.unikapi.event.events.clientkeypressevent.ClientKeyPressEvent; import ml.volder.unikapi.event.events.opensignevent.OpenSignEvent; import ml.volder.unikapi.guisystem.ModTextures; import ml.volder.unikapi.keysystem.Key; import ml.volder.unikapi.keysystem.impl.Laby4KeyMapper; import ml.volder.unikapi.types.ModColor; import ml.volder.unikapi.wrappers.tileentitysign.WrappedTileEntitySign; +import net.labymod.api.Laby; import net.labymod.api.client.gui.icon.Icon; import net.labymod.api.client.gui.screen.widget.widgets.input.KeybindWidget; import net.labymod.api.client.gui.screen.widget.widgets.input.SliderWidget; import net.labymod.api.client.gui.screen.widget.widgets.input.SwitchWidget; import net.labymod.api.configuration.settings.type.SettingHeader; +import net.labymod.api.event.Subscribe; +import net.labymod.api.event.client.input.KeyEvent; import java.util.Timer; import java.util.TimerTask; @@ -51,6 +53,7 @@ public SimpleModule init() { @Override public SimpleModule enable() { EventManager.registerEvents(this); + Laby.labyAPI().eventBus().registerListener(this); return this; } @@ -170,8 +173,8 @@ public void run() { event.setScreen(new SignGui(getDataManager(), event.getTileEntitySign())); } - @EventHandler - public void onKeyInput(ClientKeyPressEvent event) { + @Subscribe + public void onKeyPress(KeyEvent event){ if(!TransporterAddon.isEnabled() || !this.isFeatureActive) return; if(toggleKey == null) diff --git a/core/src/main/java/ml/volder/transporter/modules/TransporterMenuModule.java b/core/src/main/java/ml/volder/transporter/modules/TransporterMenuModule.java index 806beb7..cc0417c 100644 --- a/core/src/main/java/ml/volder/transporter/modules/TransporterMenuModule.java +++ b/core/src/main/java/ml/volder/transporter/modules/TransporterMenuModule.java @@ -9,18 +9,18 @@ import ml.volder.transporter.settings.classes.TransporterWidgetFactory; import ml.volder.unikapi.api.input.InputAPI; import ml.volder.unikapi.api.player.PlayerAPI; -import ml.volder.unikapi.event.EventHandler; import ml.volder.unikapi.event.EventManager; import ml.volder.unikapi.event.Listener; -import ml.volder.unikapi.event.events.clientkeypressevent.ClientKeyPressEvent; import ml.volder.unikapi.guisystem.ModTextures; -import ml.volder.unikapi.guisystem.elements.Settings; import ml.volder.unikapi.keysystem.Key; import ml.volder.unikapi.keysystem.impl.Laby4KeyMapper; +import net.labymod.api.Laby; import net.labymod.api.client.gui.icon.Icon; import net.labymod.api.client.gui.screen.widget.widgets.input.KeybindWidget; import net.labymod.api.client.gui.screen.widget.widgets.input.SliderWidget; import net.labymod.api.client.gui.screen.widget.widgets.input.SwitchWidget; +import net.labymod.api.event.Subscribe; +import net.labymod.api.event.client.input.KeyEvent; import java.util.*; import java.util.stream.Collectors; @@ -44,7 +44,7 @@ public SimpleModule init() { @Override public SimpleModule enable() { - EventManager.registerEvents(this); + Laby.labyAPI().eventBus().registerListener(this); return this; } @@ -138,8 +138,8 @@ public void loadConfig() { } - @EventHandler - public void onKeyInput(ClientKeyPressEvent event) { + @Subscribe + public void onKeyPress(KeyEvent event){ if(!TransporterAddon.isEnabled() || !this.isFeatureActive) return; if(onlyActiveInLobby && !TransporterAddon.getInstance().getServerList().contains(ModuleManager.getInstance().getModule(ServerModule.class).getCurrentServer())) diff --git a/core/src/main/java/ml/volder/transporter/modules/mcmmomodule/McmmoManager.java b/core/src/main/java/ml/volder/transporter/modules/mcmmomodule/McmmoManager.java index 7b599f4..e9c918a 100644 --- a/core/src/main/java/ml/volder/transporter/modules/mcmmomodule/McmmoManager.java +++ b/core/src/main/java/ml/volder/transporter/modules/mcmmomodule/McmmoManager.java @@ -4,7 +4,6 @@ import ml.volder.transporter.modules.mcmmomodule.skills.SimpleSkill; import ml.volder.unikapi.datasystem.Data; import ml.volder.unikapi.datasystem.DataManager; -import ml.volder.unikapi.event.events.clientmessageevent.ClientMessageEvent; import ml.volder.unikapi.types.Material; import ml.volder.unikapi.widgets.ModuleSystem; diff --git a/core/src/main/java/ml/volder/transporter/modules/mcmmomodule/McmmoSkill.java b/core/src/main/java/ml/volder/transporter/modules/mcmmomodule/McmmoSkill.java index aac7462..340429d 100644 --- a/core/src/main/java/ml/volder/transporter/modules/mcmmomodule/McmmoSkill.java +++ b/core/src/main/java/ml/volder/transporter/modules/mcmmomodule/McmmoSkill.java @@ -1,7 +1,5 @@ package ml.volder.transporter.modules.mcmmomodule; -import ml.volder.unikapi.event.events.clientmessageevent.ClientMessageEvent; - public interface McmmoSkill { void updateLevel(int level); int getLevel(); diff --git a/core/src/main/java/ml/volder/transporter/modules/mcmmomodule/skills/AbilitySkill.java b/core/src/main/java/ml/volder/transporter/modules/mcmmomodule/skills/AbilitySkill.java index 3b72199..0086182 100644 --- a/core/src/main/java/ml/volder/transporter/modules/mcmmomodule/skills/AbilitySkill.java +++ b/core/src/main/java/ml/volder/transporter/modules/mcmmomodule/skills/AbilitySkill.java @@ -2,7 +2,6 @@ import ml.volder.unikapi.datasystem.Data; import ml.volder.unikapi.datasystem.DataManager; -import ml.volder.unikapi.event.events.clientmessageevent.ClientMessageEvent; import ml.volder.unikapi.types.ModColor; import ml.volder.unikapi.widgets.ModuleSystem; diff --git a/core/src/main/java/ml/volder/unikapi/api/ApiReferenceStorage.java b/core/src/main/java/ml/volder/unikapi/api/ApiReferenceStorage.java index 2dc59ed..c3ac869 100644 --- a/core/src/main/java/ml/volder/unikapi/api/ApiReferenceStorage.java +++ b/core/src/main/java/ml/volder/unikapi/api/ApiReferenceStorage.java @@ -17,15 +17,8 @@ public interface ApiReferenceStorage { MinecraftAPI getMinecraftAPI(); PlayerAPI getPlayerAPI(); - Class getVersionedClientKeyPressEvent(); - Class getVersionedClientMessageEvent(); - Class getVersionedClientTickEvent(); - Class getVersionedDrawScreenEvent(); Class getVersionedOpenSignEvent(); Class getVersionedMainMenuOpenEvent(); - Class getVersionedSendMessageEvent(); - Class getVersionedServerSwitchEvent(); - KeyMapper getVersionedKeyMapper(); diff --git a/core/src/main/java/ml/volder/unikapi/api/ApiReferenceStorageLaby4.java b/core/src/main/java/ml/volder/unikapi/api/ApiReferenceStorageLaby4.java index e2af063..ddb2bef 100644 --- a/core/src/main/java/ml/volder/unikapi/api/ApiReferenceStorageLaby4.java +++ b/core/src/main/java/ml/volder/unikapi/api/ApiReferenceStorageLaby4.java @@ -11,14 +11,8 @@ import ml.volder.unikapi.api.player.PlayerAPI; import ml.volder.unikapi.api.player.impl.Laby4PlayerAPI; import ml.volder.unikapi.event.EventImpl; -import ml.volder.unikapi.event.events.clientkeypressevent.impl.Laby4KeyPressEvent; -import ml.volder.unikapi.event.events.clientmessageevent.impl.Laby4MessageEvent; -import ml.volder.unikapi.event.events.clienttickevent.impl.Laby4TickEvent; -import ml.volder.unikapi.event.events.drawscreenevent.impl.Laby4DrawScreenEvent; import ml.volder.unikapi.event.events.mainmenuopenevent.impl.Laby4MainMenuOpenEvent; import ml.volder.unikapi.event.events.opensignevent.impl.Laby4OpenSignEvent; -import ml.volder.unikapi.event.events.sendmessageevent.impl.Laby4SendMessageEvent; -import ml.volder.unikapi.event.events.serverswitchevent.Laby4ServerSwitchEvent; import ml.volder.unikapi.keysystem.KeyMapper; import ml.volder.unikapi.keysystem.impl.Laby4KeyMapper; import ml.volder.unikapi.wrappers.guibutton.IGuiButtonImpl; @@ -61,26 +55,6 @@ public PlayerAPI getPlayerAPI() { return Laby4PlayerAPI.getAPI(); } - @Override - public Class getVersionedClientKeyPressEvent() { - return Laby4KeyPressEvent.class; - } - - @Override - public Class getVersionedClientMessageEvent() { - return Laby4MessageEvent.class; - } - - @Override - public Class getVersionedClientTickEvent() { - return Laby4TickEvent.class; - } - - @Override - public Class getVersionedDrawScreenEvent() { - return Laby4DrawScreenEvent.class; - } - @Override public Class getVersionedOpenSignEvent() { return Laby4OpenSignEvent.class; @@ -91,16 +65,6 @@ public Class getVersionedMainMenuOpenEvent() { return Laby4MainMenuOpenEvent.class; } - @Override - public Class getVersionedSendMessageEvent() { - return Laby4SendMessageEvent.class; - } - - @Override - public Class getVersionedServerSwitchEvent() { - return Laby4ServerSwitchEvent.class; - } - @Override public KeyMapper getVersionedKeyMapper() { return Laby4KeyMapper.getAPI(); diff --git a/core/src/main/java/ml/volder/unikapi/event/events/clientkeypressevent/ClientKeyPressEvent.java b/core/src/main/java/ml/volder/unikapi/event/events/clientkeypressevent/ClientKeyPressEvent.java deleted file mode 100644 index 6a4a7ba..0000000 --- a/core/src/main/java/ml/volder/unikapi/event/events/clientkeypressevent/ClientKeyPressEvent.java +++ /dev/null @@ -1,60 +0,0 @@ -package ml.volder.unikapi.event.events.clientkeypressevent; - -import ml.volder.unikapi.UnikAPI; -import ml.volder.unikapi.api.ApiManager; -import ml.volder.unikapi.api.ApiProvider; -import ml.volder.unikapi.api.ApiReferenceStorage; -import ml.volder.unikapi.event.Event; -import ml.volder.unikapi.event.EventImpl; -import ml.volder.unikapi.event.EventType; -import ml.volder.unikapi.event.Handler; -import ml.volder.unikapi.logger.Logger; - -import java.util.ArrayList; -import java.util.List; - -public class ClientKeyPressEvent extends Event { - - private static List handlerList = new ArrayList<>(); - - public ClientKeyPressEvent(EventType eventType, String eventName) { - super(eventType, eventName); - } - - public ClientKeyPressEvent(EventType eventType) { - super(eventType); - } - - public static List getHandlers(){ - return handlerList; - } - - @Override - public List getHandlerList() { - return handlerList; - } - - private static EventImpl eventImpl; - - public static boolean isRegistred() { - return eventImpl != null; - } - - - private static ApiProvider apiProvider = new ApiProvider<>("ClientKeyPressEvent"); - - //Registers event impl if not registred - public static void registerEvent() { - if(!isRegistred()){ - Class klass = ApiManager.getClassAPI(apiProvider, "ml.volder.unikapi.event.events.clientkeypressevent.impl", ApiReferenceStorage::getVersionedClientKeyPressEvent,EventImpl.class); - if(klass != null) { - try { - eventImpl = klass.newInstance(); - eventImpl.register(); - } catch (Exception e) { - UnikAPI.LOGGER.printStackTrace(Logger.LOG_LEVEL.INFO, e); - } - } - } - } -} diff --git a/core/src/main/java/ml/volder/unikapi/event/events/clientkeypressevent/impl/Laby4KeyPressEvent.java b/core/src/main/java/ml/volder/unikapi/event/events/clientkeypressevent/impl/Laby4KeyPressEvent.java deleted file mode 100644 index 017663d..0000000 --- a/core/src/main/java/ml/volder/unikapi/event/events/clientkeypressevent/impl/Laby4KeyPressEvent.java +++ /dev/null @@ -1,29 +0,0 @@ -package ml.volder.unikapi.event.events.clientkeypressevent.impl; - -import ml.volder.unikapi.SupportedClient; -import ml.volder.unikapi.event.EventImpl; -import ml.volder.unikapi.event.EventManager; -import ml.volder.unikapi.event.EventType; -import net.labymod.api.Laby; -import net.labymod.api.event.Subscribe; -import net.labymod.api.event.client.input.KeyEvent; - -@SupportedClient(clientBrand = "labymod4", minecraftVersion = "*") -public class Laby4KeyPressEvent implements EventImpl { - @Subscribe - public void onKeyPress(KeyEvent event){ - EventManager.callEvent(new ml.volder.unikapi.event.events.clientkeypressevent.ClientKeyPressEvent(EventType.PRE, getName())); - } - - @Override - public String getName() { - return "laby4-keypressevent"; - } - - @Override - public void register() { - Laby.labyAPI().eventBus().registerListener(this); - } - - -} diff --git a/core/src/main/java/ml/volder/unikapi/event/events/clientmessageevent/ClientMessageEvent.java b/core/src/main/java/ml/volder/unikapi/event/events/clientmessageevent/ClientMessageEvent.java deleted file mode 100644 index 9d6691a..0000000 --- a/core/src/main/java/ml/volder/unikapi/event/events/clientmessageevent/ClientMessageEvent.java +++ /dev/null @@ -1,83 +0,0 @@ -package ml.volder.unikapi.event.events.clientmessageevent; - -import ml.volder.unikapi.UnikAPI; -import ml.volder.unikapi.api.ApiManager; -import ml.volder.unikapi.api.ApiProvider; -import ml.volder.unikapi.api.ApiReferenceStorage; -import ml.volder.unikapi.event.*; -import ml.volder.unikapi.logger.Logger; - -import java.util.ArrayList; -import java.util.List; - -public class ClientMessageEvent extends Event implements Cancellable { - - private String message; - private String cleanMessage; - - private static List handlerList = new ArrayList<>(); - - public ClientMessageEvent(EventType eventType, String eventName, String message, String cleanMessage) { - super(eventType, eventName); - this.message = message; - this.cleanMessage = cleanMessage; - } - - public ClientMessageEvent(EventType eventType, String message, String cleanMessage) { - super(eventType); - this.message = message; - this.cleanMessage = cleanMessage; - } - - public static List getHandlers(){ - return handlerList; - } - - @Override - public List getHandlerList() { - return handlerList; - } - - private static EventImpl eventImpl; - - public static boolean isRegistred() { - return eventImpl != null; - } - - private static ApiProvider apiProvider = new ApiProvider<>("ClientMessageEvent"); - - //Registers event impl if not registred - public static void registerEvent() { - if(!isRegistred()){ - Class klass = ApiManager.getClassAPI(apiProvider, "ml.volder.unikapi.event.events.clientmessageevent.impl", ApiReferenceStorage::getVersionedClientMessageEvent,EventImpl.class); - if(klass != null) { - try { - eventImpl = klass.newInstance(); - eventImpl.register(); - } catch (Exception e) { - UnikAPI.LOGGER.printStackTrace(Logger.LOG_LEVEL.INFO, e); - } - } - } - } - - public String getMessage() { - return message; - } - - public String getCleanMessage() { - return cleanMessage; - } - - private boolean isCancelled = false; - - @Override - public boolean isCancelled() { - return isCancelled; - } - - @Override - public void setCancelled(boolean cancel) { - isCancelled = cancel; - } -} diff --git a/core/src/main/java/ml/volder/unikapi/event/events/clientmessageevent/impl/Laby4MessageEvent.java b/core/src/main/java/ml/volder/unikapi/event/events/clientmessageevent/impl/Laby4MessageEvent.java deleted file mode 100644 index 909bc1a..0000000 --- a/core/src/main/java/ml/volder/unikapi/event/events/clientmessageevent/impl/Laby4MessageEvent.java +++ /dev/null @@ -1,32 +0,0 @@ -package ml.volder.unikapi.event.events.clientmessageevent.impl; - -import ml.volder.unikapi.SupportedClient; -import ml.volder.unikapi.event.EventImpl; -import ml.volder.unikapi.event.EventManager; -import ml.volder.unikapi.event.EventType; -import ml.volder.unikapi.event.events.clientmessageevent.ClientMessageEvent; -import net.labymod.api.Laby; -import net.labymod.api.event.Subscribe; -import net.labymod.api.event.client.chat.ChatReceiveEvent; - -@SupportedClient(clientBrand = "labymod4", minecraftVersion = "*") -public class Laby4MessageEvent implements EventImpl { - @Subscribe - public void onMessage(ChatReceiveEvent event){ - ClientMessageEvent messageEvent = new ClientMessageEvent(EventType.PRE, getName(), event.chatMessage().getFormattedText(), event.chatMessage().getPlainText()); - EventManager.callEvent(messageEvent); - event.setCancelled(messageEvent.isCancelled()); - } - - @Override - public String getName() { - return "laby4-messageevent"; - } - - @Override - public void register() { - Laby.labyAPI().eventBus().registerListener(this); - } - - -} diff --git a/core/src/main/java/ml/volder/unikapi/event/events/clienttickevent/ClientTickEvent.java b/core/src/main/java/ml/volder/unikapi/event/events/clienttickevent/ClientTickEvent.java deleted file mode 100644 index bca9dfe..0000000 --- a/core/src/main/java/ml/volder/unikapi/event/events/clienttickevent/ClientTickEvent.java +++ /dev/null @@ -1,59 +0,0 @@ -package ml.volder.unikapi.event.events.clienttickevent; - -import ml.volder.unikapi.UnikAPI; -import ml.volder.unikapi.api.ApiManager; -import ml.volder.unikapi.api.ApiProvider; -import ml.volder.unikapi.api.ApiReferenceStorage; -import ml.volder.unikapi.event.Event; -import ml.volder.unikapi.event.EventImpl; -import ml.volder.unikapi.event.EventType; -import ml.volder.unikapi.event.Handler; -import ml.volder.unikapi.logger.Logger; - -import java.util.ArrayList; -import java.util.List; - -public class ClientTickEvent extends Event { - - private static List handlerList = new ArrayList<>(); - - public ClientTickEvent(EventType eventType, String eventName) { - super(eventType, eventName); - } - - public ClientTickEvent(EventType eventType) { - super(eventType); - } - - public static List getHandlers(){ - return handlerList; - } - - @Override - public List getHandlerList() { - return handlerList; - } - - private static EventImpl eventImpl; - - public static boolean isRegistred() { - return eventImpl != null; - } - - //Registers event impl if not registred - - private static ApiProvider apiProvider = new ApiProvider<>("ClientTickEvent"); - public static void registerEvent() { - if(!isRegistred()){ - Class klass = ApiManager.getClassAPI(apiProvider, "ml.volder.unikapi.event.events.clienttickevent.impl", ApiReferenceStorage::getVersionedClientTickEvent,EventImpl.class); - if(klass != null) { - try { - eventImpl = klass.newInstance(); - eventImpl.register(); - } catch (Exception e) { - UnikAPI.LOGGER.printStackTrace(Logger.LOG_LEVEL.INFO, e); - } - } - } - } -} diff --git a/core/src/main/java/ml/volder/unikapi/event/events/clienttickevent/impl/Laby4TickEvent.java b/core/src/main/java/ml/volder/unikapi/event/events/clienttickevent/impl/Laby4TickEvent.java deleted file mode 100644 index e379a82..0000000 --- a/core/src/main/java/ml/volder/unikapi/event/events/clienttickevent/impl/Laby4TickEvent.java +++ /dev/null @@ -1,34 +0,0 @@ -package ml.volder.unikapi.event.events.clienttickevent.impl; - -import ml.volder.unikapi.SupportedClient; -import ml.volder.unikapi.event.EventImpl; -import ml.volder.unikapi.event.EventManager; -import ml.volder.unikapi.event.EventType; -import ml.volder.unikapi.event.events.clienttickevent.ClientTickEvent; -import net.labymod.api.Laby; -import net.labymod.api.event.Phase; -import net.labymod.api.event.Subscribe; -import net.labymod.api.event.client.lifecycle.GameTickEvent; -import org.jetbrains.annotations.NotNull; - -@SupportedClient(clientBrand = "labymod4", minecraftVersion = "*") -public class Laby4TickEvent implements EventImpl { - @Subscribe - public void onTick(@NotNull GameTickEvent event){ - if(event.phase() == Phase.POST) - return; - EventManager.callEvent(new ClientTickEvent(EventType.PRE, getName())); - } - - @Override - public String getName() { - return "laby4-tickevent"; - } - - @Override - public void register() { - Laby.labyAPI().eventBus().registerListener(this); - } - - -} diff --git a/core/src/main/java/ml/volder/unikapi/event/events/drawscreenevent/DrawScreenEvent.java b/core/src/main/java/ml/volder/unikapi/event/events/drawscreenevent/DrawScreenEvent.java deleted file mode 100644 index 6920c33..0000000 --- a/core/src/main/java/ml/volder/unikapi/event/events/drawscreenevent/DrawScreenEvent.java +++ /dev/null @@ -1,81 +0,0 @@ -package ml.volder.unikapi.event.events.drawscreenevent; - -import ml.volder.unikapi.UnikAPI; -import ml.volder.unikapi.api.ApiManager; -import ml.volder.unikapi.api.ApiProvider; -import ml.volder.unikapi.api.ApiReferenceStorage; -import ml.volder.unikapi.event.Event; -import ml.volder.unikapi.event.EventImpl; -import ml.volder.unikapi.event.EventType; -import ml.volder.unikapi.event.Handler; -import ml.volder.unikapi.logger.Logger; - -import java.util.ArrayList; -import java.util.List; - -public class DrawScreenEvent extends Event { - - private int mouseX; - private int mouseY; - private float renderPartialTicks; - - private static List handlerList = new ArrayList<>(); - - public DrawScreenEvent(EventType eventType, String eventName, int mouseX, int mouseY, float renderPartialTicks) { - super(eventType, eventName); - this.mouseX = mouseX; - this.mouseY = mouseY; - this.renderPartialTicks = renderPartialTicks; - } - - public DrawScreenEvent(EventType eventType, int mouseX, int mouseY, float renderPartialTicks) { - super(eventType); - this.mouseX = mouseX; - this.mouseY = mouseY; - this.renderPartialTicks = renderPartialTicks; - } - - public int getMouseX() { - return mouseX; - } - - public int getMouseY() { - return mouseY; - } - - public float getRenderPartialTicks() { - return renderPartialTicks; - } - - public static List getHandlers(){ - return handlerList; - } - - @Override - public List getHandlerList() { - return handlerList; - } - - private static EventImpl eventImpl; - - public static boolean isRegistred() { - return eventImpl != null; - } - - private static ApiProvider apiProvider = new ApiProvider<>("DrawScreenEvent"); - - //Registers event impl if not registred - public static void registerEvent() { - if(!isRegistred()){ - Class klass = ApiManager.getClassAPI(apiProvider, "ml.volder.unikapi.event.events.drawscreenevent.impl", ApiReferenceStorage::getVersionedDrawScreenEvent,EventImpl.class); - if(klass != null) { - try { - eventImpl = klass.newInstance(); - eventImpl.register(); - } catch (Exception e) { - UnikAPI.LOGGER.printStackTrace(Logger.LOG_LEVEL.INFO, e); - } - } - } - } -} diff --git a/core/src/main/java/ml/volder/unikapi/event/events/drawscreenevent/impl/Laby4DrawScreenEvent.java b/core/src/main/java/ml/volder/unikapi/event/events/drawscreenevent/impl/Laby4DrawScreenEvent.java deleted file mode 100644 index b4ba6ec..0000000 --- a/core/src/main/java/ml/volder/unikapi/event/events/drawscreenevent/impl/Laby4DrawScreenEvent.java +++ /dev/null @@ -1,40 +0,0 @@ -package ml.volder.unikapi.event.events.drawscreenevent.impl; - -import ml.volder.unikapi.SupportedClient; -import ml.volder.unikapi.api.draw.impl.Laby4DrawAPI; -import ml.volder.unikapi.event.EventImpl; -import ml.volder.unikapi.event.EventManager; -import ml.volder.unikapi.event.EventType; -import ml.volder.unikapi.event.events.drawscreenevent.DrawScreenEvent; -import net.labymod.api.Laby; -import net.labymod.api.client.gui.mouse.MutableMouse; -import net.labymod.api.client.render.matrix.Stack; -import net.labymod.api.event.Phase; -import net.labymod.api.event.Subscribe; -import net.labymod.api.event.client.render.overlay.IngameOverlayRenderEvent; - -@SupportedClient(clientBrand = "labymod4", minecraftVersion = "*") -public class Laby4DrawScreenEvent implements EventImpl { - @Subscribe - public void onDrawScreen(IngameOverlayRenderEvent event){ - if(event.phase() == Phase.POST){ - Stack currentStack = Laby4DrawAPI.CURRENT_RENDER_STACK; - Laby4DrawAPI.CURRENT_RENDER_STACK = event.stack(); - MutableMouse mouse = Laby.labyAPI().minecraft().mouse(); - EventManager.callEvent(new DrawScreenEvent(EventType.PRE, getName(), mouse.getX(), mouse.getY(), -1)); - Laby4DrawAPI.CURRENT_RENDER_STACK = currentStack; - } - } - - @Override - public String getName() { - return "laby4-drawscreenevent"; - } - - @Override - public void register() { - Laby.labyAPI().eventBus().registerListener(this); - } - - -} diff --git a/core/src/main/java/ml/volder/unikapi/event/events/sendmessageevent/SendMessageEvent.java b/core/src/main/java/ml/volder/unikapi/event/events/sendmessageevent/SendMessageEvent.java deleted file mode 100644 index 6cc2556..0000000 --- a/core/src/main/java/ml/volder/unikapi/event/events/sendmessageevent/SendMessageEvent.java +++ /dev/null @@ -1,76 +0,0 @@ -package ml.volder.unikapi.event.events.sendmessageevent; - -import ml.volder.unikapi.UnikAPI; -import ml.volder.unikapi.api.ApiManager; -import ml.volder.unikapi.api.ApiProvider; -import ml.volder.unikapi.api.ApiReferenceStorage; -import ml.volder.unikapi.event.*; -import ml.volder.unikapi.logger.Logger; - -import java.util.ArrayList; -import java.util.List; - -public class SendMessageEvent extends Event implements Cancellable { - - private String message; - - private static List handlerList = new ArrayList<>(); - - public SendMessageEvent(EventType eventType, String eventName, String message) { - super(eventType, eventName); - this.message = message; - } - - public SendMessageEvent(EventType eventType, String message) { - super(eventType); - this.message = message; - } - - public static List getHandlers(){ - return handlerList; - } - - @Override - public List getHandlerList() { - return handlerList; - } - - private static EventImpl eventImpl; - - public static boolean isRegistred() { - return eventImpl != null; - } - - private static ApiProvider apiProvider = new ApiProvider<>("SendMessageEvent"); - - //Registers event impl if not registred - public static void registerEvent() { - if(!isRegistred()){ - Class klass = ApiManager.getClassAPI(apiProvider, "ml.volder.unikapi.event.events.sendmessageevent.impl", ApiReferenceStorage::getVersionedSendMessageEvent,EventImpl.class); - if(klass != null) { - try { - eventImpl = klass.newInstance(); - eventImpl.register(); - } catch (Exception e) { - UnikAPI.LOGGER.printStackTrace(Logger.LOG_LEVEL.INFO, e); - } - } - } - } - - public String getMessage() { - return message; - } - - private boolean isCancelled = false; - - @Override - public boolean isCancelled() { - return isCancelled; - } - - @Override - public void setCancelled(boolean cancel) { - isCancelled = cancel; - } -} diff --git a/core/src/main/java/ml/volder/unikapi/event/events/sendmessageevent/impl/Laby4SendMessageEvent.java b/core/src/main/java/ml/volder/unikapi/event/events/sendmessageevent/impl/Laby4SendMessageEvent.java deleted file mode 100644 index 97851ee..0000000 --- a/core/src/main/java/ml/volder/unikapi/event/events/sendmessageevent/impl/Laby4SendMessageEvent.java +++ /dev/null @@ -1,33 +0,0 @@ -package ml.volder.unikapi.event.events.sendmessageevent.impl; - -import ml.volder.unikapi.SupportedClient; -import ml.volder.unikapi.event.EventImpl; -import ml.volder.unikapi.event.EventManager; -import ml.volder.unikapi.event.EventType; -import ml.volder.unikapi.event.events.sendmessageevent.SendMessageEvent; -import net.labymod.api.Laby; -import net.labymod.api.event.Subscribe; -import net.labymod.api.event.client.chat.ChatMessageSendEvent; -import org.jetbrains.annotations.NotNull; - -@SupportedClient(clientBrand = "labymod4", minecraftVersion = "*") -public class Laby4SendMessageEvent implements EventImpl { - @Subscribe - public void onMessage(@NotNull ChatMessageSendEvent event){ - SendMessageEvent e = new SendMessageEvent(EventType.PRE, getName(), event.getMessage()); - EventManager.callEvent(e); - event.setCancelled(e.isCancelled()); - } - - @Override - public String getName() { - return "laby4-sendmessageevent"; - } - - @Override - public void register() { - Laby.labyAPI().eventBus().registerListener(this); - } - - -} diff --git a/core/src/main/java/ml/volder/unikapi/event/events/serverswitchevent/Laby4ServerSwitchEvent.java b/core/src/main/java/ml/volder/unikapi/event/events/serverswitchevent/Laby4ServerSwitchEvent.java deleted file mode 100644 index cf03c4b..0000000 --- a/core/src/main/java/ml/volder/unikapi/event/events/serverswitchevent/Laby4ServerSwitchEvent.java +++ /dev/null @@ -1,43 +0,0 @@ -package ml.volder.unikapi.event.events.serverswitchevent; - -import ml.volder.unikapi.SupportedClient; -import ml.volder.unikapi.event.EventImpl; -import ml.volder.unikapi.event.EventManager; -import ml.volder.unikapi.event.EventType; -import ml.volder.unikapi.event.events.serverswitchevent.ServerSwitchEvent.SWITCH_TYPE; -import net.labymod.api.Laby; -import net.labymod.api.event.Subscribe; -import net.labymod.api.event.client.network.server.ServerDisconnectEvent; -import net.labymod.api.event.client.network.server.ServerJoinEvent; -import net.labymod.api.event.client.network.server.SubServerSwitchEvent; -import org.jetbrains.annotations.NotNull; - -@SupportedClient(clientBrand = "labymod4", minecraftVersion = "*") -public class Laby4ServerSwitchEvent implements EventImpl { - @Subscribe - public void onSubServerSwitch(@NotNull SubServerSwitchEvent event){ - EventManager.callEvent(new ServerSwitchEvent(EventType.PRE, getName(), SWITCH_TYPE.SWITCH_SUBSERVER)); - } - - @Subscribe - public void onDisconnect(@NotNull ServerDisconnectEvent event){ - EventManager.callEvent(new ServerSwitchEvent(EventType.PRE, getName(), SWITCH_TYPE.LEAVE)); - } - - @Subscribe - public void onJoin(@NotNull ServerJoinEvent event){ - EventManager.callEvent(new ServerSwitchEvent(EventType.PRE, getName(), SWITCH_TYPE.JOIN)); - } - - @Override - public String getName() { - return "laby4-serverswitchevent"; - } - - @Override - public void register() { - Laby.labyAPI().eventBus().registerListener(this); - } - - -} diff --git a/core/src/main/java/ml/volder/unikapi/event/events/serverswitchevent/ServerSwitchEvent.java b/core/src/main/java/ml/volder/unikapi/event/events/serverswitchevent/ServerSwitchEvent.java deleted file mode 100644 index 41db366..0000000 --- a/core/src/main/java/ml/volder/unikapi/event/events/serverswitchevent/ServerSwitchEvent.java +++ /dev/null @@ -1,74 +0,0 @@ -package ml.volder.unikapi.event.events.serverswitchevent; - -import ml.volder.unikapi.UnikAPI; -import ml.volder.unikapi.api.ApiManager; -import ml.volder.unikapi.api.ApiProvider; -import ml.volder.unikapi.api.ApiReferenceStorage; -import ml.volder.unikapi.event.Event; -import ml.volder.unikapi.event.EventImpl; -import ml.volder.unikapi.event.EventType; -import ml.volder.unikapi.event.Handler; -import ml.volder.unikapi.logger.Logger; - -import java.util.ArrayList; -import java.util.List; - -public class ServerSwitchEvent extends Event { - - public enum SWITCH_TYPE { - JOIN, - LEAVE, - SWITCH_SUBSERVER - } - - private SWITCH_TYPE switchType; - - private static List handlerList = new ArrayList<>(); - - public ServerSwitchEvent(EventType eventType, String eventName, SWITCH_TYPE switchType) { - super(eventType, eventName); - this.switchType = switchType; - } - - public ServerSwitchEvent(EventType eventType, SWITCH_TYPE switchType) { - super(eventType); - this.switchType = switchType; - } - - public SWITCH_TYPE getSwitchType() { - return switchType; - } - - public static List getHandlers(){ - return handlerList; - } - - @Override - public List getHandlerList() { - return handlerList; - } - - private static EventImpl eventImpl; - - public static boolean isRegistred() { - return eventImpl != null; - } - - - private static ApiProvider apiProvider = new ApiProvider<>("ServerSwitchEvent"); - - //Registers event impl if not registred - public static void registerEvent() { - if(!isRegistred()){ - Class klass = ApiManager.getClassAPI(apiProvider, "ml.volder.unikapi.event.events.serverswitchevent.impl", ApiReferenceStorage::getVersionedServerSwitchEvent,EventImpl.class); - if(klass != null) { - try { - eventImpl = klass.newInstance(); - eventImpl.register(); - } catch (Exception e) { - UnikAPI.LOGGER.printStackTrace(Logger.LOG_LEVEL.INFO, e); - } - } - } - } -} diff --git a/core/src/main/java/ml/volder/unikapi/widgets/GuiModuleRenderer.java b/core/src/main/java/ml/volder/unikapi/widgets/GuiModuleRenderer.java index 946f6b5..b910b0e 100644 --- a/core/src/main/java/ml/volder/unikapi/widgets/GuiModuleRenderer.java +++ b/core/src/main/java/ml/volder/unikapi/widgets/GuiModuleRenderer.java @@ -3,9 +3,7 @@ import ml.volder.unikapi.datasystem.Data; import ml.volder.unikapi.datasystem.DataManager; -import ml.volder.unikapi.event.EventHandler; import ml.volder.unikapi.event.Listener; -import ml.volder.unikapi.event.events.drawscreenevent.DrawScreenEvent; public class GuiModuleRenderer implements Listener { @@ -15,13 +13,10 @@ public GuiModuleRenderer(DefaultModuleManager moduleManager, DataManager d this.moduleManager = moduleManager; } - @EventHandler - public void drawScreenEvent(DrawScreenEvent event) { + public void drawScreenEvent(/*DrawScreenEvent event*/) { if(!ModuleSystem.shouldRenderModules()) return; - moduleManager.getGuiModuleList().forEach(guiModule -> { - if(guiModule.isEnabled()) - guiModule.drawModule(); - }); + // Not used anymore - drawn through the labymod widget system + //TODO remove old module system } }