Skip to content

Commit

Permalink
PacketEvents, Tick Rate, and Ping Command Info Changes
Browse files Browse the repository at this point in the history
- Account for /tick rate properly on Fabric once again, can be modified in the future to account for /tick rate on bukkit
- Switch back to using my PacketEvents fork for Fabric
- Add more information to the ping command including if ping has spiked or not
  • Loading branch information
Axionize authored Oct 26, 2024
2 parents 7026184 + 992ab40 commit ae76933
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import com.github.retrooper.packetevents.protocol.player.ClientVersion;
import com.github.retrooper.packetevents.protocol.player.User;
import com.github.retrooper.packetevents.protocol.world.BoundingBox;
import com.github.retrooper.packetevents.protocol.world.Location;
import com.github.retrooper.packetevents.protocol.world.states.WrappedBlockState;
import com.github.retrooper.packetevents.protocol.world.states.type.StateTypes;
import com.github.retrooper.packetevents.util.Vector3d;
Expand Down Expand Up @@ -108,16 +107,23 @@ public PlayerData(PlatformPlayer platformPlayer) {
*
* @return The compensated ping, with a minimum of 1.
*/
public double getEstimatedPing() {
public double getCompensatedPing() {
double currentPing = (ping != null) ? ping : platformPlayer.getPing();
double lastPing = (previousPing != null) ? previousPing : platformPlayer.getPing();
double ping = (currentPing - lastPing > Base.INSTANCE.getConfigManager().getSpikeThreshold()) ? lastPing : currentPing;

return Math.max(1, ping - PING_OFFSET);
}

public boolean isSpike() {
double currentPing = (ping != null) ? ping : platformPlayer.getPing();
double lastPing = (previousPing != null) ? previousPing : platformPlayer.getPing();

return (currentPing - lastPing) > Base.INSTANCE.getConfigManager().getSpikeThreshold();
}

public int getTick() {
return (int) Math.ceil(getEstimatedPing() / 50);
return (int) Math.ceil(getCompensatedPing() * TICK_RATE / 1000); // Multiply ping by seconds per tick
}

// public boolean isKeepAliveIDOurs(long id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ public static String getPingMessage(UUID senderUUID, UUID targetUUID) {

String rawReturnString = null;
if (playerData.getPing() == null) {
rawReturnString = String.format("Pong not received. %s estimated ping is &b" + playerData.getPlatformPlayer().getPing() + "&rms.", noun);
rawReturnString = String.format("Accurate ping unavailable. %s estimated ping is &b" + playerData.getPlatformPlayer().getPing() + "&rms.", noun);
} else {
rawReturnString = String.format("%s last ping packet took &b%.3f&rms. Jitter: &b%.3f&rms.", noun, playerData.getPing(), playerData.getJitter());
rawReturnString = String.format("%s real ping is &b%.3f&rms. Jitter: &b%.3f&rms. Spike: &b%s&r. Compensated ping: &b%s&r.", noun, playerData.getPing(), playerData.getJitter(), playerData.isSpike(), playerData.getCompensatedPing());
}
return ChatUtil.translateAlternateColorCodes('&', rawReturnString);
}
Expand Down

0 comments on commit ae76933

Please sign in to comment.