PaperSpigot-Parent/CraftBukkit-Patches/0115-Enable-Improved-Ping-Sending.patch
2014-04-19 09:15:37 +10:00

66 lines
2.5 KiB
Diff

From 6a3edc587a7e2707a2dff6ac6a4659b1d5301844 Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Sun, 24 Feb 2013 20:45:20 +1100
Subject: [PATCH] Enable Improved Ping Sending
diff --git a/src/main/java/net/minecraft/server/EntityPlayer.java b/src/main/java/net/minecraft/server/EntityPlayer.java
index d376beb..de20c6a 100644
--- a/src/main/java/net/minecraft/server/EntityPlayer.java
+++ b/src/main/java/net/minecraft/server/EntityPlayer.java
@@ -62,6 +62,7 @@ public class EntityPlayer extends EntityHuman implements ICrafting {
public boolean keepLevel = false;
public double maxHealthCache;
public boolean joining = true;
+ public int lastPing = -1; // Spigot
// CraftBukkit end
// Spigot start
public boolean collidesWithEntities = true;
diff --git a/src/main/java/net/minecraft/server/PlayerList.java b/src/main/java/net/minecraft/server/PlayerList.java
index cd9a8f5..8be8e9c 100644
--- a/src/main/java/net/minecraft/server/PlayerList.java
+++ b/src/main/java/net/minecraft/server/PlayerList.java
@@ -793,6 +793,8 @@ public abstract class PlayerList {
// CraftBukkit end
}
+ private int currentPing = 0;
+
public void tick() {
if (++this.t > 600) {
this.t = 0;
@@ -805,6 +807,30 @@ public abstract class PlayerList {
this.sendAll(new PacketPlayOutPlayerInfo(entityplayer.getName(), true, entityplayer.ping));
}
// CraftBukkit end */
+ // Spigot start
+ try
+ {
+ if ( !players.isEmpty() )
+ {
+ currentPing = ( currentPing + 1 ) % this.players.size();
+ EntityPlayer player = (EntityPlayer) this.players.get( currentPing );
+ if ( player.lastPing == -1 || Math.abs( player.ping - player.lastPing ) > 20 )
+ {
+ Packet packet = new PacketPlayOutPlayerInfo( player.listName, true, player.ping );
+ for ( EntityPlayer splayer : (List<EntityPlayer>) this.players )
+ {
+ if ( splayer.getBukkitEntity().canSee( player.getBukkitEntity() ) )
+ {
+ splayer.playerConnection.sendPacket( packet );
+ }
+ }
+ player.lastPing = player.ping;
+ }
+ }
+ } catch ( Exception e ) {
+ // Better safe than sorry :)
+ }
+ // Spigot end
}
public void sendAll(Packet packet) {
--
1.9.1