diff --git a/src/main/java/net/citizensnpcs/EventListen.java b/src/main/java/net/citizensnpcs/EventListen.java index e957c0da1..c01710bf0 100644 --- a/src/main/java/net/citizensnpcs/EventListen.java +++ b/src/main/java/net/citizensnpcs/EventListen.java @@ -2,6 +2,9 @@ package net.citizensnpcs; import net.citizensnpcs.Settings.Setting; import net.citizensnpcs.api.CitizensAPI; +import net.citizensnpcs.api.event.NPCCombustByBlockEvent; +import net.citizensnpcs.api.event.NPCCombustByEntityEvent; +import net.citizensnpcs.api.event.NPCCombustEvent; import net.citizensnpcs.api.event.NPCDamageByBlockEvent; import net.citizensnpcs.api.event.NPCDamageByEntityEvent; import net.citizensnpcs.api.event.NPCDamageEvent; @@ -24,6 +27,9 @@ import org.bukkit.craftbukkit.entity.CraftPlayer; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; +import org.bukkit.event.entity.EntityCombustByBlockEvent; +import org.bukkit.event.entity.EntityCombustByEntityEvent; +import org.bukkit.event.entity.EntityCombustEvent; import org.bukkit.event.entity.EntityDamageByBlockEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageEvent; @@ -79,6 +85,22 @@ public class EventListen implements Listener { /* * Entity events */ + @EventHandler + public void onEntityCombust(EntityCombustEvent event) { + NPC npc = npcRegistry.getNPC(event.getEntity()); + if (npc == null) + return; + if (event instanceof EntityCombustByEntityEvent) { + Bukkit.getPluginManager().callEvent( + new NPCCombustByEntityEvent((EntityCombustByEntityEvent) event, npc)); + } else if (event instanceof EntityCombustByBlockEvent) { + Bukkit.getPluginManager().callEvent( + new NPCCombustByBlockEvent((EntityCombustByBlockEvent) event, npc)); + } else { + Bukkit.getPluginManager().callEvent(new NPCCombustEvent(event, npc)); + } + } + @EventHandler public void onEntityDamage(EntityDamageEvent event) { if (!npcRegistry.isNPC(event.getEntity())) diff --git a/src/main/java/net/citizensnpcs/npc/CitizensMobNPC.java b/src/main/java/net/citizensnpcs/npc/CitizensMobNPC.java index 76a1657f3..73f102e84 100644 --- a/src/main/java/net/citizensnpcs/npc/CitizensMobNPC.java +++ b/src/main/java/net/citizensnpcs/npc/CitizensMobNPC.java @@ -4,7 +4,7 @@ import java.lang.reflect.Constructor; import java.util.Map; import net.citizensnpcs.api.npc.NPC; -import net.citizensnpcs.util.NMSReflection; +import net.citizensnpcs.util.NMS; import net.minecraft.server.Block; import net.minecraft.server.EntityLiving; import net.minecraft.server.World; @@ -21,7 +21,7 @@ public abstract class CitizensMobNPC extends CitizensNPC { super(id, name); this.constructor = getConstructor(clazz); - NMSReflection.registerEntityClass(clazz); + NMS.registerEntityClass(clazz); } private EntityLiving createEntityFromClass(World world) { diff --git a/src/main/java/net/citizensnpcs/npc/ai/CitizensNavigator.java b/src/main/java/net/citizensnpcs/npc/ai/CitizensNavigator.java index cda162e02..d77f6f6ed 100644 --- a/src/main/java/net/citizensnpcs/npc/ai/CitizensNavigator.java +++ b/src/main/java/net/citizensnpcs/npc/ai/CitizensNavigator.java @@ -12,7 +12,7 @@ import net.citizensnpcs.api.ai.event.NavigationCompleteEvent; import net.citizensnpcs.api.ai.event.NavigationReplaceEvent; import net.citizensnpcs.api.util.DataKey; import net.citizensnpcs.npc.CitizensNPC; -import net.citizensnpcs.util.NMSReflection; +import net.citizensnpcs.util.NMS; import org.bukkit.Bukkit; import org.bukkit.Location; @@ -48,21 +48,11 @@ public class CitizensNavigator implements Navigator { @Override public NavigatorParameters getLocalParameters() { + if (localParams == defaultParams) + throw new IllegalStateException("not navigating"); return localParams; } - @Override - public float getPathfindingRange() { - return defaultParams.range(); - } - - @Override - public float getSpeed() { - if (defaultParams.speed() == UNINITIALISED_SPEED) - throw new IllegalStateException("NPC has not been spawned"); - return defaultParams.speed(); - } - @Override public Location getTargetAsLocation() { return isNavigating() ? executing.getTargetAsLocation() : null; @@ -86,7 +76,7 @@ public class CitizensNavigator implements Navigator { public void onSpawn() { if (defaultParams.speed() == UNINITIALISED_SPEED) - defaultParams.speed(NMSReflection.getSpeedFor(npc.getHandle())); + defaultParams.speed(NMS.getSpeedFor(npc.getHandle())); updatePathfindingRange(); } @@ -95,20 +85,6 @@ public class CitizensNavigator implements Navigator { root.setDouble("pathfinding-range", defaultParams.range()); } - @Override - public void setPathfindingRange(float newRange) { - defaultParams.range(newRange); - if (isNavigating()) - localParams.range(newRange); - } - - @Override - public void setSpeed(float speed) { - defaultParams.speed(speed); - if (isNavigating()) - localParams.speed(speed); - } - @Override public void setTarget(LivingEntity target, boolean aggressive) { if (!npc.isSpawned()) @@ -156,7 +132,7 @@ public class CitizensNavigator implements Navigator { } private void updatePathfindingRange() { - NMSReflection.updatePathfindingRange(npc, localParams.range()); + NMS.updatePathfindingRange(npc, localParams.range()); } private static int UNINITIALISED_SPEED = Integer.MIN_VALUE; diff --git a/src/main/java/net/citizensnpcs/npc/entity/CitizensBlazeNPC.java b/src/main/java/net/citizensnpcs/npc/entity/CitizensBlazeNPC.java index e8fe0f9ab..2bd59fd2c 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensBlazeNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensBlazeNPC.java @@ -5,7 +5,7 @@ import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.npc.CitizensMobNPC; import net.citizensnpcs.npc.CitizensNPC; import net.citizensnpcs.npc.ai.NPCHolder; -import net.citizensnpcs.util.NMSReflection; +import net.citizensnpcs.util.NMS; import net.citizensnpcs.util.Util; import net.minecraft.server.EntityBlaze; import net.minecraft.server.World; @@ -35,10 +35,17 @@ public class CitizensBlazeNPC extends CitizensMobNPC { super(world); this.npc = (CitizensNPC) npc; if (npc != null) { - NMSReflection.clearGoals(goalSelector, targetSelector); + NMS.clearGoals(goalSelector, targetSelector); } } + @Override + public void bb() { + if (npc == null) + super.bb(); + // check despawn method, we only want to despawn on chunk unload. + } + @Override public void be() { if (npc != null) diff --git a/src/main/java/net/citizensnpcs/npc/entity/CitizensCaveSpiderNPC.java b/src/main/java/net/citizensnpcs/npc/entity/CitizensCaveSpiderNPC.java index ab5e2dc4d..0d35e4121 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensCaveSpiderNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensCaveSpiderNPC.java @@ -5,7 +5,7 @@ import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.npc.CitizensMobNPC; import net.citizensnpcs.npc.CitizensNPC; import net.citizensnpcs.npc.ai.NPCHolder; -import net.citizensnpcs.util.NMSReflection; +import net.citizensnpcs.util.NMS; import net.citizensnpcs.util.Util; import net.minecraft.server.EntityCaveSpider; import net.minecraft.server.World; @@ -14,7 +14,6 @@ import org.bukkit.entity.CaveSpider; import org.bukkit.util.Vector; public class CitizensCaveSpiderNPC extends CitizensMobNPC { - public CitizensCaveSpiderNPC(int id, String name) { super(id, name, EntityCaveSpiderNPC.class); } @@ -27,14 +26,25 @@ public class CitizensCaveSpiderNPC extends CitizensMobNPC { public static class EntityCaveSpiderNPC extends EntityCaveSpider implements NPCHolder { private final CitizensNPC npc; + public EntityCaveSpiderNPC(World world) { + this(world, null); + } + public EntityCaveSpiderNPC(World world, NPC npc) { super(world); this.npc = (CitizensNPC) npc; if (npc != null) { - NMSReflection.clearGoals(goalSelector, targetSelector); + NMS.clearGoals(goalSelector, targetSelector); } } + @Override + public void bb() { + if (npc == null) + super.bb(); + // check despawn method, we only want to despawn on chunk unload. + } + @Override public void bc() { super.bc(); @@ -45,8 +55,10 @@ public class CitizensCaveSpiderNPC extends CitizensMobNPC { public void be() { if (npc == null) super.be(); - else + else { + NMS.updateAI(this); npc.update(); + } } @Override diff --git a/src/main/java/net/citizensnpcs/npc/entity/CitizensChickenNPC.java b/src/main/java/net/citizensnpcs/npc/entity/CitizensChickenNPC.java index 88d3f4c12..2aba92fe8 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensChickenNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensChickenNPC.java @@ -5,7 +5,7 @@ import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.npc.CitizensMobNPC; import net.citizensnpcs.npc.CitizensNPC; import net.citizensnpcs.npc.ai.NPCHolder; -import net.citizensnpcs.util.NMSReflection; +import net.citizensnpcs.util.NMS; import net.citizensnpcs.util.Util; import net.minecraft.server.EntityChicken; import net.minecraft.server.World; @@ -35,7 +35,7 @@ public class CitizensChickenNPC extends CitizensMobNPC { super(world); this.npc = (CitizensNPC) npc; if (npc != null) { - NMSReflection.clearGoals(goalSelector, targetSelector); + NMS.clearGoals(goalSelector, targetSelector); } } diff --git a/src/main/java/net/citizensnpcs/npc/entity/CitizensCowNPC.java b/src/main/java/net/citizensnpcs/npc/entity/CitizensCowNPC.java index 1b8d791d4..00a994e73 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensCowNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensCowNPC.java @@ -5,7 +5,7 @@ import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.npc.CitizensMobNPC; import net.citizensnpcs.npc.CitizensNPC; import net.citizensnpcs.npc.ai.NPCHolder; -import net.citizensnpcs.util.NMSReflection; +import net.citizensnpcs.util.NMS; import net.citizensnpcs.util.Util; import net.minecraft.server.EntityCow; import net.minecraft.server.World; @@ -35,7 +35,7 @@ public class CitizensCowNPC extends CitizensMobNPC { super(world); this.npc = (CitizensNPC) npc; if (npc != null) { - NMSReflection.clearGoals(goalSelector, targetSelector); + NMS.clearGoals(goalSelector, targetSelector); } } diff --git a/src/main/java/net/citizensnpcs/npc/entity/CitizensCreeperNPC.java b/src/main/java/net/citizensnpcs/npc/entity/CitizensCreeperNPC.java index 4b40e74ac..6d45131b7 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensCreeperNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensCreeperNPC.java @@ -5,7 +5,7 @@ import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.npc.CitizensMobNPC; import net.citizensnpcs.npc.CitizensNPC; import net.citizensnpcs.npc.ai.NPCHolder; -import net.citizensnpcs.util.NMSReflection; +import net.citizensnpcs.util.NMS; import net.citizensnpcs.util.Util; import net.minecraft.server.EntityCreeper; import net.minecraft.server.EntityLightning; @@ -36,7 +36,7 @@ public class CitizensCreeperNPC extends CitizensMobNPC { super(world); this.npc = (CitizensNPC) npc; if (npc != null) { - NMSReflection.clearGoals(goalSelector, targetSelector); + NMS.clearGoals(goalSelector, targetSelector); } } @@ -46,6 +46,13 @@ public class CitizensCreeperNPC extends CitizensMobNPC { super.a(entitylightning); } + @Override + public void bb() { + if (npc == null) + super.bb(); + // check despawn method, we only want to despawn on chunk unload. + } + @Override public void bc() { super.bc(); diff --git a/src/main/java/net/citizensnpcs/npc/entity/CitizensEnderDragonNPC.java b/src/main/java/net/citizensnpcs/npc/entity/CitizensEnderDragonNPC.java index 4ca77428a..015bd9e1d 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensEnderDragonNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensEnderDragonNPC.java @@ -5,7 +5,7 @@ import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.npc.CitizensMobNPC; import net.citizensnpcs.npc.CitizensNPC; import net.citizensnpcs.npc.ai.NPCHolder; -import net.citizensnpcs.util.NMSReflection; +import net.citizensnpcs.util.NMS; import net.citizensnpcs.util.Util; import net.minecraft.server.EntityEnderDragon; import net.minecraft.server.World; @@ -31,10 +31,17 @@ public class CitizensEnderDragonNPC extends CitizensMobNPC { super(world); this.npc = (CitizensNPC) npc; if (npc != null) { - NMSReflection.clearGoals(goalSelector, targetSelector); + NMS.clearGoals(goalSelector, targetSelector); } } + @Override + public void bb() { + if (npc == null) + super.bb(); + // check despawn method, we only want to despawn on chunk unload. + } + @Override public void be() { if (npc == null) @@ -80,6 +87,5 @@ public class CitizensEnderDragonNPC extends CitizensMobNPC { public NPC getNPC() { return npc; } - } } \ No newline at end of file diff --git a/src/main/java/net/citizensnpcs/npc/entity/CitizensEndermanNPC.java b/src/main/java/net/citizensnpcs/npc/entity/CitizensEndermanNPC.java index 68c039426..c7eac9323 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensEndermanNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensEndermanNPC.java @@ -8,7 +8,7 @@ import net.citizensnpcs.npc.CitizensMobNPC; import net.citizensnpcs.npc.CitizensNPC; import net.citizensnpcs.npc.ai.NPCHolder; import net.citizensnpcs.util.Messaging; -import net.citizensnpcs.util.NMSReflection; +import net.citizensnpcs.util.NMS; import net.citizensnpcs.util.Util; import net.minecraft.server.EntityEnderman; import net.minecraft.server.World; @@ -47,9 +47,9 @@ public class CitizensEndermanNPC extends CitizensMobNPC implements Equipable { ItemStack set = hand; if (set.getType() != Material.AIR) { - if (hand.getAmount() > 1) + if (hand.getAmount() > 1) { hand.setAmount(hand.getAmount() - 1); - else + } else hand = null; equipper.setItemInHand(hand); set.setAmount(1); @@ -73,15 +73,21 @@ public class CitizensEndermanNPC extends CitizensMobNPC implements Equipable { super(world); this.npc = (CitizensNPC) npc; if (npc != null) { - NMSReflection.clearGoals(goalSelector, targetSelector); + NMS.clearGoals(goalSelector, targetSelector); } } @Override - public void bc() { + public void bb() { if (npc == null) - super.bc(); - else + super.bb(); + // check despawn method, we only want to despawn on chunk unload. + } + + @Override + public void bc() { + super.bc(); + if (npc != null) npc.update(); } @@ -89,8 +95,10 @@ public class CitizensEndermanNPC extends CitizensMobNPC implements Equipable { public void be() { if (npc == null) super.be(); - else + else { + NMS.updateAI(this); npc.update(); + } } @Override @@ -105,6 +113,10 @@ public class CitizensEndermanNPC extends CitizensMobNPC implements Equipable { public void d() { if (npc == null) super.d(); + else { + NMS.updateAI(this); + npc.update(); + } } @Override diff --git a/src/main/java/net/citizensnpcs/npc/entity/CitizensGhastNPC.java b/src/main/java/net/citizensnpcs/npc/entity/CitizensGhastNPC.java index b78fdc83c..03219744a 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensGhastNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensGhastNPC.java @@ -5,7 +5,7 @@ import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.npc.CitizensMobNPC; import net.citizensnpcs.npc.CitizensNPC; import net.citizensnpcs.npc.ai.NPCHolder; -import net.citizensnpcs.util.NMSReflection; +import net.citizensnpcs.util.NMS; import net.citizensnpcs.util.Util; import net.minecraft.server.EntityGhast; import net.minecraft.server.World; @@ -35,10 +35,17 @@ public class CitizensGhastNPC extends CitizensMobNPC { super(world); this.npc = (CitizensNPC) npc; if (npc != null) { - NMSReflection.clearGoals(goalSelector, targetSelector); + NMS.clearGoals(goalSelector, targetSelector); } } + @Override + public void bb() { + if (npc == null) + super.bb(); + // check despawn method, we only want to despawn on chunk unload. + } + @Override public void be() { if (npc != null) diff --git a/src/main/java/net/citizensnpcs/npc/entity/CitizensGiantNPC.java b/src/main/java/net/citizensnpcs/npc/entity/CitizensGiantNPC.java index 9b69f12e3..267f8b77d 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensGiantNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensGiantNPC.java @@ -5,7 +5,7 @@ import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.npc.CitizensMobNPC; import net.citizensnpcs.npc.CitizensNPC; import net.citizensnpcs.npc.ai.NPCHolder; -import net.citizensnpcs.util.NMSReflection; +import net.citizensnpcs.util.NMS; import net.citizensnpcs.util.Util; import net.minecraft.server.EntityGiantZombie; import net.minecraft.server.World; @@ -31,10 +31,17 @@ public class CitizensGiantNPC extends CitizensMobNPC { super(world); this.npc = (CitizensNPC) npc; if (npc != null) { - NMSReflection.clearGoals(goalSelector, targetSelector); + NMS.clearGoals(goalSelector, targetSelector); } } + @Override + public void bb() { + if (npc == null) + super.bb(); + // check despawn method, we only want to despawn on chunk unload. + } + @Override public void be() { if (npc == null) diff --git a/src/main/java/net/citizensnpcs/npc/entity/CitizensIronGolemNPC.java b/src/main/java/net/citizensnpcs/npc/entity/CitizensIronGolemNPC.java index 91fbfb445..e382f4ccc 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensIronGolemNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensIronGolemNPC.java @@ -5,7 +5,7 @@ import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.npc.CitizensMobNPC; import net.citizensnpcs.npc.CitizensNPC; import net.citizensnpcs.npc.ai.NPCHolder; -import net.citizensnpcs.util.NMSReflection; +import net.citizensnpcs.util.NMS; import net.citizensnpcs.util.Util; import net.minecraft.server.EntityIronGolem; import net.minecraft.server.World; @@ -31,10 +31,17 @@ public class CitizensIronGolemNPC extends CitizensMobNPC { super(world); this.npc = (CitizensNPC) npc; if (npc != null) { - NMSReflection.clearGoals(goalSelector, targetSelector); + NMS.clearGoals(goalSelector, targetSelector); } } + @Override + public void bb() { + if (npc == null) + super.bb(); + // check despawn method, we only want to despawn on chunk unload. + } + @Override public void bc() { super.bc(); diff --git a/src/main/java/net/citizensnpcs/npc/entity/CitizensMagmaCubeNPC.java b/src/main/java/net/citizensnpcs/npc/entity/CitizensMagmaCubeNPC.java index c34c851b8..1c1308ea2 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensMagmaCubeNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensMagmaCubeNPC.java @@ -5,7 +5,7 @@ import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.npc.CitizensMobNPC; import net.citizensnpcs.npc.CitizensNPC; import net.citizensnpcs.npc.ai.NPCHolder; -import net.citizensnpcs.util.NMSReflection; +import net.citizensnpcs.util.NMS; import net.citizensnpcs.util.Util; import net.minecraft.server.EntityMagmaCube; import net.minecraft.server.World; @@ -36,10 +36,17 @@ public class CitizensMagmaCubeNPC extends CitizensMobNPC { this.npc = (CitizensNPC) npc; if (npc != null) { setSize(3); - NMSReflection.clearGoals(goalSelector, targetSelector); + NMS.clearGoals(goalSelector, targetSelector); } } + @Override + public void bb() { + if (npc == null) + super.bb(); + // check despawn method, we only want to despawn on chunk unload. + } + @Override public void bc() { super.bc(); @@ -49,10 +56,12 @@ public class CitizensMagmaCubeNPC extends CitizensMobNPC { @Override public void be() { - if (npc != null) - npc.update(); - else + if (npc == null) super.be(); + else { + NMS.updateAI(this); + npc.update(); + } } @Override diff --git a/src/main/java/net/citizensnpcs/npc/entity/CitizensMushroomCowNPC.java b/src/main/java/net/citizensnpcs/npc/entity/CitizensMushroomCowNPC.java index 9e3c84b7a..2d94086c0 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensMushroomCowNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensMushroomCowNPC.java @@ -5,7 +5,7 @@ import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.npc.CitizensMobNPC; import net.citizensnpcs.npc.CitizensNPC; import net.citizensnpcs.npc.ai.NPCHolder; -import net.citizensnpcs.util.NMSReflection; +import net.citizensnpcs.util.NMS; import net.citizensnpcs.util.Util; import net.minecraft.server.EntityMushroomCow; import net.minecraft.server.World; @@ -35,7 +35,7 @@ public class CitizensMushroomCowNPC extends CitizensMobNPC { super(world); this.npc = (CitizensNPC) npc; if (npc != null) { - NMSReflection.clearGoals(goalSelector, targetSelector); + NMS.clearGoals(goalSelector, targetSelector); } } diff --git a/src/main/java/net/citizensnpcs/npc/entity/CitizensOcelotNPC.java b/src/main/java/net/citizensnpcs/npc/entity/CitizensOcelotNPC.java index 0b3e4110f..ffce2349e 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensOcelotNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensOcelotNPC.java @@ -5,7 +5,7 @@ import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.npc.CitizensMobNPC; import net.citizensnpcs.npc.CitizensNPC; import net.citizensnpcs.npc.ai.NPCHolder; -import net.citizensnpcs.util.NMSReflection; +import net.citizensnpcs.util.NMS; import net.citizensnpcs.util.Util; import net.minecraft.server.EntityOcelot; import net.minecraft.server.World; @@ -35,10 +35,17 @@ public class CitizensOcelotNPC extends CitizensMobNPC { super(world); this.npc = (CitizensNPC) npc; if (npc != null) { - NMSReflection.clearGoals(goalSelector, targetSelector); + NMS.clearGoals(goalSelector, targetSelector); } } + @Override + public void bb() { + if (npc == null) + super.bb(); + // check despawn method, we only want to despawn on chunk unload. + } + @Override public void bc() { super.bc(); diff --git a/src/main/java/net/citizensnpcs/npc/entity/CitizensPigNPC.java b/src/main/java/net/citizensnpcs/npc/entity/CitizensPigNPC.java index c7a12954d..cf37ee116 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensPigNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensPigNPC.java @@ -8,7 +8,7 @@ import net.citizensnpcs.npc.CitizensNPC; import net.citizensnpcs.npc.ai.NPCHolder; import net.citizensnpcs.trait.Saddle; import net.citizensnpcs.util.Messaging; -import net.citizensnpcs.util.NMSReflection; +import net.citizensnpcs.util.NMS; import net.citizensnpcs.util.StringHelper; import net.citizensnpcs.util.Util; import net.minecraft.server.EntityLightning; @@ -62,7 +62,7 @@ public class CitizensPigNPC extends CitizensMobNPC implements Equipable { super(world); this.npc = (CitizensNPC) npc; if (npc != null) { - NMSReflection.clearGoals(goalSelector, targetSelector); + NMS.clearGoals(goalSelector, targetSelector); } } diff --git a/src/main/java/net/citizensnpcs/npc/entity/CitizensPigZombieNPC.java b/src/main/java/net/citizensnpcs/npc/entity/CitizensPigZombieNPC.java index dc46a88e3..852b1fc0a 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensPigZombieNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensPigZombieNPC.java @@ -5,7 +5,7 @@ import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.npc.CitizensMobNPC; import net.citizensnpcs.npc.CitizensNPC; import net.citizensnpcs.npc.ai.NPCHolder; -import net.citizensnpcs.util.NMSReflection; +import net.citizensnpcs.util.NMS; import net.citizensnpcs.util.Util; import net.minecraft.server.EntityPigZombie; import net.minecraft.server.World; @@ -35,10 +35,17 @@ public class CitizensPigZombieNPC extends CitizensMobNPC { super(world); this.npc = (CitizensNPC) npc; if (npc != null) { - NMSReflection.clearGoals(goalSelector, targetSelector); + NMS.clearGoals(goalSelector, targetSelector); } } + @Override + public void bb() { + if (npc == null) + super.bb(); + // check despawn method, we only want to despawn on chunk unload. + } + @Override public void bc() { super.bc(); @@ -48,10 +55,12 @@ public class CitizensPigZombieNPC extends CitizensMobNPC { @Override public void be() { - if (npc != null) - npc.update(); - else + if (npc == null) super.be(); + else { + NMS.updateAI(this); + npc.update(); + } } @Override diff --git a/src/main/java/net/citizensnpcs/npc/entity/CitizensSheepNPC.java b/src/main/java/net/citizensnpcs/npc/entity/CitizensSheepNPC.java index 2532f6de1..fcf9d4f1a 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensSheepNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensSheepNPC.java @@ -9,7 +9,7 @@ import net.citizensnpcs.npc.ai.NPCHolder; import net.citizensnpcs.trait.Sheared; import net.citizensnpcs.trait.WoolColor; import net.citizensnpcs.util.Messaging; -import net.citizensnpcs.util.NMSReflection; +import net.citizensnpcs.util.NMS; import net.citizensnpcs.util.StringHelper; import net.citizensnpcs.util.Util; import net.minecraft.server.EntitySheep; @@ -73,7 +73,7 @@ public class CitizensSheepNPC extends CitizensMobNPC implements Equipable { super(world); this.npc = (CitizensNPC) npc; if (npc != null) { - NMSReflection.clearGoals(goalSelector, targetSelector); + NMS.clearGoals(goalSelector, targetSelector); } } diff --git a/src/main/java/net/citizensnpcs/npc/entity/CitizensSilverfishNPC.java b/src/main/java/net/citizensnpcs/npc/entity/CitizensSilverfishNPC.java index ffa1f5247..f0b3cff3d 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensSilverfishNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensSilverfishNPC.java @@ -5,7 +5,7 @@ import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.npc.CitizensMobNPC; import net.citizensnpcs.npc.CitizensNPC; import net.citizensnpcs.npc.ai.NPCHolder; -import net.citizensnpcs.util.NMSReflection; +import net.citizensnpcs.util.NMS; import net.citizensnpcs.util.Util; import net.minecraft.server.EntitySilverfish; import net.minecraft.server.World; @@ -35,10 +35,17 @@ public class CitizensSilverfishNPC extends CitizensMobNPC { super(world); this.npc = (CitizensNPC) npc; if (npc != null) { - NMSReflection.clearGoals(goalSelector, targetSelector); + NMS.clearGoals(goalSelector, targetSelector); } } + @Override + public void bb() { + if (npc == null) + super.bb(); + // check despawn method, we only want to despawn on chunk unload. + } + @Override public void bc() { super.bc(); @@ -50,8 +57,10 @@ public class CitizensSilverfishNPC extends CitizensMobNPC { public void be() { if (npc == null) super.be(); - else + else { + NMS.updateAI(this); npc.update(); + } } @Override diff --git a/src/main/java/net/citizensnpcs/npc/entity/CitizensSkeletonNPC.java b/src/main/java/net/citizensnpcs/npc/entity/CitizensSkeletonNPC.java index 7fa5a2835..d11ae380f 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensSkeletonNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensSkeletonNPC.java @@ -5,7 +5,7 @@ import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.npc.CitizensMobNPC; import net.citizensnpcs.npc.CitizensNPC; import net.citizensnpcs.npc.ai.NPCHolder; -import net.citizensnpcs.util.NMSReflection; +import net.citizensnpcs.util.NMS; import net.citizensnpcs.util.Util; import net.minecraft.server.EntitySkeleton; import net.minecraft.server.World; @@ -35,10 +35,17 @@ public class CitizensSkeletonNPC extends CitizensMobNPC { super(world); this.npc = (CitizensNPC) npc; if (npc != null) { - NMSReflection.clearGoals(goalSelector, targetSelector); + NMS.clearGoals(goalSelector, targetSelector); } } + @Override + public void bb() { + if (npc == null) + super.bb(); + // check despawn method, we only want to despawn on chunk unload. + } + @Override public void bc() { super.bc(); diff --git a/src/main/java/net/citizensnpcs/npc/entity/CitizensSlimeNPC.java b/src/main/java/net/citizensnpcs/npc/entity/CitizensSlimeNPC.java index dec2c6da4..b4309a5cf 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensSlimeNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensSlimeNPC.java @@ -5,7 +5,7 @@ import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.npc.CitizensMobNPC; import net.citizensnpcs.npc.CitizensNPC; import net.citizensnpcs.npc.ai.NPCHolder; -import net.citizensnpcs.util.NMSReflection; +import net.citizensnpcs.util.NMS; import net.citizensnpcs.util.Util; import net.minecraft.server.EntitySlime; import net.minecraft.server.World; @@ -36,10 +36,17 @@ public class CitizensSlimeNPC extends CitizensMobNPC { this.npc = (CitizensNPC) npc; if (npc != null) { setSize(3); - NMSReflection.clearGoals(goalSelector, targetSelector); + NMS.clearGoals(goalSelector, targetSelector); } } + @Override + public void bb() { + if (npc == null) + super.bb(); + // check despawn method, we only want to despawn on chunk unload. + } + @Override public void bc() { super.bc(); @@ -51,8 +58,10 @@ public class CitizensSlimeNPC extends CitizensMobNPC { public void be() { if (npc == null) super.be(); - else + else { npc.update(); + NMS.updateAI(this); + } } @Override diff --git a/src/main/java/net/citizensnpcs/npc/entity/CitizensSnowmanNPC.java b/src/main/java/net/citizensnpcs/npc/entity/CitizensSnowmanNPC.java index 8a0f04bae..3b92dba97 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensSnowmanNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensSnowmanNPC.java @@ -5,7 +5,7 @@ import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.npc.CitizensMobNPC; import net.citizensnpcs.npc.CitizensNPC; import net.citizensnpcs.npc.ai.NPCHolder; -import net.citizensnpcs.util.NMSReflection; +import net.citizensnpcs.util.NMS; import net.citizensnpcs.util.Util; import net.minecraft.server.EntitySnowman; import net.minecraft.server.World; @@ -31,14 +31,22 @@ public class CitizensSnowmanNPC extends CitizensMobNPC { super(world); this.npc = (CitizensNPC) npc; if (npc != null) { - NMSReflection.clearGoals(goalSelector, targetSelector); + NMS.clearGoals(goalSelector, targetSelector); } } + @Override + public void bb() { + if (npc == null) + super.bb(); + // check despawn method, we only want to despawn on chunk unload. + } + @Override public void bc() { super.bc(); - npc.update(); + if (npc != null) + npc.update(); } @Override diff --git a/src/main/java/net/citizensnpcs/npc/entity/CitizensSpiderNPC.java b/src/main/java/net/citizensnpcs/npc/entity/CitizensSpiderNPC.java index 351c33ddd..c907c5f3e 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensSpiderNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensSpiderNPC.java @@ -5,7 +5,7 @@ import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.npc.CitizensMobNPC; import net.citizensnpcs.npc.CitizensNPC; import net.citizensnpcs.npc.ai.NPCHolder; -import net.citizensnpcs.util.NMSReflection; +import net.citizensnpcs.util.NMS; import net.citizensnpcs.util.Util; import net.minecraft.server.EntitySpider; import net.minecraft.server.World; @@ -34,10 +34,17 @@ public class CitizensSpiderNPC extends CitizensMobNPC { super(world); this.npc = (CitizensNPC) npc; if (npc != null) { - NMSReflection.clearGoals(goalSelector, targetSelector); + NMS.clearGoals(goalSelector, targetSelector); } } + @Override + public void bb() { + if (npc == null) + super.bb(); + // check despawn method, we only want to despawn on chunk unload. + } + @Override public void bc() { super.bc(); @@ -49,8 +56,10 @@ public class CitizensSpiderNPC extends CitizensMobNPC { public void be() { if (npc == null) super.be(); - else + else { + NMS.updateAI(this); npc.update(); + } } @Override diff --git a/src/main/java/net/citizensnpcs/npc/entity/CitizensSquidNPC.java b/src/main/java/net/citizensnpcs/npc/entity/CitizensSquidNPC.java index 777a5be78..374ce1f8e 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensSquidNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensSquidNPC.java @@ -5,7 +5,7 @@ import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.npc.CitizensMobNPC; import net.citizensnpcs.npc.CitizensNPC; import net.citizensnpcs.npc.ai.NPCHolder; -import net.citizensnpcs.util.NMSReflection; +import net.citizensnpcs.util.NMS; import net.citizensnpcs.util.Util; import net.minecraft.server.EntitySquid; import net.minecraft.server.World; @@ -35,10 +35,17 @@ public class CitizensSquidNPC extends CitizensMobNPC { super(world); this.npc = (CitizensNPC) npc; if (npc != null) { - NMSReflection.clearGoals(goalSelector, targetSelector); + NMS.clearGoals(goalSelector, targetSelector); } } + @Override + public void bb() { + if (npc == null) + super.bb(); + // check despawn method, we only want to despawn on chunk unload. + } + @Override public void be() { if (npc != null) diff --git a/src/main/java/net/citizensnpcs/npc/entity/CitizensVillagerNPC.java b/src/main/java/net/citizensnpcs/npc/entity/CitizensVillagerNPC.java index 2f8da6fc7..d10b9b5ab 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensVillagerNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensVillagerNPC.java @@ -5,7 +5,7 @@ import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.npc.CitizensMobNPC; import net.citizensnpcs.npc.CitizensNPC; import net.citizensnpcs.npc.ai.NPCHolder; -import net.citizensnpcs.util.NMSReflection; +import net.citizensnpcs.util.NMS; import net.citizensnpcs.util.Util; import net.minecraft.server.EntityHuman; import net.minecraft.server.EntityVillager; @@ -36,10 +36,17 @@ public class CitizensVillagerNPC extends CitizensMobNPC { super(world); this.npc = (CitizensNPC) npc; if (npc != null) { - NMSReflection.clearGoals(goalSelector, targetSelector); + NMS.clearGoals(goalSelector, targetSelector); } } + @Override + public void bb() { + if (npc == null) + super.bb(); + // check despawn method, we only want to despawn on chunk unload. + } + @Override public void bc() { super.bc(); diff --git a/src/main/java/net/citizensnpcs/npc/entity/CitizensWolfNPC.java b/src/main/java/net/citizensnpcs/npc/entity/CitizensWolfNPC.java index 43a67ad6c..456a22a75 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensWolfNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensWolfNPC.java @@ -5,7 +5,7 @@ import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.npc.CitizensMobNPC; import net.citizensnpcs.npc.CitizensNPC; import net.citizensnpcs.npc.ai.NPCHolder; -import net.citizensnpcs.util.NMSReflection; +import net.citizensnpcs.util.NMS; import net.citizensnpcs.util.Util; import net.minecraft.server.EntityWolf; import net.minecraft.server.World; @@ -35,10 +35,17 @@ public class CitizensWolfNPC extends CitizensMobNPC { super(world); this.npc = (CitizensNPC) npc; if (npc != null) { - NMSReflection.clearGoals(goalSelector, targetSelector); + NMS.clearGoals(goalSelector, targetSelector); } } + @Override + public void bb() { + if (npc == null) + super.bb(); + // check despawn method, we only want to despawn on chunk unload. + } + @Override public void bc() { super.bc(); diff --git a/src/main/java/net/citizensnpcs/npc/entity/CitizensZombieNPC.java b/src/main/java/net/citizensnpcs/npc/entity/CitizensZombieNPC.java index b18108699..e6ffc494a 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensZombieNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensZombieNPC.java @@ -5,7 +5,7 @@ import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.npc.CitizensMobNPC; import net.citizensnpcs.npc.CitizensNPC; import net.citizensnpcs.npc.ai.NPCHolder; -import net.citizensnpcs.util.NMSReflection; +import net.citizensnpcs.util.NMS; import net.citizensnpcs.util.Util; import net.minecraft.server.EntityZombie; import net.minecraft.server.World; @@ -35,10 +35,17 @@ public class CitizensZombieNPC extends CitizensMobNPC { super(world); this.npc = (CitizensNPC) npc; if (npc != null) { - NMSReflection.clearGoals(goalSelector, targetSelector); + NMS.clearGoals(goalSelector, targetSelector); } } + @Override + public void bb() { + if (npc == null) + super.bb(); + // check despawn method, we only want to despawn on chunk unload. + } + @Override public void bc() { super.bc(); diff --git a/src/main/java/net/citizensnpcs/npc/network/EmptyNetworkManager.java b/src/main/java/net/citizensnpcs/npc/network/EmptyNetworkManager.java index 2f92803e9..41f59cf34 100644 --- a/src/main/java/net/citizensnpcs/npc/network/EmptyNetworkManager.java +++ b/src/main/java/net/citizensnpcs/npc/network/EmptyNetworkManager.java @@ -3,7 +3,7 @@ package net.citizensnpcs.npc.network; import java.net.Socket; import java.security.PrivateKey; -import net.citizensnpcs.util.NMSReflection; +import net.citizensnpcs.util.NMS; import net.minecraft.server.NetHandler; import net.minecraft.server.NetworkManager; import net.minecraft.server.Packet; @@ -13,7 +13,7 @@ public class EmptyNetworkManager extends NetworkManager { public EmptyNetworkManager(Socket socket, String string, NetHandler netHandler, PrivateKey key) { super(socket, string, netHandler, key); - NMSReflection.stopNetworkThreads(this); + NMS.stopNetworkThreads(this); } @Override diff --git a/src/main/java/net/citizensnpcs/util/NMSReflection.java b/src/main/java/net/citizensnpcs/util/NMS.java similarity index 92% rename from src/main/java/net/citizensnpcs/util/NMSReflection.java rename to src/main/java/net/citizensnpcs/util/NMS.java index c5d857422..47bf2a5fa 100644 --- a/src/main/java/net/citizensnpcs/util/NMSReflection.java +++ b/src/main/java/net/citizensnpcs/util/NMS.java @@ -17,8 +17,8 @@ import org.bukkit.entity.EntityType; import com.google.common.collect.Maps; @SuppressWarnings("unchecked") -public class NMSReflection { - private NMSReflection() { +public class NMS { + private NMS() { // util class } @@ -34,11 +34,11 @@ public class NMSReflection { private static Field THREAD_STOPPER; public static void clearGoals(PathfinderGoalSelector... goalSelectors) { - if (NMSReflection.GOAL_FIELD == null || goalSelectors == null) + if (NMS.GOAL_FIELD == null || goalSelectors == null) return; for (PathfinderGoalSelector selector : goalSelectors) { try { - List list = (List) NMSReflection.GOAL_FIELD.get(selector); + List list = (List) NMS.GOAL_FIELD.get(selector); list.clear(); } catch (Exception e) { } @@ -98,6 +98,13 @@ public class NMSReflection { } } + public static void updateAI(EntityLiving entity) { + entity.getNavigation().e(); + entity.getControllerMove().c(); + entity.getControllerLook().a(); + entity.getControllerJump().b(); + } + public static void updatePathfindingRange(CitizensNPC npc, float pathfindingRange) { if (PATHFINDING_RANGE == null) return; diff --git a/src/main/java/net/citizensnpcs/util/Util.java b/src/main/java/net/citizensnpcs/util/Util.java index 5706bda0d..26c077f4a 100644 --- a/src/main/java/net/citizensnpcs/util/Util.java +++ b/src/main/java/net/citizensnpcs/util/Util.java @@ -80,7 +80,7 @@ public class Util { if (type != null) return type; for (EntityType check : EntityType.values()) { - if (check.name().matches(toMatch) || check.name().replace('_', '-').equals(toMatch)) { + if (check.name().matches(toMatch) || check.name().replace('_', '-').equalsIgnoreCase(toMatch)) { type = check; break; }