spigot/CraftBukkit-Patches/0042-Configurable-Ping-Sample-Size.patch
2023-06-08 01:30:00 +10:00

43 lines
2 KiB
Diff

From eece7e89dd62f20e4e3962f7e3e277eb1b572f8c Mon Sep 17 00:00:00 2001
From: md_5 <git@md-5.net>
Date: Sun, 26 Jan 2014 21:48:34 +1100
Subject: [PATCH] Configurable Ping Sample Size
diff --git a/src/main/java/net/minecraft/server/network/PacketStatusListener.java b/src/main/java/net/minecraft/server/network/PacketStatusListener.java
index a0d4c27f3..5e6334239 100644
--- a/src/main/java/net/minecraft/server/network/PacketStatusListener.java
+++ b/src/main/java/net/minecraft/server/network/PacketStatusListener.java
@@ -133,6 +133,13 @@ public class PacketStatusListener implements PacketStatusInListener {
}
}
+ // Spigot Start
+ if ( !server.hidesOnlinePlayers() && !profiles.isEmpty() )
+ {
+ java.util.Collections.shuffle( profiles ); // This sucks, its inefficient but we have no simple way of doing it differently
+ profiles = profiles.subList( 0, Math.min( profiles.size(), org.spigotmc.SpigotConfig.playerSample ) ); // Cap the sample to n (or less) displayed players, ie: Vanilla behaviour
+ }
+ // Spigot End
ServerPing.ServerPingPlayerSample playerSample = new ServerPing.ServerPingPlayerSample(event.getMaxPlayers(), profiles.size(), (server.hidesOnlinePlayers()) ? Collections.emptyList() : profiles);
ServerPing ping = new ServerPing(
diff --git a/src/main/java/org/spigotmc/SpigotConfig.java b/src/main/java/org/spigotmc/SpigotConfig.java
index 4987040ff..141ba2784 100644
--- a/src/main/java/org/spigotmc/SpigotConfig.java
+++ b/src/main/java/org/spigotmc/SpigotConfig.java
@@ -271,4 +271,11 @@ public class SpigotConfig
{
commands.put( "tps", new TicksPerSecondCommand( "tps" ) );
}
+
+ public static int playerSample;
+ private static void playerSample()
+ {
+ playerSample = getInt( "settings.sample-count", 12 );
+ System.out.println( "Server Ping Player Sample Count: " + playerSample );
+ }
}
--
2.40.1