diff --git a/src/main/java/net/citizensnpcs/npc/CitizensNPCRegistry.java b/src/main/java/net/citizensnpcs/npc/CitizensNPCRegistry.java index 2a4588312..e4e718953 100644 --- a/src/main/java/net/citizensnpcs/npc/CitizensNPCRegistry.java +++ b/src/main/java/net/citizensnpcs/npc/CitizensNPCRegistry.java @@ -37,7 +37,6 @@ import net.citizensnpcs.npc.entity.CitizensWolfNPC; import net.citizensnpcs.npc.entity.CitizensZombieNPC; import net.citizensnpcs.util.ByIdArray; -import org.bukkit.craftbukkit.entity.CraftEntity; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; @@ -143,10 +142,9 @@ public class CitizensNPCRegistry implements NPCRegistry { @Override public NPC getNPC(Entity entity) { - if (entity == null || !(entity instanceof CraftEntity)) + if (entity == null) return null; - net.minecraft.server.Entity handle = ((CraftEntity) entity).getHandle(); - return handle != null && handle instanceof NPCHolder ? ((NPCHolder) handle).getNPC() : null; + return entity instanceof NPCHolder ? ((NPCHolder) entity).getNPC() : null; } @Override diff --git a/src/main/java/net/citizensnpcs/npc/entity/CitizensBlazeNPC.java b/src/main/java/net/citizensnpcs/npc/entity/CitizensBlazeNPC.java index cc31d0adf..b01bd4338 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensBlazeNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensBlazeNPC.java @@ -10,7 +10,11 @@ import net.citizensnpcs.util.Util; import net.minecraft.server.EntityBlaze; import net.minecraft.server.World; +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.CraftServer; +import org.bukkit.craftbukkit.entity.CraftBlaze; import org.bukkit.entity.Blaze; +import org.bukkit.entity.Entity; import org.bukkit.util.Vector; public class CitizensBlazeNPC extends CitizensMobNPC { @@ -24,6 +28,20 @@ public class CitizensBlazeNPC extends CitizensMobNPC { return (Blaze) super.getBukkitEntity(); } + public static class BlazeNPC extends CraftBlaze implements NPCHolder { + private final CitizensNPC npc; + + public BlazeNPC(EntityBlazeNPC entity) { + super((CraftServer) Bukkit.getServer(), entity); + this.npc = entity.npc; + } + + @Override + public NPC getNPC() { + return npc; + } + } + public static class EntityBlazeNPC extends EntityBlaze implements NPCHolder { private final CitizensNPC npc; @@ -85,6 +103,13 @@ public class CitizensBlazeNPC extends CitizensMobNPC { // cancelled. } + @Override + public Entity getBukkitEntity() { + if (bukkitEntity == null && npc != null) + bukkitEntity = new BlazeNPC(this); + return super.getBukkitEntity(); + } + @Override public NPC getNPC() { return npc; diff --git a/src/main/java/net/citizensnpcs/npc/entity/CitizensCaveSpiderNPC.java b/src/main/java/net/citizensnpcs/npc/entity/CitizensCaveSpiderNPC.java index 7cc51830f..200c92fbb 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensCaveSpiderNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensCaveSpiderNPC.java @@ -10,7 +10,11 @@ import net.citizensnpcs.util.Util; import net.minecraft.server.EntityCaveSpider; import net.minecraft.server.World; +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.CraftServer; +import org.bukkit.craftbukkit.entity.CraftCaveSpider; import org.bukkit.entity.CaveSpider; +import org.bukkit.entity.Entity; import org.bukkit.util.Vector; public class CitizensCaveSpiderNPC extends CitizensMobNPC { @@ -23,6 +27,20 @@ public class CitizensCaveSpiderNPC extends CitizensMobNPC { return (CaveSpider) super.getBukkitEntity(); } + public static class CaveSpiderNPC extends CraftCaveSpider implements NPCHolder { + private final CitizensNPC npc; + + public CaveSpiderNPC(EntityCaveSpiderNPC entity) { + super((CraftServer) Bukkit.getServer(), entity); + this.npc = entity.npc; + } + + @Override + public NPC getNPC() { + return npc; + } + } + public static class EntityCaveSpiderNPC extends EntityCaveSpider implements NPCHolder { private final CitizensNPC npc; @@ -92,6 +110,13 @@ public class CitizensCaveSpiderNPC extends CitizensMobNPC { // cancelled. } + @Override + public Entity getBukkitEntity() { + if (bukkitEntity == null && npc != null) + bukkitEntity = new CaveSpiderNPC(this); + return super.getBukkitEntity(); + } + @Override public NPC getNPC() { return npc; diff --git a/src/main/java/net/citizensnpcs/npc/entity/CitizensChickenNPC.java b/src/main/java/net/citizensnpcs/npc/entity/CitizensChickenNPC.java index 622c6b7a6..858918a4e 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensChickenNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensChickenNPC.java @@ -10,7 +10,11 @@ import net.citizensnpcs.util.Util; import net.minecraft.server.EntityChicken; import net.minecraft.server.World; +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.CraftServer; +import org.bukkit.craftbukkit.entity.CraftChicken; import org.bukkit.entity.Chicken; +import org.bukkit.entity.Entity; import org.bukkit.util.Vector; public class CitizensChickenNPC extends CitizensMobNPC { @@ -24,6 +28,20 @@ public class CitizensChickenNPC extends CitizensMobNPC { return (Chicken) super.getBukkitEntity(); } + public static class ChickenNPC extends CraftChicken implements NPCHolder { + private final CitizensNPC npc; + + public ChickenNPC(EntityChickenNPC entity) { + super((CraftServer) Bukkit.getServer(), entity); + this.npc = entity.npc; + } + + @Override + public NPC getNPC() { + return npc; + } + } + public static class EntityChickenNPC extends EntityChicken implements NPCHolder { private final CitizensNPC npc; @@ -77,6 +95,13 @@ public class CitizensChickenNPC extends CitizensMobNPC { // cancelled. } + @Override + public Entity getBukkitEntity() { + if (bukkitEntity == null && npc != null) + bukkitEntity = new ChickenNPC(this); + return super.getBukkitEntity(); + } + @Override public NPC getNPC() { return npc; diff --git a/src/main/java/net/citizensnpcs/npc/entity/CitizensCowNPC.java b/src/main/java/net/citizensnpcs/npc/entity/CitizensCowNPC.java index 5820e8ddc..7d36c55af 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensCowNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensCowNPC.java @@ -10,7 +10,11 @@ import net.citizensnpcs.util.Util; import net.minecraft.server.EntityCow; import net.minecraft.server.World; +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.CraftServer; +import org.bukkit.craftbukkit.entity.CraftCow; import org.bukkit.entity.Cow; +import org.bukkit.entity.Entity; import org.bukkit.util.Vector; public class CitizensCowNPC extends CitizensMobNPC { @@ -24,6 +28,20 @@ public class CitizensCowNPC extends CitizensMobNPC { return (Cow) super.getBukkitEntity(); } + public static class CowNPC extends CraftCow implements NPCHolder { + private final CitizensNPC npc; + + public CowNPC(EntityCowNPC entity) { + super((CraftServer) Bukkit.getServer(), entity); + this.npc = entity.npc; + } + + @Override + public NPC getNPC() { + return npc; + } + } + public static class EntityCowNPC extends EntityCow implements NPCHolder { private final CitizensNPC npc; @@ -77,6 +95,13 @@ public class CitizensCowNPC extends CitizensMobNPC { // cancelled. } + @Override + public Entity getBukkitEntity() { + if (bukkitEntity == null && npc != null) + bukkitEntity = new CowNPC(this); + return super.getBukkitEntity(); + } + @Override public NPC getNPC() { return npc; diff --git a/src/main/java/net/citizensnpcs/npc/entity/CitizensCreeperNPC.java b/src/main/java/net/citizensnpcs/npc/entity/CitizensCreeperNPC.java index c36c80aa3..87c9da692 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensCreeperNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensCreeperNPC.java @@ -11,7 +11,11 @@ import net.minecraft.server.EntityCreeper; import net.minecraft.server.EntityLightning; import net.minecraft.server.World; +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.CraftServer; +import org.bukkit.craftbukkit.entity.CraftCreeper; import org.bukkit.entity.Creeper; +import org.bukkit.entity.Entity; import org.bukkit.util.Vector; public class CitizensCreeperNPC extends CitizensMobNPC { @@ -25,6 +29,20 @@ public class CitizensCreeperNPC extends CitizensMobNPC { return (Creeper) super.getBukkitEntity(); } + public static class CreeperNPC extends CraftCreeper implements NPCHolder { + private final CitizensNPC npc; + + public CreeperNPC(EntityCreeperNPC entity) { + super((CraftServer) Bukkit.getServer(), entity); + this.npc = entity.npc; + } + + @Override + public NPC getNPC() { + return npc; + } + } + public static class EntityCreeperNPC extends EntityCreeper implements NPCHolder { private final CitizensNPC npc; @@ -91,6 +109,13 @@ public class CitizensCreeperNPC extends CitizensMobNPC { // cancelled. } + @Override + public Entity getBukkitEntity() { + if (bukkitEntity == null && npc != null) + bukkitEntity = new CreeperNPC(this); + return super.getBukkitEntity(); + } + @Override public NPC getNPC() { return npc; diff --git a/src/main/java/net/citizensnpcs/npc/entity/CitizensEnderDragonNPC.java b/src/main/java/net/citizensnpcs/npc/entity/CitizensEnderDragonNPC.java index 2880927c5..3a3a77e7a 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensEnderDragonNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensEnderDragonNPC.java @@ -10,7 +10,11 @@ import net.citizensnpcs.util.Util; import net.minecraft.server.EntityEnderDragon; import net.minecraft.server.World; +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.CraftServer; +import org.bukkit.craftbukkit.entity.CraftEnderDragon; import org.bukkit.entity.EnderDragon; +import org.bukkit.entity.Entity; import org.bukkit.util.Vector; public class CitizensEnderDragonNPC extends CitizensMobNPC { @@ -24,6 +28,20 @@ public class CitizensEnderDragonNPC extends CitizensMobNPC { return (EnderDragon) super.getBukkitEntity(); } + public static class EnderDragonNPC extends CraftEnderDragon implements NPCHolder { + private final CitizensNPC npc; + + public EnderDragonNPC(EntityEnderDragonNPC entity) { + super((CraftServer) Bukkit.getServer(), entity); + this.npc = entity.npc; + } + + @Override + public NPC getNPC() { + return npc; + } + } + public static class EntityEnderDragonNPC extends EntityEnderDragon implements NPCHolder { private final CitizensNPC npc; @@ -87,6 +105,13 @@ public class CitizensEnderDragonNPC extends CitizensMobNPC { // cancelled. } + @Override + public Entity getBukkitEntity() { + if (bukkitEntity == null && npc != null) + bukkitEntity = new EnderDragonNPC(this); + return super.getBukkitEntity(); + } + @Override public NPC getNPC() { return npc; diff --git a/src/main/java/net/citizensnpcs/npc/entity/CitizensEndermanNPC.java b/src/main/java/net/citizensnpcs/npc/entity/CitizensEndermanNPC.java index 1c3f4de73..97edcf3b7 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensEndermanNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensEndermanNPC.java @@ -14,8 +14,12 @@ import net.citizensnpcs.util.Util; import net.minecraft.server.EntityEnderman; import net.minecraft.server.World; +import org.bukkit.Bukkit; import org.bukkit.Material; +import org.bukkit.craftbukkit.CraftServer; +import org.bukkit.craftbukkit.entity.CraftEnderman; import org.bukkit.entity.Enderman; +import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.material.MaterialData; @@ -57,6 +61,20 @@ public class CitizensEndermanNPC extends CitizensMobNPC implements Equipable { return (Enderman) super.getBukkitEntity(); } + public static class EndermanNPC extends CraftEnderman implements NPCHolder { + private final CitizensNPC npc; + + public EndermanNPC(EntityEndermanNPC entity) { + super((CraftServer) Bukkit.getServer(), entity); + this.npc = entity.npc; + } + + @Override + public NPC getNPC() { + return npc; + } + } + public static class EntityEndermanNPC extends EntityEnderman implements NPCHolder { private final CitizensNPC npc; @@ -137,6 +155,13 @@ public class CitizensEndermanNPC extends CitizensMobNPC implements Equipable { // cancelled. } + @Override + public Entity getBukkitEntity() { + if (bukkitEntity == null && npc != null) + bukkitEntity = new EndermanNPC(this); + return super.getBukkitEntity(); + } + @Override public NPC getNPC() { return npc; diff --git a/src/main/java/net/citizensnpcs/npc/entity/CitizensGhastNPC.java b/src/main/java/net/citizensnpcs/npc/entity/CitizensGhastNPC.java index af547e68a..b40e7fb76 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensGhastNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensGhastNPC.java @@ -10,6 +10,10 @@ import net.citizensnpcs.util.Util; import net.minecraft.server.EntityGhast; import net.minecraft.server.World; +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.CraftServer; +import org.bukkit.craftbukkit.entity.CraftGhast; +import org.bukkit.entity.Entity; import org.bukkit.entity.Ghast; import org.bukkit.util.Vector; @@ -85,6 +89,27 @@ public class CitizensGhastNPC extends CitizensMobNPC { // cancelled. } + @Override + public Entity getBukkitEntity() { + if (bukkitEntity == null && npc != null) + bukkitEntity = new GhastNPC(this); + return super.getBukkitEntity(); + } + + @Override + public NPC getNPC() { + return npc; + } + } + + public static class GhastNPC extends CraftGhast implements NPCHolder { + private final CitizensNPC npc; + + public GhastNPC(EntityGhastNPC entity) { + super((CraftServer) Bukkit.getServer(), entity); + this.npc = entity.npc; + } + @Override public NPC getNPC() { return npc; diff --git a/src/main/java/net/citizensnpcs/npc/entity/CitizensGiantNPC.java b/src/main/java/net/citizensnpcs/npc/entity/CitizensGiantNPC.java index 28572e90c..5cb9884ef 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensGiantNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensGiantNPC.java @@ -10,6 +10,10 @@ import net.citizensnpcs.util.Util; import net.minecraft.server.EntityGiantZombie; import net.minecraft.server.World; +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.CraftServer; +import org.bukkit.craftbukkit.entity.CraftGiant; +import org.bukkit.entity.Entity; import org.bukkit.entity.Giant; import org.bukkit.util.Vector; @@ -81,6 +85,27 @@ public class CitizensGiantNPC extends CitizensMobNPC { // cancelled. } + @Override + public Entity getBukkitEntity() { + if (bukkitEntity == null && npc != null) + bukkitEntity = new GiantNPC(this); + return super.getBukkitEntity(); + } + + @Override + public NPC getNPC() { + return npc; + } + } + + public static class GiantNPC extends CraftGiant implements NPCHolder { + private final CitizensNPC npc; + + public GiantNPC(EntityGiantNPC entity) { + super((CraftServer) Bukkit.getServer(), entity); + this.npc = entity.npc; + } + @Override public NPC getNPC() { return npc; diff --git a/src/main/java/net/citizensnpcs/npc/entity/CitizensIronGolemNPC.java b/src/main/java/net/citizensnpcs/npc/entity/CitizensIronGolemNPC.java index a380f7822..2ddcfad99 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensIronGolemNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensIronGolemNPC.java @@ -10,6 +10,10 @@ import net.citizensnpcs.util.Util; import net.minecraft.server.EntityIronGolem; import net.minecraft.server.World; +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.CraftServer; +import org.bukkit.craftbukkit.entity.CraftIronGolem; +import org.bukkit.entity.Entity; import org.bukkit.entity.IronGolem; import org.bukkit.util.Vector; @@ -80,6 +84,27 @@ public class CitizensIronGolemNPC extends CitizensMobNPC { // cancelled. } + @Override + public Entity getBukkitEntity() { + if (bukkitEntity == null && npc != null) + bukkitEntity = new IronGolemNPC(this); + return super.getBukkitEntity(); + } + + @Override + public NPC getNPC() { + return npc; + } + } + + public static class IronGolemNPC extends CraftIronGolem implements NPCHolder { + private final CitizensNPC npc; + + public IronGolemNPC(EntityIronGolemNPC entity) { + super((CraftServer) Bukkit.getServer(), entity); + this.npc = entity.npc; + } + @Override public NPC getNPC() { return npc; diff --git a/src/main/java/net/citizensnpcs/npc/entity/CitizensMagmaCubeNPC.java b/src/main/java/net/citizensnpcs/npc/entity/CitizensMagmaCubeNPC.java index c61ba6acb..c18c35344 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensMagmaCubeNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensMagmaCubeNPC.java @@ -10,6 +10,10 @@ import net.citizensnpcs.util.Util; import net.minecraft.server.EntityMagmaCube; import net.minecraft.server.World; +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.CraftServer; +import org.bukkit.craftbukkit.entity.CraftMagmaCube; +import org.bukkit.entity.Entity; import org.bukkit.entity.MagmaCube; import org.bukkit.util.Vector; @@ -95,6 +99,27 @@ public class CitizensMagmaCubeNPC extends CitizensMobNPC { // cancelled. } + @Override + public Entity getBukkitEntity() { + if (bukkitEntity == null && npc != null) + bukkitEntity = new MagmaCubeNPC(this); + return super.getBukkitEntity(); + } + + @Override + public NPC getNPC() { + return npc; + } + } + + public static class MagmaCubeNPC extends CraftMagmaCube implements NPCHolder { + private final CitizensNPC npc; + + public MagmaCubeNPC(EntityMagmaCubeNPC entity) { + super((CraftServer) Bukkit.getServer(), entity); + this.npc = entity.npc; + } + @Override public NPC getNPC() { return npc; diff --git a/src/main/java/net/citizensnpcs/npc/entity/CitizensMushroomCowNPC.java b/src/main/java/net/citizensnpcs/npc/entity/CitizensMushroomCowNPC.java index c88a2fa32..37d57e367 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensMushroomCowNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensMushroomCowNPC.java @@ -10,6 +10,10 @@ import net.citizensnpcs.util.Util; import net.minecraft.server.EntityMushroomCow; import net.minecraft.server.World; +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.CraftServer; +import org.bukkit.craftbukkit.entity.CraftMushroomCow; +import org.bukkit.entity.Entity; import org.bukkit.entity.MushroomCow; import org.bukkit.util.Vector; @@ -77,6 +81,27 @@ public class CitizensMushroomCowNPC extends CitizensMobNPC { // cancelled. } + @Override + public Entity getBukkitEntity() { + if (bukkitEntity == null && npc != null) + bukkitEntity = new MushroomCowNPC(this); + return super.getBukkitEntity(); + } + + @Override + public NPC getNPC() { + return npc; + } + } + + public static class MushroomCowNPC extends CraftMushroomCow implements NPCHolder { + private final CitizensNPC npc; + + public MushroomCowNPC(EntityMushroomCowNPC entity) { + super((CraftServer) Bukkit.getServer(), entity); + this.npc = entity.npc; + } + @Override public NPC getNPC() { return npc; diff --git a/src/main/java/net/citizensnpcs/npc/entity/CitizensOcelotNPC.java b/src/main/java/net/citizensnpcs/npc/entity/CitizensOcelotNPC.java index cdc4585bf..09d8643d6 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensOcelotNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensOcelotNPC.java @@ -10,6 +10,10 @@ import net.citizensnpcs.util.Util; import net.minecraft.server.EntityOcelot; import net.minecraft.server.World; +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.CraftServer; +import org.bukkit.craftbukkit.entity.CraftOcelot; +import org.bukkit.entity.Entity; import org.bukkit.entity.Ocelot; import org.bukkit.util.Vector; @@ -84,6 +88,27 @@ public class CitizensOcelotNPC extends CitizensMobNPC { // cancelled. } + @Override + public Entity getBukkitEntity() { + if (bukkitEntity == null && npc != null) + bukkitEntity = new OcelotNPC(this); + return super.getBukkitEntity(); + } + + @Override + public NPC getNPC() { + return npc; + } + } + + public static class OcelotNPC extends CraftOcelot implements NPCHolder { + private final CitizensNPC npc; + + public OcelotNPC(EntityOcelotNPC entity) { + super((CraftServer) Bukkit.getServer(), entity); + this.npc = entity.npc; + } + @Override public NPC getNPC() { return npc; diff --git a/src/main/java/net/citizensnpcs/npc/entity/CitizensPigNPC.java b/src/main/java/net/citizensnpcs/npc/entity/CitizensPigNPC.java index 979472bb5..16635eabb 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensPigNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensPigNPC.java @@ -15,7 +15,11 @@ import net.minecraft.server.EntityLightning; import net.minecraft.server.EntityPig; import net.minecraft.server.World; +import org.bukkit.Bukkit; import org.bukkit.Material; +import org.bukkit.craftbukkit.CraftServer; +import org.bukkit.craftbukkit.entity.CraftPig; +import org.bukkit.entity.Entity; import org.bukkit.entity.Pig; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; @@ -107,6 +111,27 @@ public class CitizensPigNPC extends CitizensMobNPC implements Equipable { // cancelled. } + @Override + public Entity getBukkitEntity() { + if (bukkitEntity == null && npc != null) + bukkitEntity = new PigNPC(this); + return super.getBukkitEntity(); + } + + @Override + public NPC getNPC() { + return npc; + } + } + + public static class PigNPC extends CraftPig implements NPCHolder { + private final CitizensNPC npc; + + public PigNPC(EntityPigNPC entity) { + super((CraftServer) Bukkit.getServer(), entity); + this.npc = entity.npc; + } + @Override public NPC getNPC() { return npc; diff --git a/src/main/java/net/citizensnpcs/npc/entity/CitizensPigZombieNPC.java b/src/main/java/net/citizensnpcs/npc/entity/CitizensPigZombieNPC.java index ed2e40aad..83a5c81fa 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensPigZombieNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensPigZombieNPC.java @@ -10,6 +10,10 @@ import net.citizensnpcs.util.Util; import net.minecraft.server.EntityPigZombie; import net.minecraft.server.World; +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.CraftServer; +import org.bukkit.craftbukkit.entity.CraftPigZombie; +import org.bukkit.entity.Entity; import org.bukkit.entity.PigZombie; import org.bukkit.util.Vector; @@ -94,6 +98,27 @@ public class CitizensPigZombieNPC extends CitizensMobNPC { // cancelled. } + @Override + public Entity getBukkitEntity() { + if (bukkitEntity == null && npc != null) + bukkitEntity = new PigZombieNPC(this); + return super.getBukkitEntity(); + } + + @Override + public NPC getNPC() { + return npc; + } + } + + public static class PigZombieNPC extends CraftPigZombie implements NPCHolder { + private final CitizensNPC npc; + + public PigZombieNPC(EntityPigZombieNPC entity) { + super((CraftServer) Bukkit.getServer(), entity); + this.npc = entity.npc; + } + @Override public NPC getNPC() { return npc; diff --git a/src/main/java/net/citizensnpcs/npc/entity/CitizensSheepNPC.java b/src/main/java/net/citizensnpcs/npc/entity/CitizensSheepNPC.java index 88ced4380..da1f22907 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensSheepNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensSheepNPC.java @@ -15,15 +15,18 @@ import net.citizensnpcs.util.Util; import net.minecraft.server.EntitySheep; import net.minecraft.server.World; +import org.bukkit.Bukkit; import org.bukkit.DyeColor; import org.bukkit.Material; +import org.bukkit.craftbukkit.CraftServer; +import org.bukkit.craftbukkit.entity.CraftSheep; +import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.entity.Sheep; import org.bukkit.inventory.ItemStack; import org.bukkit.util.Vector; public class CitizensSheepNPC extends CitizensMobNPC implements Equipable { - public CitizensSheepNPC(int id, String name) { super(id, name, EntitySheepNPC.class); } @@ -107,6 +110,27 @@ public class CitizensSheepNPC extends CitizensMobNPC implements Equipable { // cancelled. } + @Override + public Entity getBukkitEntity() { + if (bukkitEntity == null && npc != null) + bukkitEntity = new SheepNPC(this); + return super.getBukkitEntity(); + } + + @Override + public NPC getNPC() { + return npc; + } + } + + public static class SheepNPC extends CraftSheep implements NPCHolder { + private final CitizensNPC npc; + + public SheepNPC(EntitySheepNPC entity) { + super((CraftServer) Bukkit.getServer(), entity); + this.npc = entity.npc; + } + @Override public NPC getNPC() { return npc; diff --git a/src/main/java/net/citizensnpcs/npc/entity/CitizensSilverfishNPC.java b/src/main/java/net/citizensnpcs/npc/entity/CitizensSilverfishNPC.java index 11729b495..be2d28dcc 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensSilverfishNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensSilverfishNPC.java @@ -10,6 +10,10 @@ import net.citizensnpcs.util.Util; import net.minecraft.server.EntitySilverfish; import net.minecraft.server.World; +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.CraftServer; +import org.bukkit.craftbukkit.entity.CraftSilverfish; +import org.bukkit.entity.Entity; import org.bukkit.entity.Silverfish; import org.bukkit.util.Vector; @@ -94,6 +98,27 @@ public class CitizensSilverfishNPC extends CitizensMobNPC { // cancelled. } + @Override + public Entity getBukkitEntity() { + if (bukkitEntity == null && npc != null) + bukkitEntity = new SilverfishNPC(this); + return super.getBukkitEntity(); + } + + @Override + public NPC getNPC() { + return npc; + } + } + + public static class SilverfishNPC extends CraftSilverfish implements NPCHolder { + private final CitizensNPC npc; + + public SilverfishNPC(EntitySilverfishNPC entity) { + super((CraftServer) Bukkit.getServer(), entity); + this.npc = entity.npc; + } + @Override public NPC getNPC() { return npc; diff --git a/src/main/java/net/citizensnpcs/npc/entity/CitizensSkeletonNPC.java b/src/main/java/net/citizensnpcs/npc/entity/CitizensSkeletonNPC.java index 1402ce5f0..d1d5cb915 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensSkeletonNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensSkeletonNPC.java @@ -10,6 +10,10 @@ import net.citizensnpcs.util.Util; import net.minecraft.server.EntitySkeleton; import net.minecraft.server.World; +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.CraftServer; +import org.bukkit.craftbukkit.entity.CraftSkeleton; +import org.bukkit.entity.Entity; import org.bukkit.entity.Skeleton; import org.bukkit.util.Vector; @@ -84,6 +88,27 @@ public class CitizensSkeletonNPC extends CitizensMobNPC { // cancelled. } + @Override + public Entity getBukkitEntity() { + if (bukkitEntity == null && npc != null) + bukkitEntity = new SkeletonNPC(this); + return super.getBukkitEntity(); + } + + @Override + public NPC getNPC() { + return npc; + } + } + + public static class SkeletonNPC extends CraftSkeleton implements NPCHolder { + private final CitizensNPC npc; + + public SkeletonNPC(EntitySkeletonNPC entity) { + super((CraftServer) Bukkit.getServer(), entity); + this.npc = entity.npc; + } + @Override public NPC getNPC() { return npc; diff --git a/src/main/java/net/citizensnpcs/npc/entity/CitizensSlimeNPC.java b/src/main/java/net/citizensnpcs/npc/entity/CitizensSlimeNPC.java index 63ccdb97c..009664cb2 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensSlimeNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensSlimeNPC.java @@ -10,6 +10,10 @@ import net.citizensnpcs.util.Util; import net.minecraft.server.EntitySlime; import net.minecraft.server.World; +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.CraftServer; +import org.bukkit.craftbukkit.entity.CraftSlime; +import org.bukkit.entity.Entity; import org.bukkit.entity.Slime; import org.bukkit.util.Vector; @@ -95,6 +99,27 @@ public class CitizensSlimeNPC extends CitizensMobNPC { // cancelled. } + @Override + public Entity getBukkitEntity() { + if (bukkitEntity == null && npc != null) + bukkitEntity = new SlimeNPC(this); + return super.getBukkitEntity(); + } + + @Override + public NPC getNPC() { + return npc; + } + } + + public static class SlimeNPC extends CraftSlime implements NPCHolder { + private final CitizensNPC npc; + + public SlimeNPC(EntitySlimeNPC entity) { + super((CraftServer) Bukkit.getServer(), entity); + this.npc = entity.npc; + } + @Override public NPC getNPC() { return npc; diff --git a/src/main/java/net/citizensnpcs/npc/entity/CitizensSnowmanNPC.java b/src/main/java/net/citizensnpcs/npc/entity/CitizensSnowmanNPC.java index 0ce3c07b3..3c45f0f60 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensSnowmanNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensSnowmanNPC.java @@ -10,6 +10,10 @@ import net.citizensnpcs.util.Util; import net.minecraft.server.EntitySnowman; import net.minecraft.server.World; +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.CraftServer; +import org.bukkit.craftbukkit.entity.CraftSnowman; +import org.bukkit.entity.Entity; import org.bukkit.entity.Snowman; import org.bukkit.util.Vector; @@ -80,6 +84,27 @@ public class CitizensSnowmanNPC extends CitizensMobNPC { // cancelled. } + @Override + public Entity getBukkitEntity() { + if (bukkitEntity == null && npc != null) + bukkitEntity = new SnowmanNPC(this); + return super.getBukkitEntity(); + } + + @Override + public NPC getNPC() { + return npc; + } + } + + public static class SnowmanNPC extends CraftSnowman implements NPCHolder { + private final CitizensNPC npc; + + public SnowmanNPC(EntitySnowmanNPC entity) { + super((CraftServer) Bukkit.getServer(), entity); + this.npc = entity.npc; + } + @Override public NPC getNPC() { return npc; diff --git a/src/main/java/net/citizensnpcs/npc/entity/CitizensSpiderNPC.java b/src/main/java/net/citizensnpcs/npc/entity/CitizensSpiderNPC.java index a4c878af6..086e9ef4b 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensSpiderNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensSpiderNPC.java @@ -10,6 +10,10 @@ import net.citizensnpcs.util.Util; import net.minecraft.server.EntitySpider; import net.minecraft.server.World; +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.CraftServer; +import org.bukkit.craftbukkit.entity.CraftSpider; +import org.bukkit.entity.Entity; import org.bukkit.entity.Spider; import org.bukkit.util.Vector; @@ -93,6 +97,27 @@ public class CitizensSpiderNPC extends CitizensMobNPC { // cancelled. } + @Override + public Entity getBukkitEntity() { + if (bukkitEntity == null && npc != null) + bukkitEntity = new SpiderNPC(this); + return super.getBukkitEntity(); + } + + @Override + public NPC getNPC() { + return npc; + } + } + + public static class SpiderNPC extends CraftSpider implements NPCHolder { + private final CitizensNPC npc; + + public SpiderNPC(EntitySpiderNPC entity) { + super((CraftServer) Bukkit.getServer(), entity); + this.npc = entity.npc; + } + @Override public NPC getNPC() { return npc; diff --git a/src/main/java/net/citizensnpcs/npc/entity/CitizensSquidNPC.java b/src/main/java/net/citizensnpcs/npc/entity/CitizensSquidNPC.java index 3154d154a..660813a87 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensSquidNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensSquidNPC.java @@ -10,6 +10,10 @@ import net.citizensnpcs.util.Util; import net.minecraft.server.EntitySquid; import net.minecraft.server.World; +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.CraftServer; +import org.bukkit.craftbukkit.entity.CraftSquid; +import org.bukkit.entity.Entity; import org.bukkit.entity.Squid; import org.bukkit.util.Vector; @@ -85,10 +89,30 @@ public class CitizensSquidNPC extends CitizensMobNPC { // cancelled. } + @Override + public Entity getBukkitEntity() { + if (bukkitEntity == null && npc != null) + bukkitEntity = new SquidNPC(this); + return super.getBukkitEntity(); + } + @Override public NPC getNPC() { return npc; } + } + public static class SquidNPC extends CraftSquid implements NPCHolder { + private final CitizensNPC npc; + + public SquidNPC(EntitySquidNPC entity) { + super((CraftServer) Bukkit.getServer(), entity); + this.npc = entity.npc; + } + + @Override + public NPC getNPC() { + return npc; + } } } \ No newline at end of file diff --git a/src/main/java/net/citizensnpcs/npc/entity/CitizensVillagerNPC.java b/src/main/java/net/citizensnpcs/npc/entity/CitizensVillagerNPC.java index 7dea12d11..069547e3b 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensVillagerNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensVillagerNPC.java @@ -11,6 +11,10 @@ import net.minecraft.server.EntityHuman; import net.minecraft.server.EntityVillager; import net.minecraft.server.World; +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.CraftServer; +import org.bukkit.craftbukkit.entity.CraftVillager; +import org.bukkit.entity.Entity; import org.bukkit.entity.Villager; import org.bukkit.util.Vector; @@ -92,6 +96,27 @@ public class CitizensVillagerNPC extends CitizensMobNPC { // cancelled. } + @Override + public Entity getBukkitEntity() { + if (bukkitEntity == null && npc != null) + bukkitEntity = new VillagerNPC(this); + return super.getBukkitEntity(); + } + + @Override + public NPC getNPC() { + return npc; + } + } + + public static class VillagerNPC extends CraftVillager implements NPCHolder { + private final CitizensNPC npc; + + public VillagerNPC(EntityVillagerNPC entity) { + super((CraftServer) Bukkit.getServer(), entity); + this.npc = entity.npc; + } + @Override public NPC getNPC() { return npc; diff --git a/src/main/java/net/citizensnpcs/npc/entity/CitizensWolfNPC.java b/src/main/java/net/citizensnpcs/npc/entity/CitizensWolfNPC.java index a4625f649..fcdb7ea09 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensWolfNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensWolfNPC.java @@ -10,6 +10,10 @@ import net.citizensnpcs.util.Util; import net.minecraft.server.EntityWolf; import net.minecraft.server.World; +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.CraftServer; +import org.bukkit.craftbukkit.entity.CraftWolf; +import org.bukkit.entity.Entity; import org.bukkit.entity.Wolf; import org.bukkit.util.Vector; @@ -84,6 +88,27 @@ public class CitizensWolfNPC extends CitizensMobNPC { // cancelled. } + @Override + public Entity getBukkitEntity() { + if (bukkitEntity == null && npc != null) + bukkitEntity = new WolfNPC(this); + return super.getBukkitEntity(); + } + + @Override + public NPC getNPC() { + return npc; + } + } + + public static class WolfNPC extends CraftWolf implements NPCHolder { + private final CitizensNPC npc; + + public WolfNPC(EntityWolfNPC entity) { + super((CraftServer) Bukkit.getServer(), entity); + this.npc = entity.npc; + } + @Override public NPC getNPC() { return npc; diff --git a/src/main/java/net/citizensnpcs/npc/entity/CitizensZombieNPC.java b/src/main/java/net/citizensnpcs/npc/entity/CitizensZombieNPC.java index 802e30f25..d35b22dd6 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensZombieNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensZombieNPC.java @@ -10,6 +10,10 @@ import net.citizensnpcs.util.Util; import net.minecraft.server.EntityZombie; import net.minecraft.server.World; +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.CraftServer; +import org.bukkit.craftbukkit.entity.CraftZombie; +import org.bukkit.entity.Entity; import org.bukkit.entity.Zombie; import org.bukkit.util.Vector; @@ -84,6 +88,27 @@ public class CitizensZombieNPC extends CitizensMobNPC { // cancelled. } + @Override + public Entity getBukkitEntity() { + if (bukkitEntity == null && npc != null) + bukkitEntity = new ZombieNPC(this); + return super.getBukkitEntity(); + } + + @Override + public NPC getNPC() { + return npc; + } + } + + public static class ZombieNPC extends CraftZombie implements NPCHolder { + private final CitizensNPC npc; + + public ZombieNPC(EntityZombieNPC entity) { + super((CraftServer) Bukkit.getServer(), entity); + this.npc = entity.npc; + } + @Override public NPC getNPC() { return npc; diff --git a/src/main/java/net/citizensnpcs/npc/entity/EntityHumanNPC.java b/src/main/java/net/citizensnpcs/npc/entity/EntityHumanNPC.java index b8d900dd1..c10daf669 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/EntityHumanNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/EntityHumanNPC.java @@ -74,31 +74,9 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder { @Override public CraftPlayer getBukkitEntity() { - if (npc == null) - return super.getBukkitEntity(); - if (bukkitEntity != null) - return (CraftPlayer) bukkitEntity; - return (CraftPlayer) (bukkitEntity = new CraftPlayer(((CraftServer) Bukkit.getServer()), this) { - @Override - public List getMetadata(String metadataKey) { - return server.getEntityMetadata().getMetadata(this, metadataKey); - } - - @Override - public boolean hasMetadata(String metadataKey) { - return server.getEntityMetadata().hasMetadata(this, metadataKey); - } - - @Override - public void removeMetadata(String metadataKey, Plugin owningPlugin) { - server.getEntityMetadata().removeMetadata(this, metadataKey, owningPlugin); - } - - @Override - public void setMetadata(String metadataKey, MetadataValue newMetadataValue) { - server.getEntityMetadata().setMetadata(this, metadataKey, newMetadataValue); - } - }); + if (npc != null && bukkitEntity == null) + bukkitEntity = new PlayerNPC(this); + return super.getBukkitEntity(); } @Override @@ -127,8 +105,6 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder { npc.update(); } - private static final float EPSILON = 0.005F; - private void initialise(MinecraftServer minecraftServer) { Socket socket = new EmptySocket(); NetworkManager netMgr = null; @@ -185,5 +161,41 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder { as = yaw; // update head yaw to match entity yaw } + public static class PlayerNPC extends CraftPlayer implements NPCHolder { + private final CitizensNPC npc; + + private PlayerNPC(EntityHumanNPC entity) { + super((CraftServer) Bukkit.getServer(), entity); + this.npc = entity.npc; + } + + @Override + public List getMetadata(String metadataKey) { + return server.getEntityMetadata().getMetadata(this, metadataKey); + } + + @Override + public NPC getNPC() { + return npc; + } + + @Override + public boolean hasMetadata(String metadataKey) { + return server.getEntityMetadata().hasMetadata(this, metadataKey); + } + + @Override + public void removeMetadata(String metadataKey, Plugin owningPlugin) { + server.getEntityMetadata().removeMetadata(this, metadataKey, owningPlugin); + } + + @Override + public void setMetadata(String metadataKey, MetadataValue newMetadataValue) { + server.getEntityMetadata().setMetadata(this, metadataKey, newMetadataValue); + } + } + + private static final float EPSILON = 0.005F; + private static final float STEP_HEIGHT = 1F; } \ No newline at end of file