3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-07-11 09:48: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 final class ProtocolSupportCompat {
public static void registerPSConnectListener(ViaVersionPlugin plugin) { public static void registerPSConnectListener(ViaVersionPlugin plugin) {
if (isMultiplatformPS()) { Via.getPlatform().getLogger().info("Registering ProtocolSupport compat connection listener");
Via.getPlatform().getLogger().info("Registering ProtocolSupport compat connection listener"); try {
try { //noinspection unchecked
//noinspection unchecked Class<? extends Event> connectionOpenEvent = (Class<? extends Event>) Class.forName("protocolsupport.api.events.ConnectionOpenEvent");
Class<? extends Event> connectionOpenEvent = (Class<? extends Event>) Class.forName("protocolsupport.api.events.ConnectionOpenEvent"); Bukkit.getPluginManager().registerEvent(connectionOpenEvent, new Listener() {
Bukkit.getPluginManager().registerEvent(connectionOpenEvent, new Listener() { }, EventPriority.HIGH, (listener, event) -> {
}, EventPriority.HIGH, (listener, event) -> { try {
try { Object connection = event.getClass().getMethod("getConnection").invoke(event);
Object connection = event.getClass().getMethod("getConnection").invoke(event); ProtocolSupportConnectionListener connectListener = new ProtocolSupportConnectionListener(connection);
ProtocolSupportConnectionListener connectListener = new ProtocolSupportConnectionListener(connection); ProtocolSupportConnectionListener.ADD_PACKET_LISTENER_METHOD.invoke(connection, connectListener);
ProtocolSupportConnectionListener.ADD_PACKET_LISTENER_METHOD.invoke(connection, connectListener); } catch (ReflectiveOperationException e) {
} catch (Exception e) { Via.getPlatform().getLogger().log(Level.WARNING, "Error when handling ProtocolSupport event", e);
Via.getPlatform().getLogger().log(Level.WARNING, "Error when handling ProtocolSupport event", e); }
} }, plugin);
}, plugin); } catch (ClassNotFoundException e) {
} catch (Exception e) { Via.getPlatform().getLogger().log(Level.WARNING, "Unable to register ProtocolSupport listener", 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; Class<?> clazz = null;
// Check for the mapped method // Check for the mapped method
try { try {
@ -88,7 +86,7 @@ public final class ProtocolSupportCompat {
} }
} }
public enum HandshakeProtocolType { enum HandshakeProtocolType {
MAPPED("getProtocolVersion"), MAPPED("getProtocolVersion"),
OBFUSCATED_B("b"), OBFUSCATED_B("b"),

Datei anzeigen

@ -70,12 +70,7 @@ final class ProtocolSupportConnectionListener extends Connection.PacketListener
// Check if we are getting handshake packet. // Check if we are getting handshake packet.
if (HANDSHAKE_PACKET_CLASS.isInstance(event.getPacket()) && GET_VERSION_METHOD.invoke(connection) == PROTOCOL_VERSION_MINECRAFT_FUTURE) { if (HANDSHAKE_PACKET_CLASS.isInstance(event.getPacket()) && GET_VERSION_METHOD.invoke(connection) == PROTOCOL_VERSION_MINECRAFT_FUTURE) {
final Object packet = event.getPacket(); final Object packet = event.getPacket();
final int protocolVersion; final int protocolVersion = (int) HANDSHAKE_PACKET_CLASS.getDeclaredMethod(ProtocolSupportCompat.handshakeVersionMethod().methodName()).invoke(packet);
try {
protocolVersion = (int) HANDSHAKE_PACKET_CLASS.getDeclaredMethod(ProtocolSupportCompat.handshakeVersionMethod().methodName()).invoke(packet);
} catch (final ReflectiveOperationException e) {
throw new RuntimeException(e);
}
// ViaVersion has at this point already spoofed the connectionversion. (Since it is higher up the pipeline) // 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. // 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"); final ViaVersionPlugin plugin = (ViaVersionPlugin) Bukkit.getPluginManager().getPlugin("ViaVersion");
// Add ProtocolSupport ConnectListener if necessary. // Add ProtocolSupport ConnectListener if necessary.
if (plugin.isProtocolSupport()) { if (plugin.isProtocolSupport() && ProtocolSupportCompat.isMultiplatformPS()) {
ProtocolSupportCompat.registerPSConnectListener(plugin); ProtocolSupportCompat.registerPSConnectListener(plugin);
} }

Datei anzeigen

@ -53,10 +53,6 @@ public class NMSUtil {
return Class.forName(BASE + "." + className); 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) * @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; package com.viaversion.viaversion.protocols.protocol1_19_3to1_19_1.packets;
import com.google.gson.JsonElement; 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.Entity1_19_3Types;
import com.viaversion.viaversion.api.minecraft.entities.EntityType; import com.viaversion.viaversion.api.minecraft.entities.EntityType;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; 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 gamemode = wrapper.read(Type.VAR_INT);
final int ping = wrapper.read(Type.VAR_INT); final int ping = wrapper.read(Type.VAR_INT);
final JsonElement displayName = wrapper.read(Type.OPTIONAL_COMPONENT); final JsonElement displayName = wrapper.read(Type.OPTIONAL_COMPONENT);
final ProfileKey profileKey = wrapper.read(Type.OPTIONAL_PROFILE_KEY); 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.write(Type.BOOLEAN, false); // No chat session data
wrapper.write(Type.VAR_INT, gamemode); wrapper.write(Type.VAR_INT, gamemode);
wrapper.write(Type.BOOLEAN, true); // Also update listed wrapper.write(Type.BOOLEAN, true); // Also update listed
wrapper.write(Type.VAR_INT, ping); wrapper.write(Type.VAR_INT, ping);