Search in sources :

Example 1 with PaperServerListPingEvent

use of com.destroystokyo.paper.event.server.PaperServerListPingEvent in project Denizen-For-Bukkit by DenizenScript.

the class ServerListPingScriptEventPaperImpl method applyDetermination.

@Override
public boolean applyDetermination(ScriptPath path, ObjectTag determinationObj) {
    String determination = determinationObj.toString();
    String lower = CoreUtilities.toLowerCase(determination);
    if (lower.startsWith("protocol_version:") && ArgumentHelper.matchesInteger(determination.substring("protocol_version:".length()))) {
        ((PaperServerListPingEvent) event).setProtocolVersion(Integer.parseInt(determination.substring("protocol_version:".length())));
        return true;
    } else if (lower.startsWith("version_name:")) {
        ((PaperServerListPingEvent) event).setVersion(determination.substring("version_name:".length()));
        return true;
    } else if (lower.startsWith("exclude_players:")) {
        HashSet<UUID> exclusions = new HashSet<>();
        for (PlayerTag player : ListTag.valueOf(determination.substring("exclude_players:".length()), getTagContext(path)).filter(PlayerTag.class, getTagContext(path))) {
            exclusions.add(player.getUUID());
        }
        Iterator<Player> players = ((PaperServerListPingEvent) event).iterator();
        while (players.hasNext()) {
            if (exclusions.contains(players.next().getUniqueId())) {
                players.remove();
            }
        }
        return true;
    }
    return super.applyDetermination(path, determinationObj);
}
Also used : Player(org.bukkit.entity.Player) PlayerTag(com.denizenscript.denizen.objects.PlayerTag) PaperServerListPingEvent(com.destroystokyo.paper.event.server.PaperServerListPingEvent) UUID(java.util.UUID) HashSet(java.util.HashSet)

Aggregations

PlayerTag (com.denizenscript.denizen.objects.PlayerTag)1 PaperServerListPingEvent (com.destroystokyo.paper.event.server.PaperServerListPingEvent)1 HashSet (java.util.HashSet)1 UUID (java.util.UUID)1 Player (org.bukkit.entity.Player)1