Skip to content

Commit

Permalink
Avoid NPE for rotationtrait removal
Browse files Browse the repository at this point in the history
  • Loading branch information
fullwall committed Dec 14, 2023
1 parent ccf4f6b commit ea2df83
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion main/src/main/java/net/citizensnpcs/ProtocolLibListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDeathEvent;

import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.PacketType.Play.Server;
Expand Down Expand Up @@ -248,9 +249,16 @@ private NPC getNPCFromPacket(PacketEvent event) {
return entity instanceof NPCHolder ? ((NPCHolder) entity).getNPC() : null;
}

@EventHandler(ignoreCancelled = true)
public void onEntityDeath(EntityDeathEvent event) {
rotationTraits.remove(event.getEntity().getEntityId());
}

@EventHandler(ignoreCancelled = true)
public void onNPCDespawn(NPCDespawnEvent event) {
rotationTraits.remove(event.getNPC().getEntity().getEntityId());
if (event.getNPC().getEntity() != null) {
rotationTraits.remove(event.getNPC().getEntity().getEntityId());
}
mirrorTraits.remove(event.getNPC().getEntity().getUniqueId());
}

Expand Down

0 comments on commit ea2df83

Please sign in to comment.