Search in sources :

Example 1 with DefinedPacket

use of net.md_5.bungee.protocol.DefinedPacket in project CloudNet by Dytanic.

the class ProxiedListener method handlePost.

@EventHandler
public void handlePost(PostLoginEvent e) {
    CloudProxy.getInstance().update();
    CloudAPI.getInstance().getNetworkConnection().sendPacket(new PacketOutLoginSuccess(e.getPlayer().getUniqueId()));
    if (CloudProxy.getInstance().getProxyGroup().getProxyConfig().isFastConnect()) {
        try {
            Field channelWrapper;
            try {
                channelWrapper = UserConnection.class.getDeclaredField("ch");
                channelWrapper.setAccessible(true);
            } catch (Exception ex) {
                channelWrapper = UserConnection.class.getField("ch");
                channelWrapper.setAccessible(true);
            }
            Field field;
            try {
                field = ChannelWrapper.class.getDeclaredField("ch");
                field.setAccessible(true);
            } catch (Exception ex) {
                field = ChannelWrapper.class.getField("ch");
                field.setAccessible(true);
            }
            Channel channel = (Channel) field.get(channelWrapper.get(e.getPlayer()));
            channel.pipeline().addAfter("packet-encoder", "cloudConnection", new MessageToMessageEncoder<DefinedPacket>() {

                @Override
                protected void encode(ChannelHandlerContext channelHandlerContext, DefinedPacket definedPacket, List<Object> out) throws Exception {
                    if (definedPacket instanceof Respawn) {
                        if (((Respawn) definedPacket).getDimension() != ((UserConnection) e.getPlayer()).getDimension())
                            ((Respawn) definedPacket).setDimension(((UserConnection) e.getPlayer()).getDimension());
                    }
                    out.add(definedPacket);
                }
            });
        } catch (IllegalAccessException | NoSuchFieldException e1) {
            e1.printStackTrace();
        }
    }
}
Also used : Channel(io.netty.channel.Channel) DefinedPacket(net.md_5.bungee.protocol.DefinedPacket) Respawn(net.md_5.bungee.protocol.packet.Respawn) ChannelWrapper(net.md_5.bungee.netty.ChannelWrapper) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) UserConnection(net.md_5.bungee.UserConnection) Field(java.lang.reflect.Field) EventHandler(net.md_5.bungee.event.EventHandler)

Aggregations

Channel (io.netty.channel.Channel)1 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)1 Field (java.lang.reflect.Field)1 UserConnection (net.md_5.bungee.UserConnection)1 EventHandler (net.md_5.bungee.event.EventHandler)1 ChannelWrapper (net.md_5.bungee.netty.ChannelWrapper)1 DefinedPacket (net.md_5.bungee.protocol.DefinedPacket)1 Respawn (net.md_5.bungee.protocol.packet.Respawn)1