ProtocolLib Help

Discussion in 'Spigot Plugin Development' started by Erouax, May 29, 2015.

  1. I'm trying to do an animated MOTD plugin.
    I'm trying to cancel the ping packet, then send another OUT_SERVER_INFO one.
    This is what i tried:
    Code (Text):

            protocolManager.addPacketListener(
                    new PacketAdapter(this, ListenerPriority.NORMAL,
                            Arrays.asList(PacketType.Status.Server.OUT_SERVER_INFO, PacketType.Status.Client.IN_PING)) {
                        @Override
                        public void onPacketSending(PacketEvent event) {
                            if (mMode) {
                                if (event.getPacketType() == PacketType.Status.Server.OUT_SERVER_INFO) {
                                    if (!addressIntegers.containsKey(event.getPlayer())) {
                                        addressIntegers.put(event.getPlayer(), 0);
                                    }
                                    handlePing(event, event.getPacket().getServerPings().read(0));
                                } else {
                                    int i = addressIntegers.get(event.getPlayer());
                                    if (i <= 5) {
                                        i = i + 1;
                                        addressIntegers.remove(event.getPlayer());
                                        addressIntegers.put(event.getPlayer(), i);
                                        event.setCancelled(true);
                                        PacketContainer packet = protocolManager.
                                                createPacket(PacketType.Status.Server.OUT_SERVER_INFO);

                                        try {
                                            protocolManager.sendServerPacket(event.getPlayer(), packet);
                                        } catch (InvocationTargetException e) {
                                            throw new RuntimeException( "Cannot send packet " + packet, e);
                                        }
                                    } else {
                                        addressIntegers.remove(event.getPlayer());
                                        addressIntegers.put(event.getPlayer(), 0);
                                    }
                                }
                            }
                        }
                    });
    But it gives this error:
    Code (Text):
    [18:48:59] [Netty Server IO #2/ERROR]: [Test] Unhandled exception occured in onPacketReceiving(PacketEvent) for Test
    java.lang.IllegalStateException: Override onPacketReceiving to get notifcations of received packets!
        at com.comphenix.protocol.events.PacketAdapter.onPacketReceiving(PacketAdapter.java:311) ~[ProtocolLib-3.4.0%20(2).jar:?]
        at com.comphenix.protocol.injector.SortedPacketListenerList.invokeReceivingListener(SortedPacketListenerList.java:114) [ProtocolLib-3.4.0%20(2).jar:?]
        at com.comphenix.protocol.injector.SortedPacketListenerList.invokePacketRecieving(SortedPacketListenerList.java:67) [ProtocolLib-3.4.0%20(2).jar:?]
        at com.comphenix.protocol.injector.PacketFilterManager.handlePacket(PacketFilterManager.java:639) [ProtocolLib-3.4.0%20(2).jar:?]
        at com.comphenix.protocol.injector.PacketFilterManager.invokePacketRecieving(PacketFilterManager.java:606) [ProtocolLib-3.4.0%20(2).jar:?]
        at com.comphenix.protocol.injector.netty.NettyProtocolInjector.packetReceived(NettyProtocolInjector.java:302) [ProtocolLib-3.4.0%20(2).jar:?]
        at com.comphenix.protocol.injector.netty.NettyProtocolInjector.onPacketReceiving(NettyProtocolInjector.java:267) [ProtocolLib-3.4.0%20(2).jar:?]
        at com.comphenix.protocol.injector.netty.ChannelInjector.decode(ChannelInjector.java:526) [ProtocolLib-3.4.0%20(2).jar:?]
        at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:241) [Spigot.jar:git-Bukkit-33d5de3]
        at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:149) [Spigot.jar:git-Bukkit-33d5de3]
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:332) [Spigot.jar:git-Bukkit-33d5de3]
        at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:318) [Spigot.jar:git-Bukkit-33d5de3]
        at com.comphenix.protocol.injector.netty.ChannelInjector$4.channelRead(ChannelInjector.java:244) [ProtocolLib-3.4.0%20(2).jar:?]
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:332) [Spigot.jar:git-Bukkit-33d5de3]
        at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:318) [Spigot.jar:git-Bukkit-33d5de3]
        at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:163) [Spigot.jar:git-Bukkit-33d5de3]
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:332) [Spigot.jar:git-Bukkit-33d5de3]
        at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:318) [Spigot.jar:git-Bukkit-33d5de3]
        at io.netty.handler.timeout.ReadTimeoutHandler.channelRead(ReadTimeoutHandler.java:150) [Spigot.jar:git-Bukkit-33d5de3]
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:332) [Spigot.jar:git-Bukkit-33d5de3]
        at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:318) [Spigot.jar:git-Bukkit-33d5de3]
        at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:787) [Spigot.jar:git-Bukkit-33d5de3]
        at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:125) [Spigot.jar:git-Bukkit-33d5de3]
        at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:507) [Spigot.jar:git-Bukkit-33d5de3]
        at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:464) [Spigot.jar:git-Bukkit-33d5de3]
        at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:378) [Spigot.jar:git-Bukkit-33d5de3]
        at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:350) [Spigot.jar:git-Bukkit-33d5de3]
        at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:116) [Spigot.jar:git-Bukkit-33d5de3]
        at java.lang.Thread.run(Unknown Source) [?:1.8.0_45]
    [18:48:59] [Netty Server IO #2/ERROR]: Parameters:
      [email protected][
        a=776568562
      ]
    Does anyone know how i can fix this?
     
  2. From your Error-Log:
    You messed with the connectionsides!

    Try to add a "onPacketRecieving" aswell...
     
    • Agree Agree x 1