From 54a7906e84460c5ebf21b81dc3c6eb855cb45c66 Mon Sep 17 00:00:00 2001 From: "Alex \"mcmonkey\" Goodwin" Date: Tue, 2 Jan 2024 14:48:11 -0800 Subject: [PATCH] proxy server list ping: add alternate_player_text --- LICENSE.txt | 2 +- README.md | 2 +- .../packets/out/ProxyPingResultPacketOut.java | 10 ++--- .../BungeeProxyServerListPingScriptEvent.java | 37 ++++++++++++++++++- 4 files changed, 42 insertions(+), 9 deletions(-) diff --git a/LICENSE.txt b/LICENSE.txt index 05eefdc80..9c7476a7d 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2019-2023 The Denizen Script Team +Copyright (c) 2019-2024 The Denizen Script Team Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 25231cef9..e40d4e730 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ Copyright (C) 2014-2019 The Denizen Script Team, All Rights Reserved. The MIT License (MIT) -Copyright (c) 2019-2023 The Denizen Script Team +Copyright (c) 2019-2024 The Denizen Script Team Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/src/main/java/com/denizenscript/depenizen/bukkit/bungee/packets/out/ProxyPingResultPacketOut.java b/src/main/java/com/denizenscript/depenizen/bukkit/bungee/packets/out/ProxyPingResultPacketOut.java index 58f4f1305..c4896bca9 100644 --- a/src/main/java/com/denizenscript/depenizen/bukkit/bungee/packets/out/ProxyPingResultPacketOut.java +++ b/src/main/java/com/denizenscript/depenizen/bukkit/bungee/packets/out/ProxyPingResultPacketOut.java @@ -1,7 +1,7 @@ package com.denizenscript.depenizen.bukkit.bungee.packets.out; -import com.denizenscript.denizen.objects.PlayerTag; import com.denizenscript.depenizen.bukkit.bungee.BungeePacketOut; +import com.denizenscript.depenizen.bukkit.events.bungee.BungeeProxyServerListPingScriptEvent; import io.netty.buffer.ByteBuf; import java.util.List; @@ -16,7 +16,7 @@ public class ProxyPingResultPacketOut extends BungeePacketOut { public String motd; - public List playerSample; + public List playerSample; @Override public int getPacketId() { @@ -35,9 +35,9 @@ public void writeTo(ByteBuf buf) { else { buf.writeInt(playerSample.size()); for (int i = 0; i < playerSample.size(); i++) { - writeString(buf, playerSample.get(i).getName()); - buf.writeLong(playerSample.get(i).getUUID().getMostSignificantBits()); - buf.writeLong(playerSample.get(i).getUUID().getLeastSignificantBits()); + writeString(buf, playerSample.get(i).name); + buf.writeLong(playerSample.get(i).id.getMostSignificantBits()); + buf.writeLong(playerSample.get(i).id.getLeastSignificantBits()); } } } diff --git a/src/main/java/com/denizenscript/depenizen/bukkit/events/bungee/BungeeProxyServerListPingScriptEvent.java b/src/main/java/com/denizenscript/depenizen/bukkit/events/bungee/BungeeProxyServerListPingScriptEvent.java index d05503f25..6d3ac718a 100644 --- a/src/main/java/com/denizenscript/depenizen/bukkit/events/bungee/BungeeProxyServerListPingScriptEvent.java +++ b/src/main/java/com/denizenscript/depenizen/bukkit/events/bungee/BungeeProxyServerListPingScriptEvent.java @@ -2,6 +2,8 @@ import com.denizenscript.denizen.objects.PlayerTag; import com.denizenscript.denizencore.objects.core.ListTag; +import com.denizenscript.denizencore.utilities.CoreConfiguration; +import com.denizenscript.denizencore.utilities.debugging.Debug; import com.denizenscript.depenizen.bukkit.bungee.BungeeBridge; import com.denizenscript.denizen.utilities.implementation.BukkitScriptEntryData; import com.denizenscript.denizen.events.BukkitScriptEvent; @@ -10,7 +12,9 @@ import com.denizenscript.denizencore.scripts.ScriptEntryData; import com.denizenscript.denizencore.utilities.CoreUtilities; +import java.util.ArrayList; import java.util.List; +import java.util.UUID; public class BungeeProxyServerListPingScriptEvent extends BukkitScriptEvent { @@ -35,6 +39,7 @@ public class BungeeProxyServerListPingScriptEvent extends BukkitScriptEvent { // "VERSION:" to change the listed server version. // "MOTD:" to change the server MOTD that will be displayed. // "PLAYERS:" to set what players are displayed in the "online players sample" view of the list ping. + // "ALTERNATE_PLAYER_TEXT:" to set custom text for the player list section of the server status. (Requires "Allow restricted actions" in Denizen/config.yml). Usage of this to present lines that look like player names (but aren't) is forbidden. // // @Plugin Depenizen, DepenizenBungee, BungeeCord // @@ -48,6 +53,12 @@ public BungeeProxyServerListPingScriptEvent() { public static BungeeProxyServerListPingScriptEvent instance; + public static class PlayerInfo { + public UUID id; + + public String name; + } + public static class PingData { public String address; @@ -62,7 +73,7 @@ public static class PingData { public String version; - public List playerSample; + public List playerSample; } public PingData data; @@ -109,7 +120,29 @@ else if (determinationLow.startsWith("motd:")) { return true; } else if (determinationLow.startsWith("players:")) { - data.playerSample = ListTag.valueOf(determination.substring("players:".length()), getTagContext(path)).filter(PlayerTag.class, getTagContext(path)); + List players = ListTag.valueOf(determination.substring("players:".length()), getTagContext(path)).filter(PlayerTag.class, getTagContext(path)); + data.playerSample = new ArrayList<>(players.size()); + for (PlayerTag player : players) { + PlayerInfo info = new PlayerInfo(); + info.id = player.getUUID(); + info.name = player.getName(); + data.playerSample.add(info); + } + return true; + } + else if (determinationLow.startsWith("alternate_player_text:")) { + if (!CoreConfiguration.allowRestrictedActions) { + Debug.echoError("Cannot use 'alternate_player_text' in proxy list ping event: 'Allow restricted actions' is disabled in Denizen config.yml."); + return true; + } + List text = ListTag.valueOf(determination.substring("alternate_player_text:".length()), getTagContext(path)); + data.playerSample = new ArrayList<>(text.size()); + for (String line : text) { + PlayerInfo info = new PlayerInfo(); + info.name = line; + info.id = new UUID(0, 0); + data.playerSample.add(info); + } return true; } }