This commit is contained in:
fullwall 2012-09-01 18:05:22 +08:00
parent ab3e917f37
commit 8cae31cc88
31 changed files with 272 additions and 107 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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