geforkt von Mirrors/Velocity
add method to get player ping
Dieser Commit ist enthalten in:
Ursprung
ebb1810392
Commit
bf2dff7693
@ -33,6 +33,12 @@ public interface Player extends CommandSource, InboundConnection, ChannelMessage
|
|||||||
*/
|
*/
|
||||||
Optional<ServerConnection> getCurrentServer();
|
Optional<ServerConnection> getCurrentServer();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the current player's ping
|
||||||
|
* @return the player's ping or -1 if ping information is currently unknown
|
||||||
|
*/
|
||||||
|
long getPing();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends a chat message to the player's client.
|
* Sends a chat message to the player's client.
|
||||||
* @param component the chat message to send
|
* @param component the chat message to send
|
||||||
|
@ -32,7 +32,8 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
|
|||||||
private static final int MAX_PLUGIN_CHANNELS = 128;
|
private static final int MAX_PLUGIN_CHANNELS = 128;
|
||||||
|
|
||||||
private final ConnectedPlayer player;
|
private final ConnectedPlayer player;
|
||||||
private long lastPing = -1;
|
private long lastPingID = -1;
|
||||||
|
private long lastPingSent = -1;
|
||||||
private boolean spawned = false;
|
private boolean spawned = false;
|
||||||
private final List<UUID> serverBossBars = new ArrayList<>();
|
private final List<UUID> serverBossBars = new ArrayList<>();
|
||||||
private final Set<String> clientPluginMsgChannels = new HashSet<>();
|
private final Set<String> clientPluginMsgChannels = new HashSet<>();
|
||||||
@ -57,11 +58,13 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
|
|||||||
public void handle(MinecraftPacket packet) {
|
public void handle(MinecraftPacket packet) {
|
||||||
if (packet instanceof KeepAlive) {
|
if (packet instanceof KeepAlive) {
|
||||||
KeepAlive keepAlive = (KeepAlive) packet;
|
KeepAlive keepAlive = (KeepAlive) packet;
|
||||||
if (keepAlive.getRandomId() != lastPing) {
|
if (keepAlive.getRandomId() != lastPingID) {
|
||||||
// The last keep alive we got was probably from a different server. Let's ignore it, and hope the next
|
// The last keep alive we got was probably from a different server. Let's ignore it, and hope the next
|
||||||
// ping is alright.
|
// ping is alright.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
player.setPing(System.currentTimeMillis() - lastPingSent);
|
||||||
|
resetPingData();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (packet instanceof ClientSettings) {
|
if (packet instanceof ClientSettings) {
|
||||||
@ -148,7 +151,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void handleBackendJoinGame(JoinGame joinGame) {
|
public void handleBackendJoinGame(JoinGame joinGame) {
|
||||||
lastPing = Long.MIN_VALUE; // reset last ping
|
resetPingData(); // reset ping data;
|
||||||
if (!spawned) {
|
if (!spawned) {
|
||||||
// nothing special to do here
|
// nothing special to do here
|
||||||
spawned = true;
|
spawned = true;
|
||||||
@ -256,6 +259,12 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setLastPing(long lastPing) {
|
public void setLastPing(long lastPing) {
|
||||||
this.lastPing = lastPing;
|
this.lastPingID = lastPing;
|
||||||
|
this.lastPingSent = System.currentTimeMillis();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void resetPingData() {
|
||||||
|
this.lastPingID = -1;
|
||||||
|
this.lastPingSent = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -52,6 +52,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
|
|||||||
private final GameProfile profile;
|
private final GameProfile profile;
|
||||||
private PermissionFunction permissionFunction = null;
|
private PermissionFunction permissionFunction = null;
|
||||||
private int tryIndex = 0;
|
private int tryIndex = 0;
|
||||||
|
private long ping = -1;
|
||||||
private VelocityServerConnection connectedServer;
|
private VelocityServerConnection connectedServer;
|
||||||
private ClientSettings clientSettings;
|
private ClientSettings clientSettings;
|
||||||
private VelocityServerConnection connectionInFlight;
|
private VelocityServerConnection connectionInFlight;
|
||||||
@ -85,6 +86,15 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
|
|||||||
return connection;
|
return connection;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getPing() {
|
||||||
|
return this.ping;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPing(long ping) {
|
||||||
|
this.ping = ping;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InetSocketAddress getRemoteAddress() {
|
public InetSocketAddress getRemoteAddress() {
|
||||||
return (InetSocketAddress) connection.getChannel().remoteAddress();
|
return (InetSocketAddress) connection.getChannel().remoteAddress();
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren