Remove NMS-specific code from some places

This commit is contained in:
fullwall 2016-07-13 20:18:49 +08:00
parent b90b98bad2
commit f5ba51880c
10 changed files with 148 additions and 140 deletions

View File

@ -31,6 +31,7 @@ import org.bukkit.entity.ItemFrame;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Ocelot;
import org.bukkit.entity.Player;
import org.bukkit.entity.Rabbit;
import org.bukkit.entity.Skeleton.SkeletonType;
import org.bukkit.entity.Villager.Profession;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
@ -88,7 +89,6 @@ import net.citizensnpcs.trait.OcelotModifiers;
import net.citizensnpcs.trait.Poses;
import net.citizensnpcs.trait.Powered;
import net.citizensnpcs.trait.RabbitType;
import net.citizensnpcs.trait.RabbitType.RabbitTypes;
import net.citizensnpcs.trait.ScriptTrait;
import net.citizensnpcs.trait.SheepTrait;
import net.citizensnpcs.trait.SkinLayers;
@ -101,6 +101,7 @@ import net.citizensnpcs.trait.ZombieModifier;
import net.citizensnpcs.util.Anchor;
import net.citizensnpcs.util.Messages;
import net.citizensnpcs.util.NMS;
import net.citizensnpcs.util.PlayerAnimation;
import net.citizensnpcs.util.StringHelper;
import net.citizensnpcs.util.Util;
@ -1005,7 +1006,7 @@ public class NPCCommands {
}
@Command(aliases = { "npc" }, desc = "Show basic NPC information", max = 0, permission = "citizens.npc.info")
public void npc(CommandContext args, CommandSender sender, NPC npc) {
public void npc(CommandContext args, CommandSender sender, final NPC npc) {
Messaging.send(sender, StringHelper.wrapHeader(npc.getName()));
Messaging.send(sender, " <a>ID: <e>" + npc.getId());
Messaging.send(sender, " <a>Type: <e>" + npc.getTrait(MobType.class).getType());
@ -1023,6 +1024,12 @@ public class NPCCommands {
String message = " <e>- <a>" + trait.getName();
Messaging.send(sender, message);
}
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), new Runnable() {
@Override
public void run() {
PlayerAnimation.SLEEP.play((Player) npc.getEntity());
}
});
}
@Command(
@ -1270,11 +1277,11 @@ public class NPCCommands {
permission = "citizens.npc.rabbittype")
@Requirements(selected = true, ownership = true, types = { EntityType.RABBIT })
public void rabbitType(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
RabbitTypes type;
Rabbit.Type type;
try {
type = RabbitTypes.valueOf(args.getString(1).toUpperCase());
type = Rabbit.Type.valueOf(args.getString(1).toUpperCase());
} catch (IllegalArgumentException ex) {
throw new CommandException(Messages.INVALID_RABBIT_TYPE, StringUtils.join(RabbitTypes.values(), ","));
throw new CommandException(Messages.INVALID_RABBIT_TYPE, StringUtils.join(Rabbit.Type.values(), ","));
}
npc.getTrait(RabbitType.class).setType(type);
Messaging.sendTr(sender, Messages.RABBIT_TYPE_SET, npc.getName(), type.name());

View File

@ -8,8 +8,6 @@ import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.craftbukkit.v1_10_R1.entity.CraftEntity;
import org.bukkit.craftbukkit.v1_10_R1.entity.CraftPlayer;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
@ -47,7 +45,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_10_R1.PacketPlayOutEntityTeleport;
public class CitizensNPC extends AbstractNPC {
private EntityController entityController;
@ -199,8 +196,7 @@ public class CitizensNPC extends AbstractNPC {
entityController.spawn(at, this);
net.minecraft.server.v1_10_R1.Entity mcEntity = ((CraftEntity) getEntity()).getHandle();
boolean couldSpawn = !Util.isLoaded(at) ? false : mcEntity.world.addEntity(mcEntity, SpawnReason.CUSTOM);
boolean couldSpawn = !Util.isLoaded(at) ? false : NMS.addEntityToWorld(getEntity(), SpawnReason.CUSTOM);
// send skin packets, if applicable, before other NMS packets are sent
if (couldSpawn) {
@ -210,7 +206,7 @@ public class CitizensNPC extends AbstractNPC {
}
}
mcEntity.setPositionRotation(at.getX(), at.getY(), at.getZ(), at.getYaw(), at.getPitch());
getEntity().teleport(at);
if (!couldSpawn) {
Messaging.debug("Retrying spawn of", getId(), "later due to chunk being unloaded.",
@ -221,7 +217,7 @@ public class CitizensNPC extends AbstractNPC {
return false;
}
NMS.setHeadYaw(mcEntity, at.getYaw());
NMS.setHeadYaw(getEntity(), at.getYaw());
getEntity().setMetadata(NPC_METADATA_MARKER, new FixedMetadataValue(CitizensAPI.getPlugin(), true));
@ -262,11 +258,9 @@ public class CitizensNPC extends AbstractNPC {
}
if (getEntity() instanceof Player) {
final CraftPlayer player = (CraftPlayer) getEntity();
NMS.replaceTrackerEntry(player);
NMS.replaceTrackerEntry((Player) getEntity());
}
}
Messaging.debug("Spawned", getId(), at, mcEntity.valid);
return true;
}
@ -315,8 +309,7 @@ public class CitizensNPC extends AbstractNPC {
}
}
Player player = getEntity() instanceof Player ? (Player) getEntity() : null;
NMS.sendPacketNearby(player, getStoredLocation(),
new PacketPlayOutEntityTeleport(NMS.getHandle(getEntity())));
NMS.sendPositionUpdate(player, getEntity(), getStoredLocation());
}
if (getEntity() instanceof LivingEntity) {

View File

@ -61,17 +61,17 @@ public class AStarNavigationStrategy extends AbstractPathStrategy {
if (getCancelReason() != null || plan == null || plan.isComplete()) {
return true;
}
if (npc.getEntity().getLocation(NPC_LOCATION).toVector().distanceSquared(vector) <= params.distanceMargin()) {
Location currLoc = npc.getEntity().getLocation(NPC_LOCATION);
if (currLoc.toVector().distanceSquared(vector) <= params.distanceMargin()) {
plan.update(npc);
if (plan.isComplete()) {
return true;
}
vector = plan.getCurrentVector();
}
net.minecraft.server.v1_10_R1.Entity handle = NMS.getHandle(npc.getEntity());
double dX = vector.getBlockX() - handle.locX;
double dZ = vector.getBlockZ() - handle.locZ;
double dY = vector.getY() - handle.locY;
double dX = vector.getBlockX() - currLoc.getX();
double dZ = vector.getBlockZ() - currLoc.getZ();
double dY = vector.getY() - currLoc.getY();
double xzDistance = dX * dX + dZ * dZ;
double distance = xzDistance + dY * dY;
if (Setting.DEBUG_PATHFINDING.asBoolean()) {

View File

@ -16,8 +16,7 @@ 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.NMS;
import net.minecraft.server.v1_10_R1.MathHelper;
import net.citizensnpcs.util.NMS;
public class FlyingAStarNavigationStrategy extends AbstractPathStrategy {
private final NPC npc;
@ -94,7 +93,13 @@ public class FlyingAStarNavigationStrategy extends AbstractPathStrategy {
motY += (Math.signum(d1) * 0.7D - motY) * 0.1;
motZ += (Math.signum(d2) * 0.5D - motZ) * 0.1;
float targetYaw = (float) (Math.atan2(motZ, motX) * 180.0D / Math.PI) - 90.0F;
float normalisedTargetYaw = MathHelper.g(targetYaw - current.getYaw());
float normalisedTargetYaw = (targetYaw - current.getYaw()) % 360;
if (normalisedTargetYaw >= 180.0F) {
normalisedTargetYaw -= 360.0F;
}
if (normalisedTargetYaw < -180.0F) {
normalisedTargetYaw += 360.0F;
}
velocity.setX(motX).setY(motY).setZ(motZ).multiply(parameters.speed());
npc.getEntity().setVelocity(velocity);

View File

@ -1,9 +1,11 @@
package net.citizensnpcs.trait;
import java.lang.reflect.Constructor;
import java.util.List;
import java.util.Map;
import org.bukkit.craftbukkit.v1_10_R1.entity.CraftPlayer;
import org.bukkit.Location;
import org.bukkit.entity.EnderDragon;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
@ -27,11 +29,7 @@ import net.citizensnpcs.api.trait.trait.Owner;
import net.citizensnpcs.api.util.DataKey;
import net.citizensnpcs.util.NMS;
import net.citizensnpcs.util.Util;
import net.minecraft.server.v1_10_R1.EntityEnderDragon;
import net.minecraft.server.v1_10_R1.EntityLiving;
import net.minecraft.server.v1_10_R1.EntityPlayer;
//TODO: reduce reliance on CitizensNPC
@TraitName("controllable")
public class Controllable extends Trait implements Toggleable, CommandConfigurable {
private MovementController controller = new GroundController();
@ -60,31 +58,29 @@ public class Controllable extends Trait implements Toggleable, CommandConfigurab
explicitType = EntityType.UNKNOWN;
} else if (args.hasFlag('r')) {
explicitType = null;
} else if (args.hasValueFlag("explicittype"))
} else if (args.hasValueFlag("explicittype")) {
explicitType = Util.matchEntityType(args.getFlag("explicittype"));
}
if (npc.isSpawned()) {
loadController();
}
}
private void enterOrLeaveVehicle(Player player) {
EntityPlayer handle = ((CraftPlayer) player).getHandle();
if (getHandle().isVehicle()) {
if (getHandle().passengers.contains(handle)) {
List<Entity> passengers = NMS.getPassengers(player);
if (passengers.size() > 0) {
if (passengers.contains(player)) {
player.leaveVehicle();
}
return;
}
if (ownerRequired && !npc.getTrait(Owner.class).isOwnedBy(handle.getBukkitEntity())) {
if (ownerRequired && !npc.getTrait(Owner.class).isOwnedBy(player)) {
return;
}
NMS.mount(npc.getEntity(), player);
}
private net.minecraft.server.v1_10_R1.Entity getHandle() {
return NMS.getHandle(npc.getEntity());
}
public boolean isEnabled() {
return enabled;
}
@ -138,7 +134,7 @@ public class Controllable extends Trait implements Toggleable, CommandConfigurab
if (!npc.isSpawned() || !enabled)
return;
Action performed = event.getAction();
if (!getHandle().passengers.contains(getHandle()))
if (NMS.getPassengers(npc.getEntity()).contains(npc.getEntity()))
return;
switch (performed) {
case RIGHT_CLICK_BLOCK:
@ -168,10 +164,12 @@ public class Controllable extends Trait implements Toggleable, CommandConfigurab
@Override
public void run() {
if (!enabled || !npc.isSpawned() || !getHandle().isVehicle()
|| !(getHandle().passengers.get(0).getBukkitEntity() instanceof Player))
if (!enabled || !npc.isSpawned())
return;
controller.run((Player) getHandle().passengers.get(0).getBukkitEntity());
List<Entity> passengers = NMS.getPassengers(npc.getEntity());
if (passengers.size() == 0 || !(passengers.get(0) instanceof Player))
return;
controller.run((Player) passengers.get(0));
}
@Override
@ -188,17 +186,20 @@ public class Controllable extends Trait implements Toggleable, CommandConfigurab
return enabled;
}
private void setMountedYaw(net.minecraft.server.v1_10_R1.Entity handle) {
if (handle instanceof EntityEnderDragon || !Setting.USE_BOAT_CONTROLS.asBoolean())
private void setMountedYaw(Entity entity) {
if (entity instanceof EnderDragon || !Setting.USE_BOAT_CONTROLS.asBoolean())
return; // EnderDragon handles this separately
double tX = handle.locX + handle.motX;
double tZ = handle.locZ + handle.motZ;
if (handle.locZ > tZ) {
handle.yaw = (float) -Math.toDegrees(Math.atan((handle.locX - tX) / (handle.locZ - tZ))) + 180F;
} else if (handle.locZ < tZ) {
handle.yaw = (float) -Math.toDegrees(Math.atan((handle.locX - tX) / (handle.locZ - tZ)));
Location loc = entity.getLocation();
Vector vel = entity.getVelocity();
double tX = loc.getX() + vel.getX();
double tZ = loc.getZ() + vel.getZ();
if (loc.getX() > tZ) {
loc.setYaw((float) -Math.toDegrees(Math.atan((loc.getX() - tX) / (loc.getZ() - tZ))) + 180F);
} else if (loc.getZ() < tZ) {
loc.setYaw((float) -Math.toDegrees(Math.atan((loc.getX() - tX) / (loc.getZ() - tZ))));
}
NMS.setHeadYaw(handle, handle.yaw);
entity.teleport(loc);
NMS.setHeadYaw(entity, loc.getYaw());
}
public void setOwnerRequired(boolean ownerRequired) {
@ -208,20 +209,21 @@ public class Controllable extends Trait implements Toggleable, CommandConfigurab
@Override
public boolean toggle() {
enabled = !enabled;
if (!enabled && getHandle().isVehicle()) {
getHandle().passengers.get(0).getBukkitEntity().leaveVehicle();
if (!enabled && NMS.getPassengers(npc.getEntity()).size() > 0) {
NMS.getPassengers(npc.getEntity()).get(0).leaveVehicle();
}
return enabled;
}
private double updateHorizontalSpeed(net.minecraft.server.v1_10_R1.Entity handle,
net.minecraft.server.v1_10_R1.Entity passenger, double speed, float speedMod) {
double oldSpeed = Math.sqrt(handle.motX * handle.motX + handle.motZ * handle.motZ);
double angle = Math.toRadians(passenger.yaw - ((EntityLiving) passenger).bf * 45.0F);
handle.motX += speedMod * -Math.sin(angle) * ((EntityLiving) passenger).bg * 0.05;
handle.motZ += speedMod * Math.cos(angle) * ((EntityLiving) passenger).bg * 0.05;
private double updateHorizontalSpeed(Entity handle, Entity passenger, double speed, float speedMod) {
Vector hvel = handle.getVelocity();
double oldSpeed = Math.sqrt(hvel.getX() * hvel.getX() + hvel.getZ() * hvel.getZ());
double angle = Math.toRadians(passenger.getLocation().getYaw() - NMS.getVerticalMovement(passenger) * 45.0F);
hvel = hvel.add(new Vector(speedMod * -Math.sin(angle) * NMS.getHorizontalMovement(passenger) * 0.05, 0,
speedMod * Math.cos(angle) * NMS.getHorizontalMovement(passenger) * 0.05));
handle.setVelocity(hvel);
double newSpeed = Math.sqrt(handle.motX * handle.motX + handle.motZ * handle.motZ);
double newSpeed = Math.sqrt(hvel.getX() * hvel.getX() + hvel.getZ() * hvel.getZ());
if (newSpeed > oldSpeed && speed < 0.35D) {
return (float) Math.min(0.35D, (speed + ((0.35D - speed) / 35.0D)));
} else {
@ -248,25 +250,22 @@ public class Controllable extends Trait implements Toggleable, CommandConfigurab
@Override
public void run(Player rider) {
net.minecraft.server.v1_10_R1.Entity handle = getHandle();
net.minecraft.server.v1_10_R1.Entity passenger = ((CraftPlayer) rider).getHandle();
boolean onGround = handle.onGround;
boolean onGround = NMS.isOnGround(npc.getEntity());
float speedMod = npc.getNavigator().getDefaultParameters()
.modifiedSpeed((onGround ? GROUND_SPEED : AIR_SPEED));
speed = updateHorizontalSpeed(handle, passenger, speed, speedMod);
speed = updateHorizontalSpeed(npc.getEntity(), rider, speed, speedMod);
boolean shouldJump = NMS.shouldJump(passenger);
boolean shouldJump = NMS.shouldJump(rider);
if (shouldJump) {
if (handle.onGround && jumpTicks == 0) {
getHandle().motY = JUMP_VELOCITY;
if (onGround && jumpTicks == 0) {
npc.getEntity().setVelocity(npc.getEntity().getVelocity().setY(JUMP_VELOCITY));
jumpTicks = 10;
}
} else {
jumpTicks = 0;
}
jumpTicks = Math.max(0, jumpTicks - 1);
setMountedYaw(handle);
setMountedYaw(npc.getEntity());
}
private static final float AIR_SPEED = 1.5F;
@ -295,16 +294,13 @@ public class Controllable extends Trait implements Toggleable, CommandConfigurab
@Override
public void run(Player rider) {
if (paused) {
getHandle().motY = 0.001;
npc.getEntity().setVelocity(npc.getEntity().getVelocity().setY(0.001));
return;
}
Vector dir = rider.getEyeLocation().getDirection();
dir.multiply(npc.getNavigator().getDefaultParameters().speedModifier());
net.minecraft.server.v1_10_R1.Entity handle = getHandle();
handle.motX = dir.getX();
handle.motY = dir.getY();
handle.motZ = dir.getZ();
setMountedYaw(handle);
npc.getEntity().setVelocity(dir);
setMountedYaw(npc.getEntity());
}
}
@ -329,7 +325,7 @@ public class Controllable extends Trait implements Toggleable, CommandConfigurab
@Override
public void rightClick(PlayerInteractEvent event) {
getHandle().motY = -0.3F;
npc.getEntity().setVelocity(npc.getEntity().getVelocity().setY(-0.3F));
}
@Override
@ -340,18 +336,16 @@ public class Controllable extends Trait implements Toggleable, CommandConfigurab
@Override
public void run(Player rider) {
if (paused) {
getHandle().motY = 0.001;
npc.getEntity().setVelocity(npc.getEntity().getVelocity().setY(0.001F));
return;
}
net.minecraft.server.v1_10_R1.Entity handle = getHandle();
net.minecraft.server.v1_10_R1.Entity passenger = ((CraftPlayer) rider).getHandle();
speed = updateHorizontalSpeed(handle, passenger, speed, 1F);
boolean shouldJump = NMS.shouldJump(passenger);
speed = updateHorizontalSpeed(npc.getEntity(), rider, speed, 1F);
boolean shouldJump = NMS.shouldJump(rider);
if (shouldJump) {
handle.motY = 0.3F;
npc.getEntity().setVelocity(npc.getEntity().getVelocity().setY(0.3F));
}
handle.motY *= 0.98F;
npc.getEntity().setVelocity(npc.getEntity().getVelocity().multiply(new Vector(1, 0.98, 1)));
}
}

View File

@ -1,6 +1,5 @@
package net.citizensnpcs.trait;
import org.bukkit.craftbukkit.v1_10_R1.entity.CraftRabbit;
import org.bukkit.entity.Rabbit;
import net.citizensnpcs.api.persistence.Persist;
@ -11,7 +10,7 @@ import net.citizensnpcs.api.trait.TraitName;
public class RabbitType extends Trait {
private Rabbit rabbit;
@Persist
private RabbitTypes type = RabbitTypes.BROWN;
private Rabbit.Type type = Rabbit.Type.BROWN;
public RabbitType() {
super("rabbittype");
@ -23,25 +22,10 @@ public class RabbitType extends Trait {
setType(type);
}
public void setType(RabbitTypes type) {
public void setType(Rabbit.Type type) {
this.type = type;
if (rabbit != null && rabbit.isValid()) {
((CraftRabbit) rabbit).getHandle().setRabbitType(type.type);
}
}
public enum RabbitTypes {
BLACK(2),
BLACKANDWHITE(3),
BROWN(0),
GOLD(4),
KILLER(99),
SALTANDPEPPER(5),
WHITE(1);
public int type;
RabbitTypes(int type) {
this.type = type;
rabbit.setRabbitType(type);
}
}
}

View File

@ -1,12 +1,11 @@
package net.citizensnpcs.trait;
import org.bukkit.craftbukkit.v1_10_R1.entity.CraftWither;
import org.bukkit.entity.Wither;
import net.citizensnpcs.api.persistence.Persist;
import net.citizensnpcs.api.trait.Trait;
import net.citizensnpcs.api.trait.TraitName;
import net.minecraft.server.v1_10_R1.EntityWither;
import net.citizensnpcs.util.NMS;
@TraitName("withertrait")
public class WitherTrait extends Trait {
@ -29,8 +28,7 @@ public class WitherTrait extends Trait {
public void run() {
if (npc.getEntity() instanceof Wither) {
Wither wither = (Wither) npc.getEntity();
EntityWither handle = ((CraftWither) wither).getHandle();
handle.l(charged ? 20 : 0);
NMS.setWitherCharged(wither, charged);
}
}

View File

@ -1,28 +0,0 @@
package net.citizensnpcs.trait.waypoint;
import net.minecraft.server.v1_10_R1.DamageSource;
import net.minecraft.server.v1_10_R1.EntityEnderSignal;
import net.minecraft.server.v1_10_R1.World;
public class EntityEnderSignalMarker extends EntityEnderSignal {
public EntityEnderSignalMarker(World world) {
super(world);
}
public EntityEnderSignalMarker(World world, double d0, double d1, double d2) {
super(world, d0, d1, d2);
}
@Override
public boolean damageEntity(DamageSource damagesource, float i) {
return false;
}
@Override
public void i() {
}
@Override
public void m() {
}
}

View File

@ -2,6 +2,8 @@ package net.citizensnpcs.trait.waypoint;
import java.util.Map;
import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.util.NMS;
import org.bukkit.Location;
@ -36,11 +38,14 @@ public class WaypointMarkers {
public void removeWaypointMarker(Waypoint waypoint) {
Entity entity = waypointMarkers.remove(waypoint);
if (entity != null)
if (entity != null) {
entity.remove();
}
}
public Entity spawnMarker(World world, Location at) {
return NMS.spawnCustomEntity(world, at, EntityEnderSignalMarker.class, EntityType.ENDER_SIGNAL);
NPC npc = CitizensAPI.getNPCRegistry().createNPC(EntityType.ENDER_SIGNAL, "");
npc.spawn(at);
return npc.getEntity();
}
}

View File

@ -30,6 +30,7 @@ import org.bukkit.craftbukkit.v1_10_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_10_R1.boss.CraftBossBar;
import org.bukkit.craftbukkit.v1_10_R1.entity.CraftEntity;
import org.bukkit.craftbukkit.v1_10_R1.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_10_R1.entity.CraftWither;
import org.bukkit.craftbukkit.v1_10_R1.event.CraftEventFactory;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.FishHook;
@ -37,11 +38,15 @@ import org.bukkit.entity.Horse;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Tameable;
import org.bukkit.entity.Wither;
import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
import org.bukkit.inventory.meta.SkullMeta;
import org.bukkit.plugin.PluginLoadOrder;
import com.google.common.base.Function;
import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
import com.mojang.authlib.GameProfile;
import com.mojang.authlib.GameProfileRepository;
import com.mojang.authlib.HttpAuthenticationService;
@ -93,6 +98,7 @@ import net.minecraft.server.v1_10_R1.MobEffects;
import net.minecraft.server.v1_10_R1.NavigationAbstract;
import net.minecraft.server.v1_10_R1.NetworkManager;
import net.minecraft.server.v1_10_R1.Packet;
import net.minecraft.server.v1_10_R1.PacketPlayOutEntityTeleport;
import net.minecraft.server.v1_10_R1.PacketPlayOutPlayerInfo;
import net.minecraft.server.v1_10_R1.PathfinderGoalSelector;
import net.minecraft.server.v1_10_R1.SoundEffect;
@ -107,6 +113,10 @@ public class NMS {
// util class
}
public static boolean addEntityToWorld(org.bukkit.entity.Entity entity, SpawnReason custom) {
return getHandle(entity).world.addEntity(getHandle(entity), custom);
}
public static void addOrRemoveFromPlayerList(org.bukkit.entity.Entity entity, boolean remove) {
if (entity == null)
return;
@ -449,11 +459,27 @@ public class NMS {
return handle.aP;
}
public static float getHorizontalMovement(org.bukkit.entity.Entity bukkitEntity) {
if (!bukkitEntity.getType().isAlive())
return Float.NaN;
EntityLiving handle = NMS.getHandle((LivingEntity) bukkitEntity);
return handle.bg;
}
public static NavigationAbstract getNavigation(Entity handle) {
return handle instanceof EntityInsentient ? ((EntityInsentient) handle).getNavigation()
: handle instanceof EntityHumanNPC ? ((EntityHumanNPC) handle).getNavigation() : null;
}
public static List<org.bukkit.entity.Entity> getPassengers(org.bukkit.entity.Entity entity) {
return Lists.transform(NMS.getHandle(entity).passengers, new Function<Entity, org.bukkit.entity.Entity>() {
@Override
public org.bukkit.entity.Entity apply(Entity input) {
return input.getBukkitEntity();
}
});
}
public static GameProfile getProfile(SkullMeta meta) {
if (SKULL_PROFILE_FIELD == null) {
try {
@ -530,6 +556,13 @@ public class NMS {
return e == getHandle(entity) ? null : e;
}
public static float getVerticalMovement(org.bukkit.entity.Entity bukkitEntity) {
if (!bukkitEntity.getType().isAlive())
return Float.NaN;
EntityLiving handle = NMS.getHandle((LivingEntity) bukkitEntity);
return handle.bf;
}
public static void initNetworkManager(NetworkManager network) {
if (NETWORK_ADDRESS == null)
return;
@ -556,6 +589,10 @@ public class NMS {
return navigation.n();
}
public static boolean isOnGround(org.bukkit.entity.Entity entity) {
return getHandle(entity).onGround;
}
public static boolean isPassenger(org.bukkit.entity.Entity entity) {
return NMS.getHandle(entity).isPassenger();
}
@ -719,6 +756,10 @@ public class NMS {
NMS.sendPacketsNearby(from, location, Arrays.asList(packets), 64);
}
public static void sendPositionUpdate(Player excluding, org.bukkit.entity.Entity from, Location storedLocation) {
sendPacketNearby(excluding, storedLocation, new PacketPlayOutEntityTeleport(getHandle(from)));
}
public static void sendTabListAdd(Player recipient, Player listPlayer) {
Preconditions.checkNotNull(recipient);
Preconditions.checkNotNull(listPlayer);
@ -787,6 +828,10 @@ public class NMS {
handle.aQ = yaw;
}
public static void setHeadYaw(org.bukkit.entity.Entity entity, float yaw) {
setHeadYaw(getHandle(entity), yaw);
}
public static void setKnockbackResistance(org.bukkit.entity.LivingEntity entity, double d) {
EntityLiving handle = NMS.getHandle(entity);
handle.getAttributeInstance(GenericAttributes.c).setValue(d);
@ -848,11 +893,16 @@ public class NMS {
handle.bf = (float) d;
}
public static boolean shouldJump(net.minecraft.server.v1_10_R1.Entity entity) {
if (JUMP_FIELD == null || !(entity instanceof EntityLiving))
public static void setWitherCharged(Wither wither, boolean charged) {
EntityWither handle = ((CraftWither) wither).getHandle();
handle.l(charged ? 20 : 0);
}
public static boolean shouldJump(org.bukkit.entity.Entity entity) {
if (JUMP_FIELD == null || !(entity instanceof LivingEntity))
return false;
try {
return JUMP_FIELD.getBoolean(entity);
return JUMP_FIELD.getBoolean(getHandle(entity));
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {