Use Ageable instead of Animals

This commit is contained in:
aPunch 2012-03-22 00:19:54 -05:00
parent 7521e1765d
commit 98dbdfd784
3 changed files with 13 additions and 15 deletions

View File

@ -11,8 +11,8 @@
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<bukkit.version>1.2.3-R0.2-SNAPSHOT</bukkit.version> <bukkit.version>1.2.3-R0.3-SNAPSHOT</bukkit.version>
<craftbukkit.version>1.2.3-R0.2-SNAPSHOT</craftbukkit.version> <craftbukkit.version>1.2.3-R0.3-SNAPSHOT</craftbukkit.version>
<citizensapi.version>2.0-SNAPSHOT</citizensapi.version> <citizensapi.version>2.0-SNAPSHOT</citizensapi.version>
<build.number>Unknown</build.number> <build.number>Unknown</build.number>
</properties> </properties>

View File

@ -31,7 +31,7 @@ import net.citizensnpcs.util.Paginator;
import net.citizensnpcs.util.StringHelper; import net.citizensnpcs.util.StringHelper;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.entity.Animals; import org.bukkit.entity.Ageable;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.entity.Villager.Profession; import org.bukkit.entity.Villager.Profession;
@ -123,8 +123,7 @@ public class NPCCommands {
int age = 0; int age = 0;
if (args.hasFlag('b')) { if (args.hasFlag('b')) {
// TODO: Use Ageable when it is implemented if (!Ageable.class.isAssignableFrom(type.getEntityClass()))
if (!Animals.class.isAssignableFrom(type.getEntityClass()))
Messaging.sendError(player, "The mob type '" + type.name().toLowerCase().replace("_", "-") Messaging.sendError(player, "The mob type '" + type.name().toLowerCase().replace("_", "-")
+ "' cannot be aged."); + "' cannot be aged.");
else { else {

View File

@ -1,6 +1,6 @@
package net.citizensnpcs.trait; package net.citizensnpcs.trait;
import org.bukkit.entity.Animals; import org.bukkit.entity.Ageable;
import net.citizensnpcs.api.exception.NPCLoadException; import net.citizensnpcs.api.exception.NPCLoadException;
import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.api.npc.NPC;
@ -30,31 +30,30 @@ public class Age extends Trait implements Runnable, Toggleable {
@Override @Override
public void onNPCSpawn() { public void onNPCSpawn() {
// TODO: Switch to use Ageable when that is implemented if (npc.getBukkitEntity() instanceof Ageable) {
if (npc.getBukkitEntity() instanceof Animals) { Ageable entity = (Ageable) npc.getBukkitEntity();
Animals animal = (Animals) npc.getBukkitEntity(); entity.setAge(age);
animal.setAge(age); entity.setAgeLock(locked);
animal.setAgeLock(locked);
} }
} }
@Override @Override
public void run() { public void run() {
if (!locked) if (!locked)
age = ((Animals) npc.getBukkitEntity()).getAge(); age = ((Ageable) npc.getBukkitEntity()).getAge();
} }
@Override @Override
public boolean toggle() { public boolean toggle() {
locked = !locked; locked = !locked;
((Animals) npc.getBukkitEntity()).setAgeLock(locked); ((Ageable) npc.getBukkitEntity()).setAgeLock(locked);
return locked; return locked;
} }
public void setAge(int age) { public void setAge(int age) {
this.age = age; this.age = age;
if (npc.getBukkitEntity() instanceof Animals) if (npc.getBukkitEntity() instanceof Ageable)
((Animals) npc.getBukkitEntity()).setAge(age); ((Ageable) npc.getBukkitEntity()).setAge(age);
} }
@Override @Override