Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-11-03 14:50:30 +01:00
Merge pull request #1099 from creeper123123321/master
Fix Velocity platform breaking changes
Dieser Commit ist enthalten in:
Commit
2812b121ab
@ -2,20 +2,18 @@ package us.myles.ViaVersion.velocity.handlers;
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelInitializer;
|
||||
import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.AllArgsConstructor;
|
||||
import us.myles.ViaVersion.api.data.UserConnection;
|
||||
import us.myles.ViaVersion.api.protocol.ProtocolPipeline;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class VelocityChannelInitializer extends ChannelInitializer {
|
||||
@NonNull
|
||||
private ChannelInitializer original;
|
||||
private Method initChannel;
|
||||
private static Method initChannel;
|
||||
|
||||
{
|
||||
static {
|
||||
try {
|
||||
initChannel = ChannelInitializer.class.getDeclaredMethod("initChannel", Channel.class);
|
||||
initChannel.setAccessible(true);
|
||||
|
@ -4,6 +4,7 @@ import com.velocitypowered.api.event.PostOrder;
|
||||
import com.velocitypowered.api.event.Subscribe;
|
||||
import com.velocitypowered.api.event.player.ServerConnectedEvent;
|
||||
import com.velocitypowered.api.event.player.ServerPreConnectEvent;
|
||||
import com.velocitypowered.api.network.ProtocolVersion;
|
||||
import us.myles.ViaVersion.api.Pair;
|
||||
import us.myles.ViaVersion.api.Via;
|
||||
import us.myles.ViaVersion.api.boss.BossBar;
|
||||
@ -28,8 +29,10 @@ public class VelocityServerHandler {
|
||||
|
||||
static {
|
||||
try {
|
||||
setProtocolVersion = Class.forName("com.velocitypowered.proxy.connection.MinecraftConnection").getDeclaredMethod("setProtocolVersion", int.class);
|
||||
setNextProtocolVersion = Class.forName("com.velocitypowered.proxy.connection.MinecraftConnection").getDeclaredMethod("setNextProtocolVersion", int.class);
|
||||
setProtocolVersion = Class.forName("com.velocitypowered.proxy.connection.MinecraftConnection")
|
||||
.getDeclaredMethod("setProtocolVersion", ProtocolVersion.class);
|
||||
setNextProtocolVersion = Class.forName("com.velocitypowered.proxy.connection.MinecraftConnection")
|
||||
.getDeclaredMethod("setNextProtocolVersion", ProtocolVersion.class);
|
||||
} catch (NoSuchMethodException | ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -49,7 +52,9 @@ public class VelocityServerHandler {
|
||||
|
||||
// Check if ViaVersion can support that version
|
||||
Object connection = ReflectionUtil.invoke(e.getPlayer(), "getConnection");
|
||||
setNextProtocolVersion.invoke(connection, protocols == null ? user.get(ProtocolInfo.class).getProtocolVersion() : protocolId);
|
||||
setNextProtocolVersion.invoke(connection, ProtocolVersion.getProtocolVersion(protocols == null
|
||||
? user.get(ProtocolInfo.class).getProtocolVersion()
|
||||
: protocolId));
|
||||
|
||||
} catch (IllegalAccessException | NoSuchMethodException | InvocationTargetException e1) {
|
||||
e1.printStackTrace();
|
||||
@ -128,8 +133,8 @@ public class VelocityServerHandler {
|
||||
}
|
||||
|
||||
Object connection = ReflectionUtil.invoke(e.getPlayer(), "getConnection");
|
||||
int version = (int) ReflectionUtil.invoke(connection,"getNextProtocolVersion");
|
||||
setProtocolVersion.invoke(ReflectionUtil.invoke(e.getPlayer(), "getConnection"), version);
|
||||
ProtocolVersion version = (ProtocolVersion) ReflectionUtil.invoke(connection,"getNextProtocolVersion");
|
||||
setProtocolVersion.invoke(connection, version);
|
||||
}
|
||||
}
|
||||
user.getVelocityLock().writeLock().unlock();
|
||||
|
@ -29,8 +29,8 @@ public class VelocityViaInjector implements ViaInjector {
|
||||
return getLowestSupportedProtocolVersion();
|
||||
}
|
||||
|
||||
public static int getLowestSupportedProtocolVersion() throws Exception {
|
||||
return ReflectionUtil.getStatic(Class.forName("com.velocitypowered.proxy.protocol.ProtocolConstants"), "MINIMUM_GENERIC_VERSION", int.class);
|
||||
public static int getLowestSupportedProtocolVersion() {
|
||||
return com.velocitypowered.api.network.ProtocolVersion.MINIMUM_VERSION.getProtocol();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -6,42 +6,30 @@ import us.myles.ViaVersion.api.data.UserConnection;
|
||||
import us.myles.ViaVersion.api.protocol.ProtocolVersion;
|
||||
import us.myles.ViaVersion.protocols.base.ProtocolInfo;
|
||||
import us.myles.ViaVersion.protocols.base.VersionProvider;
|
||||
import us.myles.ViaVersion.util.ReflectionUtil;
|
||||
import us.myles.ViaVersion.velocity.platform.VelocityViaInjector;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class VelocityVersionProvider extends VersionProvider {
|
||||
private static Class<?> ref ;
|
||||
|
||||
static {
|
||||
try {
|
||||
ref = Class.forName("com.velocitypowered.proxy.protocol.ProtocolConstants");
|
||||
} catch (Exception e) {
|
||||
Via.getPlatform().getLogger().severe("Could not detect the ProtocolConstants class");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getServerProtocol(UserConnection user) throws Exception {
|
||||
if (ref == null)
|
||||
return super.getServerProtocol(user);
|
||||
// TODO Have one constant list forever until restart? (Might limit plugins if they change this)
|
||||
Object list = ReflectionUtil.getStatic(ref, "SUPPORTED_VERSIONS", Object.class);
|
||||
List<Integer> sorted = new ArrayList<Integer>((List) ReflectionUtil.invoke(list, "asList"));
|
||||
List<Integer> sorted = new ArrayList<>(com.velocitypowered.api.network.ProtocolVersion.ID_TO_PROTOCOL_CONSTANT.keySet());
|
||||
sorted.remove(Integer.valueOf(-1)); // Unknown/legacy
|
||||
Collections.sort(sorted);
|
||||
|
||||
ProtocolInfo info = user.get(ProtocolInfo.class);
|
||||
int playerVersion = user.get(ProtocolInfo.class).getProtocolVersion();
|
||||
|
||||
// Bungee supports it
|
||||
if (sorted.contains(info.getProtocolVersion()))
|
||||
return info.getProtocolVersion();
|
||||
if (sorted.contains(playerVersion))
|
||||
return playerVersion;
|
||||
|
||||
// Older than bungee supports, get the lowest version
|
||||
if (info.getProtocolVersion() < sorted.get(0)) {
|
||||
return getLowestSupportedVersion();
|
||||
if (playerVersion < sorted.get(0)) {
|
||||
return VelocityViaInjector.getLowestSupportedProtocolVersion();
|
||||
}
|
||||
|
||||
// Loop through all protocols to get the closest protocol id that bungee supports (and that viaversion does too)
|
||||
@ -49,25 +37,11 @@ public class VelocityVersionProvider extends VersionProvider {
|
||||
// TODO: This needs a better fix, i.e checking ProtocolRegistry to see if it would work.
|
||||
// This is more of a workaround for snapshot support by bungee.
|
||||
for (Integer protocol : Lists.reverse(sorted)) {
|
||||
if (info.getProtocolVersion() > protocol && ProtocolVersion.isRegistered(protocol))
|
||||
if (playerVersion > protocol && ProtocolVersion.isRegistered(protocol))
|
||||
return protocol;
|
||||
}
|
||||
|
||||
Via.getPlatform().getLogger().severe("Panic, no protocol id found for " + info.getProtocolVersion());
|
||||
return info.getProtocolVersion();
|
||||
}
|
||||
|
||||
public static int getLowestSupportedVersion() {
|
||||
List<Integer> list;
|
||||
try {
|
||||
return ReflectionUtil.getStatic(
|
||||
Class.forName("com.velocitypowered.proxy.protocol.ProtocolConstants"),
|
||||
"MINIMUM_GENERIC_VERSION",
|
||||
int.class);
|
||||
} catch (NoSuchFieldException | IllegalAccessException | ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
// Fallback
|
||||
return -1;
|
||||
Via.getPlatform().getLogger().severe("Panic, no protocol id found for " + playerVersion);
|
||||
return playerVersion;
|
||||
}
|
||||
}
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren