Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.destroystokyo.paper.profile.PlayerProfile;
import com.destroystokyo.paper.profile.ProfileProperty;
import net.md_5.bungee.api.ChatColor;
import org.apache.commons.lang3.mutable.MutableInt;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.profile.PlayerTextures;
Expand Down Expand Up @@ -70,6 +71,17 @@ public ServerListPingScriptEventPaperImpl() {
ListedPlayersEditor.setListedPlayerInfo(evt.getEvent(), text);
return true;
});
this.<ServerListPingScriptEventPaperImpl, ElementTag>registerOptionalDetermination("player_count", ElementTag.class, (evt, context, input) -> {
if (!CoreConfiguration.allowRestrictedActions) {
Debug.echoError("Cannot use 'player_count' in list ping event: 'Allow restricted actions' is disabled in Denizen config.yml.");
return false;
}
if (input.isInt()) {
evt.getEvent().setNumPlayers(input.asInt());
return true;
}
return false;
});
}

public PaperServerListPingEvent getEvent() {
Expand All @@ -86,7 +98,15 @@ public static void setListedPlayerInfo(PaperServerListPingEvent event, List<Stri
}

public static void excludeListedPlayers(PaperServerListPingEvent event, Set<UUID> exclude) {
event.getListedPlayers().removeIf(listedPlayerInfo -> exclude.contains(listedPlayerInfo.id()));
MutableInt counter = new MutableInt();
event.getListedPlayers().removeIf(listedPlayerInfo -> {
if (exclude.contains(listedPlayerInfo.id())) {
counter.increment();
return true;
}
return false;
});
event.setNumPlayers(event.getNumPlayers() - counter.intValue());

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good, but missing one check:
If a plugin modified the player count to something else already we don't want to mess with that, so should start by checking if NumPlayers is the same as listed.size(), and only decrease NumPlayers if it is.

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public class ListPingScriptEvent extends BukkitScriptEvent implements Listener {
// "VERSION_NAME:<ElementTag>" to change the server's version name (only on Paper).
// "EXCLUDE_PLAYERS:<ListTag(PlayerTag)>" to exclude a set of players from showing in the player count or preview of online players (only on Paper).
// "ALTERNATE_PLAYER_TEXT:<ListTag>" to set custom text for the player list section of the server status (only on Paper). (Requires "Allow restricted actions" in Denizen/config.yml). Usage of this to present lines that look like player names (but aren't) is forbidden.
// "PLAYER_COUNT:<ElementTag(Number)>" to set the amount of players that are online (only on Paper). (Requires "Allow restricted actions" in Denizen/config.yml). Usage of this to display a higher number of players than are actually connected is forbidden.
// "MOTD:<ElementTag>" to change the MOTD that will show.
//
// -->
Expand Down