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
public LivingEntity getBukkitEntity() {
if (getHandle() == null)
return null;
return (LivingEntity) getHandle().getBukkitEntity();
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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