3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-07-06 07:18:03 +02:00

Small refactoring

Dieser Commit ist enthalten in:
Nassim Jahnke 2022-11-03 18:30:59 +01:00
Ursprung d3d8d1cab3
Commit fad350c811
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 6BE3B555EBC5982B
5 geänderte Dateien mit 22 neuen und 40 gelöschten Zeilen

Datei anzeigen

@ -30,24 +30,22 @@ import java.util.logging.Level;
public final class ProtocolSupportCompat {
public static void registerPSConnectListener(ViaVersionPlugin plugin) {
if (isMultiplatformPS()) {
Via.getPlatform().getLogger().info("Registering ProtocolSupport compat connection listener");
try {
//noinspection unchecked
Class<? extends Event> connectionOpenEvent = (Class<? extends Event>) Class.forName("protocolsupport.api.events.ConnectionOpenEvent");
Bukkit.getPluginManager().registerEvent(connectionOpenEvent, new Listener() {
}, EventPriority.HIGH, (listener, event) -> {
try {
Object connection = event.getClass().getMethod("getConnection").invoke(event);
ProtocolSupportConnectionListener connectListener = new ProtocolSupportConnectionListener(connection);
ProtocolSupportConnectionListener.ADD_PACKET_LISTENER_METHOD.invoke(connection, connectListener);
} catch (Exception e) {
Via.getPlatform().getLogger().log(Level.WARNING, "Error when handling ProtocolSupport event", e);
}
}, plugin);
} catch (Exception e) {
Via.getPlatform().getLogger().log(Level.WARNING, "Unable to register ProtocolSupport listener", e);
}
Via.getPlatform().getLogger().info("Registering ProtocolSupport compat connection listener");
try {
//noinspection unchecked
Class<? extends Event> connectionOpenEvent = (Class<? extends Event>) Class.forName("protocolsupport.api.events.ConnectionOpenEvent");
Bukkit.getPluginManager().registerEvent(connectionOpenEvent, new Listener() {
}, EventPriority.HIGH, (listener, event) -> {
try {
Object connection = event.getClass().getMethod("getConnection").invoke(event);
ProtocolSupportConnectionListener connectListener = new ProtocolSupportConnectionListener(connection);
ProtocolSupportConnectionListener.ADD_PACKET_LISTENER_METHOD.invoke(connection, connectListener);
} catch (ReflectiveOperationException e) {
Via.getPlatform().getLogger().log(Level.WARNING, "Error when handling ProtocolSupport event", e);
}
}, plugin);
} catch (ClassNotFoundException e) {
Via.getPlatform().getLogger().log(Level.WARNING, "Unable to register ProtocolSupport listener", e);
}
}
@ -60,7 +58,7 @@ public final class ProtocolSupportCompat {
}
}
public static HandshakeProtocolType handshakeVersionMethod() {
static HandshakeProtocolType handshakeVersionMethod() {
Class<?> clazz = null;
// Check for the mapped method
try {
@ -88,7 +86,7 @@ public final class ProtocolSupportCompat {
}
}
public enum HandshakeProtocolType {
enum HandshakeProtocolType {
MAPPED("getProtocolVersion"),
OBFUSCATED_B("b"),

Datei anzeigen

@ -70,12 +70,7 @@ final class ProtocolSupportConnectionListener extends Connection.PacketListener
// Check if we are getting handshake packet.
if (HANDSHAKE_PACKET_CLASS.isInstance(event.getPacket()) && GET_VERSION_METHOD.invoke(connection) == PROTOCOL_VERSION_MINECRAFT_FUTURE) {
final Object packet = event.getPacket();
final int protocolVersion;
try {
protocolVersion = (int) HANDSHAKE_PACKET_CLASS.getDeclaredMethod(ProtocolSupportCompat.handshakeVersionMethod().methodName()).invoke(packet);
} catch (final ReflectiveOperationException e) {
throw new RuntimeException(e);
}
final int protocolVersion = (int) HANDSHAKE_PACKET_CLASS.getDeclaredMethod(ProtocolSupportCompat.handshakeVersionMethod().methodName()).invoke(packet);
// ViaVersion has at this point already spoofed the connectionversion. (Since it is higher up the pipeline)
// If via has put the protoVersion to the server we can spoof ProtocolSupport's version.

Datei anzeigen

@ -88,7 +88,7 @@ public class BukkitViaLoader implements ViaPlatformLoader {
final ViaVersionPlugin plugin = (ViaVersionPlugin) Bukkit.getPluginManager().getPlugin("ViaVersion");
// Add ProtocolSupport ConnectListener if necessary.
if (plugin.isProtocolSupport()) {
if (plugin.isProtocolSupport() && ProtocolSupportCompat.isMultiplatformPS()) {
ProtocolSupportCompat.registerPSConnectListener(plugin);
}

Datei anzeigen

@ -53,10 +53,6 @@ public class NMSUtil {
return Class.forName(BASE + "." + className);
}
public static String getVersion() {
return BASE.substring(BASE.lastIndexOf('.') + 1);
}
/**
* @return true if debug=true is set in the server.properties (added by CB)
*/

Datei anzeigen

@ -18,7 +18,6 @@
package com.viaversion.viaversion.protocols.protocol1_19_3to1_19_1.packets;
import com.google.gson.JsonElement;
import com.viaversion.viaversion.api.minecraft.ProfileKey;
import com.viaversion.viaversion.api.minecraft.entities.Entity1_19_3Types;
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
@ -125,15 +124,9 @@ public final class EntityPackets extends EntityRewriter<Protocol1_19_3To1_19_1>
final int gamemode = wrapper.read(Type.VAR_INT);
final int ping = wrapper.read(Type.VAR_INT);
final JsonElement displayName = wrapper.read(Type.OPTIONAL_COMPONENT);
final ProfileKey profileKey = wrapper.read(Type.OPTIONAL_PROFILE_KEY);
if (profileKey != null) {
wrapper.write(Type.BOOLEAN, true);
wrapper.write(Type.UUID, UUID.randomUUID());
wrapper.write(Type.PROFILE_KEY, profileKey);
} else {
wrapper.write(Type.BOOLEAN, false);
}
wrapper.read(Type.OPTIONAL_PROFILE_KEY);
wrapper.write(Type.BOOLEAN, false); // No chat session data
wrapper.write(Type.VAR_INT, gamemode);
wrapper.write(Type.BOOLEAN, true); // Also update listed
wrapper.write(Type.VAR_INT, ping);