Skip to content

Commit

Permalink
Added basic support for Griefergames Cloud
Browse files Browse the repository at this point in the history
  • Loading branch information
Neocraftr committed Jul 24, 2023
1 parent e934ec3 commit f2a336f
Show file tree
Hide file tree
Showing 11 changed files with 146 additions and 71 deletions.
11 changes: 11 additions & 0 deletions core/src/main/java/de/neocraftr/griefergames/GrieferGames.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -76,6 +78,7 @@ public class GrieferGames extends LabyAddon<GrieferGamesConfig> {
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;
Expand All @@ -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));

Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package de.neocraftr.griefergames.enums;

public enum SubServerType {
REGULAR,
CLOUD
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<Component> children = new ArrayList<>(playerInfo.displayName().getChildren());
for(int i=0; i<children.size(); i++) {
Component component = children.get(i);
String plain = griefergames.helper().componentToPlainText(component);
List<Component> children = new ArrayList<>(playerInfo.displayName().getChildren());
for(int i=0; i<children.size(); i++) {
Component component = children.get(i);
String plain = griefergames.helper().componentToPlainText(component);

if(plain.equals(matcher.group(1))) {
component.style(component.style().undecorate(TextDecoration.OBFUSCATED));
Component ampPrefix = Component.text(ampReplacement+" ", component.style());
children.add(i, ampPrefix);
i++;
} else if(plain.equals(matcher.group(2))) {
component.style(component.style().undecorate(TextDecoration.OBFUSCATED));
if(plain.equals(matcher.group(1))) {
component.style(component.style().undecorate(TextDecoration.OBFUSCATED));
Component ampPrefix = Component.text(ampReplacement+" ", component.style());
children.add(i, ampPrefix);
i++;
} else if(plain.equals(matcher.group(2))) {
component.style(component.style().undecorate(TextDecoration.OBFUSCATED));
}
}
playerInfo.displayName().setChildren(children);
}
playerInfo.displayName().setChildren(children);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import de.neocraftr.griefergames.GrieferGames;
import de.neocraftr.griefergames.chat.events.GGChatProcessEvent;
import de.neocraftr.griefergames.enums.SubServerType;
import net.labymod.api.Laby;
import net.labymod.api.configuration.labymod.chat.AdvancedChatMessage;
import net.labymod.api.event.Subscribe;
Expand All @@ -20,18 +21,20 @@ public void onMessage(ChatReceiveEvent event) {
if(!griefergames.isOnGrieferGames()) return;
//System.out.println(GsonComponentSerializer.gson().serialize(event.message()));

GGChatProcessEvent processEvent = new GGChatProcessEvent(event.chatMessage());
Laby.labyAPI().eventBus().fire(processEvent);
if(processEvent.isCancelled()) {
event.setCancelled(true);
} else if(processEvent.isSecondChat()) {
griefergames.helper().displayInSecondChat(AdvancedChatMessage.chat(processEvent.getMessage()));
if(!processEvent.isKeepInRegularChat()) event.setCancelled(true);
}
if(griefergames.getSubServerType() == SubServerType.REGULAR) {
GGChatProcessEvent processEvent = new GGChatProcessEvent(event.chatMessage());
Laby.labyAPI().eventBus().fire(processEvent);
if(processEvent.isCancelled()) {
event.setCancelled(true);
} else if(processEvent.isSecondChat()) {
griefergames.helper().displayInSecondChat(AdvancedChatMessage.chat(processEvent.getMessage()));
if(!processEvent.isKeepInRegularChat()) event.setCancelled(true);
}

if(event.chatMessage().getPlainText().equals("[Switcher] Daten heruntergeladen!")) {
griefergames.setHideBoosterMenu(true);
griefergames.sendMessage("/booster");
if(event.chatMessage().getPlainText().equals("[Switcher] Daten heruntergeladen!")) {
griefergames.setHideBoosterMenu(true);
griefergames.sendMessage("/booster");
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import de.neocraftr.griefergames.GrieferGames;
import de.neocraftr.griefergames.enums.ChatColor;
import de.neocraftr.griefergames.enums.SubServerType;
import net.labymod.api.client.component.Component;
import net.labymod.api.client.component.format.NamedTextColor;
import net.labymod.api.event.Subscribe;
Expand All @@ -21,19 +22,21 @@ public void onSend(ChatMessageSendEvent event) {
if(!griefergames.isOnGrieferGames()) return;
String msg = event.getMessage();

if(griefergames.configuration().chatConfig().preventCommandFailure().get()) {
if(msg.startsWith("7") && !msg.equalsIgnoreCase(lastMessage)) {
griefergames.displayAddonMessage(Component.text(I18n.translate(griefergames.namespace()+".messages.commandFailure"), NamedTextColor.RED));
lastMessage = msg;
event.setCancelled(true);
} else {
lastMessage = "";
if(griefergames.getSubServerType() == SubServerType.REGULAR) {
if(griefergames.configuration().chatConfig().preventCommandFailure().get()) {
if(msg.startsWith("7") && !msg.equalsIgnoreCase(lastMessage)) {
griefergames.displayAddonMessage(Component.text(I18n.translate(griefergames.namespace()+".messages.commandFailure"), NamedTextColor.RED));
lastMessage = msg;
event.setCancelled(true);
} else {
lastMessage = "";
}
}
}

if(griefergames.configuration().automations().autoColor().get() != ChatColor.NONE &&
!msg.startsWith("/") && !msg.startsWith(".") && !msg.startsWith("-")) {
event.changeMessage("&"+griefergames.configuration().automations().autoColor().get().getColorCode()+msg);
if(griefergames.configuration().automations().autoColor().get() != ChatColor.NONE &&
!msg.startsWith("/") && !msg.startsWith(".") && !msg.startsWith("-")) {
event.changeMessage("&"+griefergames.configuration().automations().autoColor().get().getColorCode()+msg);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import de.neocraftr.griefergames.GrieferGames;
import de.neocraftr.griefergames.chat.events.GGSubServerChangeEvent;
import de.neocraftr.griefergames.enums.SubServerType;
import net.labymod.api.Laby;
import net.labymod.api.event.Subscribe;
import net.labymod.api.event.client.scoreboard.ScoreboardTeamUpdateEvent;
Expand All @@ -21,6 +22,7 @@ public void onScoreboardTeams(ScoreboardTeamUpdateEvent event) {
String subServerName = griefergames.helper().componentToPlainText(event.team().getPrefix()).toLowerCase();
if(subServerName.isBlank() || subServerName.contains("lade")) return;

griefergames.setSubServerType(SubServerType.REGULAR);
if(!griefergames.getSubServer().equals(subServerName)) {
griefergames.setSubServer(subServerName);
GGSubServerChangeEvent changeEvent = new GGSubServerChangeEvent(subServerName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
import net.labymod.api.event.client.network.server.ServerJoinEvent;
import net.labymod.api.notification.Notification;
import net.labymod.api.util.I18n;
import java.util.Timer;
import java.util.TimerTask;

public class GGServerJoinListener {
private final GrieferGames griefergames;
Expand Down Expand Up @@ -63,15 +61,6 @@ public void onServerJoin(ServerJoinEvent event) {
.icon(Icon.texture(ResourceLocation.create(griefergames.namespace(), "textures/update.png"))).build());
}
}

if(griefergames.configuration().automations().autoPortal().get()) {
new Timer().schedule(new TimerTask() {
@Override
public void run() {
griefergames.sendMessage("/portal");
}
}, 500);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import net.labymod.core.labyconnect.DefaultLabyConnect;
import net.labymod.core.labyconnect.protocol.packets.PacketPlayServerStatusUpdate;
import net.labymod.core.thirdparty.discord.DefaultDiscordApp;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.TimeUnit;

public class GGSubServerChangeListener {
Expand Down Expand Up @@ -46,7 +48,6 @@ public void onSubServerChange(GGSubServerChangeEvent event) {
labyConnect.sendPacket(packet);
}


if(griefergames.helper().isCityBuild(event.subServerName())) {
if(!griefergames.isCitybuildDelay()) griefergames.setWaitTime(System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(15));
griefergames.setCitybuildDelay(false);
Expand All @@ -59,6 +60,15 @@ public void onSubServerChange(GGSubServerChangeEvent event) {
if(!griefergames.isCitybuildDelay()) griefergames.setWaitTime(System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(12));
} else if(event.subServerName().equals("skyblock")) {
if(!griefergames.isCitybuildDelay()) griefergames.setWaitTime(System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(15));
} else if(event.subServerName().equals("lobby")) {
if(griefergames.configuration().automations().autoPortal().get()) {
new Timer().schedule(new TimerTask() {
@Override
public void run() {
griefergames.sendMessage("/portal");
}
}, 500);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package de.neocraftr.griefergames.listener;

import de.neocraftr.griefergames.GrieferGames;
import de.neocraftr.griefergames.chat.events.GGSubServerChangeEvent;
import de.neocraftr.griefergames.enums.SubServerType;
import net.labymod.api.Laby;
import net.labymod.api.client.component.Component;
import net.labymod.api.client.scoreboard.TabList;
import net.labymod.api.event.Subscribe;
import net.labymod.api.event.client.scoreboard.TabListUpdateEvent;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class GGTablistListener {
private final GrieferGames griefergames;
private final Pattern tabListServerRegex = Pattern.compile("Current Server: (.+) ", Pattern.MULTILINE);

public GGTablistListener(GrieferGames griefergames) {
this.griefergames = griefergames;
}

@Subscribe
public void onTablistUpdate(TabListUpdateEvent event) {
TabList tablist = Laby.labyAPI().minecraft().getTabList();
if(tablist == null) return;
Component header = tablist.header();
if(header != null) {
String headerText = griefergames.helper().componentToPlainText(header);
Matcher matcher = tabListServerRegex.matcher(headerText);
if(matcher.find()) {
String subServerName = "cloud_"+matcher.group(1).toLowerCase().split("-")[0];
griefergames.setSubServerType(SubServerType.CLOUD);
if(!griefergames.getSubServer().equals(subServerName)) {
griefergames.setSubServer(subServerName);
GGSubServerChangeEvent changeEvent = new GGSubServerChangeEvent(subServerName);
Laby.labyAPI().eventBus().fire(changeEvent);
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package de.neocraftr.griefergames.listener;

import de.neocraftr.griefergames.GrieferGames;
import de.neocraftr.griefergames.enums.SubServerType;
import net.labymod.api.event.Phase;
import net.labymod.api.event.Subscribe;
import net.labymod.api.event.client.lifecycle.GameTickEvent;
Expand All @@ -18,21 +19,23 @@ public void onTick(GameTickEvent event) {
if(!griefergames.isOnGrieferGames()) return;

if(event.phase() == Phase.POST) {
long currentTime = System.currentTimeMillis();
if(griefergames.getSubServerType() == SubServerType.REGULAR) {
//long currentTime = System.currentTimeMillis();

/*if(currentTime > 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);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down

0 comments on commit f2a336f

Please sign in to comment.