3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-11-08 17:20:24 +01:00

Merge pull request #1340 from KennyTV/master

Support latest Velocity changes
Dieser Commit ist enthalten in:
Myles 2019-05-15 22:23:37 +01:00 committet von GitHub
Commit cb857d828f
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23

Datei anzeigen

@ -16,15 +16,14 @@ import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.protocols.base.ProtocolInfo; import us.myles.ViaVersion.protocols.base.ProtocolInfo;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.packets.InventoryPackets; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.packets.InventoryPackets;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9To1_8; import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9To1_8;
import us.myles.ViaVersion.util.ReflectionUtil;
import us.myles.ViaVersion.velocity.service.ProtocolDetectorService; import us.myles.ViaVersion.velocity.service.ProtocolDetectorService;
import us.myles.ViaVersion.velocity.storage.VelocityStorage; import us.myles.ViaVersion.velocity.storage.VelocityStorage;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Set;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.Semaphore; import java.util.concurrent.Semaphore;
@ -34,7 +33,6 @@ public class VelocityServerHandler {
private static Method getMinecraftConnection; private static Method getMinecraftConnection;
private static Method getNextProtocolVersion; private static Method getNextProtocolVersion;
private static Method getKnownChannels; private static Method getKnownChannels;
private static Class<?> clientPlaySessionHandler;
static { static {
try { try {
@ -42,13 +40,11 @@ public class VelocityServerHandler {
.getDeclaredMethod("setProtocolVersion", ProtocolVersion.class); .getDeclaredMethod("setProtocolVersion", ProtocolVersion.class);
setNextProtocolVersion = Class.forName("com.velocitypowered.proxy.connection.MinecraftConnection") setNextProtocolVersion = Class.forName("com.velocitypowered.proxy.connection.MinecraftConnection")
.getDeclaredMethod("setNextProtocolVersion", ProtocolVersion.class); .getDeclaredMethod("setNextProtocolVersion", ProtocolVersion.class);
getMinecraftConnection = Class.forName("com.velocitypowered.proxy.connection.client.ConnectedPlayer") Class<?> connectedPlayer = Class.forName("com.velocitypowered.proxy.connection.client.ConnectedPlayer");
.getDeclaredMethod("getMinecraftConnection"); getMinecraftConnection = connectedPlayer.getDeclaredMethod("getMinecraftConnection");
getNextProtocolVersion = Class.forName("com.velocitypowered.proxy.connection.MinecraftConnection") getNextProtocolVersion = Class.forName("com.velocitypowered.proxy.connection.MinecraftConnection")
.getDeclaredMethod("getNextProtocolVersion"); .getDeclaredMethod("getNextProtocolVersion");
clientPlaySessionHandler = Class.forName("com.velocitypowered.proxy.connection.client.ClientPlaySessionHandler"); getKnownChannels = connectedPlayer.getDeclaredMethod("getKnownChannels");
getKnownChannels = clientPlaySessionHandler
.getDeclaredMethod("getKnownChannels");
} catch (NoSuchMethodException | ClassNotFoundException e) { } catch (NoSuchMethodException | ClassNotFoundException e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -79,7 +75,6 @@ public class VelocityServerHandler {
@Subscribe(order = PostOrder.LATE) @Subscribe(order = PostOrder.LATE)
public void connectedEvent(ServerConnectedEvent e) { public void connectedEvent(ServerConnectedEvent e) {
UserConnection user = Via.getManager().getConnection(e.getPlayer().getUniqueId());
try { try {
checkServerChange(e, Via.getManager().getConnection(e.getPlayer().getUniqueId())); checkServerChange(e, Via.getManager().getConnection(e.getPlayer().getUniqueId()));
} catch (Exception e1) { } catch (Exception e1) {
@ -144,18 +139,11 @@ public class VelocityServerHandler {
// Add version-specific base Protocol // Add version-specific base Protocol
pipeline.add(ProtocolRegistry.getBaseProtocol(protocolId)); pipeline.add(ProtocolRegistry.getBaseProtocol(protocolId));
// Workaround 1.13 server change Collection<String> knownChannels = (Collection<String>) getKnownChannels.invoke(e.getPlayer());
Object sessionHandler = ReflectionUtil.invoke(
getMinecraftConnection.invoke(e.getPlayer()),
"getSessionHandler"
);
if (clientPlaySessionHandler.isInstance(sessionHandler)) { // It may be InitialConnectSessionHandler on the first server connection
Set<String> knownChannels = (Set<String>) getKnownChannels.invoke(sessionHandler);
if (previousServerProtocol != -1) { if (previousServerProtocol != -1) {
int id1_13 = ProtocolVersion.MINECRAFT_1_13.getProtocol(); int id1_13 = ProtocolVersion.MINECRAFT_1_13.getProtocol();
if (previousServerProtocol < id1_13 && protocolId >= id1_13) { if (previousServerProtocol < id1_13 && protocolId >= id1_13) {
ArrayList<String> newChannels = new ArrayList<>(); List<String> newChannels = new ArrayList<>();
for (String oldChannel : knownChannels) { for (String oldChannel : knownChannels) {
String transformed = InventoryPackets.getNewPluginChannelId(oldChannel); String transformed = InventoryPackets.getNewPluginChannelId(oldChannel);
if (transformed != null) { if (transformed != null) {
@ -165,7 +153,7 @@ public class VelocityServerHandler {
knownChannels.clear(); knownChannels.clear();
knownChannels.addAll(newChannels); knownChannels.addAll(newChannels);
} else if (previousServerProtocol >= id1_13 && protocolId < id1_13) { } else if (previousServerProtocol >= id1_13 && protocolId < id1_13) {
ArrayList<String> newChannels = new ArrayList<>(); List<String> newChannels = new ArrayList<>();
for (String oldChannel : knownChannels) { for (String oldChannel : knownChannels) {
String transformed = InventoryPackets.getOldPluginChannelId(oldChannel); String transformed = InventoryPackets.getOldPluginChannelId(oldChannel);
if (transformed != null) { if (transformed != null) {
@ -176,7 +164,6 @@ public class VelocityServerHandler {
knownChannels.addAll(newChannels); knownChannels.addAll(newChannels);
} }
} }
}
user.put(info); user.put(info);
user.put(storage); user.put(storage);