Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-11-03 14:50:30 +01:00
Merge remote-tracking branch 'upstream/1.11-DEV' into 1.11-DEV
Dieser Commit ist enthalten in:
Commit
839d46f5ed
@ -3,11 +3,10 @@ package us.myles.ViaVersion.bukkit.handlers;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.handler.codec.MessageToByteEncoder;
|
||||
import us.myles.ViaVersion.ViaVersionPlugin;
|
||||
import us.myles.ViaVersion.api.PacketWrapper;
|
||||
import us.myles.ViaVersion.api.Via;
|
||||
import us.myles.ViaVersion.api.data.UserConnection;
|
||||
import us.myles.ViaVersion.api.type.Type;
|
||||
import us.myles.ViaVersion.bukkit.util.NMSUtil;
|
||||
import us.myles.ViaVersion.exception.CancelException;
|
||||
import us.myles.ViaVersion.packets.Direction;
|
||||
import us.myles.ViaVersion.protocols.base.ProtocolInfo;
|
||||
@ -17,6 +16,16 @@ import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
public class BukkitEncodeHandler extends MessageToByteEncoder {
|
||||
private static Field versionField = null;
|
||||
|
||||
static {
|
||||
try {
|
||||
versionField = NMSUtil.nms("PacketEncoder").getDeclaredField("version");
|
||||
versionField.setAccessible(true);
|
||||
} catch (Exception e){
|
||||
// Not compat version
|
||||
}
|
||||
}
|
||||
private final UserConnection info;
|
||||
private final MessageToByteEncoder minecraftEncoder;
|
||||
|
||||
@ -28,10 +37,8 @@ public class BukkitEncodeHandler extends MessageToByteEncoder {
|
||||
|
||||
@Override
|
||||
protected void encode(final ChannelHandlerContext ctx, Object o, final ByteBuf bytebuf) throws Exception {
|
||||
if (((ViaVersionPlugin) Via.getPlatform()).isCompatSpigotBuild()) {
|
||||
Field ver = minecraftEncoder.getClass().getDeclaredField("version");
|
||||
ver.setAccessible(true);
|
||||
ver.set(minecraftEncoder, ver.get(this));
|
||||
if (versionField != null) {
|
||||
versionField.set(minecraftEncoder, versionField.get(this));
|
||||
}
|
||||
// handle the packet type
|
||||
if (!(o instanceof ByteBuf)) {
|
||||
|
@ -43,11 +43,11 @@ public class BukkitViaBulkChunkTranslator extends BulkChunkTranslatorProvider {
|
||||
if (Via.getConfig().isAntiXRay() && ((ViaVersionPlugin) Via.getPlatform()).isSpigot()) { //Spigot anti-xray patch
|
||||
try {
|
||||
Object world = mapChunkBulkRef.getFieldValue("world", packet, Object.class);
|
||||
Object spigotConfig = ReflectionUtil.getPublic(world, "spigotConfig", Object.class);
|
||||
Object antiXrayInstance = ReflectionUtil.getPublic(spigotConfig, "antiXrayInstance", Object.class);
|
||||
|
||||
for (int i = 0; i < xcoords.length; ++i) {
|
||||
Object spigotConfig = ReflectionUtil.getPublic(world, "spigotConfig", Object.class);
|
||||
Object antiXrayInstance = ReflectionUtil.getPublic(spigotConfig, "antiXrayInstance", Object.class);
|
||||
|
||||
// TODO: Possibly optimise this
|
||||
Object b = ReflectionUtil.get(chunkMaps[i], "b", Object.class);
|
||||
Object a = ReflectionUtil.get(chunkMaps[i], "a", Object.class);
|
||||
|
||||
|
@ -28,7 +28,6 @@ import us.myles.ViaVersion.bungee.storage.BungeeStorage;
|
||||
import us.myles.ViaVersion.dump.PluginInfo;
|
||||
import us.myles.ViaVersion.protocols.base.ProtocolInfo;
|
||||
import us.myles.ViaVersion.util.GsonUtil;
|
||||
import us.myles.ViaVersion.util.ReflectionUtil;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
@ -39,11 +38,26 @@ import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class BungeePlugin extends Plugin implements ViaPlatform, Listener {
|
||||
private static Method getPendingConnection;
|
||||
private static Method getHandshake;
|
||||
private static Method setProtocol;
|
||||
|
||||
private BungeeViaAPI api;
|
||||
private BungeeConfigAPI config;
|
||||
private BungeeCommandHandler commandHandler;
|
||||
|
||||
static {
|
||||
try {
|
||||
getPendingConnection = Class.forName("net.md_5.bungee.UserConnection").getDeclaredMethod("getPendingConnection");
|
||||
getHandshake = Class.forName("net.md_5.bungee.connection.InitialHandler").getDeclaredMethod("getHandshake");
|
||||
setProtocol = Class.forName("net.md_5.bungee.protocol.packet.Handshake").getDeclaredMethod("setProtocolVersion", int.class);
|
||||
} catch (NoSuchMethodException e) {
|
||||
e.printStackTrace();
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
api = new BungeeViaAPI();
|
||||
@ -179,13 +193,11 @@ public class BungeePlugin extends Plugin implements ViaPlatform, Listener {
|
||||
|
||||
// Check if ViaVersion can support that version
|
||||
try {
|
||||
Object pendingConnection = ReflectionUtil.invoke(e.getPlayer(), "getPendingConnection");
|
||||
Object handshake = ReflectionUtil.invoke(pendingConnection, "getHandshake");
|
||||
Method setProtocol = handshake.getClass().getDeclaredMethod("setProtocolVersion", int.class);
|
||||
Object pendingConnection = getPendingConnection.invoke(e.getPlayer());
|
||||
Object handshake = getHandshake.invoke(pendingConnection);
|
||||
setProtocol.invoke(handshake, protocols == null ? user.get(ProtocolInfo.class).getProtocolVersion() : protocolId);
|
||||
} catch (NoSuchMethodException | InvocationTargetException e1) {
|
||||
} catch (InvocationTargetException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -20,8 +20,9 @@ import us.myles.ViaVersion.exception.CancelException;
|
||||
import us.myles.ViaVersion.packets.Direction;
|
||||
import us.myles.ViaVersion.protocols.base.ProtocolInfo;
|
||||
import us.myles.ViaVersion.util.PipelineUtil;
|
||||
import us.myles.ViaVersion.util.ReflectionUtil;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.List;
|
||||
|
||||
@ChannelHandler.Sharable
|
||||
@ -128,13 +129,34 @@ public class BungeeEncodeHandler extends MessageToMessageEncoder<ByteBuf> {
|
||||
protocol.init(viaConnection);
|
||||
}
|
||||
|
||||
Object wrapper = ReflectionUtil.get(player, "ch", Object.class);
|
||||
wrapper.getClass().getDeclaredMethod("setVersion", int.class).invoke(wrapper, protocolId);
|
||||
Object wrapper = channelWrapper.get(player);
|
||||
setVersion.invoke(wrapper, protocolId);
|
||||
|
||||
Object entityMap = Class.forName("net.md_5.bungee.entitymap.EntityMap").getDeclaredMethod("getEntityMap", int.class).invoke(null, protocolId);
|
||||
ReflectionUtil.set(player, "entityRewrite", entityMap);
|
||||
Object entityMap = getEntityMap.invoke(null, protocolId);
|
||||
entityRewrite.set(player, entityMap);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
private static Method getEntityMap = null;
|
||||
private static Method setVersion = null;
|
||||
private static Field entityRewrite = null;
|
||||
private static Field channelWrapper = null;
|
||||
|
||||
static {
|
||||
try {
|
||||
getEntityMap = Class.forName("net.md_5.bungee.entitymap.EntityMap").getDeclaredMethod("getEntityMap", int.class);
|
||||
setVersion = Class.forName("net.md_5.bungee.netty.ChannelWrapper").getDeclaredMethod("setVersion", int.class);
|
||||
channelWrapper = Class.forName("net.md_5.bungee.UserConnection").getDeclaredField("ch");
|
||||
channelWrapper.setAccessible(true);
|
||||
entityRewrite = Class.forName("net.md_5.bungee.UserConnection").getDeclaredField("entityRewrite");
|
||||
entityRewrite.setAccessible(true);
|
||||
} catch (NoSuchMethodException e) {
|
||||
e.printStackTrace();
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} catch (NoSuchFieldException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,17 +2,14 @@ package us.myles.ViaVersion.bungee.service;
|
||||
|
||||
import lombok.Getter;
|
||||
import net.md_5.bungee.api.Callback;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.api.ServerPing;
|
||||
import net.md_5.bungee.api.config.ServerInfo;
|
||||
import us.myles.ViaVersion.BungeePlugin;
|
||||
import us.myles.ViaVersion.api.Via;
|
||||
import us.myles.ViaVersion.bungee.platform.BungeeConfigAPI;
|
||||
import us.myles.ViaVersion.bungee.providers.BungeeVersionProvider;
|
||||
import us.myles.ViaVersion.util.ReflectionUtil;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
|
@ -11,7 +11,7 @@ public class VersionInfo {
|
||||
private String javaVersion;
|
||||
private String operatingSystem;
|
||||
private int serverProtocol;
|
||||
private Set<Integer> enabledPipelines;
|
||||
private Set<Integer> enabledProtocols;
|
||||
private String platformName;
|
||||
private String platformVersion;
|
||||
}
|
||||
|
@ -8,10 +8,12 @@ import us.myles.ViaVersion.api.minecraft.item.Item;
|
||||
import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
|
||||
import us.myles.ViaVersion.api.platform.providers.ViaProviders;
|
||||
import us.myles.ViaVersion.api.protocol.Protocol;
|
||||
import us.myles.ViaVersion.api.remapper.PacketRemapper;
|
||||
import us.myles.ViaVersion.api.remapper.ValueTransformer;
|
||||
import us.myles.ViaVersion.api.type.Type;
|
||||
import us.myles.ViaVersion.api.type.types.version.Metadata1_8Type;
|
||||
import us.myles.ViaVersion.api.type.types.version.MetadataList1_8Type;
|
||||
import us.myles.ViaVersion.packets.State;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.packets.*;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.BulkChunkTranslatorProvider;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.HandItemProvider;
|
||||
@ -79,6 +81,15 @@ public class Protocol1_9TO1_8 extends Protocol {
|
||||
|
||||
@Override
|
||||
protected void registerPackets() {
|
||||
// Disconnect workaround (JSON!)
|
||||
registerOutgoing(State.LOGIN, 0x00, 0x00, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
map(Type.STRING, Protocol1_9TO1_8.FIX_JSON); // 0 - Reason
|
||||
}
|
||||
});
|
||||
|
||||
// Other Handlers
|
||||
SpawnPackets.register(this);
|
||||
InventoryPackets.register(this);
|
||||
EntityPackets.register(this);
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren