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,18 @@ 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()));
int size = event.getListedPlayers().size();
MutableInt counter = new MutableInt();
event.getListedPlayers().removeIf(listedPlayerInfo -> {
if (exclude.contains(listedPlayerInfo.id())) {
counter.increment();
return true;
}
return false;
});
if (size == event.getNumPlayers()) {
event.setNumPlayers(event.getNumPlayers() - counter.intValue());
}
}
}

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