Skip to content

Commit

Permalink
Add isFlyable and setFlyable to NPC
Browse files Browse the repository at this point in the history
  • Loading branch information
fullwall committed Nov 5, 2013
1 parent 225ac8e commit b1d8ba7
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 8 deletions.
31 changes: 31 additions & 0 deletions src/main/java/net/citizensnpcs/api/npc/NPC.java
Expand Up @@ -83,6 +83,8 @@ public interface NPC extends Agent, Cloneable {
* <code>null</code> if {@link #isSpawned()} is false.
*
* @return Entity associated with this NPC
* @deprecated Use {@link #getEntity()} instead
* @see #getEntity()
*/
@Deprecated
public LivingEntity getBukkitEntity();
Expand All @@ -101,6 +103,12 @@ public interface NPC extends Agent, Cloneable {
*/
public SpeechController getDefaultSpeechController();

/**
* Gets the Bukkit entity associated with this NPC. This may be
* <code>null</code> if {@link #isSpawned()} is false.
*
* @return Entity associated with this NPC
*/
public Entity getEntity();

/**
Expand Down Expand Up @@ -166,6 +174,19 @@ public interface NPC extends Agent, Cloneable {
*/
public boolean hasTrait(Class<? extends Trait> trait);

/**
* Returns whether this NPC is flyable or not.
*
* @return Whether this NPC is flyable
*/
public boolean isFlyable();

/**
* Gets whether this NPC is protected from damage, movement and other events
* that players and mobs use to change the entity state of the NPC.
*
* @return Whether this NPC is protected
*/
public boolean isProtected();

/**
Expand Down Expand Up @@ -216,6 +237,15 @@ public interface NPC extends Agent, Cloneable {
*/
public void setBukkitEntityType(EntityType type);

/**
* Sets whether this NPC is <tt>flyable</tt> or not. Note that this is
* intended for normally <em>ground-based</em> entities only - it will
* generally have no effect on mob types that were originally flyable.
*
* @param flyable
*/
public void setFlyable(boolean flyable);

/**
* Sets the name of this NPC.
*
Expand Down Expand Up @@ -256,6 +286,7 @@ public interface NPC extends Agent, Cloneable {
public void teleport(Location location, TeleportCause cause);

public static final String DEFAULT_PROTECTED_METADATA = "protected";
public static final String FLYABLE_METADATA = "flyable";
public static final String LEASH_PROTECTED_METADATA = "protected-leash";
public static final String RESPAWN_DELAY_METADATA = "respawn-delay";
public static final String TARGETABLE_METADATA = "protected-target";
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/citizensnpcs/api/trait/Trait.java
Expand Up @@ -72,7 +72,7 @@ public void onCopy() {

/**
* Called just before the attached {@link NPC} is despawned.
* {@link NPC#getBukkitEntity()} will be non-null.
* {@link NPC#getEntity()} will be non-null.
*/
public void onDespawn() {
}
Expand All @@ -84,7 +84,7 @@ public void onRemove() {
}

/**
* Called when an {@link NPC} is spawned. {@link NPC#getBukkitEntity()} will
* Called when an {@link NPC} is spawned. {@link NPC#getEntity()} will
* return null until this is called. This is also called onAttach when the
* NPC is already spawned.
*/
Expand Down
11 changes: 6 additions & 5 deletions src/main/java/net/citizensnpcs/api/trait/trait/Equipment.java
Expand Up @@ -71,23 +71,24 @@ public void load(DataKey key) throws NPCLoadException {
@Override
@SuppressWarnings("deprecation")
public void onSpawn() {
if (!(npc.getBukkitEntity() instanceof LivingEntity))
if (!(npc.getEntity() instanceof LivingEntity))
return;
if (npc.getBukkitEntity() instanceof Enderman) {
Enderman enderman = (Enderman) npc.getBukkitEntity();
if (npc.getEntity() instanceof Enderman) {
Enderman enderman = (Enderman) npc.getEntity();
if (equipment[0] != null)
enderman.setCarriedMaterial(equipment[0].getData());
} else {
LivingEntity entity = npc.getBukkitEntity();
LivingEntity entity = (LivingEntity) npc.getEntity();
EntityEquipment equip = getEquipmentFromEntity(entity);
if (equipment[0] != null)
equip.setItemInHand(equipment[0]);
equip.setHelmet(equipment[1]);
equip.setChestplate(equipment[2]);
equip.setLeggings(equipment[3]);
equip.setBoots(equipment[4]);
if (entity instanceof Player)
if (entity instanceof Player) {
((Player) entity).updateInventory();
}
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/net/citizensnpcs/api/trait/trait/MobType.java
Expand Up @@ -27,8 +27,9 @@ public EntityType getType() {
@Override
public void load(DataKey key) {
type = EntityType.fromName(key.getString(""));
if (type == null)
if (type == null) {
type = EntityType.PLAYER;
}
}

@Override
Expand Down

0 comments on commit b1d8ba7

Please sign in to comment.