The method Player.damage
method to make everything as "normal".
If you want to send your own packet, yous should use the PacketPlayOutAnimation
, with the value 1
(Why?)
For 1.16 and lower:
import net.minecraft.server.MC_VERSION.PacketPlayOutAnimation;
EntityPlayer ep = ((CraftPlayer) p).getHandle();
ep.playerConnection.sendPacket(new PacketPlayOutAnimation(ep, 1));
For 1.17 and more:
import net.minecraft.network.protocol.game.PacketPlayOutAnimation;
EntityPlayer ep = ((CraftPlayer) p).getHandle();
ep.b.sendPacket(new PacketPlayOutAnimation(ep, 1));
Here is a version with import of direct minecraft version. You can use reflection to use those NMS for all versions.
Or with ProtocolLib, it seems to be something like that:
PacketContainer packetContainer = protocolManager.createPacket(Play.Server.ANIMATION);
packetContainer.getIntegers().write(0, entityId);
packetContainer.getIntegers().write(0, 1);
manager.sendServerPacket(p, packetContainer); // seems to be how you send packet
More informations about the packet in ProtocolLib here