Implement ProtocolState API (#1224)
* Implement ProtocolState API * Renamed method to #getProtocolState * Added sinceMinecraft javadoc tag * Fixed PreLoginEvent#getUniqueId documentation
This commit is contained in:
@@ -33,6 +33,7 @@ import com.velocitypowered.api.event.player.KickedFromServerEvent.ServerKickResu
|
||||
import com.velocitypowered.api.event.player.PlayerModInfoEvent;
|
||||
import com.velocitypowered.api.event.player.PlayerSettingsChangedEvent;
|
||||
import com.velocitypowered.api.event.player.ServerPreConnectEvent;
|
||||
import com.velocitypowered.api.network.ProtocolState;
|
||||
import com.velocitypowered.api.network.ProtocolVersion;
|
||||
import com.velocitypowered.api.permission.PermissionFunction;
|
||||
import com.velocitypowered.api.permission.PermissionProvider;
|
||||
@@ -1170,6 +1171,11 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player,
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProtocolState getProtocolState() {
|
||||
return connection.getState().toProtocolState();
|
||||
}
|
||||
|
||||
private final class ConnectionRequestBuilderImpl implements ConnectionRequestBuilder {
|
||||
|
||||
private final RegisteredServer toConnect;
|
||||
|
@@ -20,6 +20,7 @@ package com.velocitypowered.proxy.connection.client;
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.velocitypowered.api.event.connection.ConnectionHandshakeEvent;
|
||||
import com.velocitypowered.api.network.ProtocolState;
|
||||
import com.velocitypowered.api.network.ProtocolVersion;
|
||||
import com.velocitypowered.proxy.VelocityServer;
|
||||
import com.velocitypowered.proxy.config.PlayerInfoForwarding;
|
||||
@@ -247,9 +248,9 @@ public class HandshakeSessionHandler implements MinecraftSessionHandler {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
boolean isPlayerAddressLoggingEnabled = connection.server.getConfiguration()
|
||||
final boolean isPlayerAddressLoggingEnabled = connection.server.getConfiguration()
|
||||
.isPlayerAddressLoggingEnabled();
|
||||
String playerIp =
|
||||
final String playerIp =
|
||||
isPlayerAddressLoggingEnabled
|
||||
? this.getRemoteAddress().toString() : "<ip address withheld>";
|
||||
return "[legacy connection] " + playerIp;
|
||||
@@ -259,5 +260,10 @@ public class HandshakeSessionHandler implements MinecraftSessionHandler {
|
||||
public MinecraftConnection getConnection() {
|
||||
return connection;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProtocolState getProtocolState() {
|
||||
return connection.getState().toProtocolState();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -17,6 +17,7 @@
|
||||
|
||||
package com.velocitypowered.proxy.connection.client;
|
||||
|
||||
import com.velocitypowered.api.network.ProtocolState;
|
||||
import com.velocitypowered.api.network.ProtocolVersion;
|
||||
import com.velocitypowered.api.proxy.InboundConnection;
|
||||
import com.velocitypowered.proxy.connection.MinecraftConnection;
|
||||
@@ -87,6 +88,11 @@ public final class InitialInboundConnection implements VelocityInboundConnection
|
||||
return connection;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProtocolState getProtocolState() {
|
||||
return connection.getState().toProtocolState();
|
||||
}
|
||||
|
||||
/**
|
||||
* Disconnects the connection from the server.
|
||||
*
|
||||
|
@@ -17,6 +17,7 @@
|
||||
|
||||
package com.velocitypowered.proxy.connection.client;
|
||||
|
||||
import com.velocitypowered.api.network.ProtocolState;
|
||||
import com.velocitypowered.api.network.ProtocolVersion;
|
||||
import com.velocitypowered.api.proxy.LoginPhaseConnection;
|
||||
import com.velocitypowered.api.proxy.crypto.IdentifiedKey;
|
||||
@@ -166,4 +167,9 @@ public class LoginInboundConnection implements LoginPhaseConnection, KeyIdentifi
|
||||
public IdentifiedKey getIdentifiedKey() {
|
||||
return playerKey;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProtocolState getProtocolState() {
|
||||
return delegate.getProtocolState();
|
||||
}
|
||||
}
|
||||
|
@@ -45,6 +45,7 @@ import static com.velocitypowered.proxy.protocol.ProtocolUtils.Direction;
|
||||
import static com.velocitypowered.proxy.protocol.ProtocolUtils.Direction.CLIENTBOUND;
|
||||
import static com.velocitypowered.proxy.protocol.ProtocolUtils.Direction.SERVERBOUND;
|
||||
|
||||
import com.velocitypowered.api.network.ProtocolState;
|
||||
import com.velocitypowered.api.network.ProtocolVersion;
|
||||
import com.velocitypowered.proxy.protocol.packet.AvailableCommandsPacket;
|
||||
import com.velocitypowered.proxy.protocol.packet.BossBarPacket;
|
||||
@@ -623,6 +624,21 @@ public enum StateRegistry {
|
||||
return (direction == SERVERBOUND ? serverbound : clientbound).getProtocolRegistry(version);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the API representation of the StateRegistry.
|
||||
*
|
||||
* @return the API representation
|
||||
*/
|
||||
public ProtocolState toProtocolState() {
|
||||
return switch (this) {
|
||||
case HANDSHAKE -> ProtocolState.HANDSHAKE;
|
||||
case STATUS -> ProtocolState.STATUS;
|
||||
case LOGIN -> ProtocolState.LOGIN;
|
||||
case CONFIG -> ProtocolState.CONFIGURATION;
|
||||
case PLAY -> ProtocolState.PLAY;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Packet registry.
|
||||
*/
|
||||
|
Reference in New Issue
Block a user