Allow minecraft to remove NPCs on death instead of going through Citizens

This commit is contained in:
fullwall 2018-02-13 17:18:15 +08:00
parent 9ad7c976bf
commit 72ac9134b1
3 changed files with 15 additions and 5 deletions

View File

@ -23,6 +23,11 @@ public abstract class AbstractEntityController implements EntityController {
return bukkitEntity;
}
@Override
public void setEntity(Entity entity) {
this.bukkitEntity = entity;
}
@Override
public void remove() {
if (bukkitEntity == null)

View File

@ -73,7 +73,7 @@ public class CitizensNPC extends AbstractNPC {
event.setCancelled(Setting.KEEP_CHUNKS_LOADED.asBoolean());
}
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) {
if (event.isCancelled() && reason != DespawnReason.DEATH) {
getEntity().getLocation().getChunk();
Messaging.debug("Couldn't despawn", getId(), "due to despawn event cancellation. Force loaded chunk.",
getEntity().isValid());
@ -91,8 +91,11 @@ public class CitizensNPC extends AbstractNPC {
trait.onDespawn();
}
Messaging.debug("Despawned", getId(), "DespawnReason.", reason);
entityController.remove();
if (reason == DespawnReason.DEATH) {
entityController.setEntity(null);
} else {
entityController.remove();
}
return true;
}

View File

@ -1,14 +1,16 @@
package net.citizensnpcs.npc;
import net.citizensnpcs.api.npc.NPC;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import net.citizensnpcs.api.npc.NPC;
public interface EntityController {
Entity getBukkitEntity();
void remove();
void setEntity(Entity entity);
void spawn(Location at, NPC npc);
}