Skip to content

Commit

Permalink
proxy server list ping: add alternate_player_text
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Jan 2, 2024
1 parent 34cbb34 commit 54a7906
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 9 deletions.
2 changes: 1 addition & 1 deletion 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
Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -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
Expand Down
@@ -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;
Expand All @@ -16,7 +16,7 @@ public class ProxyPingResultPacketOut extends BungeePacketOut {

public String motd;

public List<PlayerTag> playerSample;
public List<BungeeProxyServerListPingScriptEvent.PlayerInfo> playerSample;

@Override
public int getPacketId() {
Expand All @@ -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());
}
}
}
Expand Down
Expand Up @@ -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;
Expand All @@ -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 {

Expand All @@ -35,6 +39,7 @@ public class BungeeProxyServerListPingScriptEvent extends BukkitScriptEvent {
// "VERSION:<ElementTag>" to change the listed server version.
// "MOTD:<ElementTag>" to change the server MOTD that will be displayed.
// "PLAYERS:<List(PlayerTag)>" to set what players are displayed in the "online players sample" view of the list ping.
// "ALTERNATE_PLAYER_TEXT:<ListTag>" 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
//
Expand All @@ -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;
Expand All @@ -62,7 +73,7 @@ public static class PingData {

public String version;

public List<PlayerTag> playerSample;
public List<PlayerInfo> playerSample;
}

public PingData data;
Expand Down Expand Up @@ -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<PlayerTag> 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<String> 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;
}
}
Expand Down

0 comments on commit 54a7906

Please sign in to comment.