Use new getEntity() call

This commit is contained in:
fullwall 2013-11-05 19:29:18 +08:00
parent 05f3667a37
commit 7803313e8c
42 changed files with 251 additions and 233 deletions

View File

@ -111,7 +111,7 @@ public class EventListen implements Listener {
for (NPC npc : getAllNPCs()) {
if (!npc.isSpawned())
continue;
loc = npc.getBukkitEntity().getLocation(loc);
loc = npc.getEntity().getLocation(loc);
boolean sameChunkCoordinates = coord.z == loc.getBlockZ() >> 4 && coord.x == loc.getBlockX() >> 4;
if (!sameChunkCoordinates || !event.getWorld().equals(loc.getWorld()))
continue;
@ -180,7 +180,7 @@ public class EventListen implements Listener {
return;
}
Bukkit.getPluginManager().callEvent(new NPCDeathEvent(npc, event));
final Location location = npc.getBukkitEntity().getLocation();
final Location location = npc.getEntity().getLocation();
npc.despawn(DespawnReason.DEATH);
if (npc.data().get(NPC.RESPAWN_DELAY_METADATA, -1) >= 0) {
@ -224,7 +224,7 @@ public class EventListen implements Listener {
@EventHandler
public void onNPCDespawn(NPCDespawnEvent event) {
if (event.getReason() == DespawnReason.PLUGIN || event.getReason() == DespawnReason.REMOVAL) {
toRespawn.remove(toCoord(event.getNPC().getBukkitEntity().getLocation()), event.getNPC());
toRespawn.remove(toCoord(event.getNPC().getEntity().getLocation()), event.getNPC());
}
}
@ -270,7 +270,7 @@ public class EventListen implements Listener {
if (!npcRegistry.isNPC(event.getEntered()))
return;
NPC npc = npcRegistry.getNPC(event.getEntered());
if (npc.getBukkitEntity().getType() == EntityType.HORSE && !npc.getTrait(Controllable.class).isEnabled()) {
if (npc.getEntity().getType() == EntityType.HORSE && !npc.getTrait(Controllable.class).isEnabled()) {
event.setCancelled(true);
}
}
@ -288,7 +288,7 @@ public class EventListen implements Listener {
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onWorldUnload(WorldUnloadEvent event) {
for (NPC npc : getAllNPCs()) {
if (!npc.isSpawned() || !npc.getBukkitEntity().getWorld().equals(event.getWorld()))
if (!npc.isSpawned() || !npc.getEntity().getWorld().equals(event.getWorld()))
continue;
boolean despawned = npc.despawn(DespawnReason.WORLD_UNLOAD);
if (event.isCancelled() || !despawned) {
@ -329,7 +329,7 @@ public class EventListen implements Listener {
}
private void storeForRespawn(NPC npc) {
toRespawn.put(toCoord(npc.getBukkitEntity().getLocation()), npc);
toRespawn.put(toCoord(npc.getEntity().getLocation()), npc);
}
private ChunkCoord toCoord(Chunk chunk) {

View File

@ -99,7 +99,7 @@ public class NPCCommands {
max = 2,
permission = "citizens.npc.age")
public void age(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
if (!npc.isSpawned() || !(npc.getBukkitEntity() instanceof Ageable))
if (!npc.isSpawned() || !(npc.getEntity() instanceof Ageable))
throw new CommandException(Messages.MOBTYPE_CANNOT_BE_AGED);
Age trait = npc.getTrait(Age.class);
@ -219,7 +219,7 @@ public class NPCCommands {
flags = "myn")
public void controllable(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
if ((npc.isSpawned() && !sender.hasPermission("citizens.npc.controllable."
+ npc.getBukkitEntity().getType().name().toLowerCase().replace("_", "")))
+ npc.getEntity().getType().name().toLowerCase().replace("_", "")))
|| !sender.hasPermission("citizens.npc.controllable"))
throw new NoPermissionsException();
if (!npc.hasTrait(Controllable.class)) {
@ -390,8 +390,9 @@ public class NPCCommands {
}
// Set age after entity spawns
if (npc.getBukkitEntity() instanceof Ageable)
if (npc.getEntity() instanceof Ageable) {
npc.getTrait(Age.class).setAge(age);
}
selector.select(sender, npc);
Messaging.send(sender, msg + '.');
}
@ -429,7 +430,7 @@ public class NPCCommands {
permission = "citizens.npc.gravity")
@Requirements(selected = true, ownership = true, types = { EntityType.PLAYER })
public void gamemode(CommandContext args, CommandSender sender, NPC npc) {
Player player = (Player) npc.getBukkitEntity();
Player player = (Player) npc.getEntity();
if (args.argsLength() == 1) {
Messaging.sendTr(sender, Messages.GAMEMODE_DESCRIBE, npc.getName(), player.getGameMode().name()
.toLowerCase());
@ -654,12 +655,13 @@ public class NPCCommands {
permission = "citizens.npc.moveto")
public void moveto(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
// Spawn the NPC if it isn't spawned to prevent NPEs
if (!npc.isSpawned())
if (!npc.isSpawned()) {
npc.spawn(npc.getTrait(CurrentLocation.class).getLocation());
if (npc.getBukkitEntity() == null) {
}
if (!npc.isSpawned()) {
throw new CommandException("NPC could not be spawned.");
}
Location current = npc.getBukkitEntity().getLocation();
Location current = npc.getEntity().getLocation();
Location to;
if (args.argsLength() > 1) {
String[] parts = Iterables.toArray(Splitter.on(':').split(args.getJoinedStrings(1, ':')), String.class);
@ -704,9 +706,10 @@ public class NPCCommands {
min = 1,
max = 1,
permission = "citizens.npc.name")
@Requirements(selected = true, ownership = true)
@Requirements(selected = true, ownership = true, livingEntity = true)
public void name(CommandContext args, CommandSender sender, NPC npc) {
npc.getBukkitEntity().setCustomNameVisible(!npc.getBukkitEntity().isCustomNameVisible());
LivingEntity entity = (LivingEntity) npc.getEntity();
entity.setCustomNameVisible(!entity.isCustomNameVisible());
Messaging.sendTr(sender, Messages.NAMEPLATE_VISIBILITY_TOGGLED);
}
@ -716,7 +719,7 @@ public class NPCCommands {
Messaging.send(sender, " <a>ID: <e>" + npc.getId());
Messaging.send(sender, " <a>Type: <e>" + npc.getTrait(MobType.class).getType());
if (npc.isSpawned()) {
Location loc = npc.getBukkitEntity().getLocation();
Location loc = npc.getEntity().getLocation();
String format = " <a>Spawned at <e>%d, %d, %d <a>in world<e> %s";
Messaging.send(sender,
String.format(format, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), loc.getWorld().getName()));
@ -822,8 +825,9 @@ public class NPCCommands {
} else if (args.hasFlag('r'))
remove = true;
npc.data().setPersistent("removefromplayerlist", remove);
if (npc.isSpawned())
NMS.addOrRemoveFromPlayerList(npc.getBukkitEntity(), remove);
if (npc.isSpawned()) {
NMS.addOrRemoveFromPlayerList(npc.getEntity(), remove);
}
Messaging.sendTr(sender, remove ? Messages.REMOVED_FROM_PLAYERLIST : Messages.ADDED_TO_PLAYERLIST,
npc.getName());
}
@ -953,7 +957,7 @@ public class NPCCommands {
Messaging.sendErrorTr(sender, Messages.NPC_NAME_TOO_LONG);
newName = newName.substring(0, 15);
}
Location prev = npc.isSpawned() ? npc.getBukkitEntity().getLocation() : null;
Location prev = npc.isSpawned() ? npc.getEntity().getLocation() : null;
npc.despawn(DespawnReason.PENDING_RESPAWN);
npc.setName(newName);
if (prev != null)
@ -1028,8 +1032,8 @@ public class NPCCommands {
if (test.getName().equalsIgnoreCase(name)) {
if (range > 0
&& test.isSpawned()
&& !Util.locationWithinRange(args.getSenderLocation(), test.getBukkitEntity()
.getLocation(), range))
&& !Util.locationWithinRange(args.getSenderLocation(), test.getEntity().getLocation(),
range))
continue;
possible.add(test);
}
@ -1137,7 +1141,7 @@ public class NPCCommands {
if (args.getFlag("target").matches("\\d+")) {
NPC target = CitizensAPI.getNPCRegistry().getById(Integer.valueOf(args.getFlag("target")));
if (target != null)
context.addRecipient(target.getBukkitEntity());
context.addRecipient(target.getEntity());
} else {
Player player = Bukkit.getPlayer(args.getFlag("target"));
if (player != null)
@ -1216,13 +1220,13 @@ public class NPCCommands {
if (!npc.isSpawned()) {
npc.spawn(args.getSenderLocation());
if (!sender.hasPermission("citizens.npc.tphere.multiworld")
&& npc.getBukkitEntity().getLocation().getWorld() != args.getSenderLocation().getWorld()) {
&& npc.getEntity().getLocation().getWorld() != args.getSenderLocation().getWorld()) {
npc.despawn(DespawnReason.REMOVAL);
throw new CommandException(Messages.CANNOT_TELEPORT_ACROSS_WORLDS);
}
} else {
if (!sender.hasPermission("citizens.npc.tphere.multiworld")
&& npc.getBukkitEntity().getLocation().getWorld() != args.getSenderLocation().getWorld()) {
&& npc.getEntity().getLocation().getWorld() != args.getSenderLocation().getWorld()) {
npc.despawn(DespawnReason.REMOVAL);
throw new CommandException(Messages.CANNOT_TELEPORT_ACROSS_WORLDS);
}
@ -1242,14 +1246,15 @@ public class NPCCommands {
@Requirements
public void tpto(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
Entity from = null, to = null;
if (npc != null)
from = npc.getBukkitEntity();
if (npc != null) {
from = npc.getEntity();
}
boolean firstWasPlayer = false;
try {
int id = args.getInteger(1);
NPC fromNPC = CitizensAPI.getNPCRegistry().getById(id);
if (fromNPC != null)
from = fromNPC.getBukkitEntity();
from = fromNPC.getEntity();
} catch (NumberFormatException e) {
from = Bukkit.getPlayerExact(args.getString(1));
firstWasPlayer = true;
@ -1257,8 +1262,9 @@ public class NPCCommands {
try {
int id = args.getInteger(2);
NPC toNPC = CitizensAPI.getNPCRegistry().getById(id);
if (toNPC != null)
to = toNPC.getBukkitEntity();
if (toNPC != null) {
to = toNPC.getEntity();
}
} catch (NumberFormatException e) {
if (!firstWasPlayer)
to = Bukkit.getPlayerExact(args.getString(2));

View File

@ -20,15 +20,15 @@ public class EndermanEquipper implements Equipper {
return;
}
MaterialData carried = ((Enderman) npc.getBukkitEntity()).getCarriedMaterial();
MaterialData carried = ((Enderman) npc.getEntity()).getCarriedMaterial();
if (carried.getItemType() == Material.AIR) {
if (hand.getType() == Material.AIR) {
Messaging.sendErrorTr(equipper, Messages.EQUIPMENT_EDITOR_INVALID_BLOCK);
return;
}
} else {
equipper.getWorld().dropItemNaturally(npc.getBukkitEntity().getLocation(), carried.toItemStack(1));
((Enderman) npc.getBukkitEntity()).setCarriedMaterial(hand.getData());
equipper.getWorld().dropItemNaturally(npc.getEntity().getLocation(), carried.toItemStack(1));
((Enderman) npc.getEntity()).setCarriedMaterial(hand.getData());
}
ItemStack set = hand.clone();

View File

@ -48,7 +48,7 @@ public class EquipmentEditor extends Editor {
|| !npc.equals(CitizensAPI.getNPCRegistry().getNPC(event.getRightClicked())))
return;
Equipper equipper = EQUIPPERS.get(npc.getBukkitEntity().getType());
Equipper equipper = EQUIPPERS.get(npc.getEntity().getType());
if (equipper == null)
equipper = new GenericEquipper();
equipper.equip(event.getPlayer(), npc);

View File

@ -56,7 +56,7 @@ public class GenericEquipper implements Equipper {
case AIR:
for (int i = 0; i < 5; i++) {
if (trait.get(i) != null && trait.get(i).getType() != Material.AIR) {
equipper.getWorld().dropItemNaturally(toEquip.getBukkitEntity().getLocation(), trait.get(i));
equipper.getWorld().dropItemNaturally(toEquip.getEntity().getLocation(), trait.get(i));
trait.set(i, null);
}
}
@ -68,7 +68,7 @@ public class GenericEquipper implements Equipper {
// Drop any previous equipment on the ground
ItemStack equippedItem = trait.get(slot);
if (equippedItem != null && equippedItem.getType() != Material.AIR)
equipper.getWorld().dropItemNaturally(toEquip.getBukkitEntity().getLocation(), equippedItem);
equipper.getWorld().dropItemNaturally(toEquip.getEntity().getLocation(), equippedItem);
// Now edit the equipment based on the slot
if (type != Material.AIR) {

View File

@ -9,7 +9,7 @@ import org.bukkit.entity.Player;
public class HorseEquipper implements Equipper {
@Override
public void equip(Player equipper, NPC toEquip) {
Horse horse = (Horse) toEquip.getBukkitEntity();
Horse horse = (Horse) toEquip.getEntity();
NMS.openHorseScreen(horse, equipper);
}
}

View File

@ -14,7 +14,7 @@ public class PigEquipper implements Equipper {
@Override
public void equip(Player equipper, NPC toEquip) {
ItemStack hand = equipper.getItemInHand();
Pig pig = (Pig) toEquip.getBukkitEntity();
Pig pig = (Pig) toEquip.getEntity();
if (hand.getType() == Material.SADDLE) {
if (!pig.hasSaddle()) {
toEquip.getTrait(Saddle.class).toggle();

View File

@ -17,7 +17,7 @@ public class SheepEquipper implements Equipper {
@Override
public void equip(Player equipper, NPC toEquip) {
ItemStack hand = equipper.getItemInHand();
Sheep sheep = (Sheep) toEquip.getBukkitEntity();
Sheep sheep = (Sheep) toEquip.getEntity();
if (hand.getType() == Material.SHEARS) {
Messaging.sendTr(equipper, toEquip.getTrait(Sheared.class).toggle() ? Messages.SHEARED_SET
: Messages.SHEARED_STOPPED, toEquip.getName());

View File

@ -20,7 +20,6 @@ import net.citizensnpcs.trait.CurrentLocation;
import net.citizensnpcs.util.Messages;
import net.citizensnpcs.util.NMS;
import net.citizensnpcs.util.Util;
import net.minecraft.server.v1_6_R3.EntityLiving;
import net.minecraft.server.v1_6_R3.Packet34EntityTeleport;
import org.bukkit.Bukkit;
@ -59,15 +58,17 @@ public class CitizensNPC extends AbstractNPC {
event.setCancelled(Setting.KEEP_CHUNKS_LOADED.asBoolean());
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) {
getBukkitEntity().getLocation().getChunk().load();
getEntity().getLocation().getChunk().load();
Messaging.debug("Couldn't despawn", getId(), "due to despawn event cancellation. Force loaded chunk.");
return false;
}
boolean keepSelected = getTrait(Spawned.class).shouldSpawn();
if (!keepSelected)
if (!keepSelected) {
data().remove("selectors");
for (Trait trait : traits.values())
}
for (Trait trait : traits.values()) {
trait.onDespawn();
}
navigator.onDespawn();
entityController.remove();
return true;
@ -77,10 +78,11 @@ public class CitizensNPC extends AbstractNPC {
public void faceLocation(Location location) {
if (!isSpawned())
return;
Util.faceLocation(getBukkitEntity(), location);
Util.faceLocation(getEntity(), location);
}
@Override
@Deprecated
public LivingEntity getBukkitEntity() {
return entityController == null ? null : entityController.getBukkitEntity();
}
@ -92,12 +94,12 @@ public class CitizensNPC extends AbstractNPC {
@Override
public Location getStoredLocation() {
return isSpawned() ? getBukkitEntity().getLocation() : getTrait(CurrentLocation.class).getLocation();
return isSpawned() ? getEntity().getLocation() : getTrait(CurrentLocation.class).getLocation();
}
@Override
public boolean isSpawned() {
return getBukkitEntity() != null;
return getEntity() != null;
}
@Override
@ -131,7 +133,7 @@ public class CitizensNPC extends AbstractNPC {
boolean wasSpawned = isSpawned();
Location prev = null;
if (wasSpawned) {
prev = getBukkitEntity().getLocation();
prev = getEntity().getLocation();
despawn(DespawnReason.PENDING_RESPAWN);
}
entityController = newController;
@ -150,7 +152,7 @@ public class CitizensNPC extends AbstractNPC {
at = at.clone();
entityController.spawn(at, this);
EntityLiving mcEntity = ((CraftLivingEntity) getBukkitEntity()).getHandle();
net.minecraft.server.v1_6_R3.Entity mcEntity = ((CraftLivingEntity) getEntity()).getHandle();
boolean couldSpawn = !Util.isLoaded(at) ? false : mcEntity.world.addEntity(mcEntity, SpawnReason.CUSTOM);
mcEntity.setPositionRotation(at.getX(), at.getY(), at.getZ(), at.getYaw(), at.getPitch());
if (!couldSpawn) {
@ -171,7 +173,7 @@ public class CitizensNPC extends AbstractNPC {
return false;
}
getBukkitEntity().setMetadata(NPC_METADATA_MARKER, new FixedMetadataValue(CitizensAPI.getPlugin(), true));
getEntity().setMetadata(NPC_METADATA_MARKER, new FixedMetadataValue(CitizensAPI.getPlugin(), true));
// Set the spawned state
getTrait(CurrentLocation.class).setLocation(at);
@ -189,8 +191,11 @@ public class CitizensNPC extends AbstractNPC {
ex.printStackTrace();
}
}
getBukkitEntity().setRemoveWhenFarAway(false);
getBukkitEntity().setCustomName(getFullName());
if (getEntity() instanceof LivingEntity) {
LivingEntity entity = (LivingEntity) getEntity();
entity.setRemoveWhenFarAway(false);
entity.setCustomName(getFullName());
}
return true;
}
@ -220,7 +225,7 @@ public class CitizensNPC extends AbstractNPC {
public void teleport(Location location, TeleportCause cause) {
if (!isSpawned())
return;
teleport(NMS.getRootVehicle(getBukkitEntity()), location, false, 5);
teleport(NMS.getRootVehicle(getEntity()), location, false, 5);
}
@Override
@ -228,12 +233,12 @@ public class CitizensNPC extends AbstractNPC {
try {
super.update();
if (isSpawned()) {
NMS.trySwim(getBukkitEntity());
NMS.trySwim(getEntity());
navigator.run();
if (++packetUpdateCount > 30) {
if (!getNavigator().isNavigating()) {
NMS.sendPacketNearby(getStoredLocation(),
new Packet34EntityTeleport(NMS.getHandle(getBukkitEntity())));
new Packet34EntityTeleport(NMS.getHandle(getEntity())));
}
packetUpdateCount = 0;
}

View File

@ -11,7 +11,7 @@ import net.citizensnpcs.api.astar.pathfinder.VectorGoal;
import net.citizensnpcs.api.astar.pathfinder.VectorNode;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.util.NMS;
import net.minecraft.server.v1_6_R3.EntityLiving;
import net.citizensnpcs.util.Util;
import org.bukkit.Effect;
import org.bukkit.Location;
@ -29,7 +29,7 @@ public class AStarNavigationStrategy extends AbstractPathStrategy {
this.params = params;
this.destination = dest;
this.npc = npc;
Location location = npc.getBukkitEntity().getEyeLocation();
Location location = Util.getEyeLocation(npc.getEntity());
plan = ASTAR.runFully(new VectorGoal(dest, (float) params.distanceMargin()), new VectorNode(location,
new ChunkBlockSource(location, params.range()), params.examiners()), 50000);
if (plan == null || plan.isComplete()) {
@ -54,15 +54,14 @@ public class AStarNavigationStrategy extends AbstractPathStrategy {
if (getCancelReason() != null || plan == null || plan.isComplete()) {
return true;
}
if (npc.getBukkitEntity().getLocation(NPC_LOCATION).toVector().distanceSquared(vector) <= params
.distanceMargin()) {
if (npc.getEntity().getLocation(NPC_LOCATION).toVector().distanceSquared(vector) <= params.distanceMargin()) {
plan.update(npc);
if (plan.isComplete()) {
return true;
}
vector = plan.getCurrentVector();
}
EntityLiving handle = NMS.getHandle(npc.getBukkitEntity());
net.minecraft.server.v1_6_R3.Entity handle = NMS.getHandle(npc.getEntity());
double dX = vector.getBlockX() - handle.locX;
double dZ = vector.getBlockZ() - handle.locZ;
double dY = vector.getY() - handle.locY;
@ -70,13 +69,13 @@ public class AStarNavigationStrategy extends AbstractPathStrategy {
double distance = xzDistance + dY * dY;
if (Setting.DEBUG_PATHFINDING.asBoolean()) {
for (int i = 0; i < 5; i++) {
npc.getBukkitEntity().getWorld().playEffect(npc.getStoredLocation(), Effect.MOBSPAWNER_FLAMES, 0);
npc.getEntity().getWorld().playEffect(npc.getStoredLocation(), Effect.MOBSPAWNER_FLAMES, 0);
}
}
if (distance > 0 && dY > 0 && xzDistance <= 2.75) {
NMS.setShouldJump(npc.getBukkitEntity());
NMS.setShouldJump(npc.getEntity());
}
NMS.setDestination(npc.getBukkitEntity(), vector.getX(), vector.getY(), vector.getZ(), params.speed());
NMS.setDestination(npc.getEntity(), vector.getX(), vector.getY(), vector.getZ(), params.speed());
return false;
}

View File

@ -180,9 +180,9 @@ public class CitizensNavigator implements Navigator, Runnable {
localParams = defaultParams;
stationaryTicks = 0;
if (npc.isSpawned()) {
Vector velocity = npc.getBukkitEntity().getVelocity();
Vector velocity = npc.getEntity().getVelocity();
velocity.setX(0).setY(0).setZ(0);
npc.getBukkitEntity().setVelocity(velocity);
npc.getEntity().setVelocity(velocity);
}
}
@ -224,7 +224,7 @@ public class CitizensNavigator implements Navigator, Runnable {
executing = newStrategy;
stationaryTicks = 0;
if (npc.isSpawned()) {
NMS.updateNavigationWorld(npc.getBukkitEntity(), npc.getBukkitEntity().getWorld());
NMS.updateNavigationWorld(npc.getEntity(), npc.getEntity().getWorld());
}
Bukkit.getPluginManager().callEvent(new NavigationBeginEvent(this));
}
@ -236,7 +236,7 @@ public class CitizensNavigator implements Navigator, Runnable {
private boolean updateStationaryStatus() {
if (localParams.stationaryTicks() < 0)
return false;
Location current = npc.getBukkitEntity().getLocation(STATIONARY_LOCATION);
Location current = npc.getEntity().getLocation(STATIONARY_LOCATION);
if (lastX == current.getBlockX() && lastY == current.getBlockY() && lastZ == current.getBlockZ()) {
if (++stationaryTicks >= localParams.stationaryTicks()) {
stopNavigating(CancelReason.STUCK);

View File

@ -10,6 +10,7 @@ import net.citizensnpcs.api.astar.pathfinder.VectorGoal;
import net.citizensnpcs.api.astar.pathfinder.VectorNode;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.util.NMS;
import net.citizensnpcs.util.Util;
import net.minecraft.server.v1_6_R3.MathHelper;
import org.bukkit.Location;
@ -27,7 +28,7 @@ public class FlyingAStarNavigationStrategy extends AbstractPathStrategy {
this.target = dest;
this.parameters = params;
this.npc = npc;
Location location = npc.getBukkitEntity().getEyeLocation();
Location location = Util.getEyeLocation(npc.getEntity());
plan = ASTAR.runFully(new VectorGoal(dest, (float) params.distanceMargin()), new VectorNode(location,
new ChunkBlockSource(location, params.range()), params.examiners()), 50000);
if (plan == null || plan.isComplete()) {
@ -52,7 +53,7 @@ public class FlyingAStarNavigationStrategy extends AbstractPathStrategy {
if (getCancelReason() != null || plan == null || plan.isComplete()) {
return true;
}
Location current = npc.getBukkitEntity().getLocation(NPC_LOCATION);
Location current = npc.getEntity().getLocation(NPC_LOCATION);
if (current.toVector().distanceSquared(vector) <= parameters.distanceMargin()) {
plan.update(npc);
if (plan.isComplete()) {
@ -65,7 +66,7 @@ public class FlyingAStarNavigationStrategy extends AbstractPathStrategy {
double d1 = vector.getY() + 0.1D - current.getY();
double d2 = vector.getZ() + 0.5D - current.getZ();
Vector velocity = npc.getBukkitEntity().getVelocity();
Vector velocity = npc.getEntity().getVelocity();
double motX = velocity.getX(), motY = velocity.getY(), motZ = velocity.getZ();
motX += (Math.signum(d0) * 0.5D - motX) * 0.1;
@ -75,10 +76,10 @@ public class FlyingAStarNavigationStrategy extends AbstractPathStrategy {
float normalisedTargetYaw = MathHelper.g(targetYaw - current.getYaw());
velocity.setX(motX).setY(motY).setZ(motZ);
npc.getBukkitEntity().setVelocity(velocity);
npc.getEntity().setVelocity(velocity);
NMS.setVerticalMovement(npc.getBukkitEntity(), 0.5);
NMS.setHeadYaw(NMS.getHandle(npc.getBukkitEntity()), current.getYaw() + normalisedTargetYaw);
NMS.setVerticalMovement(npc.getEntity(), 0.5);
NMS.setHeadYaw(NMS.getHandle(npc.getEntity()), current.getYaw() + normalisedTargetYaw);
return false;
}

View File

@ -20,7 +20,7 @@ public class MCNavigationStrategy extends AbstractPathStrategy {
super(TargetType.LOCATION);
this.target = dest;
this.parameters = params;
EntityLiving handle = ((CraftLivingEntity) npc.getBukkitEntity()).getHandle();
EntityLiving handle = ((CraftLivingEntity) npc.getEntity()).getHandle();
handle.onGround = true;
// not sure of a better way around this - if onGround is false, then
// navigation won't execute, and calling entity.move doesn't

View File

@ -37,7 +37,7 @@ public class MCTargetStrategy implements PathStrategy, EntityTarget {
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.handle = ((CraftLivingEntity) npc.getEntity()).getHandle();
this.target = ((CraftEntity) target).getHandle();
Navigation nav = NMS.getNavigation(this.handle);
this.targetNavigator = nav != null && !params.useNewPathfinder() ? new NavigationFieldWrapper(nav)

View File

@ -1,7 +1,6 @@
package net.citizensnpcs.npc.ai.speech;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import net.citizensnpcs.Settings.Setting;
@ -13,7 +12,6 @@ import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.util.Messaging;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
public class Chat implements VocalChord {
public final String VOCAL_CHORD_NAME = "chat";
@ -109,27 +107,27 @@ public class Chat implements VocalChord {
private void talkToBystanders(NPC npc, String text, SpeechContext context) {
// Get list of nearby entities
List<Entity> bystanderEntities = npc.getBukkitEntity().getNearbyEntities(Setting.CHAT_RANGE.asDouble(),
List<Entity> bystanderEntities = npc.getEntity().getNearbyEntities(Setting.CHAT_RANGE.asDouble(),
Setting.CHAT_RANGE.asDouble(), Setting.CHAT_RANGE.asDouble());
for (Entity bystander : bystanderEntities)
for (Entity bystander : bystanderEntities) {
// Continue if a LivingEntity, which is compatible with
// TalkableEntity
if (bystander instanceof LivingEntity) {
boolean should_talk = true;
// Exclude targeted recipients
if (context.hasRecipients()) {
for (Talkable target : context)
if (target.getEntity().equals(bystander))
should_talk = false;
boolean shouldTalk = true;
// Exclude targeted recipients
if (context.hasRecipients()) {
for (Talkable target : context) {
if (target.getEntity().equals(bystander)) {
shouldTalk = false;
break;
}
}
// Found a nearby LivingEntity, make it Talkable and
// talkNear it if 'should_talk'
if (should_talk)
new TalkableEntity((LivingEntity) bystander).talkNear(context, text, this);
}
}
// Found a nearby LivingEntity, make it Talkable and
// talkNear it if 'should_talk'
if (shouldTalk) {
new TalkableEntity(bystander).talkNear(context, text, this);
}
}
}
}

View File

@ -8,7 +8,7 @@ import net.citizensnpcs.api.ai.speech.SpeechFactory;
import net.citizensnpcs.api.ai.speech.Talkable;
import net.citizensnpcs.api.ai.speech.VocalChord;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Entity;
import com.google.common.base.Preconditions;
@ -55,14 +55,11 @@ public class CitizensSpeechFactory implements SpeechFactory {
@Override
public boolean isRegistered(String name) {
if (registered.containsKey(name.toLowerCase()))
return true;
else
return false;
return registered.containsKey(name.toLowerCase());
}
@Override
public Talkable newTalkableEntity(LivingEntity entity) {
public Talkable newTalkableEntity(Entity entity) {
if (entity == null)
return null;
return new TalkableEntity(entity);

View File

@ -10,23 +10,22 @@ import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.util.Messaging;
import org.bukkit.Bukkit;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
public class TalkableEntity implements Talkable {
Entity entity;
LivingEntity entity;
public TalkableEntity(LivingEntity entity) {
public TalkableEntity(Entity entity) {
this.entity = entity;
}
public TalkableEntity(NPC npc) {
entity = npc.getBukkitEntity();
entity = npc.getEntity();
}
public TalkableEntity(Player player) {
entity = (LivingEntity) player;
entity = player;
}
/**
@ -38,34 +37,35 @@ public class TalkableEntity implements Talkable {
@Override
public int compareTo(Object o) {
// If not living entity, return -1
if (!(o instanceof LivingEntity))
if (!(o instanceof Entity)) {
return -1;
// If NPC and matches, return 0
else if (CitizensAPI.getNPCRegistry().isNPC((LivingEntity) o)
&& CitizensAPI.getNPCRegistry().isNPC((LivingEntity) entity)
&& CitizensAPI.getNPCRegistry().getNPC((LivingEntity) o).getId() == CitizensAPI.getNPCRegistry()
.getNPC((LivingEntity) entity).getId())
// If NPC and matches, return 0
} else if (CitizensAPI.getNPCRegistry().isNPC((Entity) o)
&& CitizensAPI.getNPCRegistry().isNPC(entity)
&& CitizensAPI.getNPCRegistry().getNPC((Entity) o).getId() == CitizensAPI.getNPCRegistry()
.getNPC(entity).getId()) {
return 0;
else if ((LivingEntity) o == entity)
} else if (entity.equals(o)) {
return 0;
// Not a match, return 1
else
} else {
return 1;
}
}
@Override
public LivingEntity getEntity() {
public Entity getEntity() {
return entity;
}
@Override
public String getName() {
if (CitizensAPI.getNPCRegistry().isNPC(entity))
if (CitizensAPI.getNPCRegistry().isNPC(entity)) {
return CitizensAPI.getNPCRegistry().getNPC(entity).getName();
else if (entity instanceof Player)
} else if (entity instanceof Player) {
return ((Player) entity).getName();
else
} else {
return entity.getType().name().replace("_", " ");
}
}
private void talk(String message) {
@ -79,8 +79,7 @@ public class TalkableEntity implements Talkable {
Bukkit.getServer().getPluginManager().callEvent(event);
if (event.isCancelled())
return;
else
talk(event.getMessage());
talk(event.getMessage());
}
@Override
@ -89,8 +88,7 @@ public class TalkableEntity implements Talkable {
Bukkit.getServer().getPluginManager().callEvent(event);
if (event.isCancelled())
return;
else
talk(event.getMessage());
talk(event.getMessage());
}
}

View File

@ -29,8 +29,8 @@ public class Age extends Trait implements Toggleable {
@Override
public void onSpawn() {
if (npc.getBukkitEntity() instanceof Ageable) {
Ageable entity = (Ageable) npc.getBukkitEntity();
if (npc.getEntity() instanceof Ageable) {
Ageable entity = (Ageable) npc.getEntity();
entity.setAge(age);
entity.setAgeLock(locked);
ageable = entity;

View File

@ -13,12 +13,10 @@ import net.citizensnpcs.util.Messages;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.world.WorldLoadEvent;
import org.bukkit.event.world.WorldUnloadEvent;
public class Anchors extends Trait {
private List<Anchor> anchors = new ArrayList<Anchor>();
private final List<Anchor> anchors = new ArrayList<Anchor>();
public Anchors() {
super("anchors");
@ -32,6 +30,13 @@ public class Anchors extends Trait {
return true;
}
@EventHandler
public void checkWorld(WorldLoadEvent event) {
for (Anchor anchor : anchors)
if (!anchor.isLoaded())
anchor.load();
}
public Anchor getAnchor(String name) {
for (Anchor anchor : anchors)
if (anchor.getName().equalsIgnoreCase(name))
@ -49,13 +54,14 @@ public class Anchors extends Trait {
String[] parts = sub.getString("").split(";");
Location location;
try {
location = new Location(Bukkit.getServer().getWorld(parts[1]), Double
.valueOf(parts[2]), Double.valueOf(parts[3]), Double.valueOf(parts[4]));
location = new Location(Bukkit.getServer().getWorld(parts[1]), Double.valueOf(parts[2]),
Double.valueOf(parts[3]), Double.valueOf(parts[4]));
anchors.add(new Anchor(parts[0], location));
} catch (NumberFormatException e) {
Messaging.logTr(Messages.SKIPPING_INVALID_ANCHOR, sub.name(), e.getMessage());
} catch (NullPointerException e) {
// Invalid world/location/etc. Still enough data to build an unloaded anchor
// Invalid world/location/etc. Still enough data to build an
// unloaded anchor
anchors.add(new Anchor(parts[0], sub.getString("").split(";", 2)[1]));
}
}
@ -76,11 +82,4 @@ public class Anchors extends Trait {
key.setString("list." + String.valueOf(i), anchors.get(i).stringValue());
}
@EventHandler
public void checkWorld(WorldLoadEvent event) {
for (Anchor anchor : anchors)
if (!anchor.isLoaded())
anchor.load();
}
}

View File

@ -18,7 +18,7 @@ import net.minecraft.server.v1_6_R3.EntityEnderDragon;
import net.minecraft.server.v1_6_R3.EntityLiving;
import net.minecraft.server.v1_6_R3.EntityPlayer;
import org.bukkit.craftbukkit.v1_6_R3.entity.CraftLivingEntity;
import org.bukkit.craftbukkit.v1_6_R3.entity.CraftEntity;
import org.bukkit.craftbukkit.v1_6_R3.entity.CraftPlayer;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
@ -75,8 +75,8 @@ public class Controllable extends Trait implements Toggleable, CommandConfigurab
}
}
private EntityLiving getHandle() {
return ((CraftLivingEntity) npc.getBukkitEntity()).getHandle();
private net.minecraft.server.v1_6_R3.Entity getHandle() {
return ((CraftEntity) npc.getEntity()).getHandle();
}
public boolean isEnabled() {
@ -90,7 +90,7 @@ public class Controllable extends Trait implements Toggleable, CommandConfigurab
}
private void loadController() {
EntityType type = npc.getBukkitEntity().getType();
EntityType type = npc.getEntity().getType();
if (explicitType != null)
type = explicitType;
Class<? extends MovementController> clazz = controllerTypes.get(type);
@ -118,7 +118,7 @@ public class Controllable extends Trait implements Toggleable, CommandConfigurab
}
public boolean mount(Player toMount) {
Entity passenger = npc.getBukkitEntity().getPassenger();
Entity passenger = npc.getEntity().getPassenger();
if (passenger != null && passenger != toMount) {
return false;
}
@ -181,7 +181,7 @@ public class Controllable extends Trait implements Toggleable, CommandConfigurab
return enabled;
}
private void setMountedYaw(EntityLiving handle) {
private void setMountedYaw(net.minecraft.server.v1_6_R3.Entity handle) {
if (handle instanceof EntityEnderDragon || !Setting.USE_BOAT_CONTROLS.asBoolean())
return; // EnderDragon handles this separately
double tX = handle.locX + handle.motX;
@ -203,7 +203,7 @@ public class Controllable extends Trait implements Toggleable, CommandConfigurab
return enabled;
}
private double updateHorizontalSpeed(EntityLiving handle, double speed, float speedMod) {
private double updateHorizontalSpeed(net.minecraft.server.v1_6_R3.Entity handle, double speed, float speedMod) {
double oldSpeed = Math.sqrt(handle.motX * handle.motX + handle.motZ * handle.motZ);
double horizontal = ((EntityLiving) handle.passenger).bf;
if (horizontal > 0.0D) {
@ -249,7 +249,7 @@ public class Controllable extends Trait implements Toggleable, CommandConfigurab
@Override
public void run(Player rider) {
EntityLiving handle = getHandle();
net.minecraft.server.v1_6_R3.Entity handle = getHandle();
boolean onGround = handle.onGround;
float speedMod = npc.getNavigator().getDefaultParameters()
.modifiedSpeed((onGround ? GROUND_SPEED : AIR_SPEED));
@ -300,7 +300,7 @@ public class Controllable extends Trait implements Toggleable, CommandConfigurab
}
Vector dir = rider.getEyeLocation().getDirection();
dir.multiply(npc.getNavigator().getDefaultParameters().speedModifier());
EntityLiving handle = getHandle();
net.minecraft.server.v1_6_R3.Entity handle = getHandle();
handle.motX = dir.getX();
handle.motY = dir.getY();
handle.motZ = dir.getZ();
@ -343,7 +343,7 @@ public class Controllable extends Trait implements Toggleable, CommandConfigurab
getHandle().motY = 0.001;
return;
}
EntityLiving handle = getHandle();
net.minecraft.server.v1_6_R3.Entity handle = getHandle();
this.speed = updateHorizontalSpeed(handle, this.speed, 1F);
boolean shouldJump = NMS.shouldJump(handle.passenger);
if (shouldJump) {

View File

@ -21,7 +21,7 @@ public class CurrentLocation extends Trait {
public void run() {
if (!npc.isSpawned())
return;
location = npc.getBukkitEntity().getLocation(location);
location = npc.getEntity().getLocation(location);
}
public void setLocation(Location loc) {

View File

@ -21,9 +21,9 @@ public class Gravity extends Trait implements Toggleable {
public void run() {
if (!npc.isSpawned() || !enabled)
return;
Vector vector = npc.getBukkitEntity().getVelocity();
Vector vector = npc.getEntity().getVelocity();
vector.setY(Math.max(0, vector.getY()));
npc.getBukkitEntity().setVelocity(vector);
npc.getEntity().setVelocity(vector);
}
@Override

View File

@ -46,8 +46,8 @@ public class HorseModifiers extends Trait {
@Override
public void run() {
if (npc.getBukkitEntity() instanceof Horse) {
Horse horse = (Horse) npc.getBukkitEntity();
if (npc.getEntity() instanceof Horse) {
Horse horse = (Horse) npc.getEntity();
saddle = horse.getInventory().getSaddle();
armor = horse.getInventory().getArmor();
}
@ -74,8 +74,8 @@ public class HorseModifiers extends Trait {
}
private void updateModifiers() {
if (npc.getBukkitEntity() instanceof Horse) {
Horse horse = (Horse) npc.getBukkitEntity();
if (npc.getEntity() instanceof Horse) {
Horse horse = (Horse) npc.getEntity();
horse.setCarryingChest(carryingChest);
horse.setColor(color);
horse.setStyle(style);

View File

@ -16,6 +16,7 @@ import net.citizensnpcs.util.Util;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
public class LookClose extends Trait implements Toggleable, CommandConfigurable {
@ -29,7 +30,8 @@ public class LookClose extends Trait implements Toggleable, CommandConfigurable
}
private boolean canSeeTarget() {
return realisticLooking ? npc.getBukkitEntity().hasLineOfSight(lookingAt) : true;
return realisticLooking && npc.getEntity() instanceof LivingEntity ? ((LivingEntity) npc.getEntity())
.hasLineOfSight(lookingAt) : true;
}
@Override
@ -40,8 +42,8 @@ public class LookClose extends Trait implements Toggleable, CommandConfigurable
}
private void findNewTarget() {
List<Entity> nearby = npc.getBukkitEntity().getNearbyEntities(range, range, range);
final Location npcLocation = npc.getBukkitEntity().getLocation(NPC_LOCATION);
List<Entity> nearby = npc.getEntity().getNearbyEntities(range, range, range);
final Location npcLocation = npc.getEntity().getLocation(NPC_LOCATION);
Collections.sort(nearby, new Comparator<Entity>() {
@Override
public int compare(Entity o1, Entity o2) {
@ -64,8 +66,8 @@ public class LookClose extends Trait implements Toggleable, CommandConfigurable
private boolean hasInvalidTarget() {
if (lookingAt == null)
return true;
if (!lookingAt.isOnline() || lookingAt.getWorld() != npc.getBukkitEntity().getWorld()
|| lookingAt.getLocation().distanceSquared(npc.getBukkitEntity().getLocation()) > range) {
if (!lookingAt.isOnline() || lookingAt.getWorld() != npc.getEntity().getWorld()
|| lookingAt.getLocation().distanceSquared(npc.getEntity().getLocation()) > range) {
lookingAt = null;
}
return lookingAt == null;
@ -96,7 +98,7 @@ public class LookClose extends Trait implements Toggleable, CommandConfigurable
findNewTarget();
}
if (lookingAt != null && canSeeTarget()) {
Util.faceEntity(npc.getBukkitEntity(), lookingAt);
Util.faceEntity(npc.getEntity(), lookingAt);
}
}

View File

@ -16,13 +16,14 @@ public class NPCSkeletonType extends Trait {
@Override
public void onSpawn() {
skeleton = npc.getBukkitEntity() instanceof Skeleton ? (Skeleton) npc.getBukkitEntity() : null;
skeleton = npc.getEntity() instanceof Skeleton ? (Skeleton) npc.getEntity() : null;
}
@Override
public void run() {
if (skeleton != null)
if (skeleton != null) {
skeleton.setSkeletonType(type);
}
}
public void setType(org.bukkit.entity.Skeleton.SkeletonType type) {

View File

@ -31,8 +31,8 @@ public class OcelotModifiers extends Trait {
}
private void updateModifiers() {
if (npc.getBukkitEntity() instanceof Ocelot) {
Ocelot ocelot = (Ocelot) npc.getBukkitEntity();
if (npc.getEntity() instanceof Ocelot) {
Ocelot ocelot = (Ocelot) npc.getEntity();
ocelot.setCatType(type);
ocelot.setSitting(sitting);
}

View File

@ -37,7 +37,7 @@ public class Poses extends Trait {
if (!npc.isSpawned())
npc.spawn(npc.getTrait(CurrentLocation.class).getLocation());
Util.assumePose(npc.getBukkitEntity(), yaw, pitch);
Util.assumePose(npc.getEntity(), yaw, pitch);
}
public void assumePose(Location location) {

View File

@ -15,15 +15,15 @@ public class Powered extends Trait implements Toggleable {
@Override
public void onSpawn() {
if (npc.getBukkitEntity() instanceof Creeper)
((Creeper) npc.getBukkitEntity()).setPowered(powered);
if (npc.getEntity() instanceof Creeper)
((Creeper) npc.getEntity()).setPowered(powered);
}
@Override
public boolean toggle() {
powered = !powered;
if (npc.getBukkitEntity() instanceof Creeper)
((Creeper) npc.getBukkitEntity()).setPowered(powered);
if (npc.getEntity() instanceof Creeper)
((Creeper) npc.getEntity()).setPowered(powered);
return powered;
}

View File

@ -25,8 +25,8 @@ public class Saddle extends Trait implements Toggleable {
@Override
public void onSpawn() {
if (npc.getBukkitEntity() instanceof Pig) {
((Pig) npc.getBukkitEntity()).setSaddle(saddle);
if (npc.getEntity() instanceof Pig) {
((Pig) npc.getEntity()).setSaddle(saddle);
pig = true;
} else
pig = false;
@ -36,7 +36,7 @@ public class Saddle extends Trait implements Toggleable {
public boolean toggle() {
saddle = !saddle;
if (pig)
((Pig) npc.getBukkitEntity()).setSaddle(saddle);
((Pig) npc.getEntity()).setSaddle(saddle);
return saddle;
}

View File

@ -24,15 +24,15 @@ public class Sheared extends Trait implements Toggleable {
@Override
public void onSpawn() {
if (npc.getBukkitEntity() instanceof Sheep)
((Sheep) npc.getBukkitEntity()).setSheared(sheared);
if (npc.getEntity() instanceof Sheep)
((Sheep) npc.getEntity()).setSheared(sheared);
}
@Override
public boolean toggle() {
sheared = !sheared;
if (npc.getBukkitEntity() instanceof Sheep)
((Sheep) npc.getBukkitEntity()).setSheared(sheared);
if (npc.getEntity() instanceof Sheep)
((Sheep) npc.getEntity()).setSheared(sheared);
return sheared;
}

View File

@ -23,17 +23,17 @@ public class SlimeSize extends Trait {
@Override
public void onSpawn() {
if (!(npc.getBukkitEntity() instanceof Slime)) {
if (!(npc.getEntity() instanceof Slime)) {
slime = false;
return;
}
((Slime) npc.getBukkitEntity()).setSize(size);
((Slime) npc.getEntity()).setSize(size);
slime = true;
}
public void setSize(int size) {
this.size = size;
if (slime)
((Slime) npc.getBukkitEntity()).setSize(size);
((Slime) npc.getEntity()).setSize(size);
}
}

View File

@ -25,8 +25,8 @@ public class VillagerProfession extends Trait {
@Override
public void onSpawn() {
if (npc.getBukkitEntity() instanceof Villager)
((Villager) npc.getBukkitEntity()).setProfession(profession);
if (npc.getEntity() instanceof Villager)
((Villager) npc.getEntity()).setProfession(profession);
}
@Override
@ -36,8 +36,8 @@ public class VillagerProfession extends Trait {
public void setProfession(Profession profession) {
this.profession = profession;
if (npc.getBukkitEntity() instanceof Villager)
((Villager) npc.getBukkitEntity()).setProfession(profession);
if (npc.getEntity() instanceof Villager)
((Villager) npc.getEntity()).setProfession(profession);
}
@Override

View File

@ -46,8 +46,8 @@ public class WolfModifiers extends Trait {
}
private void updateModifiers() {
if (npc.getBukkitEntity() instanceof Wolf) {
Wolf wolf = (Wolf) npc.getBukkitEntity();
if (npc.getEntity() instanceof Wolf) {
Wolf wolf = (Wolf) npc.getEntity();
wolf.setCollarColor(collarColor);
wolf.setSitting(sitting);
wolf.setAngry(angry);

View File

@ -35,11 +35,12 @@ public class WoolColor extends Trait {
@Override
public void onSpawn() {
if (npc.getBukkitEntity() instanceof Sheep) {
((Sheep) npc.getBukkitEntity()).setColor(color);
if (npc.getEntity() instanceof Sheep) {
((Sheep) npc.getEntity()).setColor(color);
sheep = true;
} else
} else {
sheep = false;
}
}
@Override
@ -49,8 +50,9 @@ public class WoolColor extends Trait {
public void setColor(DyeColor color) {
this.color = color;
if (sheep)
((Sheep) npc.getBukkitEntity()).setColor(color);
if (sheep) {
((Sheep) npc.getEntity()).setColor(color);
}
}
@Override

View File

@ -18,9 +18,9 @@ public class ZombieModifier extends Trait {
@Override
public void onSpawn() {
if (npc.getBukkitEntity() instanceof Zombie) {
((Zombie) npc.getBukkitEntity()).setVillager(villager);
((Zombie) npc.getBukkitEntity()).setBaby(baby);
if (npc.getEntity() instanceof Zombie) {
((Zombie) npc.getEntity()).setVillager(villager);
((Zombie) npc.getEntity()).setBaby(baby);
zombie = true;
} else
zombie = false;
@ -29,14 +29,14 @@ public class ZombieModifier extends Trait {
public boolean toggleBaby() {
baby = !baby;
if (zombie)
((Zombie) npc.getBukkitEntity()).setBaby(baby);
((Zombie) npc.getEntity()).setBaby(baby);
return baby;
}
public boolean toggleVillager() {
villager = !villager;
if (zombie)
((Zombie) npc.getBukkitEntity()).setVillager(villager);
((Zombie) npc.getEntity()).setVillager(villager);
return villager;
}
}

View File

@ -129,7 +129,7 @@ public class Text extends Trait implements Runnable, Toggleable, Listener, Conve
public void run() {
if (!talkClose || !npc.isSpawned())
return;
List<Entity> nearby = npc.getBukkitEntity().getNearbyEntities(range, range, range);
List<Entity> nearby = npc.getEntity().getNearbyEntities(range, range, range);
for (Entity search : nearby) {
if (!(search instanceof Player))
continue;

View File

@ -98,7 +98,7 @@ public class GuidedWaypointProvider implements WaypointProvider {
if (!event.getPlayer().equals(player) || event.getAction() == Action.PHYSICAL
|| event.getClickedBlock() == null)
return;
if (event.getPlayer().getWorld() != npc.getBukkitEntity().getWorld())
if (event.getPlayer().getWorld() != npc.getEntity().getWorld())
return;
event.setCancelled(true);
Location at = event.getClickedBlock().getLocation();

View File

@ -237,7 +237,7 @@ public class LinearWaypointProvider implements WaypointProvider {
public void onPlayerInteract(PlayerInteractEvent event) {
if (!event.getPlayer().equals(player) || event.getAction() == Action.PHYSICAL)
return;
if (event.getPlayer().getWorld() != npc.getBukkitEntity().getWorld())
if (event.getPlayer().getWorld() != npc.getEntity().getWorld())
return;
if (event.getAction() == Action.LEFT_CLICK_BLOCK || event.getAction() == Action.LEFT_CLICK_AIR) {
if (event.getClickedBlock() == null)
@ -405,7 +405,7 @@ public class LinearWaypointProvider implements WaypointProvider {
}
this.selector = selector;
Waypoint next = itr.next();
Location npcLoc = npc.getBukkitEntity().getLocation(cachedLocation);
Location npcLoc = npc.getEntity().getLocation(cachedLocation);
if (npcLoc.getWorld() != next.getLocation().getWorld()
|| npcLoc.distanceSquared(next.getLocation()) < npc.getNavigator().getLocalParameters()
.distanceMargin()) {
@ -418,7 +418,7 @@ public class LinearWaypointProvider implements WaypointProvider {
public void onCompletion(@Nullable CancelReason cancelReason) {
if (npc.isSpawned()
&& currentDestination != null
&& Util.locationWithinRange(npc.getBukkitEntity().getLocation(),
&& Util.locationWithinRange(npc.getEntity().getLocation(),
currentDestination.getLocation(), 4)) {
currentDestination.onReach(npc);
}

View File

@ -32,10 +32,11 @@ public class AnimationTrigger implements WaypointTrigger {
@Override
public void onWaypointReached(NPC npc, Location waypoint) {
if (npc.getBukkitEntity().getType() != EntityType.PLAYER)
if (npc.getEntity().getType() != EntityType.PLAYER)
return;
Player player = (Player) npc.getBukkitEntity();
for (PlayerAnimation animation : animations)
Player player = (Player) npc.getEntity();
for (PlayerAnimation animation : animations) {
animation.play(player);
}
}
}

View File

@ -36,12 +36,12 @@ public class ChatTrigger implements WaypointTrigger {
@Override
public void onWaypointReached(NPC npc, Location waypoint) {
if (radius < 0) {
for (Player player : npc.getBukkitEntity().getWorld().getPlayers()) {
for (Player player : npc.getEntity().getWorld().getPlayers()) {
for (String line : lines)
Messaging.send(player, line);
}
} else {
for (Entity entity : npc.getBukkitEntity().getNearbyEntities(radius, radius, radius)) {
for (Entity entity : npc.getEntity().getNearbyEntities(radius, radius, radius)) {
if (!(entity instanceof Player))
continue;
for (String line : lines)

View File

@ -52,10 +52,10 @@ public class NMS {
// util class
}
public static void addOrRemoveFromPlayerList(LivingEntity bukkitEntity, boolean remove) {
if (bukkitEntity == null)
public static void addOrRemoveFromPlayerList(org.bukkit.entity.Entity entity, boolean remove) {
if (entity == null)
return;
EntityLiving handle = getHandle(bukkitEntity);
Entity handle = getHandle(entity);
if (handle.world == null)
return;
if (remove) {
@ -178,8 +178,8 @@ public class NMS {
return DEFAULT_SPEED;
}
public static boolean inWater(LivingEntity entity) {
EntityLiving mcEntity = getHandle(entity);
public static boolean inWater(org.bukkit.entity.Entity entity) {
Entity mcEntity = getHandle(entity);
return mcEntity.H() || mcEntity.J();
}
@ -199,8 +199,8 @@ public class NMS {
}
}
public static void look(LivingEntity bukkitEntity, float yaw, float pitch) {
EntityLiving handle = getHandle(bukkitEntity);
public static void look(org.bukkit.entity.Entity entity, float yaw, float pitch) {
Entity handle = getHandle(entity);
handle.yaw = yaw;
setHeadYaw(handle, yaw);
handle.pitch = pitch;
@ -287,8 +287,8 @@ public class NMS {
}
}
public static void setDestination(LivingEntity bukkitEntity, double x, double y, double z, float speed) {
EntityLiving handle = ((CraftLivingEntity) bukkitEntity).getHandle();
public static void setDestination(org.bukkit.entity.Entity entity, double x, double y, double z, float speed) {
Entity handle = ((CraftEntity) entity).getHandle();
if (handle instanceof EntityInsentient) {
((EntityInsentient) handle).getControllerMove().a(x, y, z, speed);
} else if (handle instanceof EntityHumanNPC) {
@ -296,7 +296,10 @@ public class NMS {
}
}
public static void setHeadYaw(EntityLiving handle, float yaw) {
public static void setHeadYaw(Entity en, float yaw) {
if (!(en instanceof EntityLiving))
return;
EntityLiving handle = (EntityLiving) en;
while (yaw < -180.0F) {
yaw += 360.0F;
}
@ -310,8 +313,8 @@ public class NMS {
handle.aQ = yaw;
}
public static void setShouldJump(LivingEntity entity) {
EntityLiving handle = getHandle(entity);
public static void setShouldJump(org.bukkit.entity.Entity entity) {
Entity handle = getHandle(entity);
if (handle instanceof EntityInsentient) {
ControllerJump controller = ((EntityInsentient) handle).getControllerJump();
controller.a();
@ -324,8 +327,10 @@ public class NMS {
entity.Y = height;
}
public static void setVerticalMovement(LivingEntity bukkitEntity, double d) {
EntityLiving handle = NMS.getHandle(bukkitEntity);
public static void setVerticalMovement(org.bukkit.entity.Entity bukkitEntity, double d) {
if (!bukkitEntity.getType().isAlive())
return;
EntityLiving handle = NMS.getHandle((LivingEntity) bukkitEntity);
handle.bf = (float) d;
}
@ -374,11 +379,11 @@ public class NMS {
}
}
public static void trySwim(LivingEntity handle) {
trySwim(handle, 0.04F);
public static void trySwim(org.bukkit.entity.Entity entity) {
trySwim(entity, 0.04F);
}
public static void trySwim(LivingEntity entity, float power) {
public static void trySwim(org.bukkit.entity.Entity entity, float power) {
Entity handle = getHandle(entity);
if (RANDOM.nextFloat() < 0.8F && inWater(entity)) {
handle.motY += power;
@ -402,10 +407,10 @@ public class NMS {
navigation.f();
}
public static void updateNavigationWorld(LivingEntity entity, org.bukkit.World world) {
public static void updateNavigationWorld(org.bukkit.entity.Entity entity, org.bukkit.World world) {
if (NAVIGATION_WORLD_FIELD == null)
return;
EntityLiving en = ((CraftLivingEntity) entity).getHandle();
Entity en = ((CraftEntity) entity).getHandle();
if (!(en instanceof EntityInsentient))
return;
EntityInsentient handle = (EntityInsentient) en;
@ -418,9 +423,9 @@ public class NMS {
}
public static void updatePathfindingRange(NPC npc, float pathfindingRange) {
if (!npc.isSpawned())
if (!npc.isSpawned() || !npc.getEntity().getType().isAlive())
return;
EntityLiving en = ((CraftLivingEntity) npc.getBukkitEntity()).getHandle();
EntityLiving en = ((CraftLivingEntity) npc.getEntity()).getHandle();
if (!(en instanceof EntityInsentient)) {
if (en instanceof EntityHumanNPC) {
((EntityHumanNPC) en).updatePathfindingRange(pathfindingRange);

View File

@ -23,7 +23,7 @@ public class Util {
private Util() {
}
public static void assumePose(LivingEntity entity, float yaw, float pitch) {
public static void assumePose(Entity entity, float yaw, float pitch) {
NMS.look(entity, yaw, pitch);
}
@ -39,16 +39,16 @@ public class Util {
return event;
}
public static void faceEntity(LivingEntity from, LivingEntity at) {
if (from.getWorld() != at.getWorld())
public static void faceEntity(Entity entity, Entity at) {
if (entity.getWorld() != at.getWorld())
return;
faceLocation(from, at.getLocation(AT_LOCATION));
faceLocation(entity, at.getLocation(AT_LOCATION));
}
public static void faceLocation(LivingEntity from, Location to) {
if (from.getWorld() != to.getWorld())
public static void faceLocation(Entity entity, Location to) {
if (entity.getWorld() != to.getWorld())
return;
Location fromLocation = from.getLocation(FROM_LOCATION);
Location fromLocation = entity.getLocation(FROM_LOCATION);
double xDiff, yDiff, zDiff;
xDiff = to.getX() - fromLocation.getX();
yDiff = to.getY() - fromLocation.getY();
@ -62,7 +62,11 @@ public class Util {
if (zDiff < 0.0)
yaw += Math.abs(180 - yaw) * 2;
NMS.look(from, (float) yaw - 90, (float) pitch);
NMS.look(entity, (float) yaw - 90, (float) pitch);
}
public static Location getEyeLocation(Entity entity) {
return entity instanceof LivingEntity ? ((LivingEntity) entity).getEyeLocation() : entity.getLocation();
}
public static Random getFastRandom() {