Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skift til labymod events #62

Merged
merged 1 commit into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ public void onEnable() {
ModuleManager.getInstance().enableModules();

//Events
EventManager.registerEvents(new KeyboardListener());
EventManager.registerEvents(new MainMenuOpenListener());

//Developer tools
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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;
}

Expand All @@ -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()))
Expand All @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -54,7 +58,7 @@ public SimpleModule init() {

@Override
public SimpleModule enable() {
EventManager.registerEvents(this);
Laby.labyAPI().eventBus().registerListener(this);
return this;
}

Expand Down Expand Up @@ -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()))
Expand Down Expand Up @@ -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()))
Expand All @@ -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)
Expand Down
26 changes: 15 additions & 11 deletions core/src/main/java/ml/volder/transporter/modules/BalanceModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -52,6 +53,7 @@ public SimpleModule init() {
@Override
public SimpleModule enable() {
EventManager.registerEvents(this);
Laby.labyAPI().eventBus().registerListener(this);
return this;
}

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down
19 changes: 8 additions & 11 deletions core/src/main/java/ml/volder/transporter/modules/McmmoModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -37,7 +37,6 @@ public SimpleModule init() {
@Override
public SimpleModule enable() {
mcmmoManager.registerModules();
EventManager.registerEvents(this);
Laby.labyAPI().eventBus().registerListener(this);
return this;
}
Expand All @@ -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
Expand All @@ -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"))
Expand All @@ -81,8 +80,6 @@ public void run() {
}
}
}, 1000L);


}

public boolean isFeatureActive() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -117,7 +118,7 @@ private void loadMessageRegexFromCsv() {

@Override
public SimpleModule enable() {
EventManager.registerEvents(this);
Laby.labyAPI().eventBus().registerListener(this);
return this;
}

Expand Down Expand Up @@ -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())
Expand Down
Loading
Loading