From c87965bff7c8818e4d49561f5369209d406da4b2 Mon Sep 17 00:00:00 2001 From: RappyTV Date: Sun, 17 Mar 2024 13:34:46 +0100 Subject: [PATCH 1/5] Bump labygradle --- settings.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.gradle.kts b/settings.gradle.kts index 70340cb..9acc7d0 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,7 +1,7 @@ rootProject.name = "OPSUCHT-Utilities" pluginManagement { - val labyGradlePluginVersion = "0.3.38" + val labyGradlePluginVersion = "0.3.44" plugins { id("net.labymod.gradle") version (labyGradlePluginVersion) } From d5d46d358ae26d11ef57e9b2dd06df38430accd7 Mon Sep 17 00:00:00 2001 From: RappyTV Date: Sun, 17 Mar 2024 13:35:14 +0100 Subject: [PATCH 2/5] Register new versions --- build.gradle.kts | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index db1dea7..06508ed 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -26,15 +26,12 @@ labyMod { minecraft { registerVersions( - "1.8.9", - "1.12.2", - "1.16.5", - "1.17.1", - "1.18.2", "1.19.2", "1.19.3", "1.19.4", - "1.20.1" + "1.20.1", + "1.20.2", + "1.20.4" ) { version, provider -> configureRun(provider, version) } From 7a26dc0c35d38602af251f3e3a957c805fa96d42 Mon Sep 17 00:00:00 2001 From: RappyTV Date: Sun, 17 Mar 2024 14:34:17 +0100 Subject: [PATCH 3/5] Replace ServerNavigationListener by AbstractServer implementation --- .../com/rappytv/opsucht/OPSuchtAddon.java | 14 ++--- .../com/rappytv/opsucht/OPSuchtServer.java | 41 +++++++++++++ .../listeners/ServerNavigationListener.java | 57 ------------------- 3 files changed, 45 insertions(+), 67 deletions(-) create mode 100644 core/src/main/java/com/rappytv/opsucht/OPSuchtServer.java delete mode 100644 core/src/main/java/com/rappytv/opsucht/listeners/ServerNavigationListener.java diff --git a/core/src/main/java/com/rappytv/opsucht/OPSuchtAddon.java b/core/src/main/java/com/rappytv/opsucht/OPSuchtAddon.java index fd6ad40..29a705d 100644 --- a/core/src/main/java/com/rappytv/opsucht/OPSuchtAddon.java +++ b/core/src/main/java/com/rappytv/opsucht/OPSuchtAddon.java @@ -6,7 +6,6 @@ import com.rappytv.opsucht.context.PayContext; import com.rappytv.opsucht.listeners.ChatReceiveListener; import com.rappytv.opsucht.listeners.PlayerInfo; -import com.rappytv.opsucht.listeners.ServerNavigationListener; import com.rappytv.opsucht.managers.DiscordRPCManager; import net.labymod.api.Laby; import net.labymod.api.addon.LabyAddon; @@ -17,10 +16,9 @@ @AddonMain public class OPSuchtAddon extends LabyAddon { - public static final String[] ip = {"162.19.233.3", "141.95.85.60"}; public DiscordRPCManager rpcManager; private static OPSuchtAddon instance; - private static boolean connected = false; + private OPSuchtServer server; @Override protected void preConfigurationLoad() { @@ -36,10 +34,10 @@ protected void enable() { registerSettingCategory(); registerListener(new ChatReceiveListener(this)); registerListener(new PlayerInfo(this)); - registerListener(new ServerNavigationListener(this)); labyAPI().interactionMenuRegistry().register(new ClanInviteContext(this)); labyAPI().interactionMenuRegistry().register(new FriendRequestContext(this)); labyAPI().interactionMenuRegistry().register(new PayContext(this)); + labyAPI().serverController().registerServer(server = new OPSuchtServer(this)); } public static void updateRPC() { @@ -47,12 +45,8 @@ public static void updateRPC() { instance.rpcManager.updateCustomRPC(false); } - public static void setConnected(boolean value) { - connected = value; - } - - public static boolean isConnected() { - return connected; + public OPSuchtServer server() { + return server; } @Override diff --git a/core/src/main/java/com/rappytv/opsucht/OPSuchtServer.java b/core/src/main/java/com/rappytv/opsucht/OPSuchtServer.java new file mode 100644 index 0000000..8fda8bd --- /dev/null +++ b/core/src/main/java/com/rappytv/opsucht/OPSuchtServer.java @@ -0,0 +1,41 @@ +package com.rappytv.opsucht; + +import net.labymod.api.Laby; +import net.labymod.api.client.network.server.AbstractServer; +import net.labymod.api.event.Phase; + +public class OPSuchtServer extends AbstractServer { + + private final OPSuchtAddon addon; + private boolean connected; + + public OPSuchtServer(OPSuchtAddon addon) { + super("opsucht"); + this.addon = addon; + connected = false; + } + + @Override + public void loginOrSwitch(LoginPhase phase) { + if(phase == LoginPhase.LOGIN) connected = true; + else if(phase == LoginPhase.SWITCH && addon.configuration().autoFly().get()) { + Laby.labyAPI().minecraft().executeNextTick(() -> + Laby.references().chatExecutor().chat("/fly", false) + ); + } + + Laby.labyAPI().minecraft().executeNextTick(() -> + addon.rpcManager.updateCustomRPC(phase == LoginPhase.LOGIN) + ); + } + + @Override + public void disconnect(Phase phase) { + if(phase == Phase.POST) connected = false; + addon.rpcManager.removeCustomRPC(); + } + + public boolean isConnected() { + return connected; + } +} diff --git a/core/src/main/java/com/rappytv/opsucht/listeners/ServerNavigationListener.java b/core/src/main/java/com/rappytv/opsucht/listeners/ServerNavigationListener.java deleted file mode 100644 index e74a17d..0000000 --- a/core/src/main/java/com/rappytv/opsucht/listeners/ServerNavigationListener.java +++ /dev/null @@ -1,57 +0,0 @@ -package com.rappytv.opsucht.listeners; - -import com.rappytv.opsucht.OPSuchtAddon; -import net.labymod.api.Laby; -import net.labymod.api.client.network.server.ServerData; -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.ServerSwitchEvent; -import net.labymod.api.event.client.network.server.SubServerSwitchEvent; - -public class ServerNavigationListener { - - private final OPSuchtAddon addon; - - public ServerNavigationListener(OPSuchtAddon addon) { - this.addon = addon; - } - - @Subscribe - public void onServerJoin(ServerJoinEvent event) { - if(isOpSucht(event.serverData())) { - OPSuchtAddon.setConnected(true); - Laby.labyAPI().minecraft().executeNextTick(() -> addon.rpcManager.updateCustomRPC(true)); - } - } - - @Subscribe - public void onServerSwitch(ServerSwitchEvent event) { - if(isOpSucht(event.newServerData())) { - OPSuchtAddon.setConnected(true); - Laby.labyAPI().minecraft().executeNextTick(() -> addon.rpcManager.updateCustomRPC(true)); - } - } - - @Subscribe - public void onSubServerSwitch(SubServerSwitchEvent event) { - if(OPSuchtAddon.isConnected()) { - Laby.labyAPI().minecraft().executeNextTick(() -> { - addon.rpcManager.updateCustomRPC(false); - if(addon.configuration().autoFly().get()) - Laby.labyAPI().minecraft().executeNextTick(() -> Laby.references().chatExecutor().chat("/fly", false)); - }); - } - } - - @Subscribe - public void onServerDisconnect(ServerDisconnectEvent event) { - OPSuchtAddon.setConnected(false); - addon.rpcManager.removeCustomRPC(); - } - - private boolean isOpSucht(ServerData data) { - if(data == null) return false; - return data.actualAddress().getAddress().getAddress().getHostAddress().equals(OPSuchtAddon.ip[0]) || data.actualAddress().getAddress().getAddress().getHostAddress().equals(OPSuchtAddon.ip[1]); - } -} From 4dec8f361fa3033de386f4ef0f5ffd4bacbb4994 Mon Sep 17 00:00:00 2001 From: RappyTV Date: Sun, 17 Mar 2024 14:36:09 +0100 Subject: [PATCH 4/5] Update references to isConnected method --- .../rappytv/opsucht/context/ClanInviteContext.java | 7 +++---- .../rappytv/opsucht/context/FriendRequestContext.java | 7 +++---- .../java/com/rappytv/opsucht/context/PayContext.java | 7 +++---- .../opsucht/listeners/ChatReceiveListener.java | 11 +++++------ .../com/rappytv/opsucht/listeners/PlayerInfo.java | 4 ++-- 5 files changed, 16 insertions(+), 20 deletions(-) diff --git a/core/src/main/java/com/rappytv/opsucht/context/ClanInviteContext.java b/core/src/main/java/com/rappytv/opsucht/context/ClanInviteContext.java index 832b3cb..aed98b3 100644 --- a/core/src/main/java/com/rappytv/opsucht/context/ClanInviteContext.java +++ b/core/src/main/java/com/rappytv/opsucht/context/ClanInviteContext.java @@ -1,7 +1,6 @@ package com.rappytv.opsucht.context; import com.rappytv.opsucht.OPSuchtAddon; -import com.rappytv.opsucht.config.OPSuchtConfig; import net.labymod.api.Laby; import net.labymod.api.client.component.Component; import net.labymod.api.client.entity.player.Player; @@ -11,10 +10,10 @@ public class ClanInviteContext implements BulletPoint { - private final OPSuchtConfig config; + private final OPSuchtAddon addon; public ClanInviteContext(OPSuchtAddon addon) { - this.config = addon.configuration(); + this.addon = addon; } @Override @@ -36,6 +35,6 @@ public void execute(Player player) { @Override public boolean isVisible(Player playerInfo) { - return OPSuchtAddon.isConnected() && config.contextSubconfig().clanInviteContext().get(); + return addon.server().isConnected() && addon.configuration().contextSubconfig().clanInviteContext().get(); } } diff --git a/core/src/main/java/com/rappytv/opsucht/context/FriendRequestContext.java b/core/src/main/java/com/rappytv/opsucht/context/FriendRequestContext.java index e52ced8..c57f3ff 100644 --- a/core/src/main/java/com/rappytv/opsucht/context/FriendRequestContext.java +++ b/core/src/main/java/com/rappytv/opsucht/context/FriendRequestContext.java @@ -1,7 +1,6 @@ package com.rappytv.opsucht.context; import com.rappytv.opsucht.OPSuchtAddon; -import com.rappytv.opsucht.config.OPSuchtConfig; import net.labymod.api.Laby; import net.labymod.api.client.component.Component; import net.labymod.api.client.entity.player.Player; @@ -11,10 +10,10 @@ public class FriendRequestContext implements BulletPoint { - private final OPSuchtConfig config; + private final OPSuchtAddon addon; public FriendRequestContext(OPSuchtAddon addon) { - this.config = addon.configuration(); + this.addon = addon; } @Override @@ -36,6 +35,6 @@ public void execute(Player player) { @Override public boolean isVisible(Player playerInfo) { - return OPSuchtAddon.isConnected() && config.contextSubconfig().friendRequestContext().get(); + return addon.server().isConnected() && addon.configuration().contextSubconfig().friendRequestContext().get(); } } diff --git a/core/src/main/java/com/rappytv/opsucht/context/PayContext.java b/core/src/main/java/com/rappytv/opsucht/context/PayContext.java index 9a22998..6e5004b 100644 --- a/core/src/main/java/com/rappytv/opsucht/context/PayContext.java +++ b/core/src/main/java/com/rappytv/opsucht/context/PayContext.java @@ -1,7 +1,6 @@ package com.rappytv.opsucht.context; import com.rappytv.opsucht.OPSuchtAddon; -import com.rappytv.opsucht.config.OPSuchtConfig; import net.labymod.api.Laby; import net.labymod.api.client.component.Component; import net.labymod.api.client.entity.player.Player; @@ -11,10 +10,10 @@ public class PayContext implements BulletPoint { - private final OPSuchtConfig config; + private final OPSuchtAddon addon; public PayContext(OPSuchtAddon addon) { - this.config = addon.configuration(); + this.addon = addon; } @Override @@ -36,6 +35,6 @@ public void execute(Player player) { @Override public boolean isVisible(Player playerInfo) { - return OPSuchtAddon.isConnected() && config.contextSubconfig().payContext().get(); + return addon.server().isConnected() && addon.configuration().contextSubconfig().payContext().get(); } } diff --git a/core/src/main/java/com/rappytv/opsucht/listeners/ChatReceiveListener.java b/core/src/main/java/com/rappytv/opsucht/listeners/ChatReceiveListener.java index 234777d..6b0233a 100644 --- a/core/src/main/java/com/rappytv/opsucht/listeners/ChatReceiveListener.java +++ b/core/src/main/java/com/rappytv/opsucht/listeners/ChatReceiveListener.java @@ -1,7 +1,6 @@ package com.rappytv.opsucht.listeners; import com.rappytv.opsucht.OPSuchtAddon; -import com.rappytv.opsucht.config.OPSuchtConfig; import net.labymod.api.client.component.Component; import net.labymod.api.client.component.TextComponent; import net.labymod.api.client.component.TranslatableComponent; @@ -17,27 +16,27 @@ public class ChatReceiveListener { - private final OPSuchtConfig config; + private final OPSuchtAddon addon; private final Pattern pattern = Pattern.compile("@\\w{3,16}", Pattern.CASE_INSENSITIVE); public ChatReceiveListener(OPSuchtAddon addon) { - this.config = addon.configuration(); + this.addon = addon; } @Subscribe public void onChatReceive(ChatReceiveEvent event) { - if(!OPSuchtAddon.isConnected()) return; + if(!addon.server().isConnected()) return; Component message = event.message(); String text = event.chatMessage().getPlainText(); - if(config.coloredMentions().get() && text.contains("@")) { + if(addon.configuration().coloredMentions().get() && text.contains("@")) { for(MatchResult matcher : pattern.matcher(text).results().toList()) { if(matcher.group().equals("@TEAM") || matcher.group().equals("@CLAN")) continue; replaceComponent(message, matcher.group(), () -> Component.text(matcher.group(), NamedTextColor.AQUA).copy()); } event.setMessage(message); } - if(config.clickableNicknames().get()) { + if(addon.configuration().clickableNicknames().get()) { if(!text.contains("|") || !text.contains("~") || text.length() < 3) return; String nick = text.split(" ")[2]; diff --git a/core/src/main/java/com/rappytv/opsucht/listeners/PlayerInfo.java b/core/src/main/java/com/rappytv/opsucht/listeners/PlayerInfo.java index 2c4139f..8feb2b4 100644 --- a/core/src/main/java/com/rappytv/opsucht/listeners/PlayerInfo.java +++ b/core/src/main/java/com/rappytv/opsucht/listeners/PlayerInfo.java @@ -16,13 +16,13 @@ public PlayerInfo(OPSuchtAddon addon) { @Subscribe public void onPlayerInfoAdd(PlayerInfoAddEvent event) { - if(!OPSuchtAddon.isConnected()) return; + if(!addon.server().isConnected()) return; Debounce.of("refresh-opsucht-discord-rpc", 2000, () -> addon.rpcManager.updateCustomRPC(false)); } @Subscribe public void onPlayerInfoRemove(PlayerInfoRemoveEvent event) { - if(!OPSuchtAddon.isConnected()) return; + if(!addon.server().isConnected()) return; Debounce.of("refresh-opsucht-discord-rpc", 2000, () -> addon.rpcManager.updateCustomRPC(false)); } From 5a3eac0b5bc2b4e54f84d2283a95ead178fac2ee Mon Sep 17 00:00:00 2001 From: RappyTV Date: Sun, 17 Mar 2024 14:39:57 +0100 Subject: [PATCH 5/5] Bump version --- build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle.kts b/build.gradle.kts index 06508ed..ef79132 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -21,7 +21,7 @@ labyMod { author = "RappyTV" description = "Adds some ingame utilities for OPSUCHT.net | Not affiliated with Interwebmedia GmbH" minecraftVersion = "1.19<*" - version = System.getenv().getOrDefault("VERSION", "1.1.9") + version = System.getenv().getOrDefault("VERSION", "1.2.0") } minecraft {