2017-12-30 08:36:36 +01:00
|
|
|
package net.citizensnpcs.npc;
|
|
|
|
|
|
|
|
import org.bukkit.Location;
|
|
|
|
import org.bukkit.entity.Entity;
|
2022-10-16 19:17:32 +02:00
|
|
|
import org.bukkit.entity.Player;
|
2023-01-03 13:55:27 +01:00
|
|
|
import org.bukkit.event.entity.CreatureSpawnEvent;
|
2017-12-30 08:36:36 +01:00
|
|
|
|
2019-02-05 11:12:02 +01:00
|
|
|
import net.citizensnpcs.api.npc.NPC;
|
|
|
|
import net.citizensnpcs.util.NMS;
|
2023-01-03 13:55:27 +01:00
|
|
|
import net.citizensnpcs.util.Util;
|
2019-02-05 11:12:02 +01:00
|
|
|
|
2017-12-30 08:36:36 +01:00
|
|
|
public abstract class AbstractEntityController implements EntityController {
|
|
|
|
private Entity bukkitEntity;
|
|
|
|
|
|
|
|
public AbstractEntityController() {
|
|
|
|
}
|
|
|
|
|
|
|
|
public AbstractEntityController(Class<?> clazz) {
|
|
|
|
NMS.registerEntityClass(clazz);
|
|
|
|
}
|
|
|
|
|
2023-01-03 13:55:27 +01:00
|
|
|
@Override
|
|
|
|
public void create(Location at, NPC npc) {
|
|
|
|
bukkitEntity = createEntity(at, npc);
|
|
|
|
}
|
|
|
|
|
2017-12-30 08:36:36 +01:00
|
|
|
protected abstract Entity createEntity(Location at, NPC npc);
|
|
|
|
|
2023-01-03 13:55:27 +01:00
|
|
|
@Override
|
|
|
|
public void die() {
|
|
|
|
bukkitEntity = null;
|
|
|
|
}
|
|
|
|
|
2017-12-30 08:36:36 +01:00
|
|
|
@Override
|
|
|
|
public Entity getBukkitEntity() {
|
|
|
|
return bukkitEntity;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void remove() {
|
|
|
|
if (bukkitEntity == null)
|
|
|
|
return;
|
2022-10-16 19:17:32 +02:00
|
|
|
if (bukkitEntity instanceof Player) {
|
|
|
|
NMS.removeFromWorld(bukkitEntity);
|
|
|
|
NMS.remove(bukkitEntity);
|
|
|
|
} else {
|
|
|
|
bukkitEntity.remove();
|
|
|
|
}
|
2023-11-05 13:58:37 +01:00
|
|
|
bukkitEntity = null;
|
2017-12-30 08:36:36 +01:00
|
|
|
}
|
|
|
|
|
2019-02-05 11:12:02 +01:00
|
|
|
@Override
|
2023-01-03 13:55:27 +01:00
|
|
|
public boolean spawn(Location at) {
|
|
|
|
return !Util.isLoaded(at) ? false : NMS.addEntityToWorld(bukkitEntity, CreatureSpawnEvent.SpawnReason.CUSTOM);
|
2017-12-30 08:36:36 +01:00
|
|
|
}
|
2012-12-08 13:08:58 +01:00
|
|
|
}
|