// Path: api/src/main/java/net/techcable/npclib/ai/AITask.java
// public interface AITask {
// 
//     /**
//      * Run this task in the given ai environment
//      *
//      * @param environment the ai environment
//      */
//     public void tick(AIEnvironment environment);
// }
// 
// Path: citizens/src/main/java/net/techcable/npclib/citizens/ai/CitizensAIEnvironment.java
// public class CitizensAIEnvironment extends AIEnvironment {
// 
//     private final CitizensNPC npc;
// 
//     public CitizensAIEnvironment(CitizensNPC npc) {
//         this.npc = npc;
//         new BukkitRunnable() {
// 
//             @Override
//             public void run() {
//                 tick();
//             }
//         }.runTaskTimer(CitizensAPI.getPlugin(), 0, 1);
//     }
// }


import lombok.*;
import java.lang.ref.WeakReference;
import java.util.UUID;
import net.citizensnpcs.api.npc.NPC;
import net.techcable.npclib.ai.AITask;
import net.techcable.npclib.citizens.ai.CitizensAIEnvironment;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import com.google.common.base.Preconditions;

    public boolean isDestroyed() {
        return getHandle() == null || destroyed;
    }

    @Override
    public void spawn(Location toSpawn) {
        Preconditions.checkNotNull(toSpawn, "Null location");
        Preconditions.checkState(getHandle() != null, "This npc has been destroyed");
        Preconditions.checkState(!isSpawned(), "Already spawned");
        getHandle().spawn(toSpawn);
    }

    @Override
    public void setProtected(boolean protect) {
        Preconditions.checkState(getHandle() != null, "This npc has been destroyed");
        getHandle().setProtected(protect);
    }

    @Override
    public boolean isProtected() {
        if (getHandle() == null) return false;
        return getHandle().isProtected();
    }

    @Override
    public void addTask(AITask task) {
        getAIEnvironment().addTask(task);
    }

    @Getter(lazy = true)

// Path: api/src/main/java/net/techcable/npclib/ai/AITask.java
// public interface AITask {
// 
//     /**
//      * Run this task in the given ai environment
//      *
//      * @param environment the ai environment
//      */
//     public void tick(AIEnvironment environment);
// }
// 
// Path: citizens/src/main/java/net/techcable/npclib/citizens/ai/CitizensAIEnvironment.java
// public class CitizensAIEnvironment extends AIEnvironment {
// 
//     private final CitizensNPC npc;
// 
//     public CitizensAIEnvironment(CitizensNPC npc) {
//         this.npc = npc;
//         new BukkitRunnable() {
// 
//             @Override
//             public void run() {
//                 tick();
//             }
//         }.runTaskTimer(CitizensAPI.getPlugin(), 0, 1);
//     }
// }


// Path: citizens/src/main/java/net/techcable/npclib/citizens/CitizensNPC.java
import lombok.*;
import java.lang.ref.WeakReference;
import java.util.UUID;
import net.citizensnpcs.api.npc.NPC;
import net.techcable.npclib.ai.AITask;
import net.techcable.npclib.citizens.ai.CitizensAIEnvironment;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import com.google.common.base.Preconditions;

    public boolean isDestroyed() {
        return getHandle() == null || destroyed;
    }

    @Override
    public void spawn(Location toSpawn) {
        Preconditions.checkNotNull(toSpawn, "Null location");
        Preconditions.checkState(getHandle() != null, "This npc has been destroyed");
        Preconditions.checkState(!isSpawned(), "Already spawned");
        getHandle().spawn(toSpawn);
    }

    @Override
    public void setProtected(boolean protect) {
        Preconditions.checkState(getHandle() != null, "This npc has been destroyed");
        getHandle().setProtected(protect);
    }

    @Override
    public boolean isProtected() {
        if (getHandle() == null) return false;
        return getHandle().isProtected();
    }

    @Override
    public void addTask(AITask task) {
        getAIEnvironment().addTask(task);
    }

    @Getter(lazy = true)

    private final CitizensAIEnvironment aIEnvironment = new CitizensAIEnvironment(this);
