From f2a336f0fad51c6efea571928ab3f6c30ef5cad2 Mon Sep 17 00:00:00 2001 From: Neocraftr <51837582+Neocraftr@users.noreply.github.com> Date: Mon, 24 Jul 2023 22:36:00 +0200 Subject: [PATCH] Added basic support for Griefergames Cloud --- .../neocraftr/griefergames/GrieferGames.java | 11 ++++ .../griefergames/enums/SubServerType.java | 6 ++ .../griefergames/listener/GGKeyListener.java | 61 ++++++++++--------- .../listener/GGMessageReceiveListener.java | 25 ++++---- .../listener/GGMessageSendListener.java | 25 ++++---- .../listener/GGScoreboardListener.java | 2 + .../listener/GGServerJoinListener.java | 11 ---- .../listener/GGSubServerChangeListener.java | 12 +++- .../listener/GGTablistListener.java | 41 +++++++++++++ .../griefergames/listener/GGTickListener.java | 19 +++--- .../neocraftr/griefergames/utils/Helper.java | 4 ++ 11 files changed, 146 insertions(+), 71 deletions(-) create mode 100644 core/src/main/java/de/neocraftr/griefergames/enums/SubServerType.java create mode 100644 core/src/main/java/de/neocraftr/griefergames/listener/GGTablistListener.java diff --git a/core/src/main/java/de/neocraftr/griefergames/GrieferGames.java b/core/src/main/java/de/neocraftr/griefergames/GrieferGames.java index 0b10306..77cf5ca 100644 --- a/core/src/main/java/de/neocraftr/griefergames/GrieferGames.java +++ b/core/src/main/java/de/neocraftr/griefergames/GrieferGames.java @@ -21,6 +21,7 @@ import de.neocraftr.griefergames.chat.modules.Vote; import de.neocraftr.griefergames.commands.GGMessageCommand; import de.neocraftr.griefergames.core.generated.DefaultReferenceStorage; +import de.neocraftr.griefergames.enums.SubServerType; import de.neocraftr.griefergames.hud.BoosterHudWidget; import de.neocraftr.griefergames.hud.DelayHudWidget; import de.neocraftr.griefergames.hud.FlyHudWidget; @@ -35,6 +36,7 @@ import de.neocraftr.griefergames.listener.GGServerMessageListener; import de.neocraftr.griefergames.listener.GGServerQuitListener; import de.neocraftr.griefergames.listener.GGSubServerChangeListener; +import de.neocraftr.griefergames.listener.GGTablistListener; import de.neocraftr.griefergames.listener.GGTickListener; import de.neocraftr.griefergames.settings.GrieferGamesConfig; import de.neocraftr.griefergames.utils.FileManager; @@ -76,6 +78,7 @@ public class GrieferGames extends LabyAddon { private long waitTime = 0; private boolean citybuildDelay = false; private String subServer = ""; + private SubServerType subServerType = SubServerType.REGULAR; private long lastActivety = 0; private boolean afk = false; private boolean hideBoosterMenu = false; @@ -101,6 +104,7 @@ protected void enable() { registerListener(new GGKeyListener(this)); registerListener(new GGServerMessageListener(this)); registerListener(new GGScoreboardListener(this)); + registerListener(new GGTablistListener(this)); registerListener(new GGSubServerChangeListener(this)); registerListener(new GGTickListener(this)); @@ -253,6 +257,13 @@ public void setSubServer(String subServer) { this.subServer = subServer; } + public SubServerType getSubServerType() { + return subServerType; + } + public void setSubServerType(SubServerType subServerType) { + this.subServerType = subServerType; + } + public long getLastActivety() { return lastActivety; } diff --git a/core/src/main/java/de/neocraftr/griefergames/enums/SubServerType.java b/core/src/main/java/de/neocraftr/griefergames/enums/SubServerType.java new file mode 100644 index 0000000..08f4ae1 --- /dev/null +++ b/core/src/main/java/de/neocraftr/griefergames/enums/SubServerType.java @@ -0,0 +1,6 @@ +package de.neocraftr.griefergames.enums; + +public enum SubServerType { + REGULAR, + CLOUD +} diff --git a/core/src/main/java/de/neocraftr/griefergames/listener/GGKeyListener.java b/core/src/main/java/de/neocraftr/griefergames/listener/GGKeyListener.java index 8a67166..3c96b2c 100644 --- a/core/src/main/java/de/neocraftr/griefergames/listener/GGKeyListener.java +++ b/core/src/main/java/de/neocraftr/griefergames/listener/GGKeyListener.java @@ -1,6 +1,7 @@ package de.neocraftr.griefergames.listener; import de.neocraftr.griefergames.GrieferGames; +import de.neocraftr.griefergames.enums.SubServerType; import de.neocraftr.griefergames.settings.GrieferGamesConfig; import net.labymod.api.Laby; import net.labymod.api.client.component.Component; @@ -26,43 +27,45 @@ public GGKeyListener(GrieferGames griefergames) { public void onKeyInput(KeyEvent event) { if(!griefergames.isOnGrieferGames()) return; - if(event.state() == State.PRESS) { - griefergames.setLastActivety(System.currentTimeMillis()); - if(griefergames.isAfk()) { - griefergames.setAfk(false); - griefergames.helper().performAfkActions(false); - } + if(griefergames.getSubServerType() == SubServerType.REGULAR) { + if(event.state() == State.PRESS) { + griefergames.setLastActivety(System.currentTimeMillis()); + if(griefergames.isAfk()) { + griefergames.setAfk(false); + griefergames.helper().performAfkActions(false); + } - if(griefergames.configuration().chatConfig().ampEnabled().get() && - event.key().getId() == Laby.labyAPI().minecraft().options().getInputMapping("key.playerlist").getKeyCode()) { + if(griefergames.configuration().chatConfig().ampEnabled().get() && + event.key().getId() == Laby.labyAPI().minecraft().options().getInputMapping("key.playerlist").getKeyCode()) { - for(NetworkPlayerInfo playerInfo : Laby.labyAPI().minecraft().getClientPacketListener().getNetworkPlayerInfos()) { - if(playerInfo == null) continue; - if(!griefergames.helper().componentToFormattedText(playerInfo.displayName()).contains("§k")) continue; + for(NetworkPlayerInfo playerInfo : Laby.labyAPI().minecraft().getClientPacketListener().getNetworkPlayerInfos()) { + if(playerInfo == null) continue; + if(!griefergames.helper().componentToFormattedText(playerInfo.displayName()).contains("§k")) continue; - Matcher matcher = antiMagicPrefixRegex.matcher(griefergames.helper().componentToPlainText(playerInfo.displayName())); - if(!matcher.find()) continue; + Matcher matcher = antiMagicPrefixRegex.matcher(griefergames.helper().componentToPlainText(playerInfo.displayName())); + if(!matcher.find()) continue; - String ampReplacement = griefergames.configuration().chatConfig().ampReplacement().get(); - if(ampReplacement.isBlank()) { - ampReplacement = GrieferGamesConfig.DEFAULT_AMP_REPLACEMENT; - } + String ampReplacement = griefergames.configuration().chatConfig().ampReplacement().get(); + if(ampReplacement.isBlank()) { + ampReplacement = GrieferGamesConfig.DEFAULT_AMP_REPLACEMENT; + } - List children = new ArrayList<>(playerInfo.displayName().getChildren()); - for(int i=0; i children = new ArrayList<>(playerInfo.displayName().getChildren()); + for(int i=0; i nextNameColorize) { nextNameColorize = currentTime + 20000L; griefergames.helper().colorizePlayerNames(); }*/ - if(!griefergames.isAfk() && griefergames.getLastActivety() + (griefergames.configuration().automations().afkTime().get() * 60000) < System.currentTimeMillis()) { - griefergames.setAfk(true); - griefergames.helper().performAfkActions(true); - } + if(!griefergames.isAfk() && griefergames.getLastActivety() + (griefergames.configuration().automations().afkTime().get() * 60000) < System.currentTimeMillis()) { + griefergames.setAfk(true); + griefergames.helper().performAfkActions(true); + } - if(griefergames.isHideBoosterMenu() || griefergames.configuration().automations().hideBoosterMenu().get()) { - if(griefergames.controller().hideBoosterMenu()) { - griefergames.setHideBoosterMenu(false); + if(griefergames.isHideBoosterMenu() || griefergames.configuration().automations().hideBoosterMenu().get()) { + if(griefergames.controller().hideBoosterMenu()) { + griefergames.setHideBoosterMenu(false); + } } } } diff --git a/core/src/main/java/de/neocraftr/griefergames/utils/Helper.java b/core/src/main/java/de/neocraftr/griefergames/utils/Helper.java index 028563f..25bd7f9 100644 --- a/core/src/main/java/de/neocraftr/griefergames/utils/Helper.java +++ b/core/src/main/java/de/neocraftr/griefergames/utils/Helper.java @@ -117,6 +117,10 @@ public String formatServerName(String serverName) { return "CityBuild " + capitalize(serverName); } else if (serverName.equals("lava") || serverName.equals("wasser")) { return "Farmserver " + capitalize(serverName); + } else if(serverName.startsWith("cloud_")) { + String cloudServerName = serverName.replace("cloud_", ""); + cloudServerName = cloudServerName.startsWith("cb") ? cloudServerName.toUpperCase() : capitalize(cloudServerName); + return "Cloud "+cloudServerName; } else { Matcher matcher = serverCityBuildRegex.matcher(serverName.toLowerCase()); if (matcher.find()) {