diff --git a/nmshandler/src/main/java/net/aufdemrand/denizen/nms/NMSHandler.java b/nmshandler/src/main/java/net/aufdemrand/denizen/nms/NMSHandler.java index 8e41c41573..f9b1425d26 100644 --- a/nmshandler/src/main/java/net/aufdemrand/denizen/nms/NMSHandler.java +++ b/nmshandler/src/main/java/net/aufdemrand/denizen/nms/NMSHandler.java @@ -19,7 +19,10 @@ import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.util.Vector; +import java.util.HashMap; +import java.util.HashSet; import java.util.Map; +import java.util.UUID; public abstract class NMSHandler { @@ -144,8 +147,32 @@ public static Vector fixOffset(Vector offset, double yaw, double pitch) { return offsetPatched; } + + public HashMap attachmentsA = new HashMap<>(); // Key follows value + public HashMap attachments2 = new HashMap<>(); // Value follows key + public HashMap attachmentOffsets = new HashMap<>(); + public HashSet attachmentRotations = new HashSet<>(); + public HashMap visiblePositions = new HashMap<>(); + public void forceAttachMove(Entity a, Entity b, Vector offset, boolean matchRotation) { - throw new RuntimeException("Unsupported forceAttachMove!"); + if (!getVersion().isAtLeast(NMSVersion.v1_12_R1)) { + throw new RuntimeException("Unsupported forceAttachMove!"); + } + if (attachmentsA.containsKey(a.getUniqueId())) { + attachments2.remove(attachmentsA.get(a.getUniqueId())); + attachmentsA.remove(a.getUniqueId()); + attachmentOffsets.remove(a.getUniqueId()); + attachmentRotations.remove(a.getUniqueId()); + } + if (b == null) { + return; + } + attachmentsA.put(a.getUniqueId(), b.getUniqueId()); + attachments2.put(b.getUniqueId(), a.getUniqueId()); + attachmentOffsets.put(a.getUniqueId(), offset); + if (matchRotation) { + attachmentRotations.add(a.getUniqueId()); + } } public Boolean getSwitchState(Block b) { diff --git a/nmshandler/src/main/java/net/aufdemrand/denizen/nms/interfaces/EntityHelper.java b/nmshandler/src/main/java/net/aufdemrand/denizen/nms/interfaces/EntityHelper.java index 22ee3645e3..08ea477e94 100644 --- a/nmshandler/src/main/java/net/aufdemrand/denizen/nms/interfaces/EntityHelper.java +++ b/nmshandler/src/main/java/net/aufdemrand/denizen/nms/interfaces/EntityHelper.java @@ -3,80 +3,240 @@ import net.aufdemrand.denizen.nms.util.BoundingBox; import net.aufdemrand.denizen.nms.util.jnbt.CompoundTag; import net.aufdemrand.denizencore.utilities.debugging.dB; +import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.World; import org.bukkit.block.BlockFace; import org.bukkit.entity.*; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerFishEvent; +import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.inventory.ItemStack; +import org.bukkit.plugin.Plugin; +import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.util.Vector; -import java.util.UUID; +import java.util.*; -public interface EntityHelper { +public abstract class EntityHelper { - default void setRiptide(Entity entity, boolean state) { + public void setRiptide(Entity entity, boolean state) { dB.echoError("Riptide control not available on this server version."); } - default void setCarriedItem(Enderman entity, ItemStack item) { + public void setCarriedItem(Enderman entity, ItemStack item) { entity.setCarriedMaterial(item.getData()); } - int getBodyArrows(Entity entity); + public abstract int getBodyArrows(Entity entity); - void setBodyArrows(Entity entity, int numArrows); + public abstract void setBodyArrows(Entity entity, int numArrows); - Entity getFishHook(PlayerFishEvent event); + public abstract Entity getFishHook(PlayerFishEvent event); - void forceInteraction(Player player, Location location); + public abstract void forceInteraction(Player player, Location location); - Entity getEntity(World world, UUID uuid); + public abstract Entity getEntity(World world, UUID uuid); - boolean isBreeding(Animals entity); + public abstract boolean isBreeding(Animals entity); - void setBreeding(Animals entity, boolean breeding); + public abstract void setBreeding(Animals entity, boolean breeding); - void setTarget(Creature entity, LivingEntity target); + public abstract void setTarget(Creature entity, LivingEntity target); - CompoundTag getNbtData(Entity entity); + public abstract CompoundTag getNbtData(Entity entity); - void setNbtData(Entity entity, CompoundTag compoundTag); + public abstract void setNbtData(Entity entity, CompoundTag compoundTag); - void setSilent(Entity entity, boolean silent); + public abstract void setSilent(Entity entity, boolean silent); - boolean isSilent(Entity entity); + public abstract boolean isSilent(Entity entity); - ItemStack getItemInHand(LivingEntity entity); + public abstract ItemStack getItemInHand(LivingEntity entity); - void setItemInHand(LivingEntity entity, ItemStack itemStack); + public abstract void setItemInHand(LivingEntity entity, ItemStack itemStack); - ItemStack getItemInOffHand(LivingEntity entity); + public abstract ItemStack getItemInOffHand(LivingEntity entity); - void setItemInOffHand(LivingEntity entity, ItemStack itemStack); + public abstract void setItemInOffHand(LivingEntity entity, ItemStack itemStack); - void stopFollowing(Entity follower); + public abstract void stopFollowing(Entity follower); - void stopWalking(Entity entity); + public abstract void stopWalking(Entity entity); - void toggleAI(Entity entity, boolean hasAI); + public abstract void toggleAI(Entity entity, boolean hasAI); - boolean isAIDisabled(Entity entity); + public abstract boolean isAIDisabled(Entity entity); - double getSpeed(Entity entity); + public abstract double getSpeed(Entity entity); - void setSpeed(Entity entity, double speed); + public abstract void setSpeed(Entity entity, double speed); - void follow(final Entity target, final Entity follower, final double speed, final double lead, + public abstract void follow(final Entity target, final Entity follower, final double speed, final double lead, final double maxRange, final boolean allowWander); - void walkTo(final Entity entity, Location location, double speed, final Runnable callback); + public abstract void walkTo(final Entity entity, Location location, double speed, final Runnable callback); - void hideEntity(Player player, Entity entity, boolean keepInTabList); + public class EnforcePlayerHides implements Listener { - void unhideEntity(Player player, Entity entity); + public Plugin denizenPlugin; - boolean isHidden(Player player, Entity entity); + @EventHandler + public void onPlayerJoin(PlayerJoinEvent event) { + for (UUID id : hiddenByDefaultPlayers) { + Entity pTarget = Bukkit.getEntity(id); + if (pTarget != null && pTarget instanceof Player) { + event.getPlayer().hidePlayer((Player) pTarget); + } + } + final Player pl = event.getPlayer(); + final Set hides = hiddenEntitiesPlEnt.get(pl.getUniqueId()); + if (hides == null || hides.isEmpty()) { + return; + } + new BukkitRunnable() { + @Override + public void run() { + if (pl.isOnline()) { + for (UUID id : hides) { + Entity ent = Bukkit.getEntity(id); + if (ent != null) { + sendHidePacket(pl, ent); + } + } + } + } + }.runTaskLater(denizenPlugin, 5); + } + } + + public void ensurePlayerHiding() { + if (EPH == null) { + Plugin pl = Bukkit.getPluginManager().getPlugin("Denizen"); // Very lazy way to get the correct plugin instance + EPH = new EnforcePlayerHides(); + EPH.denizenPlugin = pl; + Bukkit.getPluginManager().registerEvents(EPH, pl); + } + } + + public boolean addHide(UUID player, UUID entity) { + Set hidden = hiddenEntitiesEntPl.get(entity); + if (hidden == null) { + hidden = new HashSet(); + hiddenEntitiesEntPl.put(entity, hidden); + } + if (player.equals(DEFAULT_HIDE)) { + for (UUID pl : hidden) { + Set plHid = hiddenEntitiesPlEnt.get(pl); + if (plHid != null) { + plHid.remove(entity); + } + } + hidden.clear(); + } + else { + Set plHid = hiddenEntitiesPlEnt.get(player); + if (plHid == null) { + plHid = new HashSet(); + hiddenEntitiesPlEnt.put(player, plHid); + } + plHid.add(entity); + } + return hidden.add(player); + } + + public void hideEntity(Player player, Entity entity, boolean keepInTabList) { // TODO: remove or reimplement tablist option somehow? + if (player == null) { + addHide(DEFAULT_HIDE, entity.getUniqueId()); + if (entity instanceof Player) { + hiddenByDefaultPlayers.add(entity.getUniqueId()); + } + for (Player pl : Bukkit.getOnlinePlayers()) { + sendHidePacket(pl, entity); + } + return; + } + if (isHiddenByDefault(entity)) { + removeHide(player.getUniqueId(), entity.getUniqueId()); + } + else { + addHide(player.getUniqueId(), entity.getUniqueId()); + } + sendHidePacket(player, entity); + } + + public static boolean removeHide(UUID player, UUID entity) { + Set hidden = hiddenEntitiesEntPl.get(entity); + if (hidden == null) { + return false; + } + boolean toRet = hidden.remove(player); + if (player.equals(DEFAULT_HIDE)) { + for (UUID pl : hidden) { + Set plHid = hiddenEntitiesPlEnt.get(pl); + if (plHid != null) { + plHid.remove(entity); + } + } + hidden.clear(); + } + else { + Set plHid = hiddenEntitiesPlEnt.get(player); + if (plHid != null) { + plHid.remove(entity); + } + } + return toRet; + } + + public void unhideEntity(Player player, Entity entity) { + if (player == null) { + removeHide(DEFAULT_HIDE, entity.getUniqueId()); + if (entity instanceof Player) { + hiddenByDefaultPlayers.remove(entity.getUniqueId()); + } + for (Player pl : Bukkit.getOnlinePlayers()) { + sendShowPacket(pl, entity); + } + return; + } + if (isHiddenByDefault(entity)) { + addHide(player.getUniqueId(), entity.getUniqueId()); + } + else { + removeHide(player.getUniqueId(), entity.getUniqueId()); + } + sendShowPacket(player, entity); + } + + public static UUID DEFAULT_HIDE = new UUID(0, 0); + + public boolean isHiddenByDefault(Entity ent) { // TODO: Backport? + Set hiding = hiddenEntitiesEntPl.get(ent.getUniqueId()); + return hiding != null && hiding.contains(DEFAULT_HIDE); + } + + public boolean isHidden(Player player, Entity entity) { + if (isHiddenByDefault(entity)) { + Set hiding = hiddenEntitiesEntPl.get(entity.getUniqueId()); + return hiding == null || !hiding.contains(player.getUniqueId()); + } + Set hiding = hiddenEntitiesEntPl.get(entity.getUniqueId()); + return hiding != null && hiding.contains(player.getUniqueId()); + } + + public static Map> hiddenEntitiesEntPl = new HashMap<>(); + + public static Map> hiddenEntitiesPlEnt = new HashMap<>(); + + public static EnforcePlayerHides EPH = null; + + public static Set hiddenByDefaultPlayers = new HashSet<>(); + + public abstract void sendHidePacket(Player pl, Entity entity); + + public abstract void sendShowPacket(Player pl, Entity entity); /** * Rotates an entity. @@ -85,21 +245,21 @@ void follow(final Entity target, final Entity follower, final double speed, fina * @param yaw The new yaw of the entity. * @param pitch The new pitch of the entity. */ - void rotate(Entity entity, float yaw, float pitch); + public abstract void rotate(Entity entity, float yaw, float pitch); - float getBaseYaw(Entity entity); + public abstract float getBaseYaw(Entity entity); // Taken from C2 NMS class for less dependency on C2 - void look(Entity entity, float yaw, float pitch); + public abstract void look(Entity entity, float yaw, float pitch); - class MapTraceResult { + public static class MapTraceResult { public Location hitLocation; public BlockFace angle; } - boolean canTrace(World world, Vector start, Vector end); + public abstract boolean canTrace(World world, Vector start, Vector end); - MapTraceResult mapTrace(LivingEntity from, double range); + public abstract MapTraceResult mapTrace(LivingEntity from, double range); /** * Gets the precise location in the specified direction. @@ -109,9 +269,9 @@ class MapTraceResult { * @param range The maximum distance between the start and end. * @return The location, or null if it isn't in range. */ - Location rayTrace(Location start, Vector direction, double range); + public abstract Location rayTrace(Location start, Vector direction, double range); - Location getImpactNormal(Location start, Vector direction, double range); + public abstract Location getImpactNormal(Location start, Vector direction, double range); /** * Gets the precise location a LivingEntity is looking at. @@ -120,9 +280,16 @@ class MapTraceResult { * @param range The maximum distance between the LivingEntity and the location. * @return The location, or null if it isn't in range. */ - Location eyeTrace(LivingEntity from, double range); + public Location eyeTrace(LivingEntity from, double range) { + Location start = from.getEyeLocation(); + double xzLen = Math.cos((start.getPitch() % 360) * (Math.PI / 180)); + double nx = xzLen * Math.sin(-start.getYaw() * (Math.PI / 180)); + double ny = Math.sin(start.getPitch() * (Math.PI / 180)); + double nz = xzLen * Math.cos(start.getYaw() * (Math.PI / 180)); + return rayTrace(start, new Vector(nx, -ny, nz), range); + } - default Location faceLocation(Location from, Location at) { + public Location faceLocation(Location from, Location at) { Vector direction = from.toVector().subtract(at.toVector()).normalize(); Location newLocation = from.clone(); newLocation.setYaw(180 - (float) Math.toDegrees(Math.atan2(direction.getX(), direction.getZ()))); @@ -136,7 +303,7 @@ default Location faceLocation(Location from, Location at) { * @param from The Entity whose yaw and pitch you want to change. * @param at The Location it should be looking at. */ - void faceLocation(Entity from, Location at); + public abstract void faceLocation(Entity from, Location at); /** * Changes an entity's yaw and pitch to make it face another entity. @@ -144,9 +311,11 @@ default Location faceLocation(Location from, Location at) { * @param entity The Entity whose yaw and pitch you want to change. * @param target The Entity it should be looking at. */ - void faceEntity(Entity entity, Entity target); + public void faceEntity(Entity entity, Entity target) { + faceLocation(entity, target.getLocation()); + } - default boolean isFacingLocation(Location from, Location at, float yawLimitDegrees, float pitchLimitDegrees) { + public boolean isFacingLocation(Location from, Location at, float yawLimitDegrees, float pitchLimitDegrees) { Vector direction = from.toVector().subtract(at.toVector()).normalize(); float pitch = 90 - (float) Math.toDegrees(Math.acos(direction.getY())); if (from.getPitch() > pitch + pitchLimitDegrees @@ -172,7 +341,7 @@ default boolean isFacingLocation(Location from, Location at, float yawLimitDegre * we check if it is facing. * @return Returns a boolean. */ - default boolean isFacingLocation(Location from, Location at, float degreeLimit) { + public boolean isFacingLocation(Location from, Location at, float degreeLimit) { double currentYaw = normalizeYaw(from.getYaw()); double requiredYaw = normalizeYaw(getYaw(at.toVector().subtract( from.toVector()).normalize())); @@ -191,7 +360,7 @@ default boolean isFacingLocation(Location from, Location at, float degreeLimit) * is facing. * @return Returns a boolean. */ - default boolean isFacingLocation(Entity from, Location at, float degreeLimit) { + public boolean isFacingLocation(Entity from, Location at, float degreeLimit) { return isFacingLocation(from.getLocation(), at, degreeLimit); } @@ -205,7 +374,7 @@ default boolean isFacingLocation(Entity from, Location at, float degreeLimit) { * is facing. * @return Returns a boolean. */ - default boolean isFacingEntity(Entity from, Entity at, float degreeLimit) { + public boolean isFacingEntity(Entity from, Entity at, float degreeLimit) { return isFacingLocation(from.getLocation(), at.getLocation(), degreeLimit); } @@ -216,7 +385,7 @@ default boolean isFacingEntity(Entity from, Entity at, float degreeLimit) { * @param yaw The original yaw. * @return The normalized yaw. */ - default float normalizeYaw(float yaw) { + public float normalizeYaw(float yaw) { yaw = yaw % 360; if (yaw < 0) { yaw += 360.0; @@ -232,7 +401,7 @@ default float normalizeYaw(float yaw) { * @param vector The vector you want to get a yaw from. * @return The yaw. */ - default float getYaw(Vector vector) { + public float getYaw(Vector vector) { double dx = vector.getX(); double dz = vector.getZ(); double yaw = 0; @@ -259,7 +428,7 @@ else if (dz < 0) { * @param yaw The yaw you want to get a cardinal direction from. * @return The name of the cardinal direction as a String. */ - default String getCardinal(float yaw) { + public String getCardinal(float yaw) { yaw = normalizeYaw(yaw); // Compare yaws, return closest direction. if (0 <= yaw && yaw < 22.5) { @@ -294,17 +463,17 @@ else if (337.5 <= yaw && yaw < 360.0) { } } - void move(Entity entity, Vector vector); + public abstract void move(Entity entity, Vector vector); - void teleport(Entity entity, Vector vector); + public abstract void teleport(Entity entity, Vector vector); - BoundingBox getBoundingBox(Entity entity); + public abstract BoundingBox getBoundingBox(Entity entity); - void setBoundingBox(Entity entity, BoundingBox boundingBox); + public abstract void setBoundingBox(Entity entity, BoundingBox boundingBox); - boolean isChestedHorse(Entity horse); + public abstract boolean isChestedHorse(Entity horse); - boolean isCarryingChest(Entity horse); + public abstract boolean isCarryingChest(Entity horse); - void setCarryingChest(Entity horse, boolean carrying); + public abstract void setCarryingChest(Entity horse, boolean carrying); } diff --git a/v1_10_R1/src/main/java/net/aufdemrand/denizen/nms/helpers/EntityHelper_v1_10_R1.java b/v1_10_R1/src/main/java/net/aufdemrand/denizen/nms/helpers/EntityHelper_v1_10_R1.java index ece0abe3ca..566fb5ccb3 100644 --- a/v1_10_R1/src/main/java/net/aufdemrand/denizen/nms/helpers/EntityHelper_v1_10_R1.java +++ b/v1_10_R1/src/main/java/net/aufdemrand/denizen/nms/helpers/EntityHelper_v1_10_R1.java @@ -31,7 +31,7 @@ import java.util.Set; import java.util.UUID; -public class EntityHelper_v1_10_R1 implements EntityHelper { +public class EntityHelper_v1_10_R1 extends EntityHelper { /* General Entity Methods @@ -318,54 +318,34 @@ public void run() { Hide Entity */ - public static Map> hiddenEntities = new HashMap>(); - @Override - public void hideEntity(Player player, Entity entity, boolean keepInTabList) { - // Use Bukkit API for Player entities + public void sendHidePacket(Player pl, Entity entity) { if (entity instanceof Player) { - player.hidePlayer((Player) entity); + ensurePlayerHiding(); + pl.hidePlayer((Player) entity); return; } - CraftPlayer craftPlayer = (CraftPlayer) player; + CraftPlayer craftPlayer = (CraftPlayer) pl; EntityPlayer entityPlayer = craftPlayer.getHandle(); - UUID playerUUID = player.getUniqueId(); if (entityPlayer.playerConnection != null && !craftPlayer.equals(entity)) { - if (!hiddenEntities.containsKey(playerUUID)) { - hiddenEntities.put(playerUUID, new HashSet()); - } - Set hidden = hiddenEntities.get(playerUUID); - UUID entityUUID = entity.getUniqueId(); - if (!hidden.contains(entityUUID)) { - hidden.add(entityUUID); - EntityTracker tracker = ((WorldServer) craftPlayer.getHandle().world).tracker; - net.minecraft.server.v1_10_R1.Entity other = ((CraftEntity) entity).getHandle(); - EntityTrackerEntry entry = tracker.trackedEntities.get(other.getId()); - if (entry != null) { - entry.clear(entityPlayer); - } + EntityTracker tracker = ((WorldServer) craftPlayer.getHandle().world).tracker; + net.minecraft.server.v1_10_R1.Entity other = ((CraftEntity) entity).getHandle(); + EntityTrackerEntry entry = tracker.trackedEntities.get(other.getId()); + if (entry != null) { + entry.clear(entityPlayer); } } } @Override - public void unhideEntity(Player player, Entity entity) { - // Use Bukkit API for Player entities + public void sendShowPacket(Player pl, Entity entity) { if (entity instanceof Player) { - player.showPlayer((Player) entity); + pl.showPlayer((Player) entity); return; } - CraftPlayer craftPlayer = (CraftPlayer) player; + CraftPlayer craftPlayer = (CraftPlayer) pl; EntityPlayer entityPlayer = craftPlayer.getHandle(); - UUID playerUUID = player.getUniqueId(); if (entityPlayer.playerConnection != null && !craftPlayer.equals(entity)) { - UUID entityUUID = entity.getUniqueId(); - if (hiddenEntities.containsKey(playerUUID)) { - Set hidden = hiddenEntities.get(playerUUID); - if (hidden.contains(entityUUID)) { - hidden.remove(entityUUID); - } - } EntityTracker tracker = ((WorldServer) craftPlayer.getHandle().world).tracker; net.minecraft.server.v1_10_R1.Entity other = ((CraftEntity) entity).getHandle(); EntityTrackerEntry entry = tracker.trackedEntities.get(other.getId()); @@ -376,16 +356,6 @@ public void unhideEntity(Player player, Entity entity) { } } - @Override - public boolean isHidden(Player player, Entity entity) { - if (entity instanceof Player) { - return !player.canSee((Player) entity); - } - UUID uuid = player.getUniqueId(); - Set hiding = hiddenEntities.get(uuid); - return hiding != null && hiding.contains(entity.getUniqueId()); - } - @Override public void rotate(Entity entity, float yaw, float pitch) { // If this entity is a real player instead of a player type NPC, @@ -503,16 +473,6 @@ public Location getImpactNormal(Location start, Vector direction, double range) return null; } - @Override - public Location eyeTrace(LivingEntity from, double range) { - Location start = from.getEyeLocation(); - double xzLen = Math.cos((start.getPitch() % 360) * (Math.PI / 180)); - double nx = xzLen * Math.sin(-start.getYaw() * (Math.PI / 180)); - double ny = Math.sin(start.getPitch() * (Math.PI / 180)); - double nz = xzLen * Math.cos(start.getYaw() * (Math.PI / 180)); - return rayTrace(start, new Vector(nx, -ny, nz), range); - } - @Override public void faceLocation(Entity from, Location at) { if (from.getWorld() != at.getWorld()) { @@ -524,11 +484,6 @@ public void faceLocation(Entity from, Location at) { rotate(from, rotated.getYaw(), rotated.getPitch()); } - @Override - public void faceEntity(Entity entity, Entity target) { - faceLocation(entity, target.getLocation()); - } - @Override public void move(Entity entity, Vector vector) { ((CraftEntity) entity).getHandle().move(vector.getX(), vector.getY(), vector.getZ()); diff --git a/v1_11_R1/src/main/java/net/aufdemrand/denizen/nms/helpers/EntityHelper_v1_11_R1.java b/v1_11_R1/src/main/java/net/aufdemrand/denizen/nms/helpers/EntityHelper_v1_11_R1.java index 59971815bc..5a51c0999b 100644 --- a/v1_11_R1/src/main/java/net/aufdemrand/denizen/nms/helpers/EntityHelper_v1_11_R1.java +++ b/v1_11_R1/src/main/java/net/aufdemrand/denizen/nms/helpers/EntityHelper_v1_11_R1.java @@ -31,7 +31,7 @@ import java.util.Set; import java.util.UUID; -public class EntityHelper_v1_11_R1 implements EntityHelper { +public class EntityHelper_v1_11_R1 extends EntityHelper { /* General Entity Methods @@ -317,54 +317,34 @@ public void run() { Hide Entity */ - public static Map> hiddenEntities = new HashMap>(); - @Override - public void hideEntity(Player player, Entity entity, boolean keepInTabList) { // TODO: remove or reimplement tablist option somehow? - // Use Bukkit API for Player entities + public void sendHidePacket(Player pl, Entity entity) { if (entity instanceof Player) { - player.hidePlayer((Player) entity); + ensurePlayerHiding(); + pl.hidePlayer((Player) entity); return; } - CraftPlayer craftPlayer = (CraftPlayer) player; + CraftPlayer craftPlayer = (CraftPlayer) pl; EntityPlayer entityPlayer = craftPlayer.getHandle(); - UUID playerUUID = player.getUniqueId(); if (entityPlayer.playerConnection != null && !craftPlayer.equals(entity)) { - if (!hiddenEntities.containsKey(playerUUID)) { - hiddenEntities.put(playerUUID, new HashSet()); - } - Set hidden = hiddenEntities.get(playerUUID); - UUID entityUUID = entity.getUniqueId(); - if (!hidden.contains(entityUUID)) { - hidden.add(entityUUID); - EntityTracker tracker = ((WorldServer) craftPlayer.getHandle().world).tracker; - net.minecraft.server.v1_11_R1.Entity other = ((CraftEntity) entity).getHandle(); - EntityTrackerEntry entry = tracker.trackedEntities.get(other.getId()); - if (entry != null) { - entry.clear(entityPlayer); - } + EntityTracker tracker = ((WorldServer) craftPlayer.getHandle().world).tracker; + net.minecraft.server.v1_11_R1.Entity other = ((CraftEntity) entity).getHandle(); + EntityTrackerEntry entry = tracker.trackedEntities.get(other.getId()); + if (entry != null) { + entry.clear(entityPlayer); } } } @Override - public void unhideEntity(Player player, Entity entity) { - // Use Bukkit API for Player entities + public void sendShowPacket(Player pl, Entity entity) { if (entity instanceof Player) { - player.showPlayer((Player) entity); + pl.showPlayer((Player) entity); return; } - CraftPlayer craftPlayer = (CraftPlayer) player; + CraftPlayer craftPlayer = (CraftPlayer) pl; EntityPlayer entityPlayer = craftPlayer.getHandle(); - UUID playerUUID = player.getUniqueId(); if (entityPlayer.playerConnection != null && !craftPlayer.equals(entity)) { - UUID entityUUID = entity.getUniqueId(); - if (hiddenEntities.containsKey(playerUUID)) { - Set hidden = hiddenEntities.get(playerUUID); - if (hidden.contains(entityUUID)) { - hidden.remove(entityUUID); - } - } EntityTracker tracker = ((WorldServer) craftPlayer.getHandle().world).tracker; net.minecraft.server.v1_11_R1.Entity other = ((CraftEntity) entity).getHandle(); EntityTrackerEntry entry = tracker.trackedEntities.get(other.getId()); @@ -375,16 +355,6 @@ public void unhideEntity(Player player, Entity entity) { } } - @Override - public boolean isHidden(Player player, Entity entity) { - if (entity instanceof Player) { - return !player.canSee((Player) entity); - } - UUID uuid = player.getUniqueId(); - Set hiding = hiddenEntities.get(uuid); - return hiding != null && hiding.contains(entity.getUniqueId()); - } - @Override public void rotate(Entity entity, float yaw, float pitch) { // If this entity is a real player instead of a player type NPC, @@ -502,16 +472,6 @@ public Location getImpactNormal(Location start, Vector direction, double range) return null; } - @Override - public Location eyeTrace(LivingEntity from, double range) { - Location start = from.getEyeLocation(); - double xzLen = Math.cos((start.getPitch() % 360) * (Math.PI / 180)); - double nx = xzLen * Math.sin(-start.getYaw() * (Math.PI / 180)); - double ny = Math.sin(start.getPitch() * (Math.PI / 180)); - double nz = xzLen * Math.cos(start.getYaw() * (Math.PI / 180)); - return rayTrace(start, new Vector(nx, -ny, nz), range); - } - @Override public void faceLocation(Entity from, Location at) { if (from.getWorld() != at.getWorld()) { @@ -523,11 +483,6 @@ public void faceLocation(Entity from, Location at) { rotate(from, rotated.getYaw(), rotated.getPitch()); } - @Override - public void faceEntity(Entity entity, Entity target) { - faceLocation(entity, target.getLocation()); - } - @Override public void move(Entity entity, Vector vector) { ((CraftEntity) entity).getHandle().move(EnumMoveType.SELF, vector.getX(), vector.getY(), vector.getZ()); diff --git a/v1_12_R1/src/main/java/net/aufdemrand/denizen/nms/Handler_v1_12_R1.java b/v1_12_R1/src/main/java/net/aufdemrand/denizen/nms/Handler_v1_12_R1.java index e1a0bae2c1..5fb36de7ee 100644 --- a/v1_12_R1/src/main/java/net/aufdemrand/denizen/nms/Handler_v1_12_R1.java +++ b/v1_12_R1/src/main/java/net/aufdemrand/denizen/nms/Handler_v1_12_R1.java @@ -227,29 +227,4 @@ public ProfileEditor getProfileEditor() { public BiomeNMS getBiomeNMS(Biome biome) { return new BiomeNMS_v1_12_R1(biome); } - - public HashMap attachmentsA = new HashMap(); // Key follows value - public HashMap attachments2 = new HashMap(); // Value follows key - public HashMap attachmentOffsets = new HashMap<>(); - public HashSet attachmentRotations = new HashSet<>(); - public HashMap visiblePositions = new HashMap<>(); - - @Override - public void forceAttachMove(Entity a, Entity b, Vector offset, boolean matchRotation) { - if (attachmentsA.containsKey(a.getUniqueId())) { - attachments2.remove(attachmentsA.get(a.getUniqueId())); - attachmentsA.remove(a.getUniqueId()); - attachmentOffsets.remove(a.getUniqueId()); - attachmentRotations.remove(a.getUniqueId()); - } - if (b == null) { - return; - } - attachmentsA.put(a.getUniqueId(), b.getUniqueId()); - attachments2.put(b.getUniqueId(), a.getUniqueId()); - attachmentOffsets.put(a.getUniqueId(), offset); - if (matchRotation) { - attachmentRotations.add(a.getUniqueId()); - } - } } diff --git a/v1_12_R1/src/main/java/net/aufdemrand/denizen/nms/helpers/EntityHelper_v1_12_R1.java b/v1_12_R1/src/main/java/net/aufdemrand/denizen/nms/helpers/EntityHelper_v1_12_R1.java index b71bdd6919..40303d3049 100644 --- a/v1_12_R1/src/main/java/net/aufdemrand/denizen/nms/helpers/EntityHelper_v1_12_R1.java +++ b/v1_12_R1/src/main/java/net/aufdemrand/denizen/nms/helpers/EntityHelper_v1_12_R1.java @@ -36,7 +36,7 @@ import java.util.Set; import java.util.UUID; -public class EntityHelper_v1_12_R1 implements EntityHelper { +public class EntityHelper_v1_12_R1 extends EntityHelper { /* General Entity Methods @@ -322,83 +322,8 @@ public void run() { Hide Entity */ - public static class EnforcePlayerHides implements Listener { - - public Plugin denizenPlugin; - - @EventHandler - public void onPlayerJoin(PlayerJoinEvent event) { - for (UUID id : hiddenByDefaultPlayers) { - Entity pTarget = Bukkit.getEntity(id); - if (pTarget != null && pTarget instanceof Player) { - event.getPlayer().hidePlayer((Player) pTarget); - } - } - final Player pl = event.getPlayer(); - final Set hides = hiddenEntitiesPlEnt.get(pl.getUniqueId()); - if (hides == null || hides.isEmpty()) { - return; - } - new BukkitRunnable() { - @Override - public void run() { - if (pl.isOnline()) { - for (UUID id : hides) { - Entity ent = Bukkit.getEntity(id); - if (ent != null) { - sendHidePacket(pl, ent); - } - } - } - } - }.runTaskLater(denizenPlugin, 5); - } - } - - public static Map> hiddenEntitiesEntPl = new HashMap>(); - - public static Map> hiddenEntitiesPlEnt = new HashMap>(); - - public static EnforcePlayerHides EPH = null; - - public static Set hiddenByDefaultPlayers = new HashSet(); - - public static void ensurePlayerHiding() { - if (EPH == null) { - Plugin pl = Bukkit.getPluginManager().getPlugin("Denizen"); // Very lazy way to get the correct plugin instance - EPH = new EnforcePlayerHides(); - EPH.denizenPlugin = pl; - Bukkit.getPluginManager().registerEvents(EPH, pl); - } - } - - public boolean addHide(UUID player, UUID entity) { - Set hidden = hiddenEntitiesEntPl.get(entity); - if (hidden == null) { - hidden = new HashSet(); - hiddenEntitiesEntPl.put(entity, hidden); - } - if (player.equals(DEFAULT_HIDE)) { - for (UUID pl : hidden) { - Set plHid = hiddenEntitiesPlEnt.get(pl); - if (plHid != null) { - plHid.remove(entity); - } - } - hidden.clear(); - } - else { - Set plHid = hiddenEntitiesPlEnt.get(player); - if (plHid == null) { - plHid = new HashSet(); - hiddenEntitiesPlEnt.put(player, plHid); - } - plHid.add(entity); - } - return hidden.add(player); - } - - public static void sendHidePacket(Player pl, Entity entity) { + @Override + public void sendHidePacket(Player pl, Entity entity) { if (entity instanceof Player) { ensurePlayerHiding(); pl.hidePlayer((Player) entity); @@ -417,50 +342,6 @@ public static void sendHidePacket(Player pl, Entity entity) { } @Override - public void hideEntity(Player player, Entity entity, boolean keepInTabList) { // TODO: remove or reimplement tablist option somehow? - if (player == null) { - addHide(DEFAULT_HIDE, entity.getUniqueId()); - if (entity instanceof Player) { - hiddenByDefaultPlayers.add(entity.getUniqueId()); - } - for (Player pl : Bukkit.getOnlinePlayers()) { - sendHidePacket(pl, entity); - } - return; - } - if (isHiddenByDefault(entity)) { - removeHide(player.getUniqueId(), entity.getUniqueId()); - } - else { - addHide(player.getUniqueId(), entity.getUniqueId()); - } - sendHidePacket(player, entity); - } - - public static boolean removeHide(UUID player, UUID entity) { - Set hidden = hiddenEntitiesEntPl.get(entity); - if (hidden == null) { - return false; - } - boolean toRet = hidden.remove(player); - if (player.equals(DEFAULT_HIDE)) { - for (UUID pl : hidden) { - Set plHid = hiddenEntitiesPlEnt.get(pl); - if (plHid != null) { - plHid.remove(entity); - } - } - hidden.clear(); - } - else { - Set plHid = hiddenEntitiesPlEnt.get(player); - if (plHid != null) { - plHid.remove(entity); - } - } - return toRet; - } - public void sendShowPacket(Player pl, Entity entity) { if (entity instanceof Player) { pl.showPlayer((Player) entity); @@ -479,44 +360,6 @@ public void sendShowPacket(Player pl, Entity entity) { } } - @Override - public void unhideEntity(Player player, Entity entity) { - if (player == null) { - removeHide(DEFAULT_HIDE, entity.getUniqueId()); - if (entity instanceof Player) { - hiddenByDefaultPlayers.remove(entity.getUniqueId()); - } - for (Player pl : Bukkit.getOnlinePlayers()) { - sendShowPacket(pl, entity); - } - return; - } - if (isHiddenByDefault(entity)) { - addHide(player.getUniqueId(), entity.getUniqueId()); - } - else { - removeHide(player.getUniqueId(), entity.getUniqueId()); - } - sendShowPacket(player, entity); - } - - public static UUID DEFAULT_HIDE = new UUID(0, 0); - - public boolean isHiddenByDefault(Entity ent) { // TODO: Backport? - Set hiding = hiddenEntitiesEntPl.get(ent.getUniqueId()); - return hiding != null && hiding.contains(DEFAULT_HIDE); - } - - @Override - public boolean isHidden(Player player, Entity entity) { - if (isHiddenByDefault(entity)) { - Set hiding = hiddenEntitiesEntPl.get(entity.getUniqueId()); - return hiding == null || !hiding.contains(player.getUniqueId()); - } - Set hiding = hiddenEntitiesEntPl.get(entity.getUniqueId()); - return hiding != null && hiding.contains(player.getUniqueId()); - } - @Override public void rotate(Entity entity, float yaw, float pitch) { // If this entity is a real player instead of a player type NPC, @@ -634,16 +477,6 @@ public Location getImpactNormal(Location start, Vector direction, double range) return null; } - @Override - public Location eyeTrace(LivingEntity from, double range) { - Location start = from.getEyeLocation(); - double xzLen = Math.cos((start.getPitch() % 360) * (Math.PI / 180)); - double nx = xzLen * Math.sin(-start.getYaw() * (Math.PI / 180)); - double ny = Math.sin(start.getPitch() * (Math.PI / 180)); - double nz = xzLen * Math.cos(start.getYaw() * (Math.PI / 180)); - return rayTrace(start, new Vector(nx, -ny, nz), range); - } - @Override public void faceLocation(Entity from, Location at) { if (from.getWorld() != at.getWorld()) { @@ -655,11 +488,6 @@ public void faceLocation(Entity from, Location at) { rotate(from, rotated.getYaw(), rotated.getPitch()); } - @Override - public void faceEntity(Entity entity, Entity target) { - faceLocation(entity, target.getLocation()); - } - @Override public void move(Entity entity, Vector vector) { ((CraftEntity) entity).getHandle().move(EnumMoveType.SELF, vector.getX(), vector.getY(), vector.getZ()); diff --git a/v1_12_R1/src/main/java/net/aufdemrand/denizen/nms/impl/packets/handlers/DenizenNetworkManager_v1_12_R1.java b/v1_12_R1/src/main/java/net/aufdemrand/denizen/nms/impl/packets/handlers/DenizenNetworkManager_v1_12_R1.java index 517221bd1a..991b2415bb 100644 --- a/v1_12_R1/src/main/java/net/aufdemrand/denizen/nms/impl/packets/handlers/DenizenNetworkManager_v1_12_R1.java +++ b/v1_12_R1/src/main/java/net/aufdemrand/denizen/nms/impl/packets/handlers/DenizenNetworkManager_v1_12_R1.java @@ -134,19 +134,19 @@ else if (packet instanceof PacketPlayOutEntity) { oldManager.sendPacket(packet); } else { - if (!((Handler_v1_12_R1) NMSHandler.getInstance()).attachmentsA.containsKey(e.getUniqueID()) - || ((Handler_v1_12_R1) NMSHandler.getInstance()).attachmentsA.get(e.getUniqueID()).equals(player.getUniqueID())) { + if (!NMSHandler.getInstance().attachmentsA.containsKey(e.getUniqueID()) + || NMSHandler.getInstance().attachmentsA.get(e.getUniqueID()).equals(player.getUniqueID())) { oldManager.sendPacket(packet); } - UUID att = ((Handler_v1_12_R1) NMSHandler.getInstance()).attachments2.get(e.getUniqueID()); + UUID att = NMSHandler.getInstance().attachments2.get(e.getUniqueID()); if (att != null) { org.bukkit.entity.Entity target = Bukkit.getEntity(att); if (target != null) { Packet pNew = (Packet) duplo(packet); ENTITY_ID_PACKENT.setInt(pNew, target.getEntityId()); - Vector offset = ((Handler_v1_12_R1) NMSHandler.getInstance()).attachmentOffsets.get(att); + Vector offset = NMSHandler.getInstance().attachmentOffsets.get(att); if (offset != null && (packet instanceof PacketPlayOutEntity.PacketPlayOutRelEntityMove || packet instanceof PacketPlayOutEntity.PacketPlayOutRelEntityMoveLook)) { - boolean rotationBasis = ((Handler_v1_12_R1) NMSHandler.getInstance()).attachmentRotations.contains(att); + boolean rotationBasis = NMSHandler.getInstance().attachmentRotations.contains(att); Vector goalPosition; if (!rotationBasis) { goalPosition = new Vector(e.locX, e.locY, e.locZ).add(offset); @@ -154,12 +154,12 @@ else if (packet instanceof PacketPlayOutEntity) { else { goalPosition = new Vector(e.locX, e.locY, e.locZ).add(NMSHandler.fixOffset(offset, -e.yaw, e.pitch)); } - Vector oldPos = ((Handler_v1_12_R1) NMSHandler.getInstance()).visiblePositions.get(target.getUniqueId()); + Vector oldPos = NMSHandler.getInstance().visiblePositions.get(target.getUniqueId()); if (oldPos == null) { oldPos = target.getLocation().toVector(); } Vector moveNeeded = goalPosition.clone().subtract(oldPos); - ((Handler_v1_12_R1) NMSHandler.getInstance()).visiblePositions.put(target.getUniqueId(), goalPosition.clone()); + NMSHandler.getInstance().visiblePositions.put(target.getUniqueId(), goalPosition.clone()); int offX = (int) (moveNeeded.getX() * (32 * 128)); int offY = (int) (moveNeeded.getY() * (32 * 128)); int offZ = (int) (moveNeeded.getZ() * (32 * 128)); @@ -195,11 +195,11 @@ else if (packet instanceof PacketPlayOutEntityVelocity) { oldManager.sendPacket(packet); } else { - if (!((Handler_v1_12_R1) NMSHandler.getInstance()).attachmentsA.containsKey(e.getUniqueID()) - || ((Handler_v1_12_R1) NMSHandler.getInstance()).attachmentsA.get(e.getUniqueID()).equals(player.getUniqueID())) { + if (!NMSHandler.getInstance().attachmentsA.containsKey(e.getUniqueID()) + || NMSHandler.getInstance().attachmentsA.get(e.getUniqueID()).equals(player.getUniqueID())) { oldManager.sendPacket(packet); } - UUID att = ((Handler_v1_12_R1) NMSHandler.getInstance()).attachments2.get(e.getUniqueID()); + UUID att = NMSHandler.getInstance().attachments2.get(e.getUniqueID()); if (att != null) { org.bukkit.entity.Entity target = Bukkit.getEntity(att); if (target != null) { @@ -222,20 +222,20 @@ else if (packet instanceof PacketPlayOutEntityTeleport) { oldManager.sendPacket(packet); } else { - if (!((Handler_v1_12_R1) NMSHandler.getInstance()).attachmentsA.containsKey(e.getUniqueID()) - || ((Handler_v1_12_R1) NMSHandler.getInstance()).attachmentsA.get(e.getUniqueID()).equals(player.getUniqueID())) { + if (!NMSHandler.getInstance().attachmentsA.containsKey(e.getUniqueID()) + || NMSHandler.getInstance().attachmentsA.get(e.getUniqueID()).equals(player.getUniqueID())) { oldManager.sendPacket(packet); } - UUID att = ((Handler_v1_12_R1) NMSHandler.getInstance()).attachments2.get(e.getUniqueID()); + UUID att = NMSHandler.getInstance().attachments2.get(e.getUniqueID()); if (att != null) { org.bukkit.entity.Entity target = Bukkit.getEntity(att); if (target != null) { Packet pNew = (Packet) duplo(packet); ENTITY_ID_PACKTELENT.setInt(pNew, target.getEntityId()); - Vector offset = ((Handler_v1_12_R1) NMSHandler.getInstance()).attachmentOffsets.get(att); + Vector offset = NMSHandler.getInstance().attachmentOffsets.get(att); Vector resultPos = new Vector(POS_X_PACKTELENT.getDouble(pNew), POS_Y_PACKTELENT.getDouble(pNew), POS_Z_PACKTELENT.getDouble(pNew)); if (offset != null) { - boolean rotationBasis = ((Handler_v1_12_R1) NMSHandler.getInstance()).attachmentRotations.contains(att); + boolean rotationBasis = NMSHandler.getInstance().attachmentRotations.contains(att); Vector goalOffset; if (!rotationBasis) { goalOffset = offset; @@ -248,7 +248,7 @@ else if (packet instanceof PacketPlayOutEntityTeleport) { POS_Z_PACKTELENT.setDouble(pNew, POS_Z_PACKTELENT.getDouble(pNew) + goalOffset.getZ()); resultPos.add(goalOffset); } - ((Handler_v1_12_R1) NMSHandler.getInstance()).visiblePositions.put(target.getUniqueId(), resultPos); + NMSHandler.getInstance().visiblePositions.put(target.getUniqueId(), resultPos); oldManager.sendPacket(pNew); } } diff --git a/v1_13_R2/src/main/java/net/aufdemrand/denizen/nms/Handler_v1_13_R2.java b/v1_13_R2/src/main/java/net/aufdemrand/denizen/nms/Handler_v1_13_R2.java index 25314b2381..595c432cb5 100644 --- a/v1_13_R2/src/main/java/net/aufdemrand/denizen/nms/Handler_v1_13_R2.java +++ b/v1_13_R2/src/main/java/net/aufdemrand/denizen/nms/Handler_v1_13_R2.java @@ -237,31 +237,6 @@ public BiomeNMS getBiomeNMS(Biome biome) { return new BiomeNMS_v1_13_R2(biome); } - public HashMap attachmentsA = new HashMap(); // Key follows value - public HashMap attachments2 = new HashMap(); // Value follows key - public HashMap attachmentOffsets = new HashMap<>(); - public HashSet attachmentRotations = new HashSet<>(); - public HashMap visiblePositions = new HashMap<>(); - - @Override - public void forceAttachMove(Entity a, Entity b, Vector offset, boolean matchRotation) { - if (attachmentsA.containsKey(a.getUniqueId())) { - attachments2.remove(attachmentsA.get(a.getUniqueId())); - attachmentsA.remove(a.getUniqueId()); - attachmentOffsets.remove(a.getUniqueId()); - attachmentRotations.remove(a.getUniqueId()); - } - if (b == null) { - return; - } - attachmentsA.put(a.getUniqueId(), b.getUniqueId()); - attachments2.put(b.getUniqueId(), a.getUniqueId()); - attachmentOffsets.put(a.getUniqueId(), offset); - if (matchRotation) { - attachmentRotations.add(a.getUniqueId()); - } - } - @Override public Boolean getSwitchState(Block b) { if (b.getBlockData() instanceof Openable) { diff --git a/v1_13_R2/src/main/java/net/aufdemrand/denizen/nms/helpers/EntityHelper_v1_13_R2.java b/v1_13_R2/src/main/java/net/aufdemrand/denizen/nms/helpers/EntityHelper_v1_13_R2.java index 2e136d7c49..8e377a7ee6 100644 --- a/v1_13_R2/src/main/java/net/aufdemrand/denizen/nms/helpers/EntityHelper_v1_13_R2.java +++ b/v1_13_R2/src/main/java/net/aufdemrand/denizen/nms/helpers/EntityHelper_v1_13_R2.java @@ -37,7 +37,7 @@ import java.util.Set; import java.util.UUID; -public class EntityHelper_v1_13_R2 implements EntityHelper { +public class EntityHelper_v1_13_R2 extends EntityHelper { /* General Entity Methods @@ -333,83 +333,8 @@ public void run() { Hide Entity */ - public static class EnforcePlayerHides implements Listener { - - public Plugin denizenPlugin; - - @EventHandler - public void onPlayerJoin(PlayerJoinEvent event) { - for (UUID id : hiddenByDefaultPlayers) { - Entity pTarget = Bukkit.getEntity(id); - if (pTarget != null && pTarget instanceof Player) { - event.getPlayer().hidePlayer((Player) pTarget); - } - } - final Player pl = event.getPlayer(); - final Set hides = hiddenEntitiesPlEnt.get(pl.getUniqueId()); - if (hides == null || hides.isEmpty()) { - return; - } - new BukkitRunnable() { - @Override - public void run() { - if (pl.isOnline()) { - for (UUID id : hides) { - Entity ent = Bukkit.getEntity(id); - if (ent != null) { - sendHidePacket(pl, ent); - } - } - } - } - }.runTaskLater(denizenPlugin, 5); - } - } - - public static Map> hiddenEntitiesEntPl = new HashMap>(); - - public static Map> hiddenEntitiesPlEnt = new HashMap>(); - - public static EnforcePlayerHides EPH = null; - - public static Set hiddenByDefaultPlayers = new HashSet(); - - public static void ensurePlayerHiding() { - if (EPH == null) { - Plugin pl = Bukkit.getPluginManager().getPlugin("Denizen"); // Very lazy way to get the correct plugin instance - EPH = new EnforcePlayerHides(); - EPH.denizenPlugin = pl; - Bukkit.getPluginManager().registerEvents(EPH, pl); - } - } - - public boolean addHide(UUID player, UUID entity) { - Set hidden = hiddenEntitiesEntPl.get(entity); - if (hidden == null) { - hidden = new HashSet(); - hiddenEntitiesEntPl.put(entity, hidden); - } - if (player.equals(DEFAULT_HIDE)) { - for (UUID pl : hidden) { - Set plHid = hiddenEntitiesPlEnt.get(pl); - if (plHid != null) { - plHid.remove(entity); - } - } - hidden.clear(); - } - else { - Set plHid = hiddenEntitiesPlEnt.get(player); - if (plHid == null) { - plHid = new HashSet(); - hiddenEntitiesPlEnt.put(player, plHid); - } - plHid.add(entity); - } - return hidden.add(player); - } - - public static void sendHidePacket(Player pl, Entity entity) { + @Override + public void sendHidePacket(Player pl, Entity entity) { if (entity instanceof Player) { ensurePlayerHiding(); pl.hidePlayer((Player) entity); @@ -428,50 +353,6 @@ public static void sendHidePacket(Player pl, Entity entity) { } @Override - public void hideEntity(Player player, Entity entity, boolean keepInTabList) { // TODO: remove or reimplement tablist option somehow? - if (player == null) { - addHide(DEFAULT_HIDE, entity.getUniqueId()); - if (entity instanceof Player) { - hiddenByDefaultPlayers.add(entity.getUniqueId()); - } - for (Player pl : Bukkit.getOnlinePlayers()) { - sendHidePacket(pl, entity); - } - return; - } - if (isHiddenByDefault(entity)) { - removeHide(player.getUniqueId(), entity.getUniqueId()); - } - else { - addHide(player.getUniqueId(), entity.getUniqueId()); - } - sendHidePacket(player, entity); - } - - public static boolean removeHide(UUID player, UUID entity) { - Set hidden = hiddenEntitiesEntPl.get(entity); - if (hidden == null) { - return false; - } - boolean toRet = hidden.remove(player); - if (player.equals(DEFAULT_HIDE)) { - for (UUID pl : hidden) { - Set plHid = hiddenEntitiesPlEnt.get(pl); - if (plHid != null) { - plHid.remove(entity); - } - } - hidden.clear(); - } - else { - Set plHid = hiddenEntitiesPlEnt.get(player); - if (plHid != null) { - plHid.remove(entity); - } - } - return toRet; - } - public void sendShowPacket(Player pl, Entity entity) { if (entity instanceof Player) { pl.showPlayer((Player) entity); @@ -490,44 +371,6 @@ public void sendShowPacket(Player pl, Entity entity) { } } - @Override - public void unhideEntity(Player player, Entity entity) { - if (player == null) { - removeHide(DEFAULT_HIDE, entity.getUniqueId()); - if (entity instanceof Player) { - hiddenByDefaultPlayers.remove(entity.getUniqueId()); - } - for (Player pl : Bukkit.getOnlinePlayers()) { - sendShowPacket(pl, entity); - } - return; - } - if (isHiddenByDefault(entity)) { - addHide(player.getUniqueId(), entity.getUniqueId()); - } - else { - removeHide(player.getUniqueId(), entity.getUniqueId()); - } - sendShowPacket(player, entity); - } - - public static UUID DEFAULT_HIDE = new UUID(0, 0); - - public boolean isHiddenByDefault(Entity ent) { // TODO: Backport? - Set hiding = hiddenEntitiesEntPl.get(ent.getUniqueId()); - return hiding != null && hiding.contains(DEFAULT_HIDE); - } - - @Override - public boolean isHidden(Player player, Entity entity) { - if (isHiddenByDefault(entity)) { - Set hiding = hiddenEntitiesEntPl.get(entity.getUniqueId()); - return hiding == null || !hiding.contains(player.getUniqueId()); - } - Set hiding = hiddenEntitiesEntPl.get(entity.getUniqueId()); - return hiding != null && hiding.contains(player.getUniqueId()); - } - @Override public void rotate(Entity entity, float yaw, float pitch) { // If this entity is a real player instead of a player type NPC, @@ -645,16 +488,6 @@ public Location getImpactNormal(Location start, Vector direction, double range) return null; } - @Override - public Location eyeTrace(LivingEntity from, double range) { - Location start = from.getEyeLocation(); - double xzLen = Math.cos((start.getPitch() % 360) * (Math.PI / 180)); - double nx = xzLen * Math.sin(-start.getYaw() * (Math.PI / 180)); - double ny = Math.sin(start.getPitch() * (Math.PI / 180)); - double nz = xzLen * Math.cos(start.getYaw() * (Math.PI / 180)); - return rayTrace(start, new Vector(nx, -ny, nz), range); - } - @Override public void faceLocation(Entity from, Location at) { if (from.getWorld() != at.getWorld()) { @@ -666,11 +499,6 @@ public void faceLocation(Entity from, Location at) { rotate(from, rotated.getYaw(), rotated.getPitch()); } - @Override - public void faceEntity(Entity entity, Entity target) { - faceLocation(entity, target.getLocation()); - } - @Override public void move(Entity entity, Vector vector) { ((CraftEntity) entity).getHandle().move(EnumMoveType.SELF, vector.getX(), vector.getY(), vector.getZ()); diff --git a/v1_13_R2/src/main/java/net/aufdemrand/denizen/nms/impl/packets/handlers/DenizenNetworkManager_v1_13_R2.java b/v1_13_R2/src/main/java/net/aufdemrand/denizen/nms/impl/packets/handlers/DenizenNetworkManager_v1_13_R2.java index 34629662a6..85ec568b81 100644 --- a/v1_13_R2/src/main/java/net/aufdemrand/denizen/nms/impl/packets/handlers/DenizenNetworkManager_v1_13_R2.java +++ b/v1_13_R2/src/main/java/net/aufdemrand/denizen/nms/impl/packets/handlers/DenizenNetworkManager_v1_13_R2.java @@ -145,19 +145,19 @@ else if (packet instanceof PacketPlayOutEntity) { oldManager.sendPacket(packet, genericfuturelistener); } else { - if (!((Handler_v1_13_R2) NMSHandler.getInstance()).attachmentsA.containsKey(e.getUniqueID()) - || ((Handler_v1_13_R2) NMSHandler.getInstance()).attachmentsA.get(e.getUniqueID()).equals(player.getUniqueID())) { + if (!NMSHandler.getInstance().attachmentsA.containsKey(e.getUniqueID()) + || NMSHandler.getInstance().attachmentsA.get(e.getUniqueID()).equals(player.getUniqueID())) { oldManager.sendPacket(packet, genericfuturelistener); } - UUID att = ((Handler_v1_13_R2) NMSHandler.getInstance()).attachments2.get(e.getUniqueID()); + UUID att = NMSHandler.getInstance().attachments2.get(e.getUniqueID()); if (att != null) { org.bukkit.entity.Entity target = Bukkit.getEntity(att); if (target != null) { Packet pNew = (Packet) duplo(packet); ENTITY_ID_PACKENT.setInt(pNew, target.getEntityId()); - Vector offset = ((Handler_v1_13_R2) NMSHandler.getInstance()).attachmentOffsets.get(att); + Vector offset = NMSHandler.getInstance().attachmentOffsets.get(att); if (offset != null && (packet instanceof PacketPlayOutEntity.PacketPlayOutRelEntityMove || packet instanceof PacketPlayOutEntity.PacketPlayOutRelEntityMoveLook)) { - boolean rotationBasis = ((Handler_v1_13_R2) NMSHandler.getInstance()).attachmentRotations.contains(att); + boolean rotationBasis = NMSHandler.getInstance().attachmentRotations.contains(att); Vector goalPosition; if (!rotationBasis) { goalPosition = new Vector(e.locX, e.locY, e.locZ).add(offset); @@ -165,12 +165,12 @@ else if (packet instanceof PacketPlayOutEntity) { else { goalPosition = new Vector(e.locX, e.locY, e.locZ).add(NMSHandler.fixOffset(offset, -e.yaw, e.pitch)); } - Vector oldPos = ((Handler_v1_13_R2) NMSHandler.getInstance()).visiblePositions.get(target.getUniqueId()); + Vector oldPos = NMSHandler.getInstance().visiblePositions.get(target.getUniqueId()); if (oldPos == null) { oldPos = target.getLocation().toVector(); } Vector moveNeeded = goalPosition.clone().subtract(oldPos); - ((Handler_v1_13_R2) NMSHandler.getInstance()).visiblePositions.put(target.getUniqueId(), goalPosition.clone()); + NMSHandler.getInstance().visiblePositions.put(target.getUniqueId(), goalPosition.clone()); int offX = (int) (moveNeeded.getX() * (32 * 128)); int offY = (int) (moveNeeded.getY() * (32 * 128)); int offZ = (int) (moveNeeded.getZ() * (32 * 128)); @@ -206,11 +206,11 @@ else if (packet instanceof PacketPlayOutEntityVelocity) { oldManager.sendPacket(packet, genericfuturelistener); } else { - if (!((Handler_v1_13_R2) NMSHandler.getInstance()).attachmentsA.containsKey(e.getUniqueID()) - || ((Handler_v1_13_R2) NMSHandler.getInstance()).attachmentsA.get(e.getUniqueID()).equals(player.getUniqueID())) { + if (!NMSHandler.getInstance().attachmentsA.containsKey(e.getUniqueID()) + || NMSHandler.getInstance().attachmentsA.get(e.getUniqueID()).equals(player.getUniqueID())) { oldManager.sendPacket(packet, genericfuturelistener); } - UUID att = ((Handler_v1_13_R2) NMSHandler.getInstance()).attachments2.get(e.getUniqueID()); + UUID att = NMSHandler.getInstance().attachments2.get(e.getUniqueID()); if (att != null) { org.bukkit.entity.Entity target = Bukkit.getEntity(att); if (target != null) { @@ -233,20 +233,20 @@ else if (packet instanceof PacketPlayOutEntityTeleport) { oldManager.sendPacket(packet, genericfuturelistener); } else { - if (!((Handler_v1_13_R2) NMSHandler.getInstance()).attachmentsA.containsKey(e.getUniqueID()) - || ((Handler_v1_13_R2) NMSHandler.getInstance()).attachmentsA.get(e.getUniqueID()).equals(player.getUniqueID())) { + if (!NMSHandler.getInstance().attachmentsA.containsKey(e.getUniqueID()) + || NMSHandler.getInstance().attachmentsA.get(e.getUniqueID()).equals(player.getUniqueID())) { oldManager.sendPacket(packet, genericfuturelistener); } - UUID att = ((Handler_v1_13_R2) NMSHandler.getInstance()).attachments2.get(e.getUniqueID()); + UUID att = NMSHandler.getInstance().attachments2.get(e.getUniqueID()); if (att != null) { org.bukkit.entity.Entity target = Bukkit.getEntity(att); if (target != null) { Packet pNew = (Packet) duplo(packet); ENTITY_ID_PACKTELENT.setInt(pNew, target.getEntityId()); - Vector offset = ((Handler_v1_13_R2) NMSHandler.getInstance()).attachmentOffsets.get(att); + Vector offset = NMSHandler.getInstance().attachmentOffsets.get(att); Vector resultPos = new Vector(POS_X_PACKTELENT.getDouble(pNew), POS_Y_PACKTELENT.getDouble(pNew), POS_Z_PACKTELENT.getDouble(pNew)); if (offset != null) { - boolean rotationBasis = ((Handler_v1_13_R2) NMSHandler.getInstance()).attachmentRotations.contains(att); + boolean rotationBasis = NMSHandler.getInstance().attachmentRotations.contains(att); Vector goalOffset; if (!rotationBasis) { goalOffset = offset; @@ -259,7 +259,7 @@ else if (packet instanceof PacketPlayOutEntityTeleport) { POS_Z_PACKTELENT.setDouble(pNew, POS_Z_PACKTELENT.getDouble(pNew) + goalOffset.getZ()); resultPos.add(goalOffset); } - ((Handler_v1_13_R2) NMSHandler.getInstance()).visiblePositions.put(target.getUniqueId(), resultPos); + NMSHandler.getInstance().visiblePositions.put(target.getUniqueId(), resultPos); oldManager.sendPacket(pNew); } } diff --git a/v1_8_R3/src/main/java/net/aufdemrand/denizen/nms/helpers/EntityHelper_v1_8_R3.java b/v1_8_R3/src/main/java/net/aufdemrand/denizen/nms/helpers/EntityHelper_v1_8_R3.java index 81734cbd29..3887db7d44 100644 --- a/v1_8_R3/src/main/java/net/aufdemrand/denizen/nms/helpers/EntityHelper_v1_8_R3.java +++ b/v1_8_R3/src/main/java/net/aufdemrand/denizen/nms/helpers/EntityHelper_v1_8_R3.java @@ -32,7 +32,7 @@ import java.util.Set; import java.util.UUID; -public class EntityHelper_v1_8_R3 implements EntityHelper { +public class EntityHelper_v1_8_R3 extends EntityHelper { /* General Entity Methods @@ -318,54 +318,34 @@ public void run() { Hide Entity */ - public static Map> hiddenEntities = new HashMap>(); - @Override - public void hideEntity(Player player, Entity entity, boolean keepInTabList) { - // Use Bukkit API for Player entities + public void sendHidePacket(Player pl, Entity entity) { if (entity instanceof Player) { - player.hidePlayer((Player) entity); + ensurePlayerHiding(); + pl.hidePlayer((Player) entity); return; } - CraftPlayer craftPlayer = (CraftPlayer) player; + CraftPlayer craftPlayer = (CraftPlayer) pl; EntityPlayer entityPlayer = craftPlayer.getHandle(); - UUID playerUUID = player.getUniqueId(); if (entityPlayer.playerConnection != null && !craftPlayer.equals(entity)) { - if (!hiddenEntities.containsKey(playerUUID)) { - hiddenEntities.put(playerUUID, new HashSet()); - } - Set hidden = hiddenEntities.get(playerUUID); - UUID entityUUID = entity.getUniqueId(); - if (!hidden.contains(entityUUID)) { - hidden.add(entityUUID); - EntityTracker tracker = ((WorldServer) craftPlayer.getHandle().world).tracker; - net.minecraft.server.v1_8_R3.Entity other = ((CraftEntity) entity).getHandle(); - EntityTrackerEntry entry = tracker.trackedEntities.get(other.getId()); - if (entry != null) { - entry.clear(entityPlayer); - } + EntityTracker tracker = ((WorldServer) craftPlayer.getHandle().world).tracker; + net.minecraft.server.v1_8_R3.Entity other = ((CraftEntity) entity).getHandle(); + EntityTrackerEntry entry = tracker.trackedEntities.get(other.getId()); + if (entry != null) { + entry.clear(entityPlayer); } } } @Override - public void unhideEntity(Player player, Entity entity) { - // Use Bukkit API for Player entities + public void sendShowPacket(Player pl, Entity entity) { if (entity instanceof Player) { - player.showPlayer((Player) entity); + pl.showPlayer((Player) entity); return; } - CraftPlayer craftPlayer = (CraftPlayer) player; + CraftPlayer craftPlayer = (CraftPlayer) pl; EntityPlayer entityPlayer = craftPlayer.getHandle(); - UUID playerUUID = player.getUniqueId(); if (entityPlayer.playerConnection != null && !craftPlayer.equals(entity)) { - UUID entityUUID = entity.getUniqueId(); - if (hiddenEntities.containsKey(playerUUID)) { - Set hidden = hiddenEntities.get(playerUUID); - if (hidden.contains(entityUUID)) { - hidden.remove(entityUUID); - } - } EntityTracker tracker = ((WorldServer) craftPlayer.getHandle().world).tracker; net.minecraft.server.v1_8_R3.Entity other = ((CraftEntity) entity).getHandle(); EntityTrackerEntry entry = tracker.trackedEntities.get(other.getId()); @@ -376,16 +356,6 @@ public void unhideEntity(Player player, Entity entity) { } } - @Override - public boolean isHidden(Player player, Entity entity) { - if (entity instanceof Player) { - return !player.canSee((Player) entity); - } - UUID uuid = player.getUniqueId(); - Set hiding = hiddenEntities.get(uuid); - return hiding != null && hiding.contains(entity.getUniqueId()); - } - @Override public void rotate(Entity entity, float yaw, float pitch) { // If this entity is a real player instead of a player type NPC, @@ -503,16 +473,6 @@ public Location getImpactNormal(Location start, Vector direction, double range) return null; } - @Override - public Location eyeTrace(LivingEntity from, double range) { - Location start = from.getEyeLocation(); - double xzLen = Math.cos((start.getPitch() % 360) * (Math.PI / 180)); - double nx = xzLen * Math.sin(-start.getYaw() * (Math.PI / 180)); - double ny = Math.sin(start.getPitch() * (Math.PI / 180)); - double nz = xzLen * Math.cos(start.getYaw() * (Math.PI / 180)); - return rayTrace(start, new Vector(nx, -ny, nz), range); - } - @Override public void faceLocation(Entity from, Location at) { if (from.getWorld() != at.getWorld()) { @@ -524,11 +484,6 @@ public void faceLocation(Entity from, Location at) { rotate(from, rotated.getYaw(), rotated.getPitch()); } - @Override - public void faceEntity(Entity entity, Entity target) { - faceLocation(entity, target.getLocation()); - } - @Override public void move(Entity entity, Vector vector) { ((CraftEntity) entity).getHandle().move(vector.getX(), vector.getY(), vector.getZ()); diff --git a/v1_9_R2/src/main/java/net/aufdemrand/denizen/nms/helpers/EntityHelper_v1_9_R2.java b/v1_9_R2/src/main/java/net/aufdemrand/denizen/nms/helpers/EntityHelper_v1_9_R2.java index 0740f1d5db..cf6b12079d 100644 --- a/v1_9_R2/src/main/java/net/aufdemrand/denizen/nms/helpers/EntityHelper_v1_9_R2.java +++ b/v1_9_R2/src/main/java/net/aufdemrand/denizen/nms/helpers/EntityHelper_v1_9_R2.java @@ -31,7 +31,7 @@ import java.util.Set; import java.util.UUID; -public class EntityHelper_v1_9_R2 implements EntityHelper { +public class EntityHelper_v1_9_R2 extends EntityHelper { /* General Entity Methods @@ -318,54 +318,34 @@ public void run() { Hide Entity */ - public static Map> hiddenEntities = new HashMap>(); - @Override - public void hideEntity(Player player, Entity entity, boolean keepInTabList) { - // Use Bukkit API for Player entities + public void sendHidePacket(Player pl, Entity entity) { if (entity instanceof Player) { - player.hidePlayer((Player) entity); + ensurePlayerHiding(); + pl.hidePlayer((Player) entity); return; } - CraftPlayer craftPlayer = (CraftPlayer) player; + CraftPlayer craftPlayer = (CraftPlayer) pl; EntityPlayer entityPlayer = craftPlayer.getHandle(); - UUID playerUUID = player.getUniqueId(); if (entityPlayer.playerConnection != null && !craftPlayer.equals(entity)) { - if (!hiddenEntities.containsKey(playerUUID)) { - hiddenEntities.put(playerUUID, new HashSet()); - } - Set hidden = hiddenEntities.get(playerUUID); - UUID entityUUID = entity.getUniqueId(); - if (!hidden.contains(entityUUID)) { - hidden.add(entityUUID); - EntityTracker tracker = ((WorldServer) craftPlayer.getHandle().world).tracker; - net.minecraft.server.v1_9_R2.Entity other = ((CraftEntity) entity).getHandle(); - EntityTrackerEntry entry = tracker.trackedEntities.get(other.getId()); - if (entry != null) { - entry.clear(entityPlayer); - } + EntityTracker tracker = ((WorldServer) craftPlayer.getHandle().world).tracker; + net.minecraft.server.v1_9_R2.Entity other = ((CraftEntity) entity).getHandle(); + EntityTrackerEntry entry = tracker.trackedEntities.get(other.getId()); + if (entry != null) { + entry.clear(entityPlayer); } } } @Override - public void unhideEntity(Player player, Entity entity) { - // Use Bukkit API for Player entities + public void sendShowPacket(Player pl, Entity entity) { if (entity instanceof Player) { - player.showPlayer((Player) entity); + pl.showPlayer((Player) entity); return; } - CraftPlayer craftPlayer = (CraftPlayer) player; + CraftPlayer craftPlayer = (CraftPlayer) pl; EntityPlayer entityPlayer = craftPlayer.getHandle(); - UUID playerUUID = player.getUniqueId(); if (entityPlayer.playerConnection != null && !craftPlayer.equals(entity)) { - UUID entityUUID = entity.getUniqueId(); - if (hiddenEntities.containsKey(playerUUID)) { - Set hidden = hiddenEntities.get(playerUUID); - if (hidden.contains(entityUUID)) { - hidden.remove(entityUUID); - } - } EntityTracker tracker = ((WorldServer) craftPlayer.getHandle().world).tracker; net.minecraft.server.v1_9_R2.Entity other = ((CraftEntity) entity).getHandle(); EntityTrackerEntry entry = tracker.trackedEntities.get(other.getId()); @@ -376,16 +356,6 @@ public void unhideEntity(Player player, Entity entity) { } } - @Override - public boolean isHidden(Player player, Entity entity) { - if (entity instanceof Player) { - return !player.canSee((Player) entity); - } - UUID uuid = player.getUniqueId(); - Set hiding = hiddenEntities.get(uuid); - return hiding != null && hiding.contains(entity.getUniqueId()); - } - @Override public void rotate(Entity entity, float yaw, float pitch) { // If this entity is a real player instead of a player type NPC, @@ -503,16 +473,6 @@ public Location getImpactNormal(Location start, Vector direction, double range) return null; } - @Override - public Location eyeTrace(LivingEntity from, double range) { - Location start = from.getEyeLocation(); - double xzLen = Math.cos((start.getPitch() % 360) * (Math.PI / 180)); - double nx = xzLen * Math.sin(-start.getYaw() * (Math.PI / 180)); - double ny = Math.sin(start.getPitch() * (Math.PI / 180)); - double nz = xzLen * Math.cos(start.getYaw() * (Math.PI / 180)); - return rayTrace(start, new Vector(nx, -ny, nz), range); - } - @Override public void faceLocation(Entity from, Location at) { if (from.getWorld() != at.getWorld()) { @@ -524,11 +484,6 @@ public void faceLocation(Entity from, Location at) { rotate(from, rotated.getYaw(), rotated.getPitch()); } - @Override - public void faceEntity(Entity entity, Entity target) { - faceLocation(entity, target.getLocation()); - } - @Override public void move(Entity entity, Vector vector) { ((CraftEntity) entity).getHandle().move(vector.getX(), vector.getY(), vector.getZ());