-
Bug
-
Resolution: Fixed
-
Minor
-
None
-
None
-
3344-Spigot-3c40a6c-4b5f988 (MC: 1.18)
-
Yes
The Javadocs for the description of org.bukkit.entity.Player#getPing() is incorrect. It states the following:
"Gets the player's estimated ping in milliseconds. In Vanilla this value represents the average of the response time to the last four application layer ping packets sent. This value does not represent the network round trip time and as such may have less granularity and be impacted by other sources. For these reasons it should not be used for anti-cheat purposes. Its recommended use is only as a qualitative indicator of connection quality (Vanilla uses it for this purpose in the tab list)."
As can be seen by the following code, it's not the average of the last four response times. It's a weighted average where the most recent response time is weighted at 25% and the previous latency value is weighted at 75%.
int i = (int) (SystemUtils.getMillis() - this.keepAliveTime); this.player.latency = (this.player.latency * 3 + i) / 4;
The effect of this 75%/25% weighting can be seen in the following table (containing example values), where the first column is the individual measurement, and the second column is the calculated latency used by getPing(). If it was indeed the average of the last four values, the highlighted entry would have a value of 20 instead of 330.
I suggest the Javadocs description be changed to read:
"Gets the player's estimated ping in milliseconds. In Vanilla this value represents a weighted average of the response time to the application layer ping packets sent, with the most recent time weighted at 25% and the previous average weighted at 75%. This value does not represent the network round trip time and as such may have less granularity and be impacted by other sources. For these reasons it should not be used for anti-cheat purposes. Its recommended use is only as a qualitative indicator of connection quality (Vanilla uses it for this purpose in the tab list)."