From 50e6858b72343827ddc8ca15a387fa950d459e3a Mon Sep 17 00:00:00 2001 From: md_5 Date: Fri, 10 Aug 2018 19:48:09 +1000 Subject: Improve entity hierarchy by adding Mob interface. --- .../bukkit/craftbukkit/entity/CraftAmbient.java | 2 +- .../bukkit/craftbukkit/entity/CraftCreature.java | 18 +--------- .../org/bukkit/craftbukkit/entity/CraftFlying.java | 2 +- .../org/bukkit/craftbukkit/entity/CraftMob.java | 39 ++++++++++++++++++++++ .../org/bukkit/craftbukkit/entity/CraftSlime.java | 17 +--------- 5 files changed, 43 insertions(+), 35 deletions(-) create mode 100644 src/main/java/org/bukkit/craftbukkit/entity/CraftMob.java (limited to 'src') diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftAmbient.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftAmbient.java index 086980e7..734f5489 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftAmbient.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftAmbient.java @@ -5,7 +5,7 @@ import org.bukkit.craftbukkit.CraftServer; import org.bukkit.entity.Ambient; import org.bukkit.entity.EntityType; -public class CraftAmbient extends CraftLivingEntity implements Ambient { +public class CraftAmbient extends CraftMob implements Ambient { public CraftAmbient(CraftServer server, EntityAmbient entity) { super(server, entity); } diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftCreature.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftCreature.java index 09d42141..73db6101 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftCreature.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftCreature.java @@ -3,28 +3,12 @@ package org.bukkit.craftbukkit.entity; import net.minecraft.server.EntityCreature; import org.bukkit.craftbukkit.CraftServer; import org.bukkit.entity.Creature; -import org.bukkit.entity.LivingEntity; -public class CraftCreature extends CraftLivingEntity implements Creature { +public class CraftCreature extends CraftMob implements Creature { public CraftCreature(CraftServer server, EntityCreature entity) { super(server, entity); } - public void setTarget(LivingEntity target) { - EntityCreature entity = getHandle(); - if (target == null) { - entity.setGoalTarget(null, null, false); - } else if (target instanceof CraftLivingEntity) { - entity.setGoalTarget(((CraftLivingEntity) target).getHandle(), null, false); - } - } - - public CraftLivingEntity getTarget() { - if (getHandle().getGoalTarget() == null) return null; - - return (CraftLivingEntity) getHandle().getGoalTarget().getBukkitEntity(); - } - @Override public EntityCreature getHandle() { return (EntityCreature) entity; diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftFlying.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftFlying.java index f374c7b8..6b0c33b3 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftFlying.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftFlying.java @@ -4,7 +4,7 @@ import net.minecraft.server.EntityFlying; import org.bukkit.craftbukkit.CraftServer; import org.bukkit.entity.Flying; -public class CraftFlying extends CraftLivingEntity implements Flying { +public class CraftFlying extends CraftMob implements Flying { public CraftFlying(CraftServer server, EntityFlying entity) { super(server, entity); diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftMob.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftMob.java new file mode 100644 index 00000000..43178db8 --- /dev/null +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftMob.java @@ -0,0 +1,39 @@ +package org.bukkit.craftbukkit.entity; + +import net.minecraft.server.EntityInsentient; +import org.bukkit.craftbukkit.CraftServer; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Mob; + +public abstract class CraftMob extends CraftLivingEntity implements Mob { + public CraftMob(CraftServer server, EntityInsentient entity) { + super(server, entity); + } + + @Override + public void setTarget(LivingEntity target) { + EntityInsentient entity = getHandle(); + if (target == null) { + entity.setGoalTarget(null, null, false); + } else if (target instanceof CraftLivingEntity) { + entity.setGoalTarget(((CraftLivingEntity) target).getHandle(), null, false); + } + } + + @Override + public CraftLivingEntity getTarget() { + if (getHandle().getGoalTarget() == null) return null; + + return (CraftLivingEntity) getHandle().getGoalTarget().getBukkitEntity(); + } + + @Override + public EntityInsentient getHandle() { + return (EntityInsentient) entity; + } + + @Override + public String toString() { + return "CraftMob"; + } +} diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftSlime.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftSlime.java index 6bf30c83..18e7ef80 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftSlime.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftSlime.java @@ -4,10 +4,9 @@ import net.minecraft.server.EntitySlime; import org.bukkit.craftbukkit.CraftServer; import org.bukkit.entity.EntityType; -import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Slime; -public class CraftSlime extends CraftLivingEntity implements Slime { +public class CraftSlime extends CraftMob implements Slime { public CraftSlime(CraftServer server, EntitySlime entity) { super(server, entity); @@ -21,20 +20,6 @@ public class CraftSlime extends CraftLivingEntity implements Slime { getHandle().setSize(size, true); } - @Override - public void setTarget(LivingEntity target) { - if (target == null) { - getHandle().setGoalTarget(null, null, false); - } else if (target instanceof CraftLivingEntity) { - getHandle().setGoalTarget(((CraftLivingEntity) target).getHandle(), null, false); - } - } - - @Override - public LivingEntity getTarget() { - return getHandle().getGoalTarget() == null ? null : (LivingEntity)getHandle().getGoalTarget().getBukkitEntity(); - } - @Override public EntitySlime getHandle() { return (EntitySlime) entity; -- cgit v1.2.3