3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-12-25 15:50:10 +01:00

Move PS compatibility to an addon

PS has long been dead, so moving it away removes unnecessary complexity/the extra module. The additional code when getting the protocol version was long dead as well, since all connections are injected.
Dieser Commit ist enthalten in:
Nassim Jahnke 2024-05-12 20:48:44 +02:00
Ursprung fcfea24b36
Commit d6b5b5dc3e
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: EF6771C01F6EF02F
15 geänderte Dateien mit 3 neuen und 328 gelöschten Zeilen

Datei anzeigen

@ -78,7 +78,6 @@ public interface ViaAPI<T> {
/**
* Returns the protocol version of a player.
* This will also retrieve the version from ProtocolSupport if it's being used.
*
* @param player the platform's player object, e.g. Bukkit this is Player
* @return protocol version, for example (47=1.8-1.8.8, 107=1.9, 108=1.9.1), or -1 if no longer connected
@ -89,7 +88,6 @@ public interface ViaAPI<T> {
/**
* Returns the protocol version of a player.
* This will also retrieve the version from ProtocolSupport if it's being used.
*
* @param player the platform's player object, e.g. Bukkit this is Player
* @return the protocol version object (see {@link ProtocolVersion}), or ProtocolVersion.unknown if not connected
@ -109,7 +107,6 @@ public interface ViaAPI<T> {
/**
* Returns the protocol version of a player.
* This will also retrieve the version from ProtocolSupport if it's being used.
*
* @param uuid UUID of a player
* @return the protocol version object (see {@link ProtocolVersion}), or ProtocolVersion.unknown if not connected

Datei anzeigen

@ -54,7 +54,6 @@ public interface ConnectionManager {
* Returns the frontend UserConnection from the player connected to this proxy server
* Returns null when there isn't a server or connection was not found
* When ViaVersion is reloaded, this method may not return some players.
* May not return ProtocolSupport players.
* <p>
* Note that connections are removed as soon as their channel is closed,
* so avoid using this method during player quits for example.
@ -67,7 +66,6 @@ public interface ConnectionManager {
* Returns the UUID from the frontend connection to this proxy server
* Returns null when there isn't a server or this connection isn't frontend, or it doesn't have an id
* When ViaVersion is reloaded, this method may not return some players.
* May not return ProtocolSupport players.
* <p>
* Note that connections are removed as soon as their channel is closed,
* so avoid using this method during player quits for example.
@ -81,7 +79,6 @@ public interface ConnectionManager {
* May contain duplicated UUIDs on multiple ProtocolInfo.
* May contain frontend, backend and/or client-sided connections.
* When ViaVersion is reloaded, this method may not return some players.
* May not contain ProtocolSupport players.
*
* @return connected UserConnections
*/
@ -91,7 +88,6 @@ public interface ConnectionManager {
* Returns a map containing the UUIDs and frontend UserConnections from players connected to this proxy server
* Returns empty list when there isn't a server
* When ViaVersion is reloaded, this method may not return some players.
* May not contain ProtocolSupport players.
*
* @return map containing the UUIDs and frontend UserConnections from players connected to this proxy server
*/

Datei anzeigen

@ -200,15 +200,6 @@ public interface ViaPlatform<T> {
*/
JsonObject getDump();
/**
* Get if older clients are allowed using ViaVersion.
*
* @return True if allowed
*/
default boolean isOldClientsAllowed() {
return true;
}
/**
* Returns an immutable collection of classes to be checked as unsupported software with their software name.
* If any of the classes exist at runtime, a warning about their potential instability will be given to the console.

Datei anzeigen

@ -1,61 +0,0 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2024 ViaVersion and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.viaversion.viaversion.bukkit.util;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.logging.Level;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import com.viaversion.viaversion.api.protocol.version.VersionType;
import org.bukkit.entity.Player;
public final class ProtocolSupportUtil {
private static final Method PROTOCOL_VERSION_METHOD;
private static final Method GET_ID_METHOD;
static {
Method protocolVersionMethod = null;
Method getIdMethod = null;
try {
protocolVersionMethod = Class.forName("protocolsupport.api.ProtocolSupportAPI").getMethod("getProtocolVersion", Player.class);
getIdMethod = Class.forName("protocolsupport.api.ProtocolVersion").getMethod("getId");
} catch (ReflectiveOperationException e) {
// ProtocolSupport not installed.
}
PROTOCOL_VERSION_METHOD = protocolVersionMethod;
GET_ID_METHOD = getIdMethod;
}
public static ProtocolVersion getProtocolVersion(Player player) {
if (PROTOCOL_VERSION_METHOD == null) {
return ProtocolVersion.unknown;
}
try {
final Object version = PROTOCOL_VERSION_METHOD.invoke(null, player);
final int id = (int) GET_ID_METHOD.invoke(version);
// List of pre netty (<= 1.6.4) versions supported by ProtocolSupport, needs to be updated if ProtocolSupport adds support for new versions.
final boolean preNetty = id == 78 || id == 74 || id == 73 || id == 61 || id == 60 || id == 51;
return ProtocolVersion.getProtocol(preNetty ? VersionType.RELEASE_INITIAL : VersionType.RELEASE, id);
} catch (IllegalAccessException | InvocationTargetException e) {
Via.getPlatform().getLogger().log(Level.SEVERE, "Failed to get ProtocolSupport version", e);
}
return ProtocolVersion.unknown;
}
}

Datei anzeigen

@ -6,7 +6,6 @@ dependencies {
exclude("com.google.code.gson", "gson")
exclude("javax.persistence", "persistence-api")
}
compileOnly(projects.compat.protocolsupportCompat)
}
publishShadowJar()

Datei anzeigen

@ -59,7 +59,6 @@ public class ViaVersionPlugin extends JavaPlugin implements ViaPlatform<Player>
private final BukkitCommandHandler commandHandler = new BukkitCommandHandler();
private final BukkitViaConfig conf;
private final ViaAPI<Player> api = new BukkitViaAPI(this);
private boolean protocolSupport;
private boolean lateBind;
public ViaVersionPlugin() {
@ -78,7 +77,6 @@ public class ViaVersionPlugin extends JavaPlugin implements ViaPlatform<Player>
@Override
public void onLoad() {
protocolSupport = Bukkit.getPluginManager().getPlugin("ProtocolSupport") != null;
lateBind = !((BukkitViaInjector) Via.getManager().getInjector()).isBinded();
if (!lateBind) {
@ -241,11 +239,6 @@ public class ViaVersionPlugin extends JavaPlugin implements ViaPlatform<Player>
return platformSpecific;
}
@Override
public boolean isOldClientsAllowed() {
return !protocolSupport; // Use protocolsupport for older clients
}
@Override
public BukkitViaConfig getConf() {
return conf;
@ -279,10 +272,6 @@ public class ViaVersionPlugin extends JavaPlugin implements ViaPlatform<Player>
return lateBind;
}
public boolean isProtocolSupport() {
return protocolSupport;
}
/**
* @deprecated use {@link Via#getAPI()} instead
*/

Datei anzeigen

@ -1,104 +0,0 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2024 ViaVersion and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.viaversion.viaversion.bukkit.compat;
import com.viaversion.viaversion.ViaVersionPlugin;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.bukkit.util.NMSUtil;
import java.util.logging.Level;
import org.bukkit.Bukkit;
import org.bukkit.event.Event;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
public final class ProtocolSupportCompat {
public static void registerPSConnectListener(ViaVersionPlugin plugin) {
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);
}
}
public static boolean isMultiplatformPS() {
try {
Class.forName("protocolsupport.zplatform.impl.spigot.network.pipeline.SpigotPacketEncoder");
return true;
} catch (ClassNotFoundException e) {
return false;
}
}
static HandshakeProtocolType handshakeVersionMethod() {
Class<?> clazz = null;
// Check for the mapped method
try {
clazz = NMSUtil.nms(
"PacketHandshakingInSetProtocol",
"net.minecraft.network.protocol.handshake.PacketHandshakingInSetProtocol"
);
clazz.getMethod("getProtocolVersion");
return HandshakeProtocolType.MAPPED;
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
} catch (NoSuchMethodException ignored) {
}
// Check for obfuscated b/c methods
try {
if (clazz.getMethod("b").getReturnType() == int.class) {
return HandshakeProtocolType.OBFUSCATED_B;
} else if (clazz.getMethod("c").getReturnType() == int.class) {
return HandshakeProtocolType.OBFUSCATED_C;
}
throw new UnsupportedOperationException("Protocol version method not found in " + clazz.getSimpleName());
} catch (ReflectiveOperationException e) {
throw new RuntimeException(e);
}
}
enum HandshakeProtocolType {
MAPPED("getProtocolVersion"),
OBFUSCATED_B("b"),
OBFUSCATED_C("c");
private final String methodName;
HandshakeProtocolType(String methodName) {
this.methodName = methodName;
}
public String methodName() {
return methodName;
}
}
}

Datei anzeigen

@ -1,87 +0,0 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2024 ViaVersion and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.viaversion.viaversion.bukkit.compat;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.bukkit.util.NMSUtil;
import java.lang.reflect.Method;
import protocolsupport.api.Connection;
final class ProtocolSupportConnectionListener extends Connection.PacketListener {
static final Method ADD_PACKET_LISTENER_METHOD;
private static final Class<?> HANDSHAKE_PACKET_CLASS;
private static final Method GET_VERSION_METHOD;
private static final Method SET_VERSION_METHOD;
private static final Method REMOVE_PACKET_LISTENER_METHOD;
private static final Method GET_LATEST_METHOD;
private static final Object PROTOCOL_VERSION_MINECRAFT_FUTURE;
private static final Object PROTOCOL_TYPE_PC;
static {
try {
HANDSHAKE_PACKET_CLASS = NMSUtil.nms(
"PacketHandshakingInSetProtocol",
"net.minecraft.network.protocol.handshake.PacketHandshakingInSetProtocol"
);
final Class<?> connectionImplClass = Class.forName("protocolsupport.protocol.ConnectionImpl");
final Class<?> connectionClass = Class.forName("protocolsupport.api.Connection");
final Class<?> packetListenerClass = Class.forName("protocolsupport.api.Connection$PacketListener");
final Class<?> protocolVersionClass = Class.forName("protocolsupport.api.ProtocolVersion");
final Class<?> protocolTypeClass = Class.forName("protocolsupport.api.ProtocolType");
GET_VERSION_METHOD = connectionClass.getDeclaredMethod("getVersion");
SET_VERSION_METHOD = connectionImplClass.getDeclaredMethod("setVersion", protocolVersionClass);
PROTOCOL_VERSION_MINECRAFT_FUTURE = protocolVersionClass.getDeclaredField("MINECRAFT_FUTURE").get(null);
GET_LATEST_METHOD = protocolVersionClass.getDeclaredMethod("getLatest", protocolTypeClass);
PROTOCOL_TYPE_PC = protocolTypeClass.getDeclaredField("PC").get(null);
ADD_PACKET_LISTENER_METHOD = connectionClass.getDeclaredMethod("addPacketListener", packetListenerClass);
REMOVE_PACKET_LISTENER_METHOD = connectionClass.getDeclaredMethod("removePacketListener", packetListenerClass);
} catch (final ReflectiveOperationException e) {
throw new RuntimeException(e);
}
}
private final Object connection;
ProtocolSupportConnectionListener(final Object connection) {
this.connection = connection;
}
@Override
public void onPacketReceiving(final Connection.PacketListener.PacketEvent event) {
try {
// 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 = (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.
if (protocolVersion == Via.getAPI().getServerVersion().lowestSupportedVersion()) {
SET_VERSION_METHOD.invoke(connection, GET_LATEST_METHOD.invoke(null, PROTOCOL_TYPE_PC));
}
}
// Id version is not serverversion viaversion will not spoof. ProtocolSupport will handle the rest.
// In any case, remove the packet listener and wrap up.
REMOVE_PACKET_LISTENER_METHOD.invoke(connection, this);
} catch (final ReflectiveOperationException e) {
throw new RuntimeException(e);
}
}
}

Datei anzeigen

@ -22,10 +22,8 @@ import com.viaversion.viaversion.ViaVersionPlugin;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import com.viaversion.viaversion.bukkit.util.ProtocolSupportUtil;
import io.netty.buffer.ByteBuf;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
public class BukkitViaAPI extends ViaAPIBase<Player> {
@ -46,13 +44,6 @@ public class BukkitViaAPI extends ViaAPIBase<Player> {
if (connection != null) {
return connection.getProtocolInfo().protocolVersion();
}
if (isProtocolSupport()) {
Player player = Bukkit.getPlayer(uuid);
if (player != null) {
return ProtocolSupportUtil.getProtocolVersion(player);
}
}
return ProtocolVersion.unknown;
}
@ -60,13 +51,4 @@ public class BukkitViaAPI extends ViaAPIBase<Player> {
public void sendRawPacket(Player player, ByteBuf packet) throws IllegalArgumentException {
sendRawPacket(player.getUniqueId(), packet);
}
/**
* Returns if ProtocolSupport is also being used.
*
* @return true if ProtocolSupport is used
*/
public boolean isProtocolSupport() {
return plugin.isProtocolSupport();
}
}

Datei anzeigen

@ -23,7 +23,6 @@ import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.platform.ViaPlatformLoader;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import com.viaversion.viaversion.bukkit.compat.ProtocolSupportCompat;
import com.viaversion.viaversion.bukkit.listeners.UpdateListener;
import com.viaversion.viaversion.bukkit.listeners.multiversion.PlayerSneakListener;
import com.viaversion.viaversion.bukkit.listeners.protocol1_15to1_14_4.EntityToggleGlideListener;
@ -76,12 +75,6 @@ public class BukkitViaLoader implements ViaPlatformLoader {
/* Base Protocol */
final ViaVersionPlugin plugin = (ViaVersionPlugin) Bukkit.getPluginManager().getPlugin("ViaVersion");
// Add ProtocolSupport ConnectListener if necessary.
if (plugin.isProtocolSupport() && ProtocolSupportCompat.isMultiplatformPS()) {
ProtocolSupportCompat.registerPSConnectListener(plugin);
}
if (!Via.getAPI().getServerVersion().isKnown()) {
Via.getPlatform().getLogger().severe("Server version has not been loaded yet, cannot register additional listeners");
return;

Datei anzeigen

@ -84,7 +84,7 @@ public class BaseProtocol extends AbstractProtocol<BaseClientboundPacket, BaseCl
// Only allow newer clients (or 1.9.2 on 1.9.4 server if the server supports it)
ProtocolManager protocolManager = Via.getManager().getProtocolManager();
if (info.protocolVersion().newerThanOrEqualTo(serverProtocol) || Via.getPlatform().isOldClientsAllowed()) {
if (info.protocolVersion().newerThanOrEqualTo(serverProtocol)) {
protocolPath = protocolManager.getProtocolPath(info.protocolVersion(), serverProtocol);
}

Datei anzeigen

@ -108,7 +108,7 @@ public class BaseProtocol1_7 extends AbstractProtocol<BaseClientboundPacket, Bas
}
List<ProtocolPathEntry> protocols = null;
if (info.protocolVersion().newerThanOrEqualTo(closestServerProtocol) || Via.getPlatform().isOldClientsAllowed()) {
if (info.protocolVersion().newerThanOrEqualTo(closestServerProtocol)) {
protocols = Via.getManager().getProtocolManager()
.getProtocolPath(info.protocolVersion(), closestServerProtocol);
}

Datei anzeigen

@ -1,2 +0,0 @@
dependencies {
}

Datei anzeigen

@ -1,18 +0,0 @@
package protocolsupport.api;
public abstract class Connection {
public abstract static class PacketListener {
public void onPacketReceiving(PacketEvent event) {
throw new UnsupportedOperationException();
}
public static class PacketEvent {
public Object getPacket() {
throw new UnsupportedOperationException();
}
}
}
}

Datei anzeigen

@ -27,7 +27,7 @@ rootProject.name = "viaversion-parent"
includeBuild("build-logic")
include("compat", "compat:snakeyaml-compat-common", "compat:snakeyaml2-compat", "compat:snakeyaml1-compat", "compat:protocolsupport-compat")
include("compat", "compat:snakeyaml-compat-common", "compat:snakeyaml2-compat", "compat:snakeyaml1-compat")
setupViaSubproject("api")
setupViaSubproject("common")