Make player swing offhand

Discussion in 'Spigot Plugin Development' started by DMEpepperoni, Apr 2, 2020.

  1. I'm trying to make it so a player can dual-wield swords. I'm currently listening for the arm animation packet and if all conditions are met I want to make the player swing their offhand. I have tried both PacketPlayOutAnimation and the below packet but with no success. They are both sending the packets but it's not swinging the arm.

    Code (Text):
    PacketContainer packet = new PacketContainer(PacketType.Play.Client.ARM_ANIMATION);
    packet.getHands().write(0, Hand.OFF_HAND);
                               
    try {
        getProtocolManager().recieveClientPacket(event.getPlayer(), packet);
    } catch (InvocationTargetException | IllegalAccessException e) {
        e.printStackTrace();
    }

    Code (Text):
    PacketContainer packet = new PacketContainer(PacketType.Play.Server.ANIMATION);
    packet.getEntityModifier(event.getPlayer().getWorld()).write(0, event.getPlayer());
    packet.getIntegers().write(1, 3);
                               
    try {
        getProtocolManager().sendServerPacket(event.getPlayer(), packet);
    } catch (InvocationTargetException e) {
        e.printStackTrace();
    }
     
     
  2. this may not be the issue but the section in bold was misspelled, worth a shot though
    getProtocolManager().recieveClientPacket(event.getPlayer(), packet);
     
  3. Wasn't misspelled haha, but thanks anyway. If you got any other ideas, let me know, really trying to get this to work to improve the immersion.