3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-11-19 14:30:16 +01:00

Fix connection field search on 1.20.2

Dieser Commit ist enthalten in:
Nassim Jahnke 2023-09-25 09:57:55 +10:00
Ursprung 270d28f259
Commit d92b9fdeaa

Datei anzeigen

@ -46,8 +46,8 @@ public class JoinListener implements Listener {
Field gamePacketListenerField = null, connectionField = null, channelField = null; Field gamePacketListenerField = null, connectionField = null, channelField = null;
try { try {
getHandleMethod = NMSUtil.obc("entity.CraftPlayer").getDeclaredMethod("getHandle"); getHandleMethod = NMSUtil.obc("entity.CraftPlayer").getDeclaredMethod("getHandle");
gamePacketListenerField = findField(getHandleMethod.getReturnType(), "PlayerConnection", "ServerGamePacketListenerImpl"); gamePacketListenerField = findField(false, getHandleMethod.getReturnType(), "PlayerConnection", "ServerGamePacketListenerImpl");
connectionField = findField(gamePacketListenerField.getType(), "NetworkManager", "Connection"); connectionField = findField(true, gamePacketListenerField.getType(), "NetworkManager", "Connection");
channelField = findField(connectionField.getType(), Class.forName("io.netty.channel.Channel")); channelField = findField(connectionField.getType(), Class.forName("io.netty.channel.Channel"));
} catch (NoSuchMethodException | NoSuchFieldException | ClassNotFoundException e) { } catch (NoSuchMethodException | NoSuchFieldException | ClassNotFoundException e) {
Via.getPlatform().getLogger().log( Via.getPlatform().getLogger().log(
@ -63,8 +63,8 @@ public class JoinListener implements Listener {
} }
// Loosely search a field with any name, as long as it matches a type name. // Loosely search a field with any name, as long as it matches a type name.
private static Field findField(Class<?> clazz, String... types) throws NoSuchFieldException { private static Field findField(boolean all, Class<?> clazz, String... types) throws NoSuchFieldException {
for (Field field : clazz.getDeclaredFields()) { for (Field field : all ? clazz.getFields() : clazz.getDeclaredFields()) {
String fieldTypeName = field.getType().getSimpleName(); String fieldTypeName = field.getType().getSimpleName();
for (String type : types) { for (String type : types) {
if (!fieldTypeName.equals(type)) { if (!fieldTypeName.equals(type)) {