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.LivingEntity;
import org.bukkit.entity.Ocelot; import org.bukkit.entity.Ocelot;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.entity.Rabbit;
import org.bukkit.entity.Skeleton.SkeletonType; import org.bukkit.entity.Skeleton.SkeletonType;
import org.bukkit.entity.Villager.Profession; import org.bukkit.entity.Villager.Profession;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; 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.Poses;
import net.citizensnpcs.trait.Powered; import net.citizensnpcs.trait.Powered;
import net.citizensnpcs.trait.RabbitType; import net.citizensnpcs.trait.RabbitType;
import net.citizensnpcs.trait.RabbitType.RabbitTypes;
import net.citizensnpcs.trait.ScriptTrait; import net.citizensnpcs.trait.ScriptTrait;
import net.citizensnpcs.trait.SheepTrait; import net.citizensnpcs.trait.SheepTrait;
import net.citizensnpcs.trait.SkinLayers; import net.citizensnpcs.trait.SkinLayers;
@ -101,6 +101,7 @@ import net.citizensnpcs.trait.ZombieModifier;
import net.citizensnpcs.util.Anchor; import net.citizensnpcs.util.Anchor;
import net.citizensnpcs.util.Messages; import net.citizensnpcs.util.Messages;
import net.citizensnpcs.util.NMS; import net.citizensnpcs.util.NMS;
import net.citizensnpcs.util.PlayerAnimation;
import net.citizensnpcs.util.StringHelper; import net.citizensnpcs.util.StringHelper;
import net.citizensnpcs.util.Util; 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") @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, StringHelper.wrapHeader(npc.getName()));
Messaging.send(sender, " <a>ID: <e>" + npc.getId()); Messaging.send(sender, " <a>ID: <e>" + npc.getId());
Messaging.send(sender, " <a>Type: <e>" + npc.getTrait(MobType.class).getType()); Messaging.send(sender, " <a>Type: <e>" + npc.getTrait(MobType.class).getType());
@ -1023,6 +1024,12 @@ public class NPCCommands {
String message = " <e>- <a>" + trait.getName(); String message = " <e>- <a>" + trait.getName();
Messaging.send(sender, message); Messaging.send(sender, message);
} }
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), new Runnable() {
@Override
public void run() {
PlayerAnimation.SLEEP.play((Player) npc.getEntity());
}
});
} }
@Command( @Command(
@ -1270,11 +1277,11 @@ public class NPCCommands {
permission = "citizens.npc.rabbittype") permission = "citizens.npc.rabbittype")
@Requirements(selected = true, ownership = true, types = { EntityType.RABBIT }) @Requirements(selected = true, ownership = true, types = { EntityType.RABBIT })
public void rabbitType(CommandContext args, CommandSender sender, NPC npc) throws CommandException { public void rabbitType(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
RabbitTypes type; Rabbit.Type type;
try { try {
type = RabbitTypes.valueOf(args.getString(1).toUpperCase()); type = Rabbit.Type.valueOf(args.getString(1).toUpperCase());
} catch (IllegalArgumentException ex) { } 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); npc.getTrait(RabbitType.class).setType(type);
Messaging.sendTr(sender, Messages.RABBIT_TYPE_SET, npc.getName(), type.name()); 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.ChatColor;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.block.Block; 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.Entity;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
@ -47,7 +45,6 @@ import net.citizensnpcs.trait.CurrentLocation;
import net.citizensnpcs.util.Messages; import net.citizensnpcs.util.Messages;
import net.citizensnpcs.util.NMS; import net.citizensnpcs.util.NMS;
import net.citizensnpcs.util.Util; import net.citizensnpcs.util.Util;
import net.minecraft.server.v1_10_R1.PacketPlayOutEntityTeleport;
public class CitizensNPC extends AbstractNPC { public class CitizensNPC extends AbstractNPC {
private EntityController entityController; private EntityController entityController;
@ -199,8 +196,7 @@ public class CitizensNPC extends AbstractNPC {
entityController.spawn(at, this); entityController.spawn(at, this);
net.minecraft.server.v1_10_R1.Entity mcEntity = ((CraftEntity) getEntity()).getHandle(); boolean couldSpawn = !Util.isLoaded(at) ? false : NMS.addEntityToWorld(getEntity(), SpawnReason.CUSTOM);
boolean couldSpawn = !Util.isLoaded(at) ? false : mcEntity.world.addEntity(mcEntity, SpawnReason.CUSTOM);
// send skin packets, if applicable, before other NMS packets are sent // send skin packets, if applicable, before other NMS packets are sent
if (couldSpawn) { 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) { if (!couldSpawn) {
Messaging.debug("Retrying spawn of", getId(), "later due to chunk being unloaded.", Messaging.debug("Retrying spawn of", getId(), "later due to chunk being unloaded.",
@ -221,7 +217,7 @@ public class CitizensNPC extends AbstractNPC {
return false; return false;
} }
NMS.setHeadYaw(mcEntity, at.getYaw()); NMS.setHeadYaw(getEntity(), at.getYaw());
getEntity().setMetadata(NPC_METADATA_MARKER, new FixedMetadataValue(CitizensAPI.getPlugin(), true)); getEntity().setMetadata(NPC_METADATA_MARKER, new FixedMetadataValue(CitizensAPI.getPlugin(), true));
@ -262,11 +258,9 @@ public class CitizensNPC extends AbstractNPC {
} }
if (getEntity() instanceof Player) { if (getEntity() instanceof Player) {
final CraftPlayer player = (CraftPlayer) getEntity(); NMS.replaceTrackerEntry((Player) getEntity());
NMS.replaceTrackerEntry(player);
} }
} }
Messaging.debug("Spawned", getId(), at, mcEntity.valid);
return true; return true;
} }
@ -315,8 +309,7 @@ public class CitizensNPC extends AbstractNPC {
} }
} }
Player player = getEntity() instanceof Player ? (Player) getEntity() : null; Player player = getEntity() instanceof Player ? (Player) getEntity() : null;
NMS.sendPacketNearby(player, getStoredLocation(), NMS.sendPositionUpdate(player, getEntity(), getStoredLocation());
new PacketPlayOutEntityTeleport(NMS.getHandle(getEntity())));
} }
if (getEntity() instanceof LivingEntity) { if (getEntity() instanceof LivingEntity) {

View File

@ -61,17 +61,17 @@ public class AStarNavigationStrategy extends AbstractPathStrategy {
if (getCancelReason() != null || plan == null || plan.isComplete()) { if (getCancelReason() != null || plan == null || plan.isComplete()) {
return true; 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); plan.update(npc);
if (plan.isComplete()) { if (plan.isComplete()) {
return true; return true;
} }
vector = plan.getCurrentVector(); vector = plan.getCurrentVector();
} }
net.minecraft.server.v1_10_R1.Entity handle = NMS.getHandle(npc.getEntity()); double dX = vector.getBlockX() - currLoc.getX();
double dX = vector.getBlockX() - handle.locX; double dZ = vector.getBlockZ() - currLoc.getZ();
double dZ = vector.getBlockZ() - handle.locZ; double dY = vector.getY() - currLoc.getY();
double dY = vector.getY() - handle.locY;
double xzDistance = dX * dX + dZ * dZ; double xzDistance = dX * dX + dZ * dZ;
double distance = xzDistance + dY * dY; double distance = xzDistance + dY * dY;
if (Setting.DEBUG_PATHFINDING.asBoolean()) { 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.VectorGoal;
import net.citizensnpcs.api.astar.pathfinder.VectorNode; import net.citizensnpcs.api.astar.pathfinder.VectorNode;
import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.util.NMS; import net.citizensnpcs.util.NMS;
import net.minecraft.server.v1_10_R1.MathHelper;
public class FlyingAStarNavigationStrategy extends AbstractPathStrategy { public class FlyingAStarNavigationStrategy extends AbstractPathStrategy {
private final NPC npc; private final NPC npc;
@ -94,7 +93,13 @@ public class FlyingAStarNavigationStrategy extends AbstractPathStrategy {
motY += (Math.signum(d1) * 0.7D - motY) * 0.1; motY += (Math.signum(d1) * 0.7D - motY) * 0.1;
motZ += (Math.signum(d2) * 0.5D - motZ) * 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 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()); velocity.setX(motX).setY(motY).setZ(motZ).multiply(parameters.speed());
npc.getEntity().setVelocity(velocity); npc.getEntity().setVelocity(velocity);

View File

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

View File

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

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 java.util.Map;
import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.util.NMS; import net.citizensnpcs.util.NMS;
import org.bukkit.Location; import org.bukkit.Location;
@ -36,11 +38,14 @@ public class WaypointMarkers {
public void removeWaypointMarker(Waypoint waypoint) { public void removeWaypointMarker(Waypoint waypoint) {
Entity entity = waypointMarkers.remove(waypoint); Entity entity = waypointMarkers.remove(waypoint);
if (entity != null) if (entity != null) {
entity.remove(); entity.remove();
}
} }
public Entity spawnMarker(World world, Location at) { 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.boss.CraftBossBar;
import org.bukkit.craftbukkit.v1_10_R1.entity.CraftEntity; 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.CraftPlayer;
import org.bukkit.craftbukkit.v1_10_R1.entity.CraftWither;
import org.bukkit.craftbukkit.v1_10_R1.event.CraftEventFactory; import org.bukkit.craftbukkit.v1_10_R1.event.CraftEventFactory;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.entity.FishHook; import org.bukkit.entity.FishHook;
@ -37,11 +38,15 @@ import org.bukkit.entity.Horse;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.entity.Tameable; import org.bukkit.entity.Tameable;
import org.bukkit.entity.Wither;
import org.bukkit.event.entity.CreatureSpawnEvent; import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
import org.bukkit.inventory.meta.SkullMeta; import org.bukkit.inventory.meta.SkullMeta;
import org.bukkit.plugin.PluginLoadOrder; import org.bukkit.plugin.PluginLoadOrder;
import com.google.common.base.Function;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
import com.mojang.authlib.GameProfile; import com.mojang.authlib.GameProfile;
import com.mojang.authlib.GameProfileRepository; import com.mojang.authlib.GameProfileRepository;
import com.mojang.authlib.HttpAuthenticationService; 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.NavigationAbstract;
import net.minecraft.server.v1_10_R1.NetworkManager; import net.minecraft.server.v1_10_R1.NetworkManager;
import net.minecraft.server.v1_10_R1.Packet; 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.PacketPlayOutPlayerInfo;
import net.minecraft.server.v1_10_R1.PathfinderGoalSelector; import net.minecraft.server.v1_10_R1.PathfinderGoalSelector;
import net.minecraft.server.v1_10_R1.SoundEffect; import net.minecraft.server.v1_10_R1.SoundEffect;
@ -107,6 +113,10 @@ public class NMS {
// util class // 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) { public static void addOrRemoveFromPlayerList(org.bukkit.entity.Entity entity, boolean remove) {
if (entity == null) if (entity == null)
return; return;
@ -449,11 +459,27 @@ public class NMS {
return handle.aP; 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) { public static NavigationAbstract getNavigation(Entity handle) {
return handle instanceof EntityInsentient ? ((EntityInsentient) handle).getNavigation() return handle instanceof EntityInsentient ? ((EntityInsentient) handle).getNavigation()
: handle instanceof EntityHumanNPC ? ((EntityHumanNPC) handle).getNavigation() : null; : 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) { public static GameProfile getProfile(SkullMeta meta) {
if (SKULL_PROFILE_FIELD == null) { if (SKULL_PROFILE_FIELD == null) {
try { try {
@ -530,6 +556,13 @@ public class NMS {
return e == getHandle(entity) ? null : e; 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) { public static void initNetworkManager(NetworkManager network) {
if (NETWORK_ADDRESS == null) if (NETWORK_ADDRESS == null)
return; return;
@ -556,6 +589,10 @@ public class NMS {
return navigation.n(); 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) { public static boolean isPassenger(org.bukkit.entity.Entity entity) {
return NMS.getHandle(entity).isPassenger(); return NMS.getHandle(entity).isPassenger();
} }
@ -719,6 +756,10 @@ public class NMS {
NMS.sendPacketsNearby(from, location, Arrays.asList(packets), 64); 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) { public static void sendTabListAdd(Player recipient, Player listPlayer) {
Preconditions.checkNotNull(recipient); Preconditions.checkNotNull(recipient);
Preconditions.checkNotNull(listPlayer); Preconditions.checkNotNull(listPlayer);
@ -787,6 +828,10 @@ public class NMS {
handle.aQ = yaw; 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) { public static void setKnockbackResistance(org.bukkit.entity.LivingEntity entity, double d) {
EntityLiving handle = NMS.getHandle(entity); EntityLiving handle = NMS.getHandle(entity);
handle.getAttributeInstance(GenericAttributes.c).setValue(d); handle.getAttributeInstance(GenericAttributes.c).setValue(d);
@ -848,11 +893,16 @@ public class NMS {
handle.bf = (float) d; handle.bf = (float) d;
} }
public static boolean shouldJump(net.minecraft.server.v1_10_R1.Entity entity) { public static void setWitherCharged(Wither wither, boolean charged) {
if (JUMP_FIELD == null || !(entity instanceof EntityLiving)) 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; return false;
try { try {
return JUMP_FIELD.getBoolean(entity); return JUMP_FIELD.getBoolean(getHandle(entity));
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
e.printStackTrace(); e.printStackTrace();
} catch (IllegalAccessException e) { } catch (IllegalAccessException e) {