Check for null in getBukkitEntity() fix issue in Text

This commit is contained in:
fullwall 2012-08-12 14:39:44 +08:00
parent e0638f2df7
commit 6c93fad879
30 changed files with 43 additions and 29 deletions

View File

@ -50,6 +50,8 @@ public abstract class CitizensNPC extends AbstractNPC {
@Override @Override
public LivingEntity getBukkitEntity() { public LivingEntity getBukkitEntity() {
if (getHandle() == null)
return null;
return (LivingEntity) getHandle().getBukkitEntity(); return (LivingEntity) getHandle().getBukkitEntity();
} }

View File

@ -53,12 +53,12 @@ public class CitizensNavigator implements Navigator {
@Override @Override
public Location getTargetAsLocation() { public Location getTargetAsLocation() {
return executing.getTargetAsLocation(); return isNavigating() ? executing.getTargetAsLocation() : null;
} }
@Override @Override
public TargetType getTargetType() { public TargetType getTargetType() {
return executing.getTargetType(); return isNavigating() ? executing.getTargetType() : null;
} }
@Override @Override
@ -98,6 +98,10 @@ public class CitizensNavigator implements Navigator {
public void setTarget(LivingEntity target, boolean aggressive) { public void setTarget(LivingEntity target, boolean aggressive) {
if (!npc.isSpawned()) if (!npc.isSpawned())
throw new IllegalStateException("npc is not spawned"); throw new IllegalStateException("npc is not spawned");
if (target == null) {
cancelNavigation();
return;
}
PathStrategy newStrategy = new MCTargetStrategy(npc, target, aggressive, speed); PathStrategy newStrategy = new MCTargetStrategy(npc, target, aggressive, speed);
switchStrategyTo(newStrategy); switchStrategyTo(newStrategy);
} }
@ -106,6 +110,10 @@ public class CitizensNavigator implements Navigator {
public void setTarget(Location target) { public void setTarget(Location target) {
if (!npc.isSpawned()) if (!npc.isSpawned())
throw new IllegalStateException("npc is not spawned"); throw new IllegalStateException("npc is not spawned");
if (target == null) {
cancelNavigation();
return;
}
PathStrategy newStrategy = new MCNavigationStrategy(npc, target, speed); PathStrategy newStrategy = new MCNavigationStrategy(npc, target, speed);
switchStrategyTo(newStrategy); switchStrategyTo(newStrategy);
} }

View File

@ -21,7 +21,7 @@ public class CitizensBlazeNPC extends CitizensMobNPC {
@Override @Override
public Blaze getBukkitEntity() { public Blaze getBukkitEntity() {
return (Blaze) getHandle().getBukkitEntity(); return (Blaze) super.getBukkitEntity();
} }
public static class EntityBlazeNPC extends EntityBlaze implements NPCHolder { public static class EntityBlazeNPC extends EntityBlaze implements NPCHolder {

View File

@ -21,7 +21,7 @@ public class CitizensCaveSpiderNPC extends CitizensMobNPC {
@Override @Override
public CaveSpider getBukkitEntity() { public CaveSpider getBukkitEntity() {
return (CaveSpider) getHandle().getBukkitEntity(); return (CaveSpider) super.getBukkitEntity();
} }
public static class EntityCaveSpiderNPC extends EntityCaveSpider implements NPCHolder { public static class EntityCaveSpiderNPC extends EntityCaveSpider implements NPCHolder {

View File

@ -21,7 +21,7 @@ public class CitizensChickenNPC extends CitizensMobNPC {
@Override @Override
public Chicken getBukkitEntity() { public Chicken getBukkitEntity() {
return (Chicken) getHandle().getBukkitEntity(); return (Chicken) super.getBukkitEntity();
} }
public static class EntityChickenNPC extends EntityChicken implements NPCHolder { public static class EntityChickenNPC extends EntityChicken implements NPCHolder {

View File

@ -21,7 +21,7 @@ public class CitizensCowNPC extends CitizensMobNPC {
@Override @Override
public Cow getBukkitEntity() { public Cow getBukkitEntity() {
return (Cow) getHandle().getBukkitEntity(); return (Cow) super.getBukkitEntity();
} }
public static class EntityCowNPC extends EntityCow implements NPCHolder { public static class EntityCowNPC extends EntityCow implements NPCHolder {

View File

@ -22,7 +22,7 @@ public class CitizensCreeperNPC extends CitizensMobNPC {
@Override @Override
public Creeper getBukkitEntity() { public Creeper getBukkitEntity() {
return (Creeper) getHandle().getBukkitEntity(); return (Creeper) super.getBukkitEntity();
} }
public static class EntityCreeperNPC extends EntityCreeper implements NPCHolder { public static class EntityCreeperNPC extends EntityCreeper implements NPCHolder {

View File

@ -21,7 +21,7 @@ public class CitizensEnderDragonNPC extends CitizensMobNPC {
@Override @Override
public EnderDragon getBukkitEntity() { public EnderDragon getBukkitEntity() {
return (EnderDragon) getHandle().getBukkitEntity(); return (EnderDragon) super.getBukkitEntity();
} }
public static class EntityEnderDragonNPC extends EntityEnderDragon implements NPCHolder { public static class EntityEnderDragonNPC extends EntityEnderDragon implements NPCHolder {

View File

@ -59,7 +59,7 @@ public class CitizensEndermanNPC extends CitizensMobNPC implements Equipable {
@Override @Override
public Enderman getBukkitEntity() { public Enderman getBukkitEntity() {
return (Enderman) getHandle().getBukkitEntity(); return (Enderman) super.getBukkitEntity();
} }
public static class EntityEndermanNPC extends EntityEnderman implements NPCHolder { public static class EntityEndermanNPC extends EntityEnderman implements NPCHolder {

View File

@ -21,7 +21,7 @@ public class CitizensGhastNPC extends CitizensMobNPC {
@Override @Override
public Ghast getBukkitEntity() { public Ghast getBukkitEntity() {
return (Ghast) getHandle().getBukkitEntity(); return (Ghast) super.getBukkitEntity();
} }
public static class EntityGhastNPC extends EntityGhast implements NPCHolder { public static class EntityGhastNPC extends EntityGhast implements NPCHolder {

View File

@ -21,7 +21,7 @@ public class CitizensGiantNPC extends CitizensMobNPC {
@Override @Override
public Giant getBukkitEntity() { public Giant getBukkitEntity() {
return (Giant) getHandle().getBukkitEntity(); return (Giant) super.getBukkitEntity();
} }
public static class EntityGiantNPC extends EntityGiantZombie implements NPCHolder { public static class EntityGiantNPC extends EntityGiantZombie implements NPCHolder {

View File

@ -116,6 +116,8 @@ public class CitizensHumanNPC extends CitizensNPC implements Equipable {
@Override @Override
public Player getBukkitEntity() { public Player getBukkitEntity() {
if (getHandle() == null)
return null;
return getHandle().getBukkitEntity(); return getHandle().getBukkitEntity();
} }

View File

@ -21,7 +21,7 @@ public class CitizensIronGolemNPC extends CitizensMobNPC {
@Override @Override
public IronGolem getBukkitEntity() { public IronGolem getBukkitEntity() {
return (IronGolem) getHandle().getBukkitEntity(); return (IronGolem) super.getBukkitEntity();
} }
public static class EntityIronGolemNPC extends EntityIronGolem implements NPCHolder { public static class EntityIronGolemNPC extends EntityIronGolem implements NPCHolder {

View File

@ -21,7 +21,7 @@ public class CitizensMagmaCubeNPC extends CitizensMobNPC {
@Override @Override
public MagmaCube getBukkitEntity() { public MagmaCube getBukkitEntity() {
return (MagmaCube) getHandle().getBukkitEntity(); return (MagmaCube) super.getBukkitEntity();
} }
public static class EntityMagmaCubeNPC extends EntityMagmaCube implements NPCHolder { public static class EntityMagmaCubeNPC extends EntityMagmaCube implements NPCHolder {

View File

@ -21,7 +21,7 @@ public class CitizensMushroomCowNPC extends CitizensMobNPC {
@Override @Override
public MushroomCow getBukkitEntity() { public MushroomCow getBukkitEntity() {
return (MushroomCow) getHandle().getBukkitEntity(); return (MushroomCow) super.getBukkitEntity();
} }
public static class EntityMushroomCowNPC extends EntityMushroomCow implements NPCHolder { public static class EntityMushroomCowNPC extends EntityMushroomCow implements NPCHolder {

View File

@ -21,7 +21,7 @@ public class CitizensOcelotNPC extends CitizensMobNPC {
@Override @Override
public Ocelot getBukkitEntity() { public Ocelot getBukkitEntity() {
return (Ocelot) getHandle().getBukkitEntity(); return (Ocelot) super.getBukkitEntity();
} }
public static class EntityOcelotNPC extends EntityOcelot implements NPCHolder { public static class EntityOcelotNPC extends EntityOcelot implements NPCHolder {

View File

@ -48,7 +48,7 @@ public class CitizensPigNPC extends CitizensMobNPC implements Equipable {
@Override @Override
public Pig getBukkitEntity() { public Pig getBukkitEntity() {
return (Pig) getHandle().getBukkitEntity(); return (Pig) super.getBukkitEntity();
} }
public static class EntityPigNPC extends EntityPig implements NPCHolder { public static class EntityPigNPC extends EntityPig implements NPCHolder {

View File

@ -21,7 +21,7 @@ public class CitizensPigZombieNPC extends CitizensMobNPC {
@Override @Override
public PigZombie getBukkitEntity() { public PigZombie getBukkitEntity() {
return (PigZombie) getHandle().getBukkitEntity(); return (PigZombie) super.getBukkitEntity();
} }
public static class EntityPigZombieNPC extends EntityPigZombie implements NPCHolder { public static class EntityPigZombieNPC extends EntityPigZombie implements NPCHolder {

View File

@ -59,7 +59,7 @@ public class CitizensSheepNPC extends CitizensMobNPC implements Equipable {
@Override @Override
public Sheep getBukkitEntity() { public Sheep getBukkitEntity() {
return (Sheep) getHandle().getBukkitEntity(); return (Sheep) super.getBukkitEntity();
} }
public static class EntitySheepNPC extends EntitySheep implements NPCHolder { public static class EntitySheepNPC extends EntitySheep implements NPCHolder {

View File

@ -21,7 +21,7 @@ public class CitizensSilverfishNPC extends CitizensMobNPC {
@Override @Override
public Silverfish getBukkitEntity() { public Silverfish getBukkitEntity() {
return (Silverfish) getHandle().getBukkitEntity(); return (Silverfish) super.getBukkitEntity();
} }
public static class EntitySilverfishNPC extends EntitySilverfish implements NPCHolder { public static class EntitySilverfishNPC extends EntitySilverfish implements NPCHolder {

View File

@ -21,7 +21,7 @@ public class CitizensSkeletonNPC extends CitizensMobNPC {
@Override @Override
public Skeleton getBukkitEntity() { public Skeleton getBukkitEntity() {
return (Skeleton) getHandle().getBukkitEntity(); return (Skeleton) super.getBukkitEntity();
} }
public static class EntitySkeletonNPC extends EntitySkeleton implements NPCHolder { public static class EntitySkeletonNPC extends EntitySkeleton implements NPCHolder {

View File

@ -21,7 +21,7 @@ public class CitizensSlimeNPC extends CitizensMobNPC {
@Override @Override
public Slime getBukkitEntity() { public Slime getBukkitEntity() {
return (Slime) getHandle().getBukkitEntity(); return (Slime) super.getBukkitEntity();
} }
public static class EntitySlimeNPC extends EntitySlime implements NPCHolder { public static class EntitySlimeNPC extends EntitySlime implements NPCHolder {

View File

@ -21,7 +21,7 @@ public class CitizensSnowmanNPC extends CitizensMobNPC {
@Override @Override
public Snowman getBukkitEntity() { public Snowman getBukkitEntity() {
return (Snowman) getHandle().getBukkitEntity(); return (Snowman) super.getBukkitEntity();
} }
public static class EntitySnowmanNPC extends EntitySnowman implements NPCHolder { public static class EntitySnowmanNPC extends EntitySnowman implements NPCHolder {

View File

@ -20,7 +20,7 @@ public class CitizensSpiderNPC extends CitizensMobNPC {
@Override @Override
public Spider getBukkitEntity() { public Spider getBukkitEntity() {
return (Spider) getHandle().getBukkitEntity(); return (Spider) super.getBukkitEntity();
} }
public static class EntitySpiderNPC extends EntitySpider implements NPCHolder { public static class EntitySpiderNPC extends EntitySpider implements NPCHolder {

View File

@ -21,7 +21,7 @@ public class CitizensSquidNPC extends CitizensMobNPC {
@Override @Override
public Squid getBukkitEntity() { public Squid getBukkitEntity() {
return (Squid) getHandle().getBukkitEntity(); return (Squid) super.getBukkitEntity();
} }
public static class EntitySquidNPC extends EntitySquid implements NPCHolder { public static class EntitySquidNPC extends EntitySquid implements NPCHolder {

View File

@ -22,7 +22,7 @@ public class CitizensVillagerNPC extends CitizensMobNPC {
@Override @Override
public Villager getBukkitEntity() { public Villager getBukkitEntity() {
return (Villager) getHandle().getBukkitEntity(); return (Villager) super.getBukkitEntity();
} }
public static class EntityVillagerNPC extends EntityVillager implements NPCHolder { public static class EntityVillagerNPC extends EntityVillager implements NPCHolder {

View File

@ -21,7 +21,7 @@ public class CitizensWolfNPC extends CitizensMobNPC {
@Override @Override
public Wolf getBukkitEntity() { public Wolf getBukkitEntity() {
return (Wolf) getHandle().getBukkitEntity(); return (Wolf) super.getBukkitEntity();
} }
public static class EntityWolfNPC extends EntityWolf implements NPCHolder { public static class EntityWolfNPC extends EntityWolf implements NPCHolder {

View File

@ -21,7 +21,7 @@ public class CitizensZombieNPC extends CitizensMobNPC {
@Override @Override
public Zombie getBukkitEntity() { public Zombie getBukkitEntity() {
return (Zombie) getHandle().getBukkitEntity(); return (Zombie) super.getBukkitEntity();
} }
public static class EntityZombieNPC extends EntityZombie implements NPCHolder { public static class EntityZombieNPC extends EntityZombie implements NPCHolder {

View File

@ -1,6 +1,7 @@
package net.citizensnpcs.npc.entity; package net.citizensnpcs.npc.entity;
import java.io.IOException; import java.io.IOException;
import java.net.Socket;
import net.citizensnpcs.api.event.NPCPushEvent; import net.citizensnpcs.api.event.NPCPushEvent;
import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.api.npc.NPC;
@ -30,13 +31,14 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder {
this.npc = (CitizensNPC) npc; this.npc = (CitizensNPC) npc;
itemInWorldManager.setGameMode(EnumGamemode.SURVIVAL); itemInWorldManager.setGameMode(EnumGamemode.SURVIVAL);
EmptySocket socket = new EmptySocket(); Socket socket = new EmptySocket();
NetworkManager netMgr = new EmptyNetworkManager(socket, "npc mgr", new NetHandler() { NetworkManager netMgr = new EmptyNetworkManager(socket, "npc mgr", new NetHandler() {
@Override @Override
public boolean a() { public boolean a() {
return false; return false;
} }
}, server.E().getPrivate()); }, server.E().getPrivate());
netServerHandler = new EmptyNetHandler(minecraftServer, netMgr, this); netServerHandler = new EmptyNetHandler(minecraftServer, netMgr, this);
netMgr.a(netServerHandler); netMgr.a(netServerHandler);

View File

@ -63,7 +63,7 @@ public class Text extends Trait implements Runnable, Toggleable, Listener, Conve
public Editor getEditor(final Player player) { public Editor getEditor(final Player player) {
final Conversation conversation = new ConversationFactory(plugin) final Conversation conversation = new ConversationFactory(plugin)
.addConversationAbandonedListener(this).withLocalEcho(false).withEscapeSequence("npc text") .addConversationAbandonedListener(this).withLocalEcho(false).withEscapeSequence("/npc text")
.withEscapeSequence("exit").withModality(false).withFirstPrompt(new StartPrompt(this)) .withEscapeSequence("exit").withModality(false).withFirstPrompt(new StartPrompt(this))
.buildConversation(player); .buildConversation(player);
return new Editor() { return new Editor() {