Avoid NPE for rotationtrait removal

This commit is contained in:
fullwall 2023-12-14 21:06:50 +08:00
parent ccf4f6b085
commit ea2df83ca5

View File

@ -14,6 +14,7 @@ import org.bukkit.entity.EntityType;
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;
@ -248,9 +249,16 @@ public class ProtocolLibListener implements Listener {
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());
}