From 910f806763f30da699996916774fed48887a2636 Mon Sep 17 00:00:00 2001 From: fullwall Date: Fri, 14 Dec 2012 22:07:25 +0800 Subject: [PATCH] Remove some usage of NMS, talk-item for text trait should default to the setting always and not save if unmodified --- src/main/java/net/citizensnpcs/Citizens.java | 30 +++++++-- .../java/net/citizensnpcs/EventListen.java | 3 +- .../citizensnpcs/npc/CitizensNPCRegistry.java | 7 +- .../npc/ai/AStarNavigationStrategy.java | 23 +++++-- .../npc/entity/BatController.java | 4 +- .../npc/entity/BlazeController.java | 4 +- .../npc/entity/CaveSpiderController.java | 4 +- .../npc/entity/ChickenController.java | 4 +- .../npc/entity/CowController.java | 4 +- .../npc/entity/CreeperController.java | 4 +- .../npc/entity/EnderDragonController.java | 4 +- .../npc/entity/EndermanController.java | 4 +- .../npc/entity/EntityHumanNPC.java | 12 +++- .../npc/entity/GhastController.java | 4 +- .../npc/entity/GiantController.java | 4 +- .../npc/entity/IronGolemController.java | 4 +- .../npc/entity/MagmaCubeController.java | 4 +- .../npc/entity/MushroomCowController.java | 4 +- .../npc/entity/OcelotController.java | 4 +- .../npc/entity/PigController.java | 4 +- .../npc/entity/PigZombieController.java | 4 +- .../npc/entity/SheepController.java | 4 +- .../npc/entity/SilverfishController.java | 4 +- .../npc/entity/SkeletonController.java | 4 +- .../npc/entity/SlimeController.java | 4 +- .../npc/entity/SnowmanController.java | 4 +- .../npc/entity/SpiderController.java | 4 +- .../npc/entity/SquidController.java | 4 +- .../npc/entity/VillagerController.java | 4 +- .../npc/entity/WitchController.java | 4 +- .../npc/entity/WitherController.java | 4 +- .../npc/entity/WolfController.java | 4 +- .../npc/entity/ZombieController.java | 4 +- .../net/citizensnpcs/trait/text/Text.java | 6 +- src/main/java/net/citizensnpcs/util/NMS.java | 65 +++++++++++++++---- .../citizensnpcs/util/PlayerAnimation.java | 2 +- src/main/java/net/citizensnpcs/util/Util.java | 50 +++----------- 37 files changed, 182 insertions(+), 128 deletions(-) diff --git a/src/main/java/net/citizensnpcs/Citizens.java b/src/main/java/net/citizensnpcs/Citizens.java index 7c9ddf339..1a69c3703 100644 --- a/src/main/java/net/citizensnpcs/Citizens.java +++ b/src/main/java/net/citizensnpcs/Citizens.java @@ -2,6 +2,7 @@ package net.citizensnpcs; import java.io.File; import java.io.IOException; +import java.io.InputStream; import java.util.Iterator; import net.citizensnpcs.Settings.Setting; @@ -51,6 +52,8 @@ import org.bukkit.plugin.RegisteredServiceProvider; import org.bukkit.plugin.java.JavaPlugin; import com.google.common.collect.Iterables; +import com.google.common.io.Files; +import com.google.common.io.InputSupplier; public class Citizens extends JavaPlugin implements CitizensPlugin { private final CommandManager commands = new CommandManager(); @@ -67,9 +70,9 @@ public class Citizens extends JavaPlugin implements CitizensPlugin { NPC npc = itr.next(); try { npc.despawn(); - for (Trait t : npc.getTraits()) - t.onRemove(); - } catch (Exception e) { + for (Trait trait : npc.getTraits()) + trait.onRemove(); + } catch (Throwable e) { e.printStackTrace(); // ensure that all entities are despawned } @@ -77,6 +80,23 @@ public class Citizens extends JavaPlugin implements CitizensPlugin { } } + public void test() { + getDataFolder().mkdirs(); + final InputStream dllResource = getResource("path/to/dll"); + try { + Files.copy(new InputSupplier() { + @Override + public InputStream getInput() throws IOException { + return dllResource; + } + }, new File(getDataFolder(), "name.dll")); + } catch (IOException e) { + e.printStackTrace(); + } + // code here + new File(getDataFolder(), "name.dll").delete(); + } + private void enableSubPlugins() { File root = new File(getDataFolder(), Setting.SUBPLUGIN_FOLDER.asString()); if (!root.exists() || !root.isDirectory()) @@ -137,13 +157,13 @@ public class Citizens extends JavaPlugin implements CitizensPlugin { if (!commands.hasCommand(command, modifier) && !modifier.isEmpty()) { return suggestClosestModifier(sender, command.getName(), modifier); } - + NPC npc = selector == null ? null : selector.getSelected(sender); // TODO: change the args supplied to a context style system for // flexibility (ie. adding more context in the future without // changing everything) - Object[] methodArgs = {sender, npc}; + Object[] methodArgs = { sender, npc }; return commands.executeSafe(command, args, sender, methodArgs); } diff --git a/src/main/java/net/citizensnpcs/EventListen.java b/src/main/java/net/citizensnpcs/EventListen.java index 6b9f1ec1d..3dc29c7fb 100644 --- a/src/main/java/net/citizensnpcs/EventListen.java +++ b/src/main/java/net/citizensnpcs/EventListen.java @@ -32,6 +32,7 @@ import org.bukkit.Chunk; import org.bukkit.Location; import org.bukkit.craftbukkit.v1_4_5.CraftServer; import org.bukkit.craftbukkit.v1_4_5.entity.CraftPlayer; +import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -105,7 +106,7 @@ public class EventListen implements Listener { return; if (event.getFrom().getWorld() == event.getTo().getWorld() || !npcRegistry.isNPC(event.getEntity())) return; - NMS.updateNavigationWorld(event.getEntity(), event.getTo().getWorld()); + NMS.updateNavigationWorld((LivingEntity) event.getEntity(), event.getTo().getWorld()); } /* diff --git a/src/main/java/net/citizensnpcs/npc/CitizensNPCRegistry.java b/src/main/java/net/citizensnpcs/npc/CitizensNPCRegistry.java index 8c9cc489b..7168f6157 100644 --- a/src/main/java/net/citizensnpcs/npc/CitizensNPCRegistry.java +++ b/src/main/java/net/citizensnpcs/npc/CitizensNPCRegistry.java @@ -8,10 +8,11 @@ import net.citizensnpcs.api.npc.NPCRegistry; import net.citizensnpcs.api.trait.Trait; import net.citizensnpcs.npc.ai.NPCHolder; import net.citizensnpcs.util.ByIdArray; +import net.citizensnpcs.util.NMS; -import org.bukkit.craftbukkit.v1_4_5.entity.CraftEntity; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; +import org.bukkit.entity.LivingEntity; public class CitizensNPCRegistry implements NPCRegistry { private final ByIdArray npcs = new ByIdArray(); @@ -80,7 +81,9 @@ public class CitizensNPCRegistry implements NPCRegistry { return null; if (entity instanceof NPCHolder) return ((NPCHolder) entity).getNPC(); - net.minecraft.server.v1_4_5.Entity handle = ((CraftEntity) entity).getHandle(); + if (!(entity instanceof LivingEntity)) + return null; + Object handle = NMS.getHandle((LivingEntity) entity); return handle instanceof NPCHolder ? ((NPCHolder) handle).getNPC() : null; } diff --git a/src/main/java/net/citizensnpcs/npc/ai/AStarNavigationStrategy.java b/src/main/java/net/citizensnpcs/npc/ai/AStarNavigationStrategy.java index 705480aa5..d0048360a 100644 --- a/src/main/java/net/citizensnpcs/npc/ai/AStarNavigationStrategy.java +++ b/src/main/java/net/citizensnpcs/npc/ai/AStarNavigationStrategy.java @@ -9,10 +9,14 @@ import net.citizensnpcs.api.astar.pathfinder.Path; import net.citizensnpcs.api.astar.pathfinder.VectorGoal; import net.citizensnpcs.api.astar.pathfinder.VectorNode; import net.citizensnpcs.api.npc.NPC; +import net.citizensnpcs.util.Messaging; import net.citizensnpcs.util.NMS; +import net.minecraft.server.v1_4_5.EntityLiving; import org.bukkit.Effect; import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.World; import org.bukkit.util.Vector; public class AStarNavigationStrategy extends AbstractPathStrategy { @@ -57,15 +61,24 @@ public class AStarNavigationStrategy extends AbstractPathStrategy { if (plan.isComplete()) return true; vector = plan.getCurrentVector(); - npc.getBukkitEntity() - .getWorld() - .playEffect(vector.toLocation(npc.getBukkitEntity().getWorld()), Effect.STEP_SOUND, - org.bukkit.Material.STONE.getId()); + World world = npc.getBukkitEntity().getWorld(); + world.playEffect(vector.toLocation(world), Effect.STEP_SOUND, Material.STONE.getId()); } + EntityLiving handle = NMS.getHandle(npc.getBukkitEntity()); + double dX = vector.getBlockX() - handle.locX; + double dZ = vector.getBlockZ() - handle.locZ; + double dY = vector.getY() - Math.floor(handle.boundingBox.b + 0.5D); + double dXdZ = dX * dX + dZ * dZ; + double distance = dXdZ + dY * dY; + + if (distance >= 0.00001 && (dY > 0 && dXdZ <= 2.75)) + NMS.setShouldJump(npc.getBukkitEntity()); + else + Messaging.log(distance >= 0.0001, dY > 0, dXdZ < 1, dXdZ); NMS.setDestination(npc.getBukkitEntity(), vector.getX(), vector.getY(), vector.getZ(), params.speed()); return false; } - private static final AStarMachine ASTAR = AStarMachine.createWithDefaultStorage(); + private static final AStarMachine ASTAR = AStarMachine.createWithDefaultStorage(); private static final Location NPC_LOCATION = new Location(null, 0, 0, 0); } \ No newline at end of file diff --git a/src/main/java/net/citizensnpcs/npc/entity/BatController.java b/src/main/java/net/citizensnpcs/npc/entity/BatController.java index 535941b95..31c9e403c 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/BatController.java +++ b/src/main/java/net/citizensnpcs/npc/entity/BatController.java @@ -2,8 +2,8 @@ package net.citizensnpcs.npc.entity; import net.citizensnpcs.api.event.NPCPushEvent; import net.citizensnpcs.api.npc.NPC; -import net.citizensnpcs.npc.MobEntityController; import net.citizensnpcs.npc.CitizensNPC; +import net.citizensnpcs.npc.MobEntityController; import net.citizensnpcs.npc.ai.NPCHolder; import net.citizensnpcs.util.NMS; import net.citizensnpcs.util.Util; @@ -73,7 +73,7 @@ public class BatController extends MobEntityController { // it will not stop the NPC from moving. super.collide(entity); if (npc != null) - Util.callCollisionEvent(npc, entity); + Util.callCollisionEvent(npc, entity.getBukkitEntity()); } @Override diff --git a/src/main/java/net/citizensnpcs/npc/entity/BlazeController.java b/src/main/java/net/citizensnpcs/npc/entity/BlazeController.java index 9a5fac144..d7c9cdaa8 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/BlazeController.java +++ b/src/main/java/net/citizensnpcs/npc/entity/BlazeController.java @@ -2,8 +2,8 @@ package net.citizensnpcs.npc.entity; import net.citizensnpcs.api.event.NPCPushEvent; import net.citizensnpcs.api.npc.NPC; -import net.citizensnpcs.npc.MobEntityController; import net.citizensnpcs.npc.CitizensNPC; +import net.citizensnpcs.npc.MobEntityController; import net.citizensnpcs.npc.ai.NPCHolder; import net.citizensnpcs.util.NMS; import net.citizensnpcs.util.Util; @@ -71,7 +71,7 @@ public class BlazeController extends MobEntityController { // it will not stop the NPC from moving. super.collide(entity); if (npc != null) - Util.callCollisionEvent(npc, entity); + Util.callCollisionEvent(npc, entity.getBukkitEntity()); } @Override diff --git a/src/main/java/net/citizensnpcs/npc/entity/CaveSpiderController.java b/src/main/java/net/citizensnpcs/npc/entity/CaveSpiderController.java index 9cd81b98b..e6610b879 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CaveSpiderController.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CaveSpiderController.java @@ -2,8 +2,8 @@ package net.citizensnpcs.npc.entity; import net.citizensnpcs.api.event.NPCPushEvent; import net.citizensnpcs.api.npc.NPC; -import net.citizensnpcs.npc.MobEntityController; import net.citizensnpcs.npc.CitizensNPC; +import net.citizensnpcs.npc.MobEntityController; import net.citizensnpcs.npc.ai.NPCHolder; import net.citizensnpcs.util.NMS; import net.citizensnpcs.util.Util; @@ -80,7 +80,7 @@ public class CaveSpiderController extends MobEntityController { // it will not stop the NPC from moving. super.collide(entity); if (npc != null) - Util.callCollisionEvent(npc, entity); + Util.callCollisionEvent(npc, entity.getBukkitEntity()); } @Override diff --git a/src/main/java/net/citizensnpcs/npc/entity/ChickenController.java b/src/main/java/net/citizensnpcs/npc/entity/ChickenController.java index 085c6624a..b4dbfba2a 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/ChickenController.java +++ b/src/main/java/net/citizensnpcs/npc/entity/ChickenController.java @@ -2,8 +2,8 @@ package net.citizensnpcs.npc.entity; import net.citizensnpcs.api.event.NPCPushEvent; import net.citizensnpcs.api.npc.NPC; -import net.citizensnpcs.npc.MobEntityController; import net.citizensnpcs.npc.CitizensNPC; +import net.citizensnpcs.npc.MobEntityController; import net.citizensnpcs.npc.ai.NPCHolder; import net.citizensnpcs.util.NMS; import net.citizensnpcs.util.Util; @@ -70,7 +70,7 @@ public class ChickenController extends MobEntityController { // it will not stop the NPC from moving. super.collide(entity); if (npc != null) - Util.callCollisionEvent(npc, entity); + Util.callCollisionEvent(npc, entity.getBukkitEntity()); } @Override diff --git a/src/main/java/net/citizensnpcs/npc/entity/CowController.java b/src/main/java/net/citizensnpcs/npc/entity/CowController.java index 0c9793372..ca8a6bf89 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CowController.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CowController.java @@ -2,8 +2,8 @@ package net.citizensnpcs.npc.entity; import net.citizensnpcs.api.event.NPCPushEvent; import net.citizensnpcs.api.npc.NPC; -import net.citizensnpcs.npc.MobEntityController; import net.citizensnpcs.npc.CitizensNPC; +import net.citizensnpcs.npc.MobEntityController; import net.citizensnpcs.npc.ai.NPCHolder; import net.citizensnpcs.util.NMS; import net.citizensnpcs.util.Util; @@ -70,7 +70,7 @@ public class CowController extends MobEntityController { // it will not stop the NPC from moving. super.collide(entity); if (npc != null) - Util.callCollisionEvent(npc, entity); + Util.callCollisionEvent(npc, entity.getBukkitEntity()); } @Override diff --git a/src/main/java/net/citizensnpcs/npc/entity/CreeperController.java b/src/main/java/net/citizensnpcs/npc/entity/CreeperController.java index 6056f5cfc..4c409dcdf 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CreeperController.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CreeperController.java @@ -2,8 +2,8 @@ package net.citizensnpcs.npc.entity; import net.citizensnpcs.api.event.NPCPushEvent; import net.citizensnpcs.api.npc.NPC; -import net.citizensnpcs.npc.MobEntityController; import net.citizensnpcs.npc.CitizensNPC; +import net.citizensnpcs.npc.MobEntityController; import net.citizensnpcs.npc.ai.NPCHolder; import net.citizensnpcs.util.NMS; import net.citizensnpcs.util.Util; @@ -77,7 +77,7 @@ public class CreeperController extends MobEntityController { // it will not stop the NPC from moving. super.collide(entity); if (npc != null) - Util.callCollisionEvent(npc, entity); + Util.callCollisionEvent(npc, entity.getBukkitEntity()); } @Override diff --git a/src/main/java/net/citizensnpcs/npc/entity/EnderDragonController.java b/src/main/java/net/citizensnpcs/npc/entity/EnderDragonController.java index 73a607bb2..46e02bd98 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/EnderDragonController.java +++ b/src/main/java/net/citizensnpcs/npc/entity/EnderDragonController.java @@ -2,8 +2,8 @@ package net.citizensnpcs.npc.entity; import net.citizensnpcs.api.event.NPCPushEvent; import net.citizensnpcs.api.npc.NPC; -import net.citizensnpcs.npc.MobEntityController; import net.citizensnpcs.npc.CitizensNPC; +import net.citizensnpcs.npc.MobEntityController; import net.citizensnpcs.npc.ai.NPCHolder; import net.citizensnpcs.util.NMS; import net.citizensnpcs.util.Util; @@ -77,7 +77,7 @@ public class EnderDragonController extends MobEntityController { // it will not stop the NPC from moving. super.collide(entity); if (npc != null) - Util.callCollisionEvent(npc, entity); + Util.callCollisionEvent(npc, entity.getBukkitEntity()); } @Override diff --git a/src/main/java/net/citizensnpcs/npc/entity/EndermanController.java b/src/main/java/net/citizensnpcs/npc/entity/EndermanController.java index f765a4c73..7abde443a 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/EndermanController.java +++ b/src/main/java/net/citizensnpcs/npc/entity/EndermanController.java @@ -2,8 +2,8 @@ package net.citizensnpcs.npc.entity; import net.citizensnpcs.api.event.NPCPushEvent; import net.citizensnpcs.api.npc.NPC; -import net.citizensnpcs.npc.MobEntityController; import net.citizensnpcs.npc.CitizensNPC; +import net.citizensnpcs.npc.MobEntityController; import net.citizensnpcs.npc.ai.NPCHolder; import net.citizensnpcs.util.NMS; import net.citizensnpcs.util.Util; @@ -90,7 +90,7 @@ public class EndermanController extends MobEntityController { // it will not stop the NPC from moving. super.collide(entity); if (npc != null) - Util.callCollisionEvent(npc, entity); + Util.callCollisionEvent(npc, entity.getBukkitEntity()); } @Override diff --git a/src/main/java/net/citizensnpcs/npc/entity/EntityHumanNPC.java b/src/main/java/net/citizensnpcs/npc/entity/EntityHumanNPC.java index 92a1b2ca2..621ee7d0c 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/EntityHumanNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/EntityHumanNPC.java @@ -16,10 +16,12 @@ import net.citizensnpcs.util.Util; import net.minecraft.server.v1_4_5.EntityPlayer; import net.minecraft.server.v1_4_5.EnumGamemode; import net.minecraft.server.v1_4_5.ItemInWorldManager; +import net.minecraft.server.v1_4_5.MathHelper; import net.minecraft.server.v1_4_5.MinecraftServer; import net.minecraft.server.v1_4_5.Navigation; import net.minecraft.server.v1_4_5.NetHandler; import net.minecraft.server.v1_4_5.NetworkManager; +import net.minecraft.server.v1_4_5.Packet32EntityLook; import net.minecraft.server.v1_4_5.Packet5EntityEquipment; import net.minecraft.server.v1_4_5.World; @@ -56,7 +58,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder { // it will not stop the NPC from moving. super.collide(entity); if (npc != null) - Util.callCollisionEvent(npc, entity); + Util.callCollisionEvent(npc, entity.getBukkitEntity()); } @Override @@ -127,13 +129,17 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder { return; if (getBukkitEntity() != null && Util.isLoaded(getBukkitEntity().getLocation(LOADED_LOCATION))) { - if (!npc.getNavigator().isNavigating() && !NMS.inWater(this)) + if (!npc.getNavigator().isNavigating() && !NMS.inWater(getBukkitEntity())) move(0, -0.2, 0); // gravity. also works around an entity.onGround not updating issue // (onGround is normally updated by the client) } updateEquipment(); + NMS.sendPacketNearby( + getBukkitEntity().getLocation(), + new Packet32EntityLook(id, (byte) MathHelper.d(yaw * 256.0F / 360.0F), (byte) MathHelper + .d(pitch * 256.0F / 360.0F))); if (Math.abs(motX) < EPSILON && Math.abs(motY) < EPSILON && Math.abs(motZ) < EPSILON) motX = motY = motZ = 0; @@ -183,7 +189,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder { net.minecraft.server.v1_4_5.ItemStack previous = previousEquipment[i]; net.minecraft.server.v1_4_5.ItemStack current = getEquipment(i); if (previous != current) { - Util.sendPacketNearby(getBukkitEntity().getLocation(), new Packet5EntityEquipment(id, i, + NMS.sendPacketNearby(getBukkitEntity().getLocation(), new Packet5EntityEquipment(id, i, current)); previousEquipment[i] = current; } diff --git a/src/main/java/net/citizensnpcs/npc/entity/GhastController.java b/src/main/java/net/citizensnpcs/npc/entity/GhastController.java index 04892c593..a7c849f99 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/GhastController.java +++ b/src/main/java/net/citizensnpcs/npc/entity/GhastController.java @@ -2,8 +2,8 @@ package net.citizensnpcs.npc.entity; import net.citizensnpcs.api.event.NPCPushEvent; import net.citizensnpcs.api.npc.NPC; -import net.citizensnpcs.npc.MobEntityController; import net.citizensnpcs.npc.CitizensNPC; +import net.citizensnpcs.npc.MobEntityController; import net.citizensnpcs.npc.ai.NPCHolder; import net.citizensnpcs.util.NMS; import net.citizensnpcs.util.Util; @@ -57,7 +57,7 @@ public class GhastController extends MobEntityController { // it will not stop the NPC from moving. super.collide(entity); if (npc != null) - Util.callCollisionEvent(npc, entity); + Util.callCollisionEvent(npc, entity.getBukkitEntity()); } @Override diff --git a/src/main/java/net/citizensnpcs/npc/entity/GiantController.java b/src/main/java/net/citizensnpcs/npc/entity/GiantController.java index 18e3cfc70..0266beed9 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/GiantController.java +++ b/src/main/java/net/citizensnpcs/npc/entity/GiantController.java @@ -2,8 +2,8 @@ package net.citizensnpcs.npc.entity; import net.citizensnpcs.api.event.NPCPushEvent; import net.citizensnpcs.api.npc.NPC; -import net.citizensnpcs.npc.MobEntityController; import net.citizensnpcs.npc.CitizensNPC; +import net.citizensnpcs.npc.MobEntityController; import net.citizensnpcs.npc.ai.NPCHolder; import net.citizensnpcs.util.NMS; import net.citizensnpcs.util.Util; @@ -57,7 +57,7 @@ public class GiantController extends MobEntityController { // it will not stop the NPC from moving. super.collide(entity); if (npc != null) - Util.callCollisionEvent(npc, entity); + Util.callCollisionEvent(npc, entity.getBukkitEntity()); } @Override diff --git a/src/main/java/net/citizensnpcs/npc/entity/IronGolemController.java b/src/main/java/net/citizensnpcs/npc/entity/IronGolemController.java index f0c68abb7..fcfcb00fc 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/IronGolemController.java +++ b/src/main/java/net/citizensnpcs/npc/entity/IronGolemController.java @@ -2,8 +2,8 @@ package net.citizensnpcs.npc.entity; import net.citizensnpcs.api.event.NPCPushEvent; import net.citizensnpcs.api.npc.NPC; -import net.citizensnpcs.npc.MobEntityController; import net.citizensnpcs.npc.CitizensNPC; +import net.citizensnpcs.npc.MobEntityController; import net.citizensnpcs.npc.ai.NPCHolder; import net.citizensnpcs.util.NMS; import net.citizensnpcs.util.Util; @@ -55,7 +55,7 @@ public class IronGolemController extends MobEntityController { // it will not stop the NPC from moving. super.collide(entity); if (npc != null) - Util.callCollisionEvent(npc, entity); + Util.callCollisionEvent(npc, entity.getBukkitEntity()); } @Override diff --git a/src/main/java/net/citizensnpcs/npc/entity/MagmaCubeController.java b/src/main/java/net/citizensnpcs/npc/entity/MagmaCubeController.java index bfc1f3779..bcb20c9ab 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/MagmaCubeController.java +++ b/src/main/java/net/citizensnpcs/npc/entity/MagmaCubeController.java @@ -2,8 +2,8 @@ package net.citizensnpcs.npc.entity; import net.citizensnpcs.api.event.NPCPushEvent; import net.citizensnpcs.api.npc.NPC; -import net.citizensnpcs.npc.MobEntityController; import net.citizensnpcs.npc.CitizensNPC; +import net.citizensnpcs.npc.MobEntityController; import net.citizensnpcs.npc.ai.NPCHolder; import net.citizensnpcs.util.NMS; import net.citizensnpcs.util.Util; @@ -67,7 +67,7 @@ public class MagmaCubeController extends MobEntityController { // it will not stop the NPC from moving. super.collide(entity); if (npc != null) - Util.callCollisionEvent(npc, entity); + Util.callCollisionEvent(npc, entity.getBukkitEntity()); } @Override diff --git a/src/main/java/net/citizensnpcs/npc/entity/MushroomCowController.java b/src/main/java/net/citizensnpcs/npc/entity/MushroomCowController.java index bb003db91..e2fb9d721 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/MushroomCowController.java +++ b/src/main/java/net/citizensnpcs/npc/entity/MushroomCowController.java @@ -2,8 +2,8 @@ package net.citizensnpcs.npc.entity; import net.citizensnpcs.api.event.NPCPushEvent; import net.citizensnpcs.api.npc.NPC; -import net.citizensnpcs.npc.MobEntityController; import net.citizensnpcs.npc.CitizensNPC; +import net.citizensnpcs.npc.MobEntityController; import net.citizensnpcs.npc.ai.NPCHolder; import net.citizensnpcs.util.NMS; import net.citizensnpcs.util.Util; @@ -57,7 +57,7 @@ public class MushroomCowController extends MobEntityController { // it will not stop the NPC from moving. super.collide(entity); if (npc != null) - Util.callCollisionEvent(npc, entity); + Util.callCollisionEvent(npc, entity.getBukkitEntity()); } @Override diff --git a/src/main/java/net/citizensnpcs/npc/entity/OcelotController.java b/src/main/java/net/citizensnpcs/npc/entity/OcelotController.java index 69ab4c9fc..f4107ee6e 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/OcelotController.java +++ b/src/main/java/net/citizensnpcs/npc/entity/OcelotController.java @@ -2,8 +2,8 @@ package net.citizensnpcs.npc.entity; import net.citizensnpcs.api.event.NPCPushEvent; import net.citizensnpcs.api.npc.NPC; -import net.citizensnpcs.npc.MobEntityController; import net.citizensnpcs.npc.CitizensNPC; +import net.citizensnpcs.npc.MobEntityController; import net.citizensnpcs.npc.ai.NPCHolder; import net.citizensnpcs.util.NMS; import net.citizensnpcs.util.Util; @@ -56,7 +56,7 @@ public class OcelotController extends MobEntityController { // it will not stop the NPC from moving. super.collide(entity); if (npc != null) - Util.callCollisionEvent(npc, entity); + Util.callCollisionEvent(npc, entity.getBukkitEntity()); } @Override diff --git a/src/main/java/net/citizensnpcs/npc/entity/PigController.java b/src/main/java/net/citizensnpcs/npc/entity/PigController.java index 254a98052..42f8687e1 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/PigController.java +++ b/src/main/java/net/citizensnpcs/npc/entity/PigController.java @@ -2,8 +2,8 @@ package net.citizensnpcs.npc.entity; import net.citizensnpcs.api.event.NPCPushEvent; import net.citizensnpcs.api.npc.NPC; -import net.citizensnpcs.npc.MobEntityController; import net.citizensnpcs.npc.CitizensNPC; +import net.citizensnpcs.npc.MobEntityController; import net.citizensnpcs.npc.ai.NPCHolder; import net.citizensnpcs.util.NMS; import net.citizensnpcs.util.Util; @@ -63,7 +63,7 @@ public class PigController extends MobEntityController { // it will not stop the NPC from moving. super.collide(entity); if (npc != null) - Util.callCollisionEvent(npc, entity); + Util.callCollisionEvent(npc, entity.getBukkitEntity()); } @Override diff --git a/src/main/java/net/citizensnpcs/npc/entity/PigZombieController.java b/src/main/java/net/citizensnpcs/npc/entity/PigZombieController.java index 8c62f371a..06325e328 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/PigZombieController.java +++ b/src/main/java/net/citizensnpcs/npc/entity/PigZombieController.java @@ -2,8 +2,8 @@ package net.citizensnpcs.npc.entity; import net.citizensnpcs.api.event.NPCPushEvent; import net.citizensnpcs.api.npc.NPC; -import net.citizensnpcs.npc.MobEntityController; import net.citizensnpcs.npc.CitizensNPC; +import net.citizensnpcs.npc.MobEntityController; import net.citizensnpcs.npc.ai.NPCHolder; import net.citizensnpcs.util.NMS; import net.citizensnpcs.util.Util; @@ -67,7 +67,7 @@ public class PigZombieController extends MobEntityController { // it will not stop the NPC from moving. super.collide(entity); if (npc != null) - Util.callCollisionEvent(npc, entity); + Util.callCollisionEvent(npc, entity.getBukkitEntity()); } @Override diff --git a/src/main/java/net/citizensnpcs/npc/entity/SheepController.java b/src/main/java/net/citizensnpcs/npc/entity/SheepController.java index de20f4ff7..1f62f9a64 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/SheepController.java +++ b/src/main/java/net/citizensnpcs/npc/entity/SheepController.java @@ -2,8 +2,8 @@ package net.citizensnpcs.npc.entity; import net.citizensnpcs.api.event.NPCPushEvent; import net.citizensnpcs.api.npc.NPC; -import net.citizensnpcs.npc.MobEntityController; import net.citizensnpcs.npc.CitizensNPC; +import net.citizensnpcs.npc.MobEntityController; import net.citizensnpcs.npc.ai.NPCHolder; import net.citizensnpcs.util.NMS; import net.citizensnpcs.util.Util; @@ -56,7 +56,7 @@ public class SheepController extends MobEntityController { // it will not stop the NPC from moving. super.collide(entity); if (npc != null) - Util.callCollisionEvent(npc, entity); + Util.callCollisionEvent(npc, entity.getBukkitEntity()); } @Override diff --git a/src/main/java/net/citizensnpcs/npc/entity/SilverfishController.java b/src/main/java/net/citizensnpcs/npc/entity/SilverfishController.java index 07b0343eb..beeff5b51 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/SilverfishController.java +++ b/src/main/java/net/citizensnpcs/npc/entity/SilverfishController.java @@ -2,8 +2,8 @@ package net.citizensnpcs.npc.entity; import net.citizensnpcs.api.event.NPCPushEvent; import net.citizensnpcs.api.npc.NPC; -import net.citizensnpcs.npc.MobEntityController; import net.citizensnpcs.npc.CitizensNPC; +import net.citizensnpcs.npc.MobEntityController; import net.citizensnpcs.npc.ai.NPCHolder; import net.citizensnpcs.util.NMS; import net.citizensnpcs.util.Util; @@ -66,7 +66,7 @@ public class SilverfishController extends MobEntityController { // it will not stop the NPC from moving. super.collide(entity); if (npc != null) - Util.callCollisionEvent(npc, entity); + Util.callCollisionEvent(npc, entity.getBukkitEntity()); } @Override diff --git a/src/main/java/net/citizensnpcs/npc/entity/SkeletonController.java b/src/main/java/net/citizensnpcs/npc/entity/SkeletonController.java index db08cb6c9..b605f53f3 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/SkeletonController.java +++ b/src/main/java/net/citizensnpcs/npc/entity/SkeletonController.java @@ -2,8 +2,8 @@ package net.citizensnpcs.npc.entity; import net.citizensnpcs.api.event.NPCPushEvent; import net.citizensnpcs.api.npc.NPC; -import net.citizensnpcs.npc.MobEntityController; import net.citizensnpcs.npc.CitizensNPC; +import net.citizensnpcs.npc.MobEntityController; import net.citizensnpcs.npc.ai.NPCHolder; import net.citizensnpcs.util.NMS; import net.citizensnpcs.util.Util; @@ -56,7 +56,7 @@ public class SkeletonController extends MobEntityController { // it will not stop the NPC from moving. super.collide(entity); if (npc != null) - Util.callCollisionEvent(npc, entity); + Util.callCollisionEvent(npc, entity.getBukkitEntity()); } @Override diff --git a/src/main/java/net/citizensnpcs/npc/entity/SlimeController.java b/src/main/java/net/citizensnpcs/npc/entity/SlimeController.java index 9e2d259f4..0e3c05d0c 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/SlimeController.java +++ b/src/main/java/net/citizensnpcs/npc/entity/SlimeController.java @@ -2,8 +2,8 @@ package net.citizensnpcs.npc.entity; import net.citizensnpcs.api.event.NPCPushEvent; import net.citizensnpcs.api.npc.NPC; -import net.citizensnpcs.npc.MobEntityController; import net.citizensnpcs.npc.CitizensNPC; +import net.citizensnpcs.npc.MobEntityController; import net.citizensnpcs.npc.ai.NPCHolder; import net.citizensnpcs.util.NMS; import net.citizensnpcs.util.Util; @@ -68,7 +68,7 @@ public class SlimeController extends MobEntityController { // it will not stop the NPC from moving. super.collide(entity); if (npc != null) - Util.callCollisionEvent(npc, entity); + Util.callCollisionEvent(npc, entity.getBukkitEntity()); } @Override diff --git a/src/main/java/net/citizensnpcs/npc/entity/SnowmanController.java b/src/main/java/net/citizensnpcs/npc/entity/SnowmanController.java index 4bcf2d9dc..f69cb0c66 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/SnowmanController.java +++ b/src/main/java/net/citizensnpcs/npc/entity/SnowmanController.java @@ -2,8 +2,8 @@ package net.citizensnpcs.npc.entity; import net.citizensnpcs.api.event.NPCPushEvent; import net.citizensnpcs.api.npc.NPC; -import net.citizensnpcs.npc.MobEntityController; import net.citizensnpcs.npc.CitizensNPC; +import net.citizensnpcs.npc.MobEntityController; import net.citizensnpcs.npc.ai.NPCHolder; import net.citizensnpcs.util.NMS; import net.citizensnpcs.util.Util; @@ -56,7 +56,7 @@ public class SnowmanController extends MobEntityController { // it will not stop the NPC from moving. super.collide(entity); if (npc != null) - Util.callCollisionEvent(npc, entity); + Util.callCollisionEvent(npc, entity.getBukkitEntity()); } @Override diff --git a/src/main/java/net/citizensnpcs/npc/entity/SpiderController.java b/src/main/java/net/citizensnpcs/npc/entity/SpiderController.java index b7a3114dd..dda7c39b1 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/SpiderController.java +++ b/src/main/java/net/citizensnpcs/npc/entity/SpiderController.java @@ -2,8 +2,8 @@ package net.citizensnpcs.npc.entity; import net.citizensnpcs.api.event.NPCPushEvent; import net.citizensnpcs.api.npc.NPC; -import net.citizensnpcs.npc.MobEntityController; import net.citizensnpcs.npc.CitizensNPC; +import net.citizensnpcs.npc.MobEntityController; import net.citizensnpcs.npc.ai.NPCHolder; import net.citizensnpcs.util.NMS; import net.citizensnpcs.util.Util; @@ -66,7 +66,7 @@ public class SpiderController extends MobEntityController { // it will not stop the NPC from moving. super.collide(entity); if (npc != null) - Util.callCollisionEvent(npc, entity); + Util.callCollisionEvent(npc, entity.getBukkitEntity()); } @Override diff --git a/src/main/java/net/citizensnpcs/npc/entity/SquidController.java b/src/main/java/net/citizensnpcs/npc/entity/SquidController.java index 135f4e604..a38020e9e 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/SquidController.java +++ b/src/main/java/net/citizensnpcs/npc/entity/SquidController.java @@ -2,8 +2,8 @@ package net.citizensnpcs.npc.entity; import net.citizensnpcs.api.event.NPCPushEvent; import net.citizensnpcs.api.npc.NPC; -import net.citizensnpcs.npc.MobEntityController; import net.citizensnpcs.npc.CitizensNPC; +import net.citizensnpcs.npc.MobEntityController; import net.citizensnpcs.npc.ai.NPCHolder; import net.citizensnpcs.util.NMS; import net.citizensnpcs.util.Util; @@ -57,7 +57,7 @@ public class SquidController extends MobEntityController { // it will not stop the NPC from moving. super.collide(entity); if (npc != null) - Util.callCollisionEvent(npc, entity); + Util.callCollisionEvent(npc, entity.getBukkitEntity()); } @Override diff --git a/src/main/java/net/citizensnpcs/npc/entity/VillagerController.java b/src/main/java/net/citizensnpcs/npc/entity/VillagerController.java index b2c4eff42..21c9235c2 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/VillagerController.java +++ b/src/main/java/net/citizensnpcs/npc/entity/VillagerController.java @@ -2,8 +2,8 @@ package net.citizensnpcs.npc.entity; import net.citizensnpcs.api.event.NPCPushEvent; import net.citizensnpcs.api.npc.NPC; -import net.citizensnpcs.npc.MobEntityController; import net.citizensnpcs.npc.CitizensNPC; +import net.citizensnpcs.npc.MobEntityController; import net.citizensnpcs.npc.ai.NPCHolder; import net.citizensnpcs.util.NMS; import net.citizensnpcs.util.Util; @@ -64,7 +64,7 @@ public class VillagerController extends MobEntityController { // it will not stop the NPC from moving. super.collide(entity); if (npc != null) - Util.callCollisionEvent(npc, entity); + Util.callCollisionEvent(npc, entity.getBukkitEntity()); } @Override diff --git a/src/main/java/net/citizensnpcs/npc/entity/WitchController.java b/src/main/java/net/citizensnpcs/npc/entity/WitchController.java index 6e57860ee..18efeefd6 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/WitchController.java +++ b/src/main/java/net/citizensnpcs/npc/entity/WitchController.java @@ -2,8 +2,8 @@ package net.citizensnpcs.npc.entity; import net.citizensnpcs.api.event.NPCPushEvent; import net.citizensnpcs.api.npc.NPC; -import net.citizensnpcs.npc.MobEntityController; import net.citizensnpcs.npc.CitizensNPC; +import net.citizensnpcs.npc.MobEntityController; import net.citizensnpcs.npc.ai.NPCHolder; import net.citizensnpcs.util.NMS; import net.citizensnpcs.util.Util; @@ -56,7 +56,7 @@ public class WitchController extends MobEntityController { // it will not stop the NPC from moving. super.collide(entity); if (npc != null) - Util.callCollisionEvent(npc, entity); + Util.callCollisionEvent(npc, entity.getBukkitEntity()); } @Override diff --git a/src/main/java/net/citizensnpcs/npc/entity/WitherController.java b/src/main/java/net/citizensnpcs/npc/entity/WitherController.java index 29003c1f5..913d0e3d5 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/WitherController.java +++ b/src/main/java/net/citizensnpcs/npc/entity/WitherController.java @@ -2,8 +2,8 @@ package net.citizensnpcs.npc.entity; import net.citizensnpcs.api.event.NPCPushEvent; import net.citizensnpcs.api.npc.NPC; -import net.citizensnpcs.npc.MobEntityController; import net.citizensnpcs.npc.CitizensNPC; +import net.citizensnpcs.npc.MobEntityController; import net.citizensnpcs.npc.ai.NPCHolder; import net.citizensnpcs.util.NMS; import net.citizensnpcs.util.Util; @@ -62,7 +62,7 @@ public class WitherController extends MobEntityController { // it will not stop the NPC from moving. super.collide(entity); if (npc != null) - Util.callCollisionEvent(npc, entity); + Util.callCollisionEvent(npc, entity.getBukkitEntity()); } @Override diff --git a/src/main/java/net/citizensnpcs/npc/entity/WolfController.java b/src/main/java/net/citizensnpcs/npc/entity/WolfController.java index 256f8cb5f..fd6959bd6 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/WolfController.java +++ b/src/main/java/net/citizensnpcs/npc/entity/WolfController.java @@ -2,8 +2,8 @@ package net.citizensnpcs.npc.entity; import net.citizensnpcs.api.event.NPCPushEvent; import net.citizensnpcs.api.npc.NPC; -import net.citizensnpcs.npc.MobEntityController; import net.citizensnpcs.npc.CitizensNPC; +import net.citizensnpcs.npc.MobEntityController; import net.citizensnpcs.npc.ai.NPCHolder; import net.citizensnpcs.util.NMS; import net.citizensnpcs.util.Util; @@ -56,7 +56,7 @@ public class WolfController extends MobEntityController { // it will not stop the NPC from moving. super.collide(entity); if (npc != null) - Util.callCollisionEvent(npc, entity); + Util.callCollisionEvent(npc, entity.getBukkitEntity()); } @Override diff --git a/src/main/java/net/citizensnpcs/npc/entity/ZombieController.java b/src/main/java/net/citizensnpcs/npc/entity/ZombieController.java index a76be5cd4..1627d5020 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/ZombieController.java +++ b/src/main/java/net/citizensnpcs/npc/entity/ZombieController.java @@ -2,8 +2,8 @@ package net.citizensnpcs.npc.entity; import net.citizensnpcs.api.event.NPCPushEvent; import net.citizensnpcs.api.npc.NPC; -import net.citizensnpcs.npc.MobEntityController; import net.citizensnpcs.npc.CitizensNPC; +import net.citizensnpcs.npc.MobEntityController; import net.citizensnpcs.npc.ai.NPCHolder; import net.citizensnpcs.util.NMS; import net.citizensnpcs.util.Util; @@ -56,7 +56,7 @@ public class ZombieController extends MobEntityController { // it will not stop the NPC from moving. super.collide(entity); if (npc != null) - Util.callCollisionEvent(npc, entity); + Util.callCollisionEvent(npc, entity.getBukkitEntity()); } @Override diff --git a/src/main/java/net/citizensnpcs/trait/text/Text.java b/src/main/java/net/citizensnpcs/trait/text/Text.java index 846ef3101..d9ef72d95 100644 --- a/src/main/java/net/citizensnpcs/trait/text/Text.java +++ b/src/main/java/net/citizensnpcs/trait/text/Text.java @@ -35,7 +35,7 @@ import org.bukkit.plugin.Plugin; public class Text extends Trait implements Runnable, Toggleable, Listener, ConversationAbandonedListener { private final Map cooldowns = new HashMap(); private int currentIndex; - private String itemInHandPattern = Setting.TALK_ITEM.asString(); + private String itemInHandPattern = "default"; private final Plugin plugin; private boolean randomTalker = Setting.DEFAULT_RANDOM_TALKER.asBoolean(); private double range = Setting.DEFAULT_TALK_CLOSE_RANGE.asDouble(); @@ -108,7 +108,9 @@ public class Text extends Trait implements Runnable, Toggleable, Listener, Conve public void onRightClick(NPCRightClickEvent event) { if (!event.getNPC().equals(npc)) return; - if (Util.matchesItemInHand(event.getClicker(), itemInHandPattern) && !shouldTalkClose()) + String localPattern = itemInHandPattern.equals("default") ? Setting.TALK_ITEM.asString() + : itemInHandPattern; + if (Util.matchesItemInHand(event.getClicker(), localPattern) && !shouldTalkClose()) sendText(event.getClicker()); } diff --git a/src/main/java/net/citizensnpcs/util/NMS.java b/src/main/java/net/citizensnpcs/util/NMS.java index fc44f7f1e..362d7d9a7 100644 --- a/src/main/java/net/citizensnpcs/util/NMS.java +++ b/src/main/java/net/citizensnpcs/util/NMS.java @@ -9,6 +9,7 @@ import java.util.Set; import java.util.WeakHashMap; import net.citizensnpcs.api.npc.NPC; +import net.minecraft.server.v1_4_5.ControllerJump; import net.minecraft.server.v1_4_5.ControllerLook; import net.minecraft.server.v1_4_5.DamageSource; import net.minecraft.server.v1_4_5.EnchantmentManager; @@ -24,6 +25,7 @@ import net.minecraft.server.v1_4_5.Packet; import net.minecraft.server.v1_4_5.PathfinderGoalSelector; import net.minecraft.server.v1_4_5.World; +import org.apache.commons.lang.Validate; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; @@ -48,6 +50,35 @@ public class NMS { // util class } + public static void sendToOnline(Packet... packets) { + Validate.notNull(packets, "packets cannot be null"); + for (Player player : Bukkit.getOnlinePlayers()) { + if (player == null || !player.isOnline()) + continue; + for (Packet packet : packets) { + sendPacket(player, packet); + } + } + } + + public static void sendPacketNearby(Location location, Packet packet, double radius) { + radius *= radius; + final org.bukkit.World world = location.getWorld(); + for (Player ply : Bukkit.getServer().getOnlinePlayers()) { + if (ply == null || world != ply.getWorld()) { + continue; + } + if (location.distanceSquared(ply.getLocation()) > radius) { + continue; + } + sendPacket(ply, packet); + } + } + + public static void sendPacketNearby(Location location, Packet packet) { + NMS.sendPacketNearby(location, packet, 64); + } + private static final float DEFAULT_SPEED = 0.4F; private static Map, Integer> ENTITY_CLASS_TO_INT; private static final Map, Constructor> ENTITY_CONSTRUCTOR_CACHE = new WeakHashMap, Constructor>(); @@ -67,7 +98,7 @@ public class NMS { public static void addOrRemoveFromPlayerList(LivingEntity bukkitEntity, boolean remove) { if (bukkitEntity == null) return; - EntityLiving handle = ((CraftLivingEntity) bukkitEntity).getHandle(); + EntityLiving handle = getHandle(bukkitEntity); if (handle.world == null) return; if (remove) { @@ -149,6 +180,10 @@ public class NMS { return f; } + public static EntityLiving getHandle(LivingEntity entity) { + return ((CraftLivingEntity) entity).getHandle(); + } + public static float getSpeedFor(NPC npc) { EntityType entityType = npc.getBukkitEntity().getType(); Float cached = MOVEMENT_SPEEDS.get(entityType); @@ -168,7 +203,8 @@ public class NMS { } } - public static boolean inWater(Entity mcEntity) { + public static boolean inWater(LivingEntity entity) { + EntityLiving mcEntity = getHandle(entity); return mcEntity.I() || mcEntity.J(); } @@ -180,7 +216,8 @@ public class NMS { controllerLook.a(target, 10.0F, handle.bp()); } - public static void look(EntityLiving handle, float yaw, float pitch) { + public static void look(LivingEntity bukkitEntity, float yaw, float pitch) { + EntityLiving handle = getHandle(bukkitEntity); handle.yaw = handle.ay = yaw; handle.pitch = pitch; } @@ -222,6 +259,11 @@ public class NMS { } } + public static void setShouldJump(LivingEntity entity) { + ControllerJump controller = getHandle(entity).getControllerJump(); + controller.a(); + } + public static org.bukkit.entity.Entity spawnCustomEntity(org.bukkit.World world, Location at, Class clazz, EntityType type) { World handle = ((CraftWorld) world).getHandle(); @@ -248,14 +290,15 @@ public class NMS { } } - public static void trySwim(Entity handle, float power) { - if (RANDOM.nextFloat() < 0.8F && inWater(handle)) { - handle.motY += power; - } + public static void trySwim(LivingEntity handle) { + trySwim(handle, 0.04F); } - public static void trySwim(org.bukkit.entity.Entity handle) { - trySwim(((CraftEntity) handle).getHandle(), 0.04F); + public static void trySwim(LivingEntity entity, float power) { + Entity handle = getHandle(entity); + if (RANDOM.nextFloat() < 0.8F && inWater(entity)) { + handle.motY += power; + } } public static void updateAI(EntityLiving entity) { @@ -266,8 +309,8 @@ public class NMS { entity.getControllerJump().b(); } - public static void updateNavigationWorld(org.bukkit.entity.Entity entity, org.bukkit.World world) { - if (NAVIGATION_WORLD_FIELD == null || !(entity instanceof LivingEntity)) + public static void updateNavigationWorld(LivingEntity entity, org.bukkit.World world) { + if (NAVIGATION_WORLD_FIELD == null) return; EntityLiving handle = ((CraftLivingEntity) entity).getHandle(); World worldHandle = ((CraftWorld) world).getHandle(); diff --git a/src/main/java/net/citizensnpcs/util/PlayerAnimation.java b/src/main/java/net/citizensnpcs/util/PlayerAnimation.java index 7c802e324..62e7e3204 100644 --- a/src/main/java/net/citizensnpcs/util/PlayerAnimation.java +++ b/src/main/java/net/citizensnpcs/util/PlayerAnimation.java @@ -81,6 +81,6 @@ public enum PlayerAnimation { } protected void sendPacketNearby(Packet packet, EntityPlayer player, int radius) { - Util.sendPacketNearby(player.getBukkitEntity().getLocation(), packet, radius); + NMS.sendPacketNearby(player.getBukkitEntity().getLocation(), packet, radius); } } diff --git a/src/main/java/net/citizensnpcs/util/Util.java b/src/main/java/net/citizensnpcs/util/Util.java index e5361d923..9557af1e5 100644 --- a/src/main/java/net/citizensnpcs/util/Util.java +++ b/src/main/java/net/citizensnpcs/util/Util.java @@ -5,17 +5,13 @@ import java.util.Random; import net.citizensnpcs.api.event.NPCCollisionEvent; import net.citizensnpcs.api.event.NPCPushEvent; import net.citizensnpcs.api.npc.NPC; -import net.minecraft.server.v1_4_5.EntityLiving; -import net.minecraft.server.v1_4_5.Packet; -import org.apache.commons.lang.Validate; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; -import org.bukkit.World; -import org.bukkit.craftbukkit.v1_4_5.entity.CraftLivingEntity; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; +import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.util.Vector; @@ -32,15 +28,15 @@ public class Util { private static Class RNG_CLASS = null; - public static void assumePose(org.bukkit.entity.Entity entity, float yaw, float pitch) { - EntityLiving handle = ((CraftLivingEntity) entity).getHandle(); - NMS.look(handle, yaw, pitch); + public static void assumePose(LivingEntity entity, float yaw, float pitch) { + NMS.look(entity, yaw, pitch); } - public static void callCollisionEvent(NPC npc, net.minecraft.server.v1_4_5.Entity entity) { + public static void callCollisionEvent(NPC npc, Entity entity) { if (NPCCollisionEvent.getHandlerList().getRegisteredListeners().length > 0) - Bukkit.getPluginManager().callEvent(new NPCCollisionEvent(npc, entity.getBukkitEntity())); + Bukkit.getPluginManager().callEvent(new NPCCollisionEvent(npc, entity)); } + public static NPCPushEvent callPushEvent(NPC npc, Vector vector) { NPCPushEvent event = new NPCPushEvent(npc, vector); event.setCancelled(npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true)); @@ -48,7 +44,7 @@ public class Util { return event; } - public static void faceEntity(Entity from, Entity at) { + public static void faceEntity(LivingEntity from, LivingEntity at) { if (from.getWorld() != at.getWorld()) return; double xDiff, yDiff, zDiff; @@ -66,8 +62,7 @@ public class Util { if (zDiff < 0.0) yaw += Math.abs(180 - yaw) * 2; - EntityLiving handle = ((CraftLivingEntity) from).getHandle(); - NMS.look(handle, (float) yaw - 90, (float) pitch); + NMS.look(from, (float) yaw - 90, (float) pitch); } public static Random getFastRandom() { @@ -130,35 +125,6 @@ public class Util { return false; } - public static void sendPacketNearby(Location location, Packet packet) { - sendPacketNearby(location, packet, 64); - } - - public static void sendPacketNearby(Location location, Packet packet, double radius) { - radius *= radius; - final World world = location.getWorld(); - for (Player ply : Bukkit.getServer().getOnlinePlayers()) { - if (ply == null || world != ply.getWorld()) { - continue; - } - if (location.distanceSquared(ply.getLocation()) > radius) { - continue; - } - NMS.sendPacket(ply, packet); - } - } - - public static void sendToOnline(Packet... packets) { - Validate.notNull(packets, "packets cannot be null"); - for (Player player : Bukkit.getOnlinePlayers()) { - if (player == null || !player.isOnline()) - continue; - for (Packet packet : packets) { - NMS.sendPacket(player, packet); - } - } - } - static { try { RNG_CLASS = Class.forName("org.uncommons.maths.random.XORShiftRNG");