1313public class VelocityPlayerImpl implements IPlayer {
1414
1515 private static final Field MINECRAFT_CONNECTION_FIELD ;
16+ private static final Field LEGACY_MINECRAFT_CONNECTION_FIELD ;
1617 private static final Field REMOTE_ADDRESS_FIELD ;
1718 private static final Method CLOSE_CHANNEL_METHOD ;
1819
1920 static {
2021 try {
2122 MINECRAFT_CONNECTION_FIELD = ReflectionUtils .getPrivateField (Class .forName ("com.velocitypowered.proxy.connection.client.InitialInboundConnection" ), "connection" );
23+ LEGACY_MINECRAFT_CONNECTION_FIELD = ReflectionUtils .getPrivateField (Class .forName ("com.velocitypowered.proxy.connection.client.HandshakeSessionHandler$LegacyInboundConnection" ), "connection" );
2224
2325 Class <?> minecraftConnection = Class .forName ("com.velocitypowered.proxy.connection.MinecraftConnection" );
2426 REMOTE_ADDRESS_FIELD = ReflectionUtils .getPrivateField (minecraftConnection , "remoteAddress" );
@@ -29,10 +31,12 @@ public class VelocityPlayerImpl implements IPlayer {
2931 }
3032
3133 private final InboundConnection inboundConnection ;
34+ private final boolean legacy ;
3235 private String ip ;
3336
3437 public VelocityPlayerImpl (InboundConnection inboundConnection ) {
3538 this .inboundConnection = inboundConnection ;
39+ this .legacy = inboundConnection .getProtocolVersion ().isUnknown () || inboundConnection .getProtocolVersion ().isLegacy ();
3640 this .ip = inboundConnection .getRemoteAddress ().getAddress ().getHostAddress ();
3741 }
3842
@@ -41,6 +45,7 @@ public String getUUID() {
4145 return "unknown" ; // not supported
4246 }
4347
48+ @ Override
4449 public String getName () {
4550 return "unknown" ; // not supported
4651 }
@@ -50,6 +55,10 @@ public String getIP() {
5055 return ip ;
5156 }
5257
58+ public boolean isLegacy () {
59+ return legacy ;
60+ }
61+
5362 @ Override
5463 public void setIP (InetSocketAddress ip ) throws IPModificationFailureException {
5564 this .ip = ip .getAddress ().getHostAddress ();
@@ -65,7 +74,8 @@ public void setIP(InetSocketAddress ip) throws IPModificationFailureException {
6574 @ Override
6675 public void disconnect () {
6776 try {
68- Object minecraftConnection = MINECRAFT_CONNECTION_FIELD .get (inboundConnection );
77+ Object minecraftConnection = legacy ? LEGACY_MINECRAFT_CONNECTION_FIELD .get (inboundConnection ) : MINECRAFT_CONNECTION_FIELD .get (inboundConnection );
78+
6979 CLOSE_CHANNEL_METHOD .invoke (minecraftConnection );
7080 } catch (Exception e ) {
7181 throw new RuntimeException (e ); // pass exception on
0 commit comments