Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-12-27 08:30:09 +01:00
Small refactoring
Dieser Commit ist enthalten in:
Ursprung
d3d8d1cab3
Commit
fad350c811
@ -30,7 +30,6 @@ 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
|
||||
@ -41,15 +40,14 @@ public final class ProtocolSupportCompat {
|
||||
Object connection = event.getClass().getMethod("getConnection").invoke(event);
|
||||
ProtocolSupportConnectionListener connectListener = new ProtocolSupportConnectionListener(connection);
|
||||
ProtocolSupportConnectionListener.ADD_PACKET_LISTENER_METHOD.invoke(connection, connectListener);
|
||||
} catch (Exception e) {
|
||||
} catch (ReflectiveOperationException e) {
|
||||
Via.getPlatform().getLogger().log(Level.WARNING, "Error when handling ProtocolSupport event", e);
|
||||
}
|
||||
}, plugin);
|
||||
} catch (Exception e) {
|
||||
} catch (ClassNotFoundException e) {
|
||||
Via.getPlatform().getLogger().log(Level.WARNING, "Unable to register ProtocolSupport listener", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isMultiplatformPS() {
|
||||
try {
|
||||
@ -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"),
|
||||
|
@ -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.
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
*/
|
||||
|
@ -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);
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren