Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-11-03 14:50:30 +01:00
Merge pull request #1340 from KennyTV/master
Support latest Velocity changes
Dieser Commit ist enthalten in:
Commit
cb857d828f
@ -16,15 +16,14 @@ import us.myles.ViaVersion.api.type.Type;
|
||||
import us.myles.ViaVersion.protocols.base.ProtocolInfo;
|
||||
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.util.ReflectionUtil;
|
||||
import us.myles.ViaVersion.velocity.service.ProtocolDetectorService;
|
||||
import us.myles.ViaVersion.velocity.storage.VelocityStorage;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.Semaphore;
|
||||
|
||||
@ -34,7 +33,6 @@ public class VelocityServerHandler {
|
||||
private static Method getMinecraftConnection;
|
||||
private static Method getNextProtocolVersion;
|
||||
private static Method getKnownChannels;
|
||||
private static Class<?> clientPlaySessionHandler;
|
||||
|
||||
static {
|
||||
try {
|
||||
@ -42,13 +40,11 @@ public class VelocityServerHandler {
|
||||
.getDeclaredMethod("setProtocolVersion", ProtocolVersion.class);
|
||||
setNextProtocolVersion = Class.forName("com.velocitypowered.proxy.connection.MinecraftConnection")
|
||||
.getDeclaredMethod("setNextProtocolVersion", ProtocolVersion.class);
|
||||
getMinecraftConnection = Class.forName("com.velocitypowered.proxy.connection.client.ConnectedPlayer")
|
||||
.getDeclaredMethod("getMinecraftConnection");
|
||||
Class<?> connectedPlayer = Class.forName("com.velocitypowered.proxy.connection.client.ConnectedPlayer");
|
||||
getMinecraftConnection = connectedPlayer.getDeclaredMethod("getMinecraftConnection");
|
||||
getNextProtocolVersion = Class.forName("com.velocitypowered.proxy.connection.MinecraftConnection")
|
||||
.getDeclaredMethod("getNextProtocolVersion");
|
||||
clientPlaySessionHandler = Class.forName("com.velocitypowered.proxy.connection.client.ClientPlaySessionHandler");
|
||||
getKnownChannels = clientPlaySessionHandler
|
||||
.getDeclaredMethod("getKnownChannels");
|
||||
getKnownChannels = connectedPlayer.getDeclaredMethod("getKnownChannels");
|
||||
} catch (NoSuchMethodException | ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -79,7 +75,6 @@ public class VelocityServerHandler {
|
||||
|
||||
@Subscribe(order = PostOrder.LATE)
|
||||
public void connectedEvent(ServerConnectedEvent e) {
|
||||
UserConnection user = Via.getManager().getConnection(e.getPlayer().getUniqueId());
|
||||
try {
|
||||
checkServerChange(e, Via.getManager().getConnection(e.getPlayer().getUniqueId()));
|
||||
} catch (Exception e1) {
|
||||
@ -144,37 +139,29 @@ public class VelocityServerHandler {
|
||||
// Add version-specific base Protocol
|
||||
pipeline.add(ProtocolRegistry.getBaseProtocol(protocolId));
|
||||
|
||||
// Workaround 1.13 server change
|
||||
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) {
|
||||
int id1_13 = ProtocolVersion.MINECRAFT_1_13.getProtocol();
|
||||
if (previousServerProtocol < id1_13 && protocolId >= id1_13) {
|
||||
ArrayList<String> newChannels = new ArrayList<>();
|
||||
for (String oldChannel : knownChannels) {
|
||||
String transformed = InventoryPackets.getNewPluginChannelId(oldChannel);
|
||||
if (transformed != null) {
|
||||
newChannels.add(transformed);
|
||||
}
|
||||
Collection<String> knownChannels = (Collection<String>) getKnownChannels.invoke(e.getPlayer());
|
||||
if (previousServerProtocol != -1) {
|
||||
int id1_13 = ProtocolVersion.MINECRAFT_1_13.getProtocol();
|
||||
if (previousServerProtocol < id1_13 && protocolId >= id1_13) {
|
||||
List<String> newChannels = new ArrayList<>();
|
||||
for (String oldChannel : knownChannels) {
|
||||
String transformed = InventoryPackets.getNewPluginChannelId(oldChannel);
|
||||
if (transformed != null) {
|
||||
newChannels.add(transformed);
|
||||
}
|
||||
knownChannels.clear();
|
||||
knownChannels.addAll(newChannels);
|
||||
} else if (previousServerProtocol >= id1_13 && protocolId < id1_13) {
|
||||
ArrayList<String> newChannels = new ArrayList<>();
|
||||
for (String oldChannel : knownChannels) {
|
||||
String transformed = InventoryPackets.getOldPluginChannelId(oldChannel);
|
||||
if (transformed != null) {
|
||||
newChannels.add(transformed);
|
||||
}
|
||||
}
|
||||
knownChannels.clear();
|
||||
knownChannels.addAll(newChannels);
|
||||
}
|
||||
knownChannels.clear();
|
||||
knownChannels.addAll(newChannels);
|
||||
} else if (previousServerProtocol >= id1_13 && protocolId < id1_13) {
|
||||
List<String> newChannels = new ArrayList<>();
|
||||
for (String oldChannel : knownChannels) {
|
||||
String transformed = InventoryPackets.getOldPluginChannelId(oldChannel);
|
||||
if (transformed != null) {
|
||||
newChannels.add(transformed);
|
||||
}
|
||||
}
|
||||
knownChannels.clear();
|
||||
knownChannels.addAll(newChannels);
|
||||
}
|
||||
}
|
||||
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren