From 2f3b5fcbc2d983739679cf9ebfc9c958a34dc3b7 Mon Sep 17 00:00:00 2001 From: Alessandro Proto Date: Sat, 26 Oct 2024 09:54:33 +0200 Subject: [PATCH] Tab list phase configurable --- .../server/RccServerConfigModel.java | 2 + .../cc/reconnected/server/core/TabList.java | 56 ++++++++++--------- 2 files changed, 32 insertions(+), 26 deletions(-) diff --git a/src/main/java/cc/reconnected/server/RccServerConfigModel.java b/src/main/java/cc/reconnected/server/RccServerConfigModel.java index b18b853..9840a58 100644 --- a/src/main/java/cc/reconnected/server/RccServerConfigModel.java +++ b/src/main/java/cc/reconnected/server/RccServerConfigModel.java @@ -21,6 +21,8 @@ public class RccServerConfigModel { public int teleportRequestTimeout = 120; public boolean enableTabList = true; + public int tabListTickDelay = 2; + public double tabPhaseFrequency = 40; public ArrayList tabHeader = new ArrayList<>(List.of( " " )); diff --git a/src/main/java/cc/reconnected/server/core/TabList.java b/src/main/java/cc/reconnected/server/core/TabList.java index b69c880..b59e47a 100644 --- a/src/main/java/cc/reconnected/server/core/TabList.java +++ b/src/main/java/cc/reconnected/server/core/TabList.java @@ -13,40 +13,44 @@ public class TabList { if (!RccServer.CONFIG.enableTabList()) return; + var minimessage = MiniMessage.miniMessage(); + ServerTickEvents.END_SERVER_TICK.register(server -> { - var phase = (Math.sin((server.getTicks() * Math.PI) / 20) + 1) / 2d; - var minimessage = MiniMessage.miniMessage(); + if(server.getTicks() % RccServer.CONFIG.tabListTickDelay() == 0) { - server.getPlayerManager().getPlayerList().forEach(player -> { - var playerContext = PlaceholderContext.of(player); - Component headerComponent = Component.empty(); - for (int i = 0; i < RccServer.CONFIG.tabHeader().size(); i++) { - var line = RccServer.CONFIG.tabHeader().get(i); - line = line.replace("{phase}", String.valueOf(phase)); - if (i > 0) { - headerComponent = headerComponent.appendNewline(); + var phase = (Math.sin((server.getTicks() * Math.PI * 2) / RccServer.CONFIG.tabPhaseFrequency()) + 1) / 2d; + + server.getPlayerManager().getPlayerList().forEach(player -> { + var playerContext = PlaceholderContext.of(player); + Component headerComponent = Component.empty(); + for (int i = 0; i < RccServer.CONFIG.tabHeader().size(); i++) { + var line = RccServer.CONFIG.tabHeader().get(i); + line = line.replace("{phase}", String.valueOf(phase)); + if (i > 0) { + headerComponent = headerComponent.appendNewline(); + } + + headerComponent = headerComponent.append(minimessage.deserialize(line)); } - headerComponent = headerComponent.append(minimessage.deserialize(line)); - } + Component footerComponent = Component.empty(); + for (int i = 0; i < RccServer.CONFIG.tabFooter().size(); i++) { + var line = RccServer.CONFIG.tabFooter().get(i); + line = line.replace("{phase}", String.valueOf(phase)); + if (i > 0) { + footerComponent = footerComponent.appendNewline(); + } - Component footerComponent = Component.empty(); - for (int i = 0; i < RccServer.CONFIG.tabFooter().size(); i++) { - var line = RccServer.CONFIG.tabFooter().get(i); - line = line.replace("{phase}", String.valueOf(phase)); - if (i > 0) { - footerComponent = footerComponent.appendNewline(); + footerComponent = footerComponent.append(minimessage.deserialize(line)); } - footerComponent = footerComponent.append(minimessage.deserialize(line)); - } + var parsedHeader = Placeholders.parseText(Components.toText(headerComponent), playerContext); + var parsedFooter = Placeholders.parseText(Components.toText(footerComponent), playerContext); - var parsedHeader = Placeholders.parseText(Components.toText(headerComponent), playerContext); - var parsedFooter = Placeholders.parseText(Components.toText(footerComponent), playerContext); - - var audience = RccServer.getInstance().adventure().player(player.getUuid()); - audience.sendPlayerListHeaderAndFooter(parsedHeader, parsedFooter); - }); + var audience = RccServer.getInstance().adventure().player(player.getUuid()); + audience.sendPlayerListHeaderAndFooter(parsedHeader, parsedFooter); + }); + } }); }