Critical animation packets not being detected?

Discussion in 'Plugin Development' started by InsertNameHere, Aug 5, 2019.

  1. Offline

    InsertNameHere

    Sorry if this is kind of a noob-ish question, but I was messing around with the animation packet the other day. More specifically, I added a listener to detect animation packets of animation ID 4 in ProtocolLib (critical hits). If a critical hit was detected, it would print, "Critical detected!"

    When I turned on criticals on my client to test it out, I was surprised that it didn't spam my console. Is there a reason why spam left-clicking with criticals doesn't detect some of the packets sent? Also, how do you make a separate class to listen to packets?

    Code:
    @Overridepublic void onEnable() {
        packetListener();
    }
    
    public void packetListener() {
        ProtocolLibrary.getProtocolManager().addPacketListener(
                new PacketAdapter(this, PacketType.Play.Server.ANIMATION) {
                    @Overridepublic void onPacketSending(PacketEvent e) {
                        if (e.getPacket().getIntegers().read(1) == 4) {
                            Bukkit.broadcastMessage("Criticals detected.");
                        }
                    }
                }
        );
    }
    
    EDIT: I tried something with the packet listener by creating a new class and then copying and pasting the code there. When it didn't work and I deleted the new file, the code now produces this nasty error

    Code:
    [01:43:03 ERROR]: [Packets] Unhandled exception occured in onPacketSending(PacketEvent) for Packets
    java.lang.IllegalStateException: Override onPacketSending to get notifcations of sent packets!
            at com.comphenix.protocol.events.PacketAdapter.onPacketSending(PacketAdapter.java:316) ~[?:?]
            at com.comphenix.protocol.injector.SortedPacketListenerList.invokeSendingListener(SortedPacketListenerList.java:195) ~[?:?]
            at com.comphenix.protocol.injector.SortedPacketListenerList.invokePacketSending(SortedPacketListenerList.java:149) ~[?:?]
            at com.comphenix.protocol.injector.PacketFilterManager.handlePacket(PacketFilterManager.java:588) ~[?:?]
            at com.comphenix.protocol.injector.PacketFilterManager.invokePacketSending(PacketFilterManager.java:564) ~[?:?]
            at com.comphenix.protocol.injector.netty.ProtocolInjector.packetQueued(ProtocolInjector.java:338) ~[?:?]
            at com.comphenix.protocol.injector.netty.ProtocolInjector.onPacketSending(ProtocolInjector.java:298) ~[?:?]
            at com.comphenix.protocol.injector.netty.ChannelInjector.processSending(ChannelInjector.java:367) ~[?:?]
            at com.comphenix.protocol.injector.netty.ChannelInjector.access$800(ChannelInjector.java:66) ~[?:?]
            at com.comphenix.protocol.injector.netty.ChannelInjector$3.handleScheduled(ChannelInjector.java:332) ~[?:?]
            at com.comphenix.protocol.injector.netty.ChannelInjector$3.onMessageScheduled(ChannelInjector.java:302) ~[?:?]
            at com.comphenix.protocol.injector.netty.ChannelProxy$2.schedulingRunnable(ChannelProxy.java:127) ~[?:?]
            at com.comphenix.protocol.injector.netty.EventLoopProxy.execute(EventLoopProxy.java:95) ~[?:?]
            at net.minecraft.server.v1_13_R2.NetworkManager.b(NetworkManager.java:193) ~[spigot-1.13.2.jar:git-Spigot-1a3504a-84f3da3]
            at net.minecraft.server.v1_13_R2.NetworkManager.sendPacket(NetworkManager.java:157) ~[spigot-1.13.2.jar:git-Spigot-1a3504a-84f3da3]
            at net.minecraft.server.v1_13_R2.PlayerConnection.a(PlayerConnection.java:1376) ~[spigot-1.13.2.jar:git-Spigot-1a3504a-84f3da3]
            at net.minecraft.server.v1_13_R2.PlayerConnection.sendPacket(PlayerConnection.java:1349) ~[spigot-1.13.2.jar:git-Spigot-1a3504a-84f3da3]
            at net.minecraft.server.v1_13_R2.EntityTrackerEntry.broadcastIncludingSelf(EntityTrackerEntry.java:300) ~[spigot-1.13.2.jar:git-Spigot-1a3504a-84f3da3]
            at net.minecraft.server.v1_13_R2.EntityTracker.sendPacketToEntity(EntityTracker.java:228) ~[spigot-1.13.2.jar:git-Spigot-1a3504a-84f3da3]
            at net.minecraft.server.v1_13_R2.EntityPlayer.a(EntityPlayer.java:1179) ~[spigot-1.13.2.jar:git-Spigot-1a3504a-84f3da3]
            at net.minecraft.server.v1_13_R2.EntityHuman.attack(EntityHuman.java:1107) ~[spigot-1.13.2.jar:git-Spigot-1a3504a-84f3da3]
            at net.minecraft.server.v1_13_R2.EntityPlayer.attack(EntityPlayer.java:1349) ~[spigot-1.13.2.jar:git-Spigot-1a3504a-84f3da3]
            at net.minecraft.server.v1_13_R2.PlayerConnection.a(PlayerConnection.java:1841) ~[spigot-1.13.2.jar:git-Spigot-1a3504a-84f3da3]
            at net.minecraft.server.v1_13_R2.PacketPlayInUseEntity.a(SourceFile:69) ~[spigot-1.13.2.jar:git-Spigot-1a3504a-84f3da3]
            at net.minecraft.server.v1_13_R2.PacketPlayInUseEntity.a(SourceFile:13) ~[spigot-1.13.2.jar:git-Spigot-1a3504a-84f3da3]
            at net.minecraft.server.v1_13_R2.PlayerConnectionUtils.lambda$0(PlayerConnectionUtils.java:9) ~[spigot-1.13.2.jar:git-Spigot-1a3504a-84f3da3]
            at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_212]
            at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_212]
            at net.minecraft.server.v1_13_R2.SystemUtils.a(SourceFile:199) [spigot-1.13.2.jar:git-Spigot-1a3504a-84f3da3]
            at net.minecraft.server.v1_13_R2.MinecraftServer.b(MinecraftServer.java:896) [spigot-1.13.2.jar:git-Spigot-1a3504a-84f3da3]
            at net.minecraft.server.v1_13_R2.DedicatedServer.b(DedicatedServer.java:417) [spigot-1.13.2.jar:git-Spigot-1a3504a-84f3da3]
            at net.minecraft.server.v1_13_R2.MinecraftServer.a(MinecraftServer.java:831) [spigot-1.13.2.jar:git-Spigot-1a3504a-84f3da3]
            at net.minecraft.server.v1_13_R2.MinecraftServer.run(MinecraftServer.java:729) [spigot-1.13.2.jar:git-Spigot-1a3504a-84f3da3]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_212]
    [01:43:03 ERROR]: Parameters:
      net.minecraft.server.v1_13_R2.PacketPlayOutAnimation@20768bd2[
        a=1858
        b=4
      ]
    
    Any ideas? (I'm relatively new to this)
     
    Last edited: Aug 5, 2019
  2. Offline

    Machine Maker

    @InsertNameHere Well does the client show the critical effect every single time you executed one? It might have a cool down internally where the server doesn't send the packet to show the animation because its too soon after.


    As for listeners in another class, just create another class with a constructor that takes the ProtocolLibrary instance. Then create an instance of that class in your onEnable() method.
     
    InsertNameHere likes this.
  3. Offline

    InsertNameHere

    @Machine Maker I'm still getting the unhandled exception error, any idea why that's occurring?
     
  4. Offline

    Machine Maker

  5. Offline

    InsertNameHere

    @Machine Maker Alright. The first class is the main class.
    Code:
    private ProtocolManager manager;
    
    @Overridepublic void onEnable() {
        manager = ProtocolLibrary.getProtocolManager();
        registerListeners(manager);
    }
    
    public void registerListeners(ProtocolManager manager) {
        CriticalsListener criticals = new CriticalsListener(this, manager);
        criticals.listenCriticals();
    }
    
    This is the listener class
    Code:
    private ProtocolManager manager;
    private Packets p;
    
    public CriticalsListener(Packets p, ProtocolManager manager) {
        this.p = p;
        this.manager = manager;
    }
    
    public void listenCriticals() {
        manager.addPacketListener(
                new PacketAdapter(p, PacketType.Play.Server.ANIMATION) {
                    @Overridepublic void onPacketReceiving(PacketEvent event) {
                        if (event.getPacketType().equals(PacketType.Play.Server.ANIMATION) && event.getPacket().getIntegers().read(1) == 4) {
                            Bukkit.broadcastMessage("Criticals detected!");
                            Bukkit.broadcastMessage("Player: " + event.getPlayer().getDisplayName());
                        }
                    }
                }
        );
    }
    
     
  6. Offline

    Machine Maker

    @InsertNameHere This is a server packet which means that its sent by the server, not received by it. change the method you are overriding in your listener to onPacketSending instead of onPacketReceiving.
     
  7. Offline

    InsertNameHere

    @Machine Maker Ah okay I see, I switched the method out and it worked just fine! Thanks!

    On another note, is there a reason why this produces an error?
    Code:
    private ProtocolManager manager;
    
    @Overridepublic void onEnable() {
        manager = ProtocolLibrary.getProtocolManager();
        manager.addPacketListener(
                new PacketAdapter(this, PacketType.Play.Client.ABILITIES) {
                    @Overridepublic void onPacketReceiving(PacketEvent event) {
                        Bukkit.broadcastMessage("Triggered.");
                    }
                }
        );
    }
    
    The Player Abilities packet is supposed to be sent from the client when the player starts/stops flying; instead, I just get this error
    Code:
    [23:53:48 ERROR]: Error occurred while enabling PacketsTest v1.0 (Is it up to date?)
    java.lang.IllegalAccessError: tried to access class me.recordtime.packetstest.Packets$1 from class me.recordtime.packetstest.Packets
            at me.recordtime.packetstest.Packets.onEnable(Packets.java:22) ~[?:?]
            at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:265) ~[spigot-1.13.2.jar:git-Spigot-1a3504a-84f3da3]
            at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:347) ~[spigot-1.13.2.jar:git-Spigot-1a3504a-84f3da3]
            at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:410) ~[spigot-1.13.2.jar:git-Spigot-1a3504a-84f3da3]
            at com.rylinaux.plugman.util.PluginUtil.load(PluginUtil.java:366) ~[?:?]
            at com.rylinaux.plugman.util.PluginUtil.load(PluginUtil.java:318) ~[?:?]
            at com.rylinaux.plugman.util.PluginUtil.reload(PluginUtil.java:380) ~[?:?]
            at com.rylinaux.plugman.command.ReloadCommand.execute(ReloadCommand.java:122) ~[?:?]
            at com.rylinaux.plugman.PlugManCommandHandler.onCommand(PlugManCommandHandler.java:95) ~[?:?]
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[spigot-1.13.2.jar:git-Spigot-1a3504a-84f3da3]
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141) ~[spigot-1.13.2.jar:git-Spigot-1a3504a-84f3da3]
            at org.bukkit.craftbukkit.v1_13_R2.CraftServer.dispatchCommand(CraftServer.java:704) ~[spigot-1.13.2.jar:git-Spigot-1a3504a-84f3da3]
            at net.minecraft.server.v1_13_R2.PlayerConnection.handleCommand(PlayerConnection.java:1621) ~[spigot-1.13.2.jar:git-Spigot-1a3504a-84f3da3]
            at net.minecraft.server.v1_13_R2.PlayerConnection.a(PlayerConnection.java:1461) ~[spigot-1.13.2.jar:git-Spigot-1a3504a-84f3da3]
            at net.minecraft.server.v1_13_R2.PacketPlayInChat.a(PacketPlayInChat.java:45) ~[spigot-1.13.2.jar:git-Spigot-1a3504a-84f3da3]
            at net.minecraft.server.v1_13_R2.PacketPlayInChat.a(PacketPlayInChat.java:1) ~[spigot-1.13.2.jar:git-Spigot-1a3504a-84f3da3]
            at net.minecraft.server.v1_13_R2.PlayerConnectionUtils.lambda$0(PlayerConnectionUtils.java:9) ~[spigot-1.13.2.jar:git-Spigot-1a3504a-84f3da3]
            at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_212]
            at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_212]
            at net.minecraft.server.v1_13_R2.SystemUtils.a(SourceFile:199) [spigot-1.13.2.jar:git-Spigot-1a3504a-84f3da3]
            at net.minecraft.server.v1_13_R2.MinecraftServer.b(MinecraftServer.java:896) [spigot-1.13.2.jar:git-Spigot-1a3504a-84f3da3]
            at net.minecraft.server.v1_13_R2.DedicatedServer.b(DedicatedServer.java:417) [spigot-1.13.2.jar:git-Spigot-1a3504a-84f3da3]
            at net.minecraft.server.v1_13_R2.MinecraftServer.a(MinecraftServer.java:831) [spigot-1.13.2.jar:git-Spigot-1a3504a-84f3da3]
            at net.minecraft.server.v1_13_R2.MinecraftServer.run(MinecraftServer.java:729) [spigot-1.13.2.jar:git-Spigot-1a3504a-84f3da3]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_212]
    
    What does it mean by IllegalAccessError: tried to access class XXXX from class XXXXX?
     
  8. Offline

    Machine Maker

  9. Offline

    InsertNameHere

    @Machine Maker It's the broadcast line... Bukkit.broadcastMessage(). Either I'm missing something obvious or I changed the code...
     

Share This Page