Experimental change: implement Bukkit interfaces for NPCs

This commit is contained in:
fullwall 2012-10-12 12:16:44 +08:00
parent eb64a43bf3
commit f8ccd0b4fd
27 changed files with 665 additions and 32 deletions

View File

@ -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

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;
}
}
}

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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<MetadataValue> 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<MetadataValue> 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;
}