diff --git a/src/main/java/net/citizensnpcs/npc/ai/MCTargetStrategy.java b/src/main/java/net/citizensnpcs/npc/ai/MCTargetStrategy.java index 4c2b55068..c6b162fe4 100644 --- a/src/main/java/net/citizensnpcs/npc/ai/MCTargetStrategy.java +++ b/src/main/java/net/citizensnpcs/npc/ai/MCTargetStrategy.java @@ -11,6 +11,7 @@ import net.citizensnpcs.api.ai.event.CancelReason; import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.util.NMS; import net.citizensnpcs.util.PlayerAnimation; +import net.minecraft.server.v1_6_R1.AttributeInstance; import net.minecraft.server.v1_6_R1.Entity; import net.minecraft.server.v1_6_R1.EntityInsentient; import net.minecraft.server.v1_6_R1.EntityLiving; @@ -30,17 +31,17 @@ public class MCTargetStrategy implements PathStrategy, EntityTarget { private final EntityLiving handle; private final NPC npc; private final NavigatorParameters parameters; - private final TargetNavigator targetNavigator; private final Entity target; + private final TargetNavigator targetNavigator; public MCTargetStrategy(NPC npc, org.bukkit.entity.Entity target, boolean aggro, NavigatorParameters params) { this.npc = npc; + this.parameters = params; this.handle = ((CraftLivingEntity) npc.getBukkitEntity()).getHandle(); this.target = ((CraftEntity) target).getHandle(); this.targetNavigator = this.handle instanceof EntityInsentient ? new NavigationFieldWrapper( ((EntityInsentient) this.handle).getNavigation()) : new AStarTargeter(); this.aggro = aggro; - this.parameters = params; } private boolean canAttack() { @@ -163,7 +164,7 @@ public class MCTargetStrategy implements PathStrategy, EntityTarget { this.l = navigation.a(); try { if (NAV_E != null) - e = NAV_E.getFloat(navigation); + e = (float) ((AttributeInstance) NAV_E.get(navigation)).e(); if (NAV_J != null) j = NAV_J.getBoolean(navigation); if (NAV_M != null) diff --git a/src/main/java/net/citizensnpcs/npc/entity/BatController.java b/src/main/java/net/citizensnpcs/npc/entity/BatController.java index bac1d831a..0a03fa074 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/BatController.java +++ b/src/main/java/net/citizensnpcs/npc/entity/BatController.java @@ -67,11 +67,6 @@ public class BatController extends MobEntityController { } } - /* @Override - public float bE() { - return NMS.modifiedSpeed(super.bE(), npc); - }*/ - @Override public void collide(net.minecraft.server.v1_6_R1.Entity entity) { // this method is called by both the entities involved - cancelling diff --git a/src/main/java/net/citizensnpcs/npc/entity/BlazeController.java b/src/main/java/net/citizensnpcs/npc/entity/BlazeController.java index 80647fde2..505998e87 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/BlazeController.java +++ b/src/main/java/net/citizensnpcs/npc/entity/BlazeController.java @@ -56,11 +56,6 @@ public class BlazeController extends MobEntityController { } } - /* @Override - public float bE() { - return NMS.modifiedSpeed(super.bE(), npc); - }*/ - @Override public void bh() { if (npc != null) { diff --git a/src/main/java/net/citizensnpcs/npc/entity/CaveSpiderController.java b/src/main/java/net/citizensnpcs/npc/entity/CaveSpiderController.java index 2f75b7729..6f76953b7 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CaveSpiderController.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CaveSpiderController.java @@ -64,11 +64,6 @@ public class CaveSpiderController extends MobEntityController { npc.update(); } - /* @Override - public float bE() { - return NMS.modifiedSpeed(super.bE(), npc); - }*/ - @Override public void bh() { if (npc == null) diff --git a/src/main/java/net/citizensnpcs/npc/entity/ChickenController.java b/src/main/java/net/citizensnpcs/npc/entity/ChickenController.java index a94bdf7a4..5c83c584d 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/ChickenController.java +++ b/src/main/java/net/citizensnpcs/npc/entity/ChickenController.java @@ -56,11 +56,6 @@ public class ChickenController extends MobEntityController { } } - /* @Override - public float bE() { - return NMS.modifiedSpeed(super.bE(), npc); - }*/ - @Override public void be() { super.be(); diff --git a/src/main/java/net/citizensnpcs/npc/entity/CowController.java b/src/main/java/net/citizensnpcs/npc/entity/CowController.java index fbfc5a6bd..ab1525efc 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CowController.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CowController.java @@ -57,12 +57,6 @@ public class CowController extends MobEntityController { } } - /* @Override - public float bE() { - return NMS.modifiedSpeed(super.bE(), npc); - } - */ - @Override public void be() { super.be(); diff --git a/src/main/java/net/citizensnpcs/npc/entity/CreeperController.java b/src/main/java/net/citizensnpcs/npc/entity/CreeperController.java index dcb1d5df7..2da3a1c32 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CreeperController.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CreeperController.java @@ -64,11 +64,6 @@ public class CreeperController extends MobEntityController { super.a(entitylightning); } - /* @Override - public float bE() { - return NMS.modifiedSpeed(super.bE(), npc); - }*/ - @Override public void be() { super.be(); diff --git a/src/main/java/net/citizensnpcs/npc/entity/EnderDragonController.java b/src/main/java/net/citizensnpcs/npc/entity/EnderDragonController.java index 59f7e9f40..39536be30 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/EnderDragonController.java +++ b/src/main/java/net/citizensnpcs/npc/entity/EnderDragonController.java @@ -56,11 +56,6 @@ public class EnderDragonController extends MobEntityController { } } - /* @Override - public float bE() { - return NMS.modifiedSpeed(super.bE(), npc); - }*/ - @Override public void bh() { if (npc == null) { diff --git a/src/main/java/net/citizensnpcs/npc/entity/EndermanController.java b/src/main/java/net/citizensnpcs/npc/entity/EndermanController.java index a9b3c078d..b0a6b6a48 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/EndermanController.java +++ b/src/main/java/net/citizensnpcs/npc/entity/EndermanController.java @@ -56,11 +56,6 @@ public class EndermanController extends MobEntityController { } } - /* @Override - public float bE() { - return NMS.modifiedSpeed(super.bE(), npc); - }*/ - @Override public void be() { super.be(); diff --git a/src/main/java/net/citizensnpcs/npc/entity/EntityHumanNPC.java b/src/main/java/net/citizensnpcs/npc/entity/EntityHumanNPC.java index 0c6cb4242..acb83ce9b 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/EntityHumanNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/EntityHumanNPC.java @@ -57,11 +57,6 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder { initialise(minecraftServer); } - /* @Override - public float bE() { - return NMS.modifiedSpeed(super.bE(), npc); - }*/ - @Override public void collide(net.minecraft.server.v1_6_R1.Entity entity) { // this method is called by both the entities involved - cancelling diff --git a/src/main/java/net/citizensnpcs/npc/entity/GhastController.java b/src/main/java/net/citizensnpcs/npc/entity/GhastController.java index 896daa7e4..d4223814e 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/GhastController.java +++ b/src/main/java/net/citizensnpcs/npc/entity/GhastController.java @@ -42,11 +42,6 @@ public class GhastController extends MobEntityController { } } - /* @Override - public float bE() { - return NMS.modifiedSpeed(super.bE(), npc); - }*/ - @Override public void bh() { if (npc != null) { diff --git a/src/main/java/net/citizensnpcs/npc/entity/GiantController.java b/src/main/java/net/citizensnpcs/npc/entity/GiantController.java index 4c62dd37f..9f2e39339 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/GiantController.java +++ b/src/main/java/net/citizensnpcs/npc/entity/GiantController.java @@ -42,11 +42,6 @@ public class GiantController extends MobEntityController { } } - /* @Override - public float bE() { - return NMS.modifiedSpeed(super.bE(), npc); - }*/ - @Override public void bh() { if (npc == null) { diff --git a/src/main/java/net/citizensnpcs/npc/entity/HorseController.java b/src/main/java/net/citizensnpcs/npc/entity/HorseController.java index e4519319f..e54d20b58 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/HorseController.java +++ b/src/main/java/net/citizensnpcs/npc/entity/HorseController.java @@ -42,11 +42,6 @@ public class HorseController extends MobEntityController { } } - /*@Override - public float bE() { - return NMS.modifiedSpeed(super.bE(), npc); - }*/ - @Override public void c() { if (npc == null) { diff --git a/src/main/java/net/citizensnpcs/npc/entity/IronGolemController.java b/src/main/java/net/citizensnpcs/npc/entity/IronGolemController.java index 81bb49441..6399ce22c 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/IronGolemController.java +++ b/src/main/java/net/citizensnpcs/npc/entity/IronGolemController.java @@ -42,11 +42,6 @@ public class IronGolemController extends MobEntityController { } } - /* @Override - public float bE() { - return NMS.modifiedSpeed(super.bE(), npc); - }*/ - @Override public void be() { super.be(); diff --git a/src/main/java/net/citizensnpcs/npc/entity/MagmaCubeController.java b/src/main/java/net/citizensnpcs/npc/entity/MagmaCubeController.java index c831aa8bd..5874cced9 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/MagmaCubeController.java +++ b/src/main/java/net/citizensnpcs/npc/entity/MagmaCubeController.java @@ -43,11 +43,6 @@ public class MagmaCubeController extends MobEntityController { } } - /*@Override - public float bE() { - return NMS.modifiedSpeed(super.bE(), npc); - }*/ - @Override public void be() { super.be(); diff --git a/src/main/java/net/citizensnpcs/npc/entity/MushroomCowController.java b/src/main/java/net/citizensnpcs/npc/entity/MushroomCowController.java index c98ea543e..0a5e751e7 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/MushroomCowController.java +++ b/src/main/java/net/citizensnpcs/npc/entity/MushroomCowController.java @@ -43,11 +43,6 @@ public class MushroomCowController extends MobEntityController { } } - /* @Override - public float bE() { - return NMS.modifiedSpeed(super.bE(), npc); - }*/ - @Override public void be() { super.be(); diff --git a/src/main/java/net/citizensnpcs/npc/entity/OcelotController.java b/src/main/java/net/citizensnpcs/npc/entity/OcelotController.java index b33dc817a..a7ca5bd36 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/OcelotController.java +++ b/src/main/java/net/citizensnpcs/npc/entity/OcelotController.java @@ -43,11 +43,6 @@ public class OcelotController extends MobEntityController { } } - /* @Override - public float bE() { - return NMS.modifiedSpeed(super.bE(), npc); - }*/ - @Override public void be() { super.be(); diff --git a/src/main/java/net/citizensnpcs/npc/entity/PigController.java b/src/main/java/net/citizensnpcs/npc/entity/PigController.java index 1d04f233c..b25dd989f 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/PigController.java +++ b/src/main/java/net/citizensnpcs/npc/entity/PigController.java @@ -49,12 +49,6 @@ public class PigController extends MobEntityController { super.a(entitylightning); } - /* @Override - public float bE() { - return NMS.modifiedSpeed(super.bE(), npc); - } - */ - @Override public void be() { super.be(); diff --git a/src/main/java/net/citizensnpcs/npc/entity/PigZombieController.java b/src/main/java/net/citizensnpcs/npc/entity/PigZombieController.java index 218f05087..7fd56bd80 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/PigZombieController.java +++ b/src/main/java/net/citizensnpcs/npc/entity/PigZombieController.java @@ -43,11 +43,6 @@ public class PigZombieController extends MobEntityController { } } - /* @Override - public float bE() { - return NMS.modifiedSpeed(super.bE(), npc); - }*/ - @Override public void be() { super.be(); diff --git a/src/main/java/net/citizensnpcs/npc/entity/SheepController.java b/src/main/java/net/citizensnpcs/npc/entity/SheepController.java index 6649e8345..d0355af06 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/SheepController.java +++ b/src/main/java/net/citizensnpcs/npc/entity/SheepController.java @@ -43,11 +43,6 @@ public class SheepController extends MobEntityController { } } - /* @Override - public float bE() { - return NMS.modifiedSpeed(super.bE(), npc); - }*/ - @Override public void be() { super.be(); diff --git a/src/main/java/net/citizensnpcs/npc/entity/SilverfishController.java b/src/main/java/net/citizensnpcs/npc/entity/SilverfishController.java index 83f9502c3..e4b2d6d0c 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/SilverfishController.java +++ b/src/main/java/net/citizensnpcs/npc/entity/SilverfishController.java @@ -43,11 +43,6 @@ public class SilverfishController extends MobEntityController { } } - /* @Override - public float bE() { - return NMS.modifiedSpeed(super.bE(), npc); - }*/ - @Override public void be() { super.be(); diff --git a/src/main/java/net/citizensnpcs/npc/entity/SkeletonController.java b/src/main/java/net/citizensnpcs/npc/entity/SkeletonController.java index d0bf50862..4fc7d84ba 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/SkeletonController.java +++ b/src/main/java/net/citizensnpcs/npc/entity/SkeletonController.java @@ -42,11 +42,6 @@ public class SkeletonController extends MobEntityController { } } - /* @Override - public float bE() { - return NMS.modifiedSpeed(super.bE(), npc); - } - */ @Override public void be() { super.be(); diff --git a/src/main/java/net/citizensnpcs/npc/entity/SlimeController.java b/src/main/java/net/citizensnpcs/npc/entity/SlimeController.java index d6806c30f..0a52d2c9c 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/SlimeController.java +++ b/src/main/java/net/citizensnpcs/npc/entity/SlimeController.java @@ -44,11 +44,6 @@ public class SlimeController extends MobEntityController { } } - /*@Override - public float bE() { - return NMS.modifiedSpeed(super.bE(), npc); - }*/ - @Override public void be() { super.be(); diff --git a/src/main/java/net/citizensnpcs/npc/entity/SnowmanController.java b/src/main/java/net/citizensnpcs/npc/entity/SnowmanController.java index 08539b8bd..c7c9f9bf9 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/SnowmanController.java +++ b/src/main/java/net/citizensnpcs/npc/entity/SnowmanController.java @@ -42,11 +42,6 @@ public class SnowmanController extends MobEntityController { } } - /* @Override - public float bE() { - return NMS.modifiedSpeed(super.bE(), npc); - }*/ - @Override public void be() { super.be(); diff --git a/src/main/java/net/citizensnpcs/npc/entity/SpiderController.java b/src/main/java/net/citizensnpcs/npc/entity/SpiderController.java index 45c118624..7760f9afe 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/SpiderController.java +++ b/src/main/java/net/citizensnpcs/npc/entity/SpiderController.java @@ -42,11 +42,6 @@ public class SpiderController extends MobEntityController { } } - /* @Override - public float bE() { - return NMS.modifiedSpeed(super.bE(), npc); - }*/ - @Override public void be() { super.be(); diff --git a/src/main/java/net/citizensnpcs/npc/entity/SquidController.java b/src/main/java/net/citizensnpcs/npc/entity/SquidController.java index 358567192..9bc9ae300 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/SquidController.java +++ b/src/main/java/net/citizensnpcs/npc/entity/SquidController.java @@ -42,11 +42,6 @@ public class SquidController extends MobEntityController { } } - /* @Override - public float bE() { - return NMS.modifiedSpeed(super.bE(), npc); - }*/ - @Override public void bh() { if (npc != null) { diff --git a/src/main/java/net/citizensnpcs/npc/entity/VillagerController.java b/src/main/java/net/citizensnpcs/npc/entity/VillagerController.java index 137107bf6..12b308c85 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/VillagerController.java +++ b/src/main/java/net/citizensnpcs/npc/entity/VillagerController.java @@ -50,11 +50,6 @@ public class VillagerController extends MobEntityController { // trades } - /* @Override - public float bE() { - return NMS.modifiedSpeed(super.bE(), npc); - }*/ - @Override public void be() { super.be(); diff --git a/src/main/java/net/citizensnpcs/npc/entity/WitchController.java b/src/main/java/net/citizensnpcs/npc/entity/WitchController.java index 4694e5843..2f4bc2399 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/WitchController.java +++ b/src/main/java/net/citizensnpcs/npc/entity/WitchController.java @@ -49,11 +49,6 @@ public class WitchController extends MobEntityController { npc.update(); } - /* @Override - public float bE() { - return NMS.modifiedSpeed(super.bE(), npc); - }*/ - @Override public void collide(net.minecraft.server.v1_6_R1.Entity entity) { // this method is called by both the entities involved - cancelling diff --git a/src/main/java/net/citizensnpcs/npc/entity/WitherController.java b/src/main/java/net/citizensnpcs/npc/entity/WitherController.java index d422c2526..964ad2218 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/WitherController.java +++ b/src/main/java/net/citizensnpcs/npc/entity/WitherController.java @@ -42,11 +42,6 @@ public class WitherController extends MobEntityController { } } - /*@Override - public float bE() { - return NMS.modifiedSpeed(super.bE(), npc); - }*/ - @Override public void be() { super.be(); diff --git a/src/main/java/net/citizensnpcs/npc/entity/WolfController.java b/src/main/java/net/citizensnpcs/npc/entity/WolfController.java index 7f2c18f47..2795cf81e 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/WolfController.java +++ b/src/main/java/net/citizensnpcs/npc/entity/WolfController.java @@ -42,11 +42,6 @@ public class WolfController extends MobEntityController { } } - /* @Override - public float bE() { - return NMS.modifiedSpeed(super.bE(), npc); - }*/ - @Override public void be() { super.be(); diff --git a/src/main/java/net/citizensnpcs/npc/entity/ZombieController.java b/src/main/java/net/citizensnpcs/npc/entity/ZombieController.java index 540795c21..d0f9b9e33 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/ZombieController.java +++ b/src/main/java/net/citizensnpcs/npc/entity/ZombieController.java @@ -42,11 +42,6 @@ public class ZombieController extends MobEntityController { } } - /* @Override - public float bE() { - return NMS.modifiedSpeed(super.bE(), npc); - }*/ - @Override public void be() { super.be(); diff --git a/src/main/java/net/citizensnpcs/util/NMS.java b/src/main/java/net/citizensnpcs/util/NMS.java index 7a3fb9cd8..bc4517346 100644 --- a/src/main/java/net/citizensnpcs/util/NMS.java +++ b/src/main/java/net/citizensnpcs/util/NMS.java @@ -35,7 +35,6 @@ import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.craftbukkit.v1_6_R1.CraftServer; import org.bukkit.craftbukkit.v1_6_R1.CraftWorld; -import org.bukkit.craftbukkit.v1_6_R1.entity.CraftEntity; import org.bukkit.craftbukkit.v1_6_R1.entity.CraftLivingEntity; import org.bukkit.craftbukkit.v1_6_R1.entity.CraftPlayer; import org.bukkit.entity.EntityType; @@ -43,8 +42,6 @@ import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.plugin.PluginLoadOrder; -import com.google.common.collect.Maps; - @SuppressWarnings("unchecked") public class NMS { private NMS() { @@ -144,22 +141,9 @@ public class NMS { } public static float getSpeedFor(NPC npc) { - EntityType entityType = npc.getBukkitEntity().getType(); - Float cached = MOVEMENT_SPEEDS.get(entityType); - if (cached != null) - return cached; - if (SPEED_FIELD == null) { - MOVEMENT_SPEEDS.put(entityType, DEFAULT_SPEED); + if (!npc.isSpawned()) return DEFAULT_SPEED; - } - try { - float speed = SPEED_FIELD.getFloat(((CraftEntity) npc.getBukkitEntity()).getHandle()); - MOVEMENT_SPEEDS.put(entityType, speed); - return speed; - } catch (IllegalAccessException ex) { - ex.printStackTrace(); - return DEFAULT_SPEED; - } + return (float) NMS.getHandle(npc.getBukkitEntity()).a(GenericAttributes.d).b(); } public static boolean inWater(LivingEntity entity) { @@ -280,16 +264,6 @@ public class NMS { handle.aQ = yaw; } - public static void setLandSpeedModifier(EntityLiving handle, float speed) { - if (LAND_SPEED_MODIFIER_FIELD == null) - return; - try { - LAND_SPEED_MODIFIER_FIELD.setFloat(handle, speed); - } catch (Exception e) { - Messaging.logTr(Messages.ERROR_UPDATING_SPEED, e.getMessage()); - } - } - public static void setShouldJump(LivingEntity entity) { EntityLiving handle = getHandle(entity); if (handle instanceof EntityInsentient) { @@ -394,25 +368,19 @@ public class NMS { } private static final float DEFAULT_SPEED = 1F; - private static Map, Integer> ENTITY_CLASS_TO_INT; private static final Map, Constructor> ENTITY_CONSTRUCTOR_CACHE = new WeakHashMap, Constructor>(); private static Map> ENTITY_INT_TO_CLASS; private static Field GOAL_FIELD = getField(PathfinderGoalSelector.class, "a"); private static final Field JUMP_FIELD = getField(EntityLiving.class, "bd"); - private static Field LAND_SPEED_MODIFIER_FIELD = getField(EntityLiving.class, "bs"); - private static final Map MOVEMENT_SPEEDS = Maps.newEnumMap(EntityType.class); private static Field NAVIGATION_WORLD_FIELD = getField(Navigation.class, "b"); private static final Location PACKET_CACHE_LOCATION = new Location(null, 0, 0, 0); private static Field PATHFINDING_RANGE = getField(Navigation.class, "d"); private static final Random RANDOM = Util.getFastRandom(); - private static Field SPEED_FIELD = getField(EntityLiving.class, "bI"); private static Field THREAD_STOPPER = getField(NetworkManager.class, "n"); // true field above false and three synchronised lists static { - // TODO: speed fields are all wrong - need to use attributes - try { Field field = getField(EntityTypes.class, "d"); ENTITY_INT_TO_CLASS = (Map>) field.get(null);