Skip to content

Commit

Permalink
Add some helper methods in NPC
Browse files Browse the repository at this point in the history
  • Loading branch information
fullwall committed Jul 28, 2013
1 parent 157f80a commit ec16055
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/main/java/net/citizensnpcs/api/npc/AbstractNPC.java
Expand Up @@ -178,6 +178,11 @@ public boolean hasTrait(Class<? extends Trait> trait) {
return traits.containsKey(trait);
}

@Override
public boolean isProtected() {
return data().get(NPC.DEFAULT_PROTECTED_METADATA, true);
}

@Override
public void removeTrait(Class<? extends Trait> traitClass) {
Trait trait = traits.remove(traitClass);
Expand Down Expand Up @@ -233,6 +238,11 @@ public void setName(String name) {
}
}

@Override
public void setProtected(boolean isProtected) {
data().setPersistent(NPC.DEFAULT_PROTECTED_METADATA, isProtected);
}

public void update() {
for (int i = 0; i < runnables.size(); ++i) {
runnables.get(i).run();
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/net/citizensnpcs/api/npc/NPC.java
Expand Up @@ -71,6 +71,11 @@ public interface NPC extends Agent, Cloneable {
*/
public void destroy();

/**
* Faces a given {@link Location} if the NPC is spawned.
*/
public void faceLocation(Location location);

/**
* Gets the Bukkit entity associated with this NPC. This may be
* <code>null</code> if {@link #isSpawned()} is false.
Expand Down Expand Up @@ -156,6 +161,8 @@ public interface NPC extends Agent, Cloneable {
*/
public boolean hasTrait(Class<? extends Trait> trait);

public boolean isProtected();

/**
* Gets whether this NPC is currently spawned.
*
Expand Down Expand Up @@ -212,6 +219,17 @@ public interface NPC extends Agent, Cloneable {
*/
public void setName(String name);

/**
* A helper method for using {@link #DEFAULT_PROTECTED_METADATA} to set the
* NPC as protected or not protected from damage/entity target events.
* Equivalent to
* <code>npc.data().set(NPC.DEFAULT_PROTECTED_METADATA, isProtected);</code>
*
* @param isProtected
* Whether the NPC should be protected
*/
public void setProtected(boolean isProtected);

/**
* Attempts to spawn this NPC.
*
Expand Down

0 comments on commit ec16055

Please sign in to comment.