Skip to content

Commit

Permalink
Add SpawnReason and method
Browse files Browse the repository at this point in the history
  • Loading branch information
fullwall committed Aug 8, 2018
1 parent afc0c69 commit ce8796a
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 7 deletions.
24 changes: 17 additions & 7 deletions src/main/java/net/citizensnpcs/api/event/NPCSpawnEvent.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
package net.citizensnpcs.api.event;

import net.citizensnpcs.api.npc.NPC;

import org.bukkit.Location;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;

import net.citizensnpcs.api.npc.NPC;

/**
* Called when an NPC spawns.
*/
public class NPCSpawnEvent extends NPCEvent implements Cancellable {
private boolean cancelled = false;

private final Location location;
private final SpawnReason reason;

public NPCSpawnEvent(NPC npc, Location location) {
public NPCSpawnEvent(NPC npc, Location location, SpawnReason reason) {
super(npc);
this.location = location;
this.reason = reason;
}

@Override
Expand All @@ -26,13 +27,22 @@ public HandlerList getHandlers() {

/**
* Gets the location where the NPC was spawned.
*
*
* @return Location where the NPC was spawned
*/
public Location getLocation() {
return location;
}

/**
* Gets the reason for spawning the NPC.
*
* @return Reason for spawning the NPC
*/
public SpawnReason getReason() {
return reason;
}

@Override
public boolean isCancelled() {
return cancelled;
Expand All @@ -43,9 +53,9 @@ public void setCancelled(boolean cancelled) {
this.cancelled = cancelled;
}

private static final HandlerList handlers = new HandlerList();

public static HandlerList getHandlerList() {
return handlers;
}

private static final HandlerList handlers = new HandlerList();
}
9 changes: 9 additions & 0 deletions src/main/java/net/citizensnpcs/api/event/SpawnReason.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package net.citizensnpcs.api.event;

public enum SpawnReason {
COMMAND,
CREATE,
PLUGIN,
RESPAWN,
TIMED_RESPAWN;
}
12 changes: 12 additions & 0 deletions src/main/java/net/citizensnpcs/api/npc/NPC.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import net.citizensnpcs.api.astar.Agent;
import net.citizensnpcs.api.event.DespawnReason;
import net.citizensnpcs.api.event.NPCDespawnEvent;
import net.citizensnpcs.api.event.SpawnReason;
import net.citizensnpcs.api.npc.BlockBreaker.BlockBreakerConfiguration;
import net.citizensnpcs.api.trait.Trait;
import net.citizensnpcs.api.trait.TraitFactory;
Expand Down Expand Up @@ -266,6 +267,17 @@ public interface NPC extends Agent, Cloneable {
*/
public boolean spawn(Location location);

/**
* Attempts to spawn this NPC.
*
* @param location
* Location to spawn this NPC
* @param reason
* Reason for spawning
* @return Whether this NPC was able to spawn at the location
*/
public boolean spawn(Location location, SpawnReason reason);

/**
* An alternative to {{@link #getBukkitEntity().getLocation()} that teleports passengers as well.
*
Expand Down

0 comments on commit ce8796a

Please sign in to comment.