3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-10-08 11:10:06 +02:00

Check SessionHandler type before getting knownChannels

Dieser Commit ist enthalten in:
creeper123123321 2019-04-21 18:56:01 -03:00
Ursprung 9fe19e763a
Commit bd7e36e38c
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 0AC57D54786721D1

Datei anzeigen

@ -34,6 +34,7 @@ public class VelocityServerHandler {
private static Method getMinecraftConnection; private static Method getMinecraftConnection;
private static Method getNextProtocolVersion; private static Method getNextProtocolVersion;
private static Method getKnownChannels; private static Method getKnownChannels;
private static Class<?> clientPlaySessionHandler;
static { static {
try { try {
@ -45,7 +46,8 @@ public class VelocityServerHandler {
.getDeclaredMethod("getMinecraftConnection"); .getDeclaredMethod("getMinecraftConnection");
getNextProtocolVersion = Class.forName("com.velocitypowered.proxy.connection.MinecraftConnection") getNextProtocolVersion = Class.forName("com.velocitypowered.proxy.connection.MinecraftConnection")
.getDeclaredMethod("getNextProtocolVersion"); .getDeclaredMethod("getNextProtocolVersion");
getKnownChannels = Class.forName("com.velocitypowered.proxy.connection.client.ClientPlaySessionHandler") clientPlaySessionHandler = Class.forName("com.velocitypowered.proxy.connection.client.ClientPlaySessionHandler");
getKnownChannels = clientPlaySessionHandler
.getDeclaredMethod("getKnownChannels"); .getDeclaredMethod("getKnownChannels");
} catch (NoSuchMethodException | ClassNotFoundException e) { } catch (NoSuchMethodException | ClassNotFoundException e) {
e.printStackTrace(); e.printStackTrace();
@ -144,34 +146,36 @@ public class VelocityServerHandler {
pipeline.add(ProtocolRegistry.getBaseProtocol(protocolId)); pipeline.add(ProtocolRegistry.getBaseProtocol(protocolId));
// Workaround 1.13 server change // Workaround 1.13 server change
Set<String> knownChannels = (Set<String>) getKnownChannels.invoke( Object sessionHandler = ReflectionUtil.invoke(
ReflectionUtil.invoke( getMinecraftConnection.invoke(e.getPlayer()),
getMinecraftConnection.invoke(e.getPlayer()), "getSessionHandler"
"getSessionHandler"
)
); );
if (previousServerProtocol != -1) { System.out.println(sessionHandler);
int id1_13 = ProtocolVersion.MINECRAFT_1_13.getProtocol(); if (clientPlaySessionHandler.isInstance(sessionHandler)) { // It may be InitialConnectSessionHandler on the first server connection
if (previousServerProtocol < id1_13 && protocolId >= id1_13) { Set<String> knownChannels = (Set<String>) getKnownChannels.invoke(sessionHandler);
ArrayList<String> newChannels = new ArrayList<>(); if (previousServerProtocol != -1) {
for (String oldChannel : knownChannels) { int id1_13 = ProtocolVersion.MINECRAFT_1_13.getProtocol();
String transformed = InventoryPackets.getNewPluginChannelId(oldChannel); if (previousServerProtocol < id1_13 && protocolId >= id1_13) {
if (transformed != null) { ArrayList<String> newChannels = new ArrayList<>();
newChannels.add(transformed); for (String oldChannel : knownChannels) {
String transformed = InventoryPackets.getNewPluginChannelId(oldChannel);
if (transformed != null) {
newChannels.add(transformed);
}
} }
} knownChannels.clear();
knownChannels.clear(); knownChannels.addAll(newChannels);
knownChannels.addAll(newChannels); } else if (previousServerProtocol >= id1_13 && protocolId < id1_13) {
} else if (previousServerProtocol >= id1_13 && protocolId < id1_13) { ArrayList<String> newChannels = new ArrayList<>();
ArrayList<String> newChannels = new ArrayList<>(); for (String oldChannel : knownChannels) {
for (String oldChannel : knownChannels) { String transformed = InventoryPackets.getOldPluginChannelId(oldChannel);
String transformed = InventoryPackets.getOldPluginChannelId(oldChannel); if (transformed != null) {
if (transformed != null) { newChannels.add(transformed);
newChannels.add(transformed); }
} }
knownChannels.clear();
knownChannels.addAll(newChannels);
} }
knownChannels.clear();
knownChannels.addAll(newChannels);
} }
} }