Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-11-20 06:50:08 +01:00
Reflection for Bungee stuffs
Dieser Commit ist enthalten in:
Ursprung
178b625ca0
Commit
ec848d7201
@ -1,7 +1,6 @@
|
||||
package us.myles.ViaVersion;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import net.md_5.bungee.UserConnection;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
@ -15,6 +14,7 @@ import us.myles.ViaVersion.api.ViaAPI;
|
||||
import us.myles.ViaVersion.api.ViaVersionConfig;
|
||||
import us.myles.ViaVersion.api.command.ViaCommandSender;
|
||||
import us.myles.ViaVersion.api.configuration.ConfigurationProvider;
|
||||
import us.myles.ViaVersion.api.data.UserConnection;
|
||||
import us.myles.ViaVersion.api.platform.TaskId;
|
||||
import us.myles.ViaVersion.api.platform.ViaPlatform;
|
||||
import us.myles.ViaVersion.bungee.commands.BungeeCommand;
|
||||
@ -25,7 +25,10 @@ import us.myles.ViaVersion.bungee.service.ProtocolDetectorService;
|
||||
import us.myles.ViaVersion.bungee.storage.BungeeStorage;
|
||||
import us.myles.ViaVersion.dump.PluginInfo;
|
||||
import us.myles.ViaVersion.util.GsonUtil;
|
||||
import us.myles.ViaVersion.util.ReflectionUtil;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
@ -153,7 +156,6 @@ public class BungeePlugin extends Plugin implements ViaPlatform, Listener {
|
||||
plugins.add(new PluginInfo(true, p.getDescription().getName(), p.getDescription().getVersion(), p.getDescription().getMain(), Arrays.asList(p.getDescription().getAuthor())));
|
||||
|
||||
platformSpecific.add("plugins", GsonUtil.getGson().toJsonTree(plugins));
|
||||
// TODO more? ProtocolLib things etc?
|
||||
|
||||
return platformSpecific;
|
||||
}
|
||||
@ -163,17 +165,25 @@ public class BungeePlugin extends Plugin implements ViaPlatform, Listener {
|
||||
Via.getManager().removePortedClient(e.getPlayer().getUniqueId());
|
||||
}
|
||||
|
||||
// Set the handshake version every time someone connects to any server TODO reflection
|
||||
// Set the handshake version every time someone connects to any server
|
||||
@EventHandler
|
||||
public void onServerConnect(ServerConnectEvent e) throws NoSuchFieldException, IllegalAccessException {
|
||||
us.myles.ViaVersion.api.data.UserConnection user = Via.getManager().getConnection(e.getPlayer().getUniqueId());
|
||||
UserConnection user = Via.getManager().getConnection(e.getPlayer().getUniqueId());
|
||||
if (!user.has(BungeeStorage.class)) {
|
||||
user.put(new BungeeStorage(user, e.getPlayer()));
|
||||
}
|
||||
|
||||
int protocolId = ProtocolDetectorService.getProtocolId(e.getTarget().getName());
|
||||
UserConnection connection = (UserConnection) e.getPlayer();
|
||||
connection.getPendingConnection().getHandshake().setProtocolVersion(protocolId);
|
||||
try {
|
||||
Object pendingConnection = ReflectionUtil.invoke(e.getPlayer(), "getPendingConnection");
|
||||
Object handshake = ReflectionUtil.invoke(pendingConnection, "getHandshake");
|
||||
Method setProtocol = handshake.getClass().getDeclaredMethod("setProtocolVersion", int.class);
|
||||
setProtocol.invoke(handshake, protocolId);
|
||||
} catch (NoSuchMethodException e1) {
|
||||
e1.printStackTrace();
|
||||
} catch (InvocationTargetException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -5,7 +5,6 @@ import io.netty.channel.ChannelHandler;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.handler.codec.MessageToMessageEncoder;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.netty.ChannelWrapper;
|
||||
import us.myles.ViaVersion.api.PacketWrapper;
|
||||
import us.myles.ViaVersion.api.Pair;
|
||||
import us.myles.ViaVersion.api.Via;
|
||||
@ -92,8 +91,7 @@ public class BungeeEncodeHandler extends MessageToMessageEncoder<ByteBuf> {
|
||||
super.exceptionCaught(ctx, cause);
|
||||
}
|
||||
|
||||
// TODO reflection
|
||||
public void checkServerChange() throws NoSuchFieldException, IllegalAccessException {
|
||||
public void checkServerChange() throws Exception {
|
||||
if (info.has(BungeeStorage.class)) {
|
||||
BungeeStorage storage = info.get(BungeeStorage.class);
|
||||
ProxiedPlayer player = storage.getPlayer();
|
||||
@ -111,10 +109,9 @@ public class BungeeEncodeHandler extends MessageToMessageEncoder<ByteBuf> {
|
||||
}
|
||||
|
||||
int protocolId = ProtocolDetectorService.getProtocolId(serverName);
|
||||
net.md_5.bungee.UserConnection connection = (net.md_5.bungee.UserConnection) player;
|
||||
|
||||
ChannelWrapper wrapper = ReflectionUtil.get(connection, "ch", ChannelWrapper.class);
|
||||
wrapper.setVersion(protocolId);
|
||||
Object wrapper = ReflectionUtil.get(player, "ch", Object.class);
|
||||
wrapper.getClass().getDeclaredMethod("setVersion", int.class).invoke(wrapper, protocolId);
|
||||
|
||||
us.myles.ViaVersion.api.data.UserConnection viaConnection = Via.getManager().getConnection(player.getUniqueId());
|
||||
ProtocolInfo info = viaConnection.get(ProtocolInfo.class);
|
||||
@ -127,7 +124,7 @@ public class BungeeEncodeHandler extends MessageToMessageEncoder<ByteBuf> {
|
||||
pipeline.add(prot.getValue());
|
||||
}
|
||||
}
|
||||
connection.init();
|
||||
ReflectionUtil.invoke(player, "init");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren