Encapsulate ping fields

This commit is contained in:
md_5 2013-04-28 11:19:19 +10:00
parent a1f928b210
commit ff32764f9a
3 changed files with 14 additions and 10 deletions

View File

@ -54,14 +54,18 @@ public final class UserConnection implements ProxiedPlayer
// reconnect stuff // reconnect stuff
public int clientEntityId; public int clientEntityId;
public int serverEntityId; public int serverEntityId;
// ping stuff
public int trackingPingId;
public long pingTime;
@Getter @Getter
private String displayName; private String displayName;
/*========================================================================*/
@Getter @Getter
@Setter @Setter
private int ping = 1000; private int sentPingId;
@Getter
@Setter
private long sentPingTime;
@Getter
@Setter
private int ping = 100;
/*========================================================================*/ /*========================================================================*/
private final Collection<String> groups = new HashSet<>(); private final Collection<String> groups = new HashSet<>();
private final Collection<String> permissions = new HashSet<>(); private final Collection<String> permissions = new HashSet<>();

View File

@ -78,8 +78,8 @@ public class DownstreamBridge extends PacketHandler
@Override @Override
public void handle(Packet0KeepAlive alive) throws Exception public void handle(Packet0KeepAlive alive) throws Exception
{ {
con.trackingPingId = alive.id; con.setSentPingId( alive.id );
con.pingTime = System.currentTimeMillis(); con.setSentPingTime( System.currentTimeMillis() );
} }
@Override @Override

View File

@ -31,12 +31,12 @@ public class UpstreamBridge extends PacketHandler
BungeeCord.getInstance().connections.put( con.getName(), con ); BungeeCord.getInstance().connections.put( con.getName(), con );
bungee.getTabListHandler().onConnect( con ); bungee.getTabListHandler().onConnect( con );
con.sendPacket(BungeeCord.getInstance().registerChannels() ); con.sendPacket( BungeeCord.getInstance().registerChannels() );
TexturePackInfo texture = con.getPendingConnection().getListener().getTexturePack(); TexturePackInfo texture = con.getPendingConnection().getListener().getTexturePack();
if ( texture != null ) if ( texture != null )
{ {
con.sendPacket(new PacketFAPluginMessage( "MC|TPack", ( texture.getUrl() + "\00" + texture.getSize() ).getBytes() ) ); con.sendPacket( new PacketFAPluginMessage( "MC|TPack", ( texture.getUrl() + "\00" + texture.getSize() ).getBytes() ) );
} }
} }
@ -74,9 +74,9 @@ public class UpstreamBridge extends PacketHandler
@Override @Override
public void handle(Packet0KeepAlive alive) throws Exception public void handle(Packet0KeepAlive alive) throws Exception
{ {
if ( alive.id == con.trackingPingId ) if ( alive.id == con.getSentPingId() )
{ {
int newPing = (int) ( System.currentTimeMillis() - con.pingTime ); int newPing = (int) ( System.currentTimeMillis() - con.getSentPingTime() );
bungee.getTabListHandler().onPingChange( con, newPing ); bungee.getTabListHandler().onPingChange( con, newPing );
con.setPing( newPing ); con.setPing( newPing );
} }