From d6e7e414687939c1aade906f11fd0d5c42dd3a7b Mon Sep 17 00:00:00 2001 From: CraftBukkit/Spigot Date: Mon, 19 Mar 2012 14:12:17 -0500 Subject: [PATCH] [Bleeding] Added Ageable interface for Villagers and Animals to extend. Addresses BUKKIT-1232 By: aPunch --- .../craftbukkit/entity/CraftAgeable.java | 67 +++++++++++++++++++ .../craftbukkit/entity/CraftAnimals.java | 46 +------------ .../craftbukkit/entity/CraftVillager.java | 2 +- 3 files changed, 69 insertions(+), 46 deletions(-) create mode 100644 paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftAgeable.java diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftAgeable.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftAgeable.java new file mode 100644 index 0000000000..ecd630c591 --- /dev/null +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftAgeable.java @@ -0,0 +1,67 @@ +package org.bukkit.craftbukkit.entity; + +import net.minecraft.server.EntityAgeable; + +import org.bukkit.craftbukkit.CraftServer; +import org.bukkit.entity.Ageable; + +public class CraftAgeable extends CraftCreature implements Ageable { + public CraftAgeable(CraftServer server, EntityAgeable entity) { + super(server, entity); + } + + public int getAge() { + return getHandle().getAge(); + } + + public void setAge(int age) { + getHandle().setAge(age); + } + + public void setAgeLock(boolean lock) { + getHandle().ageLocked = lock; + } + + public boolean getAgeLock() { + return getHandle().ageLocked; + } + + public void setBaby() { + if (isAdult()) { + setAge(-24000); + } + } + + public void setAdult() { + if (!isAdult()) { + setAge(0); + } + } + + public boolean isAdult() { + return getAge() >= 0; + } + + + public boolean canBreed() { + return getAge() == 0; + } + + public void setBreed(boolean breed) { + if (breed) { + setAge(0); + } else if (isAdult()) { + setAge(6000); + } + } + + @Override + public EntityAgeable getHandle() { + return (EntityAgeable) entity; + } + + @Override + public String toString() { + return "CraftAgeable"; + } +} diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftAnimals.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftAnimals.java index 4e229f5733..4b9b078305 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftAnimals.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftAnimals.java @@ -4,61 +4,17 @@ import net.minecraft.server.EntityAnimal; import org.bukkit.craftbukkit.CraftServer; import org.bukkit.entity.Animals; -public class CraftAnimals extends CraftCreature implements Animals { +public class CraftAnimals extends CraftAgeable implements Animals { public CraftAnimals(CraftServer server, EntityAnimal entity) { super(server, entity); } - public int getAge() { - return getHandle().getAge(); - } - - public void setAge(int age) { - getHandle().setAge(age); - } - @Override public EntityAnimal getHandle() { return (EntityAnimal) entity; } - public void setAgeLock(boolean lock) { - getHandle().ageLocked = lock; - } - - public boolean getAgeLock() { - return getHandle().ageLocked; - } - - public void setBaby() { - if (isAdult()) { - setAge(-24000); - } - } - - public void setAdult() { - if (!isAdult()) { - setAge(0); - } - } - - public boolean isAdult() { - return getAge() >= 0; - } - - public boolean canBreed() { - return getAge() == 0; - } - - public void setBreed(boolean breed) { - if (breed) { - setAge(0); - } else if (isAdult()) { - setAge(6000); - } - } - @Override public String toString() { return "CraftAnimals"; diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftVillager.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftVillager.java index 7cf5e4b720..398029b90c 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftVillager.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftVillager.java @@ -6,7 +6,7 @@ import org.bukkit.craftbukkit.CraftServer; import org.bukkit.entity.EntityType; import org.bukkit.entity.Villager; -public class CraftVillager extends CraftCreature implements Villager { +public class CraftVillager extends CraftAgeable implements Villager { public CraftVillager(CraftServer server, EntityVillager entity) { super(server, entity); }