Move updating to individual entities

This commit is contained in:
fullwall 2012-04-19 11:52:07 +08:00
parent 1048787305
commit 86dcef9ad0
31 changed files with 176 additions and 92 deletions

View File

@ -161,8 +161,6 @@ public class Citizens extends JavaPlugin {
registerCommands();
getServer().getScheduler().scheduleSyncRepeatingTask(this, new NPCUpdater(npcManager), 0, 1);
Messaging.log("v" + getDescription().getVersion() + " enabled.");
// Setup NPCs after all plugins have been enabled (allows for multiworld
@ -170,11 +168,7 @@ public class Citizens extends JavaPlugin {
if (getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
@Override
public void run() {
try {
setupNPCs();
} catch (NPCLoadException ex) {
Messaging.log(Level.SEVERE, "Issue when loading NPCs: " + ex.getMessage());
}
setupNPCs();
}
}) == -1) {
Messaging.log(Level.SEVERE, "Issue enabling plugin. Disabling.");
@ -271,20 +265,22 @@ public class Citizens extends JavaPlugin {
}
// TODO: refactor
private void setupNPCs() throws NPCLoadException {
private void setupNPCs() {
saves.load();
int created = 0, spawned = 0;
for (DataKey key : saves.getKey("npc").getIntegerSubKeys()) {
int id = Integer.parseInt(key.name());
if (!key.keyExists("name"))
throw new NPCLoadException("Could not find a name for the NPC with ID '" + id + "'.");
if (!key.keyExists("name")) {
Messaging.log("Could not find a name for the NPC with ID '" + id + "'.");
continue;
}
EntityType type = EntityType.fromName(key.getString("traits.type"));
if (type == null) {
try {
type = EntityType.valueOf(key.getString("traits.type"));
} catch (IllegalArgumentException ex) {
throw new NPCLoadException("NPC type not recognized. Did you spell it correctly?");
Messaging.log("NPC type not recognized. Did you spell it correctly?");
continue;
}
}
NPC npc = npcManager.createNPC(type, id, key.getString("name"), null);

View File

@ -1,25 +0,0 @@
package net.citizensnpcs;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.npc.CitizensNPC;
import net.citizensnpcs.npc.CitizensNPCManager;
// TODO: Move to Entity.update()?
public class NPCUpdater implements Runnable {
private final CitizensNPCManager npcManager;
public NPCUpdater(CitizensNPCManager npcManager) {
this.npcManager = npcManager;
}
@Override
public void run() {
if (!npcManager.iterator().hasNext())
return;
for (NPC npc : npcManager) {
if (!npc.isSpawned())
continue;
((CitizensNPC) npc).update();
}
}
}

View File

@ -5,8 +5,6 @@ import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import org.bukkit.plugin.Plugin;
import net.citizensnpcs.Citizens;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.trait.Trait;
@ -18,6 +16,7 @@ import net.citizensnpcs.api.trait.trait.MobType;
import net.citizensnpcs.api.trait.trait.Owner;
import net.citizensnpcs.api.trait.trait.Spawned;
import net.citizensnpcs.trait.Age;
import net.citizensnpcs.trait.Controllable;
import net.citizensnpcs.trait.CurrentLocation;
import net.citizensnpcs.trait.LookClose;
import net.citizensnpcs.trait.Powered;
@ -28,12 +27,15 @@ import net.citizensnpcs.trait.WoolColor;
import net.citizensnpcs.trait.text.Text;
import net.citizensnpcs.trait.waypoint.Waypoints;
import org.bukkit.plugin.Plugin;
public class CitizensTraitManager implements TraitManager {
private final Map<Class<? extends Trait>, Constructor<? extends Trait>> CACHED_CTORS = new HashMap<Class<? extends Trait>, Constructor<? extends Trait>>();
private final Map<Plugin, Map<String, Class<? extends Trait>>> registered = new HashMap<Plugin, Map<String, Class<? extends Trait>>>();
public CitizensTraitManager(Citizens plugin) {
// Register Citizens traits
// TODO: make it automatic without hax (annotations)
registerTrait(new TraitFactory(Age.class).withName("age").withPlugin(plugin));
registerTrait(new TraitFactory(CurrentLocation.class).withName("location").withPlugin(plugin));
registerTrait(new TraitFactory(Equipment.class).withName("equipment").withPlugin(plugin));
@ -49,6 +51,7 @@ public class CitizensTraitManager implements TraitManager {
registerTrait(new TraitFactory(VillagerProfession.class).withName("profession").withPlugin(plugin));
registerTrait(new TraitFactory(Waypoints.class).withName("waypoints").withPlugin(plugin));
registerTrait(new TraitFactory(WoolColor.class).withName("wool-color").withPlugin(plugin));
registerTrait(new TraitFactory(Controllable.class).withName("controllable").withPlugin(plugin));
}
@SuppressWarnings("unchecked")

View File

@ -2,6 +2,7 @@ package net.citizensnpcs.npc.entity;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.npc.CitizensMobNPC;
import net.citizensnpcs.npc.CitizensNPC;
import net.citizensnpcs.npc.CitizensNPCManager;
import net.citizensnpcs.npc.ai.NPCHandle;
import net.minecraft.server.EntityBlaze;
@ -22,9 +23,9 @@ public class CitizensBlazeNPC extends CitizensMobNPC {
}
public static class EntityBlazeNPC extends EntityBlaze implements NPCHandle {
private final NPC npc;
private final CitizensNPC npc;
public EntityBlazeNPC(World world, NPC npc) {
public EntityBlazeNPC(World world, CitizensNPC npc) {
super(world);
this.npc = npc;
goalSelector = new PathfinderGoalSelector();
@ -33,6 +34,7 @@ public class CitizensBlazeNPC extends CitizensMobNPC {
@Override
public void d_() {
npc.update();
}
@Override

View File

@ -2,6 +2,7 @@ package net.citizensnpcs.npc.entity;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.npc.CitizensMobNPC;
import net.citizensnpcs.npc.CitizensNPC;
import net.citizensnpcs.npc.CitizensNPCManager;
import net.citizensnpcs.npc.ai.NPCHandle;
import net.minecraft.server.EntityCaveSpider;
@ -22,9 +23,9 @@ public class CitizensCaveSpiderNPC extends CitizensMobNPC {
}
public static class EntityCaveSpiderNPC extends EntityCaveSpider implements NPCHandle {
private final NPC npc;
private final CitizensNPC npc;
public EntityCaveSpiderNPC(World world, NPC npc) {
public EntityCaveSpiderNPC(World world, CitizensNPC npc) {
super(world);
this.npc = npc;
goalSelector = new PathfinderGoalSelector();
@ -33,6 +34,7 @@ public class CitizensCaveSpiderNPC extends CitizensMobNPC {
@Override
public void d_() {
npc.update();
}
@Override

View File

@ -2,6 +2,7 @@ package net.citizensnpcs.npc.entity;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.npc.CitizensMobNPC;
import net.citizensnpcs.npc.CitizensNPC;
import net.citizensnpcs.npc.CitizensNPCManager;
import net.citizensnpcs.npc.ai.NPCHandle;
import net.minecraft.server.EntityChicken;
@ -22,9 +23,9 @@ public class CitizensChickenNPC extends CitizensMobNPC {
}
public static class EntityChickenNPC extends EntityChicken implements NPCHandle {
private final NPC npc;
private final CitizensNPC npc;
public EntityChickenNPC(World world, NPC npc) {
public EntityChickenNPC(World world, CitizensNPC npc) {
super(world);
this.npc = npc;
goalSelector = new PathfinderGoalSelector();
@ -33,6 +34,7 @@ public class CitizensChickenNPC extends CitizensMobNPC {
@Override
public void d_() {
npc.update();
}
@Override

View File

@ -2,6 +2,7 @@ package net.citizensnpcs.npc.entity;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.npc.CitizensMobNPC;
import net.citizensnpcs.npc.CitizensNPC;
import net.citizensnpcs.npc.CitizensNPCManager;
import net.citizensnpcs.npc.ai.NPCHandle;
import net.minecraft.server.EntityCow;
@ -22,9 +23,9 @@ public class CitizensCowNPC extends CitizensMobNPC {
}
public static class EntityCowNPC extends EntityCow implements NPCHandle {
private final NPC npc;
private final CitizensNPC npc;
public EntityCowNPC(World world, NPC npc) {
public EntityCowNPC(World world, CitizensNPC npc) {
super(world);
this.npc = npc;
goalSelector = new PathfinderGoalSelector();
@ -33,6 +34,7 @@ public class CitizensCowNPC extends CitizensMobNPC {
@Override
public void d_() {
npc.update();
}
@Override

View File

@ -2,6 +2,7 @@ package net.citizensnpcs.npc.entity;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.npc.CitizensMobNPC;
import net.citizensnpcs.npc.CitizensNPC;
import net.citizensnpcs.npc.CitizensNPCManager;
import net.citizensnpcs.npc.ai.NPCHandle;
import net.minecraft.server.EntityCreeper;
@ -23,9 +24,9 @@ public class CitizensCreeperNPC extends CitizensMobNPC {
}
public static class EntityCreeperNPC extends EntityCreeper implements NPCHandle {
private final NPC npc;
private final CitizensNPC npc;
public EntityCreeperNPC(World world, NPC npc) {
public EntityCreeperNPC(World world, CitizensNPC npc) {
super(world);
this.npc = npc;
goalSelector = new PathfinderGoalSelector();
@ -38,6 +39,7 @@ public class CitizensCreeperNPC extends CitizensMobNPC {
@Override
public void d_() {
npc.update();
}
@Override

View File

@ -2,6 +2,7 @@ package net.citizensnpcs.npc.entity;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.npc.CitizensMobNPC;
import net.citizensnpcs.npc.CitizensNPC;
import net.citizensnpcs.npc.CitizensNPCManager;
import net.citizensnpcs.npc.ai.NPCHandle;
import net.minecraft.server.EntityEnderDragon;
@ -22,9 +23,9 @@ public class CitizensEnderDragonNPC extends CitizensMobNPC {
}
public static class EntityEnderDragonNPC extends EntityEnderDragon implements NPCHandle {
private final NPC npc;
private final CitizensNPC npc;
public EntityEnderDragonNPC(World world, NPC npc) {
public EntityEnderDragonNPC(World world, CitizensNPC npc) {
super(world);
this.npc = npc;
goalSelector = new PathfinderGoalSelector();
@ -37,6 +38,7 @@ public class CitizensEnderDragonNPC extends CitizensMobNPC {
@Override
public void e() {
npc.update();
}
@Override

View File

@ -4,6 +4,7 @@ import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.trait.trait.Equipment;
import net.citizensnpcs.editor.Equipable;
import net.citizensnpcs.npc.CitizensMobNPC;
import net.citizensnpcs.npc.CitizensNPC;
import net.citizensnpcs.npc.CitizensNPCManager;
import net.citizensnpcs.npc.ai.NPCHandle;
import net.citizensnpcs.util.Messaging;
@ -60,9 +61,9 @@ public class CitizensEndermanNPC extends CitizensMobNPC implements Equipable {
}
public static class EntityEndermanNPC extends EntityEnderman implements NPCHandle {
private final NPC npc;
private final CitizensNPC npc;
public EntityEndermanNPC(World world, NPC npc) {
public EntityEndermanNPC(World world, CitizensNPC npc) {
super(world);
this.npc = npc;
goalSelector = new PathfinderGoalSelector();
@ -75,6 +76,7 @@ public class CitizensEndermanNPC extends CitizensMobNPC implements Equipable {
@Override
public void e() {
npc.update();
}
@Override

View File

@ -2,6 +2,7 @@ package net.citizensnpcs.npc.entity;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.npc.CitizensMobNPC;
import net.citizensnpcs.npc.CitizensNPC;
import net.citizensnpcs.npc.CitizensNPCManager;
import net.citizensnpcs.npc.ai.NPCHandle;
import net.minecraft.server.EntityGhast;
@ -22,9 +23,9 @@ public class CitizensGhastNPC extends CitizensMobNPC {
}
public static class EntityGhastNPC extends EntityGhast implements NPCHandle {
private final NPC npc;
private final CitizensNPC npc;
public EntityGhastNPC(World world, NPC npc) {
public EntityGhastNPC(World world, CitizensNPC npc) {
super(world);
this.npc = npc;
goalSelector = new PathfinderGoalSelector();
@ -33,6 +34,7 @@ public class CitizensGhastNPC extends CitizensMobNPC {
@Override
public void d_() {
npc.update();
}
@Override

View File

@ -2,6 +2,7 @@ package net.citizensnpcs.npc.entity;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.npc.CitizensMobNPC;
import net.citizensnpcs.npc.CitizensNPC;
import net.citizensnpcs.npc.CitizensNPCManager;
import net.citizensnpcs.npc.ai.NPCHandle;
import net.minecraft.server.EntityGiantZombie;
@ -22,9 +23,9 @@ public class CitizensGiantNPC extends CitizensMobNPC {
}
public static class EntityGiantNPC extends EntityGiantZombie implements NPCHandle {
private final NPC npc;
private final CitizensNPC npc;
public EntityGiantNPC(World world, NPC npc) {
public EntityGiantNPC(World world, CitizensNPC npc) {
super(world);
this.npc = npc;
goalSelector = new PathfinderGoalSelector();
@ -33,6 +34,7 @@ public class CitizensGiantNPC extends CitizensMobNPC {
@Override
public void d_() {
npc.update();
}
@Override

View File

@ -26,7 +26,7 @@ public class CitizensHumanNPC extends CitizensNPC implements Equipable {
protected EntityLiving createHandle(Location loc) {
WorldServer ws = ((CraftWorld) loc.getWorld()).getHandle();
EntityHumanNPC handle = new EntityHumanNPC(ws.getServer().getServer(), ws,
StringHelper.parseColors(getFullName()), new ItemInWorldManager(ws));
StringHelper.parseColors(getFullName()), new ItemInWorldManager(ws), this);
handle.removeFromPlayerMap(getFullName());
handle.setPositionRotation(loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch());
return handle;

View File

@ -2,6 +2,7 @@ package net.citizensnpcs.npc.entity;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.npc.CitizensMobNPC;
import net.citizensnpcs.npc.CitizensNPC;
import net.citizensnpcs.npc.CitizensNPCManager;
import net.citizensnpcs.npc.ai.NPCHandle;
import net.minecraft.server.EntityIronGolem;
@ -22,9 +23,9 @@ public class CitizensIronGolemNPC extends CitizensMobNPC {
}
public static class EntityIronGolemNPC extends EntityIronGolem implements NPCHandle {
private final NPC npc;
private final CitizensNPC npc;
public EntityIronGolemNPC(World world, NPC npc) {
public EntityIronGolemNPC(World world, CitizensNPC npc) {
super(world);
this.npc = npc;
goalSelector = new PathfinderGoalSelector();
@ -33,6 +34,7 @@ public class CitizensIronGolemNPC extends CitizensMobNPC {
@Override
public void d_() {
npc.update();
}
@Override

View File

@ -2,6 +2,7 @@ package net.citizensnpcs.npc.entity;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.npc.CitizensMobNPC;
import net.citizensnpcs.npc.CitizensNPC;
import net.citizensnpcs.npc.CitizensNPCManager;
import net.citizensnpcs.npc.ai.NPCHandle;
import net.minecraft.server.EntityMagmaCube;
@ -22,9 +23,9 @@ public class CitizensMagmaCubeNPC extends CitizensMobNPC {
}
public static class EntityMagmaCubeNPC extends EntityMagmaCube implements NPCHandle {
private final NPC npc;
private final CitizensNPC npc;
public EntityMagmaCubeNPC(World world, NPC npc) {
public EntityMagmaCubeNPC(World world, CitizensNPC npc) {
super(world);
this.npc = npc;
setSize(3);
@ -34,6 +35,7 @@ public class CitizensMagmaCubeNPC extends CitizensMobNPC {
@Override
public void d_() {
npc.update();
}
@Override

View File

@ -2,6 +2,7 @@ package net.citizensnpcs.npc.entity;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.npc.CitizensMobNPC;
import net.citizensnpcs.npc.CitizensNPC;
import net.citizensnpcs.npc.CitizensNPCManager;
import net.citizensnpcs.npc.ai.NPCHandle;
import net.minecraft.server.EntityMushroomCow;
@ -22,9 +23,9 @@ public class CitizensMushroomCowNPC extends CitizensMobNPC {
}
public static class EntityMushroomCowNPC extends EntityMushroomCow implements NPCHandle {
private final NPC npc;
private final CitizensNPC npc;
public EntityMushroomCowNPC(World world, NPC npc) {
public EntityMushroomCowNPC(World world, CitizensNPC npc) {
super(world);
this.npc = npc;
goalSelector = new PathfinderGoalSelector();
@ -33,6 +34,7 @@ public class CitizensMushroomCowNPC extends CitizensMobNPC {
@Override
public void d_() {
npc.update();
}
@Override

View File

@ -2,6 +2,7 @@ package net.citizensnpcs.npc.entity;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.npc.CitizensMobNPC;
import net.citizensnpcs.npc.CitizensNPC;
import net.citizensnpcs.npc.CitizensNPCManager;
import net.citizensnpcs.npc.ai.NPCHandle;
import net.minecraft.server.EntityOcelot;
@ -22,9 +23,9 @@ public class CitizensOcelotNPC extends CitizensMobNPC {
}
public static class EntityOcelotNPC extends EntityOcelot implements NPCHandle {
private final NPC npc;
private final CitizensNPC npc;
public EntityOcelotNPC(World world, NPC npc) {
public EntityOcelotNPC(World world, CitizensNPC npc) {
super(world);
this.npc = npc;
goalSelector = new PathfinderGoalSelector();
@ -33,6 +34,7 @@ public class CitizensOcelotNPC extends CitizensMobNPC {
@Override
public void d_() {
npc.update();
}
@Override

View File

@ -3,6 +3,7 @@ package net.citizensnpcs.npc.entity;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.editor.Equipable;
import net.citizensnpcs.npc.CitizensMobNPC;
import net.citizensnpcs.npc.CitizensNPC;
import net.citizensnpcs.npc.CitizensNPCManager;
import net.citizensnpcs.npc.ai.NPCHandle;
import net.citizensnpcs.trait.Saddle;
@ -49,9 +50,9 @@ public class CitizensPigNPC extends CitizensMobNPC implements Equipable {
}
public static class EntityPigNPC extends EntityPig implements NPCHandle {
private final NPC npc;
private final CitizensNPC npc;
public EntityPigNPC(World world, NPC npc) {
public EntityPigNPC(World world, CitizensNPC npc) {
super(world);
this.npc = npc;
goalSelector = new PathfinderGoalSelector();
@ -64,6 +65,7 @@ public class CitizensPigNPC extends CitizensMobNPC implements Equipable {
@Override
public void d_() {
npc.update();
}
@Override

View File

@ -2,6 +2,7 @@ package net.citizensnpcs.npc.entity;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.npc.CitizensMobNPC;
import net.citizensnpcs.npc.CitizensNPC;
import net.citizensnpcs.npc.CitizensNPCManager;
import net.citizensnpcs.npc.ai.NPCHandle;
import net.minecraft.server.EntityPigZombie;
@ -22,9 +23,9 @@ public class CitizensPigZombieNPC extends CitizensMobNPC {
}
public static class EntityPigZombieNPC extends EntityPigZombie implements NPCHandle {
private final NPC npc;
private final CitizensNPC npc;
public EntityPigZombieNPC(World world, NPC npc) {
public EntityPigZombieNPC(World world, CitizensNPC npc) {
super(world);
this.npc = npc;
goalSelector = new PathfinderGoalSelector();
@ -33,6 +34,7 @@ public class CitizensPigZombieNPC extends CitizensMobNPC {
@Override
public void d_() {
npc.update();
}
@Override

View File

@ -3,6 +3,7 @@ package net.citizensnpcs.npc.entity;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.editor.Equipable;
import net.citizensnpcs.npc.CitizensMobNPC;
import net.citizensnpcs.npc.CitizensNPC;
import net.citizensnpcs.npc.CitizensNPCManager;
import net.citizensnpcs.npc.ai.NPCHandle;
import net.citizensnpcs.trait.Sheared;
@ -59,9 +60,9 @@ public class CitizensSheepNPC extends CitizensMobNPC implements Equipable {
}
public static class EntitySheepNPC extends EntitySheep implements NPCHandle {
private final NPC npc;
private final CitizensNPC npc;
public EntitySheepNPC(World world, NPC npc) {
public EntitySheepNPC(World world, CitizensNPC npc) {
super(world);
this.npc = npc;
goalSelector = new PathfinderGoalSelector();
@ -70,6 +71,7 @@ public class CitizensSheepNPC extends CitizensMobNPC implements Equipable {
@Override
public void d_() {
npc.update();
}
@Override

View File

@ -2,6 +2,7 @@ package net.citizensnpcs.npc.entity;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.npc.CitizensMobNPC;
import net.citizensnpcs.npc.CitizensNPC;
import net.citizensnpcs.npc.CitizensNPCManager;
import net.citizensnpcs.npc.ai.NPCHandle;
import net.minecraft.server.EntitySilverfish;
@ -22,9 +23,9 @@ public class CitizensSilverfishNPC extends CitizensMobNPC {
}
public static class EntitySilverfishNPC extends EntitySilverfish implements NPCHandle {
private final NPC npc;
private final CitizensNPC npc;
public EntitySilverfishNPC(World world, NPC npc) {
public EntitySilverfishNPC(World world, CitizensNPC npc) {
super(world);
this.npc = npc;
goalSelector = new PathfinderGoalSelector();
@ -33,6 +34,7 @@ public class CitizensSilverfishNPC extends CitizensMobNPC {
@Override
public void d_() {
npc.update();
}
@Override

View File

@ -2,6 +2,7 @@ package net.citizensnpcs.npc.entity;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.npc.CitizensMobNPC;
import net.citizensnpcs.npc.CitizensNPC;
import net.citizensnpcs.npc.CitizensNPCManager;
import net.citizensnpcs.npc.ai.NPCHandle;
import net.minecraft.server.EntitySkeleton;
@ -22,9 +23,9 @@ public class CitizensSkeletonNPC extends CitizensMobNPC {
}
public static class EntitySkeletonNPC extends EntitySkeleton implements NPCHandle {
private final NPC npc;
private final CitizensNPC npc;
public EntitySkeletonNPC(World world, NPC npc) {
public EntitySkeletonNPC(World world, CitizensNPC npc) {
super(world);
this.npc = npc;
goalSelector = new PathfinderGoalSelector();
@ -33,6 +34,7 @@ public class CitizensSkeletonNPC extends CitizensMobNPC {
@Override
public void d_() {
npc.update();
}
@Override

View File

@ -2,6 +2,7 @@ package net.citizensnpcs.npc.entity;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.npc.CitizensMobNPC;
import net.citizensnpcs.npc.CitizensNPC;
import net.citizensnpcs.npc.CitizensNPCManager;
import net.citizensnpcs.npc.ai.NPCHandle;
import net.minecraft.server.EntitySlime;
@ -22,9 +23,9 @@ public class CitizensSlimeNPC extends CitizensMobNPC {
}
public static class EntitySlimeNPC extends EntitySlime implements NPCHandle {
private final NPC npc;
private final CitizensNPC npc;
public EntitySlimeNPC(World world, NPC npc) {
public EntitySlimeNPC(World world, CitizensNPC npc) {
super(world);
this.npc = npc;
setSize(3);
@ -34,6 +35,7 @@ public class CitizensSlimeNPC extends CitizensMobNPC {
@Override
public void d_() {
npc.update();
}
@Override

View File

@ -2,6 +2,7 @@ package net.citizensnpcs.npc.entity;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.npc.CitizensMobNPC;
import net.citizensnpcs.npc.CitizensNPC;
import net.citizensnpcs.npc.CitizensNPCManager;
import net.citizensnpcs.npc.ai.NPCHandle;
import net.minecraft.server.EntitySnowman;
@ -22,9 +23,9 @@ public class CitizensSnowmanNPC extends CitizensMobNPC {
}
public static class EntitySnowmanNPC extends EntitySnowman implements NPCHandle {
private final NPC npc;
private final CitizensNPC npc;
public EntitySnowmanNPC(World world, NPC npc) {
public EntitySnowmanNPC(World world, CitizensNPC npc) {
super(world);
this.npc = npc;
goalSelector = new PathfinderGoalSelector();
@ -33,6 +34,7 @@ public class CitizensSnowmanNPC extends CitizensMobNPC {
@Override
public void d_() {
npc.update();
}
@Override

View File

@ -2,6 +2,7 @@ package net.citizensnpcs.npc.entity;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.npc.CitizensMobNPC;
import net.citizensnpcs.npc.CitizensNPC;
import net.citizensnpcs.npc.CitizensNPCManager;
import net.citizensnpcs.npc.ai.NPCHandle;
import net.minecraft.server.EntitySpider;
@ -22,9 +23,9 @@ public class CitizensSpiderNPC extends CitizensMobNPC {
}
public static class EntitySpiderNPC extends EntitySpider implements NPCHandle {
private final NPC npc;
private final CitizensNPC npc;
public EntitySpiderNPC(World world, NPC npc) {
public EntitySpiderNPC(World world, CitizensNPC npc) {
super(world);
this.npc = npc;
goalSelector = new PathfinderGoalSelector();
@ -33,6 +34,7 @@ public class CitizensSpiderNPC extends CitizensMobNPC {
@Override
public void d_() {
npc.update();
}
@Override

View File

@ -2,6 +2,7 @@ package net.citizensnpcs.npc.entity;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.npc.CitizensMobNPC;
import net.citizensnpcs.npc.CitizensNPC;
import net.citizensnpcs.npc.CitizensNPCManager;
import net.citizensnpcs.npc.ai.NPCHandle;
import net.minecraft.server.EntitySquid;
@ -22,9 +23,9 @@ public class CitizensSquidNPC extends CitizensMobNPC {
}
public static class EntitySquidNPC extends EntitySquid implements NPCHandle {
private final NPC npc;
private final CitizensNPC npc;
public EntitySquidNPC(World world, NPC npc) {
public EntitySquidNPC(World world, CitizensNPC npc) {
super(world);
this.npc = npc;
goalSelector = new PathfinderGoalSelector();
@ -33,6 +34,7 @@ public class CitizensSquidNPC extends CitizensMobNPC {
@Override
public void d_() {
npc.update();
}
@Override

View File

@ -2,6 +2,7 @@ package net.citizensnpcs.npc.entity;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.npc.CitizensMobNPC;
import net.citizensnpcs.npc.CitizensNPC;
import net.citizensnpcs.npc.CitizensNPCManager;
import net.citizensnpcs.npc.ai.NPCHandle;
import net.minecraft.server.EntityVillager;
@ -22,9 +23,9 @@ public class CitizensVillagerNPC extends CitizensMobNPC {
}
public static class EntityVillagerNPC extends EntityVillager implements NPCHandle {
private final NPC npc;
private final CitizensNPC npc;
public EntityVillagerNPC(World world, NPC npc) {
public EntityVillagerNPC(World world, CitizensNPC npc) {
super(world);
this.npc = npc;
goalSelector = new PathfinderGoalSelector();
@ -33,6 +34,7 @@ public class CitizensVillagerNPC extends CitizensMobNPC {
@Override
public void d_() {
npc.update();
}
@Override

View File

@ -2,6 +2,7 @@ package net.citizensnpcs.npc.entity;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.npc.CitizensMobNPC;
import net.citizensnpcs.npc.CitizensNPC;
import net.citizensnpcs.npc.CitizensNPCManager;
import net.citizensnpcs.npc.ai.NPCHandle;
import net.minecraft.server.EntityWolf;
@ -22,9 +23,9 @@ public class CitizensWolfNPC extends CitizensMobNPC {
}
public static class EntityWolfNPC extends EntityWolf implements NPCHandle {
private final NPC npc;
private final CitizensNPC npc;
public EntityWolfNPC(World world, NPC npc) {
public EntityWolfNPC(World world, CitizensNPC npc) {
super(world);
this.npc = npc;
goalSelector = new PathfinderGoalSelector();
@ -33,6 +34,7 @@ public class CitizensWolfNPC extends CitizensMobNPC {
@Override
public void d_() {
npc.update();
}
@Override

View File

@ -2,6 +2,7 @@ package net.citizensnpcs.npc.entity;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.npc.CitizensMobNPC;
import net.citizensnpcs.npc.CitizensNPC;
import net.citizensnpcs.npc.CitizensNPCManager;
import net.citizensnpcs.npc.ai.NPCHandle;
import net.minecraft.server.EntityZombie;
@ -22,9 +23,9 @@ public class CitizensZombieNPC extends CitizensMobNPC {
}
public static class EntityZombieNPC extends EntityZombie implements NPCHandle {
private final NPC npc;
private final CitizensNPC npc;
public EntityZombieNPC(World world, NPC npc) {
public EntityZombieNPC(World world, CitizensNPC npc) {
super(world);
this.npc = npc;
goalSelector = new PathfinderGoalSelector();
@ -33,6 +34,7 @@ public class CitizensZombieNPC extends CitizensMobNPC {
@Override
public void d_() {
npc.update();
}
@Override

View File

@ -4,6 +4,9 @@ import java.io.IOException;
import java.lang.reflect.Field;
import java.util.Map;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.npc.CitizensNPC;
import net.citizensnpcs.npc.ai.NPCHandle;
import net.citizensnpcs.npc.network.NPCNetHandler;
import net.citizensnpcs.npc.network.NPCNetworkManager;
import net.citizensnpcs.npc.network.NPCSocket;
@ -19,11 +22,13 @@ import org.bukkit.craftbukkit.entity.CraftEntity;
import org.bukkit.craftbukkit.entity.CraftPlayer;
@SuppressWarnings("unchecked")
public class EntityHumanNPC extends EntityPlayer {
public class EntityHumanNPC extends EntityPlayer implements NPCHandle {
private CitizensNPC npc;
public EntityHumanNPC(MinecraftServer minecraftServer, World world, String string,
ItemInWorldManager itemInWorldManager) {
ItemInWorldManager itemInWorldManager, CitizensNPC npc) {
super(minecraftServer, world, string, itemInWorldManager);
this.npc = npc;
itemInWorldManager.setGameMode(0);
NPCSocket socket = new NPCSocket();
@ -43,6 +48,12 @@ public class EntityHumanNPC extends EntityPlayer {
}
}
@Override
public void d_() {
super.d_();
npc.update();
}
@Override
public CraftPlayer getBukkitEntity() {
if (bukkitEntity == null) {
@ -91,4 +102,9 @@ public class EntityHumanNPC extends EntityPlayer {
Messaging.log("Unable to fetch player map from CraftEntity: " + ex.getMessage());
}
}
@Override
public NPC getNPC() {
return this.npc;
}
}

View File

@ -0,0 +1,44 @@
package net.citizensnpcs.trait;
import net.citizensnpcs.api.event.NPCRightClickEvent;
import net.citizensnpcs.api.exception.NPCLoadException;
import net.citizensnpcs.api.trait.Trait;
import net.citizensnpcs.api.util.DataKey;
import net.citizensnpcs.npc.CitizensNPC;
import org.bukkit.craftbukkit.entity.CraftPlayer;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
public class Controllable extends Trait implements Runnable, Listener {
private final CitizensNPC npc;
private boolean mounted;
public Controllable(CitizensNPC npc) {
this.npc = npc;
}
@EventHandler
public void onRightClick(NPCRightClickEvent event) {
if (!event.getNPC().equals(npc) || npc.getBukkitEntity().getPassenger() != null)
return;
((CraftPlayer) event.getClicker()).getHandle().setPassengerOf(npc.getHandle());
mounted = true;
}
@Override
public void run() {
if (!mounted)
return;
npc.getHandle().motX += npc.getHandle().passenger.motX;
npc.getHandle().motZ += npc.getHandle().passenger.motZ;
}
@Override
public void load(DataKey key) throws NPCLoadException {
}
@Override
public void save(DataKey key) {
}
}