Cancel arm swing animation?

Discussion in 'Plugin Development' started by DarkBladee12, May 26, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    DarkBladee12

    Hey guys, is it possible to cancel the arm swing animation of a player? I tried it with the PlayerAnimationEvent, but cancelling that one didn't work for me... Or do I have to use ProtocolLib to catch the animation packet?

    Has no one any ideas?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 1, 2016
  2. Offline

    Comphenix

    It's fairly simple - just check for the ANIMATION id and cancel the packet:
    Code:java
    1. public class ExampleMod extends JavaPlugin implements Listener {
    2. @Override
    3. public void onEnable() {
    4. ProtocolLibrary.getProtocolManager().addPacketListener(
    5. new PacketAdapter(this, ConnectionSide.SERVER_SIDE, Packets.Server.ARM_ANIMATION) {
    6. @Override
    7. public void onPacketSending(PacketEvent event) {
    8. // This is the entity whose arm has just moved
    9. Entity entity = event.getPacket().getEntityModifier(event.getPlayer().getWorld()).read(0);
    10. int animation = event.getPacket().getIntegers().read(1);
    11.  
    12. // See if this is a "move arm" action
    13. if (animation == 1) {
    14. event.setCancelled(true);
    15. }
    16. }
    17. });
    18. }
    19. }
     
  3. Offline

    silthus

    Comphenix I tried this with the latest version of MC (1.6.4) and ProtocolLib but it doesn't seem to send the animation packet. Do you know if anything has changed?
     
  4. Offline

    Comphenix

    It shouldn't.

    But keep in mind that you can't stop the subtle idle animation (arms swinging), only these specific animations.
     
  5. Offline

    silthus

    I am trying to stop the player attack animation but when I register the protocol listener and add a breakpoint the breakpoint wont fire. Also when I do /packet add server 18 true it wont show any packets being send by the server.

    I am using the exact code (copy pasted) from above.
     
  6. Offline

    Comphenix

    Do you have any other players connected to the server?

    You can only prevent animations seen on other players, not your own client.
     
  7. Offline

    silthus

    Oh, too bad. I was trying to prevent the player from seeing that he has swung his arm.
    Well thanks anyways.
     
Thread Status:
Not open for further replies.

Share This Page