When player hit an immune entity, the equipment reset to the original stuff.
Zarinoow opened this issue ยท 1 comments
Context
I create a plugin that put a block on the player head.
The problem
When I hit an immune player or entity (eg: Player in creative mode or Spam an entity), the block disappears. I think the client sends a packet to get their own armor. So I already listen to the packet "ENTITY_EQUIPMENT" for another thing, and when the player hits the immune entity, the event is not triggered but the armor reset to the non-modified packet (The event work but is triggered for another occasion). So I think another packet is called, but which?
API method(s) used
- PacketType.Play.Server.ENTITY_EQUIPMENT
Expected behavior
I want the player to still show their block on their heads.
Code
- Send the packet to the player
private void updateHat(Player client) {
PacketContainer equipmentPacket = new PacketContainer(ENTITY_EQUIPMENT);
ItemStack hat = restoreHat(client);
if(hat == null) return;
List<Pair<EnumWrappers.ItemSlot, ItemStack>> pairList = new ArrayList<>();
pairList.add(new Pair<>(ItemSlot.HEAD, hat));
equipmentPacket.getIntegers().write(0, client.getEntityId());
equipmentPacket.getSlotStackPairLists().write(0, pairList);
try {
ProtocolLibrary.getProtocolManager().sendServerPacket(client, equipmentPacket);
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
- Listen the packet
manager.addPacketListener(
listener = new PacketAdapter(plugin, ENTITY_EQUIPMENT) {
@Override
public void onPacketSending(PacketEvent event) {
System.out.println("Packet Intercepted !"); // Debug
}
});