diff --git a/core/src/main/java/me/filoghost/holographicdisplays/core/nms/entity/NMSEntityHelper.java b/core/src/main/java/me/filoghost/holographicdisplays/core/nms/entity/NMSEntityHelper.java new file mode 100644 index 00000000..2727fc7a --- /dev/null +++ b/core/src/main/java/me/filoghost/holographicdisplays/core/nms/entity/NMSEntityHelper.java @@ -0,0 +1,23 @@ +/* + * Copyright (C) filoghost and contributors + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ +package me.filoghost.holographicdisplays.core.nms.entity; + +public abstract class NMSEntityHelper { + + private T tracker; + + protected final T getTracker() { + if (tracker == null) { + // Cache it the first time it's available + tracker = getTracker0(); + } + + return tracker; + } + + protected abstract T getTracker0(); + +} diff --git a/nms/v1_10_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_10_R1/EntityNMSArmorStand.java b/nms/v1_10_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_10_R1/EntityNMSArmorStand.java index a829f988..52a745bc 100644 --- a/nms/v1_10_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_10_R1/EntityNMSArmorStand.java +++ b/nms/v1_10_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_10_R1/EntityNMSArmorStand.java @@ -9,7 +9,6 @@ import me.filoghost.fcommons.Preconditions; import me.filoghost.fcommons.Strings; import me.filoghost.fcommons.reflection.ReflectField; import me.filoghost.holographicdisplays.core.DebugLogger; -import me.filoghost.holographicdisplays.core.Utils; import me.filoghost.holographicdisplays.core.hologram.StandardHologramLine; import me.filoghost.holographicdisplays.core.nms.ProtocolPacketSettings; import me.filoghost.holographicdisplays.core.nms.entity.NMSArmorStand; @@ -19,7 +18,6 @@ import net.minecraft.server.v1_10_R1.DamageSource; import net.minecraft.server.v1_10_R1.Entity; import net.minecraft.server.v1_10_R1.EntityArmorStand; import net.minecraft.server.v1_10_R1.EntityHuman; -import net.minecraft.server.v1_10_R1.EntityPlayer; import net.minecraft.server.v1_10_R1.EnumHand; import net.minecraft.server.v1_10_R1.EnumInteractionResult; import net.minecraft.server.v1_10_R1.EnumItemSlot; @@ -39,12 +37,14 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta private final StandardHologramLine parentHologramLine; private final ProtocolPacketSettings protocolPacketSettings; + private final VersionNMSEntityHelper helper; private String customName; public EntityNMSArmorStand(World world, StandardHologramLine parentHologramLine, ProtocolPacketSettings protocolPacketSettings) { super(world); this.parentHologramLine = parentHologramLine; this.protocolPacketSettings = protocolPacketSettings; + this.helper = new VersionNMSEntityHelper(this); super.setInvisible(true); super.setSmall(true); @@ -208,22 +208,7 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta public void setLocationNMS(double x, double y, double z) { super.setPosition(x, y, z); if (protocolPacketSettings.sendAccurateLocationPackets()) { - broadcastLocationPacketNMS(); - } - } - - private void broadcastLocationPacketNMS() { - PacketPlayOutEntityTeleport teleportPacket = new PacketPlayOutEntityTeleport(this); - - for (EntityHuman humanEntity : super.world.players) { - if (humanEntity instanceof EntityPlayer) { - EntityPlayer nmsPlayer = (EntityPlayer) humanEntity; - - double distanceSquared = Utils.distanceSquared(nmsPlayer.locX, super.locX, nmsPlayer.locZ, super.locZ); - if (distanceSquared < 64 * 64 * 2 && nmsPlayer.playerConnection != null) { - nmsPlayer.playerConnection.sendPacket(teleportPacket); - } - } + helper.broadcastPacket(new PacketPlayOutEntityTeleport(this)); } } diff --git a/nms/v1_10_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_10_R1/EntityNMSItem.java b/nms/v1_10_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_10_R1/EntityNMSItem.java index 016eed04..0cae8438 100644 --- a/nms/v1_10_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_10_R1/EntityNMSItem.java +++ b/nms/v1_10_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_10_R1/EntityNMSItem.java @@ -5,7 +5,6 @@ */ package me.filoghost.holographicdisplays.nms.v1_10_R1; -import me.filoghost.holographicdisplays.core.Utils; import me.filoghost.holographicdisplays.core.hologram.StandardHologramLine; import me.filoghost.holographicdisplays.core.hologram.StandardItemLine; import me.filoghost.holographicdisplays.core.nms.NMSCommons; @@ -28,12 +27,14 @@ import org.bukkit.craftbukkit.v1_10_R1.inventory.CraftItemStack; public class EntityNMSItem extends EntityItem implements NMSItem { private final StandardItemLine parentHologramLine; + private final VersionNMSEntityHelper helper; private int resendMountPacketTicks; public EntityNMSItem(World world, StandardItemLine parentHologramLine) { super(world); this.parentHologramLine = parentHologramLine; + this.helper = new VersionNMSEntityHelper(this); super.pickupDelay = Integer.MAX_VALUE; } @@ -51,18 +52,7 @@ public class EntityNMSItem extends EntityItem implements NMSItem { Entity vehicle = bB(); if (vehicle != null) { // Send a packet near to "remind" players that the item is riding the armor stand (Spigot bug or client bug) - PacketPlayOutMount mountPacket = new PacketPlayOutMount(vehicle); - - for (EntityHuman humanEntity : super.world.players) { - if (humanEntity instanceof EntityPlayer) { - EntityPlayer nmsPlayer = (EntityPlayer) humanEntity; - - double distanceSquared = Utils.distanceSquared(nmsPlayer.locX, super.locX, nmsPlayer.locZ, super.locZ); - if (distanceSquared < 32 * 32 && nmsPlayer.playerConnection != null) { - nmsPlayer.playerConnection.sendPacket(mountPacket); - } - } - } + helper.broadcastPacket(new PacketPlayOutMount(vehicle)); } } } diff --git a/nms/v1_10_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_10_R1/EntityNMSSlime.java b/nms/v1_10_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_10_R1/EntityNMSSlime.java index c99bf286..e18e773c 100644 --- a/nms/v1_10_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_10_R1/EntityNMSSlime.java +++ b/nms/v1_10_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_10_R1/EntityNMSSlime.java @@ -5,14 +5,12 @@ */ package me.filoghost.holographicdisplays.nms.v1_10_R1; -import me.filoghost.holographicdisplays.core.Utils; import me.filoghost.holographicdisplays.core.hologram.StandardHologramLine; import me.filoghost.holographicdisplays.core.nms.entity.NMSSlime; import net.minecraft.server.v1_10_R1.AxisAlignedBB; import net.minecraft.server.v1_10_R1.DamageSource; import net.minecraft.server.v1_10_R1.Entity; import net.minecraft.server.v1_10_R1.EntityDamageSource; -import net.minecraft.server.v1_10_R1.EntityHuman; import net.minecraft.server.v1_10_R1.EntityPlayer; import net.minecraft.server.v1_10_R1.EntitySlime; import net.minecraft.server.v1_10_R1.NBTTagCompound; @@ -26,12 +24,14 @@ import org.bukkit.event.player.PlayerInteractEntityEvent; public class EntityNMSSlime extends EntitySlime implements NMSSlime { private final StandardHologramLine parentHologramLine; + private final VersionNMSEntityHelper helper; private int resendMountPacketTicks; public EntityNMSSlime(World world, StandardHologramLine parentHologramLine) { super(world); this.parentHologramLine = parentHologramLine; + this.helper = new VersionNMSEntityHelper(this); super.persistent = true; super.collides = false; @@ -54,18 +54,7 @@ public class EntityNMSSlime extends EntitySlime implements NMSSlime { Entity vehicle = bB(); if (vehicle != null) { // Send a packet near to "remind" players that the slime is riding the armor stand (Spigot bug or client bug) - PacketPlayOutMount mountPacket = new PacketPlayOutMount(vehicle); - - for (EntityHuman humanEntity : super.world.players) { - if (humanEntity instanceof EntityPlayer) { - EntityPlayer nmsPlayer = (EntityPlayer) humanEntity; - - double distanceSquared = Utils.distanceSquared(nmsPlayer.locX, super.locX, nmsPlayer.locZ, super.locZ); - if (distanceSquared < 32 * 32 && nmsPlayer.playerConnection != null) { - nmsPlayer.playerConnection.sendPacket(mountPacket); - } - } - } + helper.broadcastPacket(new PacketPlayOutMount(vehicle)); } } } diff --git a/nms/v1_10_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_10_R1/VersionNMSEntityHelper.java b/nms/v1_10_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_10_R1/VersionNMSEntityHelper.java new file mode 100644 index 00000000..ab5e4302 --- /dev/null +++ b/nms/v1_10_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_10_R1/VersionNMSEntityHelper.java @@ -0,0 +1,34 @@ +/* + * Copyright (C) filoghost and contributors + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ +package me.filoghost.holographicdisplays.nms.v1_10_R1; + +import me.filoghost.holographicdisplays.core.nms.entity.NMSEntityHelper; +import net.minecraft.server.v1_10_R1.Entity; +import net.minecraft.server.v1_10_R1.EntityTrackerEntry; +import net.minecraft.server.v1_10_R1.Packet; +import net.minecraft.server.v1_10_R1.WorldServer; + +public class VersionNMSEntityHelper extends NMSEntityHelper { + + private final Entity entity; + + public VersionNMSEntityHelper(Entity entity) { + this.entity = entity; + } + + @Override + protected EntityTrackerEntry getTracker0() { + return ((WorldServer) entity.world).tracker.trackedEntities.get(entity.getId()); + } + + public void broadcastPacket(Packet packet) { + EntityTrackerEntry tracker = getTracker(); + if (tracker != null) { + tracker.broadcast(packet); + } + } + +} diff --git a/nms/v1_11_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_11_R1/EntityNMSArmorStand.java b/nms/v1_11_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_11_R1/EntityNMSArmorStand.java index 8bfe038f..8a58bebf 100644 --- a/nms/v1_11_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_11_R1/EntityNMSArmorStand.java +++ b/nms/v1_11_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_11_R1/EntityNMSArmorStand.java @@ -9,7 +9,6 @@ import me.filoghost.fcommons.Preconditions; import me.filoghost.fcommons.Strings; import me.filoghost.fcommons.reflection.ReflectField; import me.filoghost.holographicdisplays.core.DebugLogger; -import me.filoghost.holographicdisplays.core.Utils; import me.filoghost.holographicdisplays.core.hologram.StandardHologramLine; import me.filoghost.holographicdisplays.core.nms.ProtocolPacketSettings; import me.filoghost.holographicdisplays.core.nms.entity.NMSArmorStand; @@ -19,7 +18,6 @@ import net.minecraft.server.v1_11_R1.DamageSource; import net.minecraft.server.v1_11_R1.Entity; import net.minecraft.server.v1_11_R1.EntityArmorStand; import net.minecraft.server.v1_11_R1.EntityHuman; -import net.minecraft.server.v1_11_R1.EntityPlayer; import net.minecraft.server.v1_11_R1.EnumHand; import net.minecraft.server.v1_11_R1.EnumInteractionResult; import net.minecraft.server.v1_11_R1.EnumItemSlot; @@ -39,12 +37,14 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta private final StandardHologramLine parentHologramLine; private final ProtocolPacketSettings protocolPacketSettings; + private final VersionNMSEntityHelper helper; private String customName; public EntityNMSArmorStand(World world, StandardHologramLine parentHologramLine, ProtocolPacketSettings protocolPacketSettings) { super(world); this.parentHologramLine = parentHologramLine; this.protocolPacketSettings = protocolPacketSettings; + this.helper = new VersionNMSEntityHelper(this); super.setInvisible(true); super.setSmall(true); @@ -208,22 +208,7 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta public void setLocationNMS(double x, double y, double z) { super.setPosition(x, y, z); if (protocolPacketSettings.sendAccurateLocationPackets()) { - broadcastLocationPacketNMS(); - } - } - - private void broadcastLocationPacketNMS() { - PacketPlayOutEntityTeleport teleportPacket = new PacketPlayOutEntityTeleport(this); - - for (EntityHuman humanEntity : super.world.players) { - if (humanEntity instanceof EntityPlayer) { - EntityPlayer nmsPlayer = (EntityPlayer) humanEntity; - - double distanceSquared = Utils.distanceSquared(nmsPlayer.locX, super.locX, nmsPlayer.locZ, super.locZ); - if (distanceSquared < 64 * 64 * 2 && nmsPlayer.playerConnection != null) { - nmsPlayer.playerConnection.sendPacket(teleportPacket); - } - } + helper.broadcastPacket(new PacketPlayOutEntityTeleport(this)); } } diff --git a/nms/v1_11_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_11_R1/VersionNMSEntityHelper.java b/nms/v1_11_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_11_R1/VersionNMSEntityHelper.java new file mode 100644 index 00000000..fede4bf1 --- /dev/null +++ b/nms/v1_11_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_11_R1/VersionNMSEntityHelper.java @@ -0,0 +1,34 @@ +/* + * Copyright (C) filoghost and contributors + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ +package me.filoghost.holographicdisplays.nms.v1_11_R1; + +import me.filoghost.holographicdisplays.core.nms.entity.NMSEntityHelper; +import net.minecraft.server.v1_11_R1.Entity; +import net.minecraft.server.v1_11_R1.EntityTrackerEntry; +import net.minecraft.server.v1_11_R1.Packet; +import net.minecraft.server.v1_11_R1.WorldServer; + +public class VersionNMSEntityHelper extends NMSEntityHelper { + + private final Entity entity; + + public VersionNMSEntityHelper(Entity entity) { + this.entity = entity; + } + + @Override + protected EntityTrackerEntry getTracker0() { + return ((WorldServer) entity.world).tracker.trackedEntities.get(entity.getId()); + } + + public void broadcastPacket(Packet packet) { + EntityTrackerEntry tracker = getTracker(); + if (tracker != null) { + tracker.broadcast(packet); + } + } + +} diff --git a/nms/v1_12_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_12_R1/EntityNMSArmorStand.java b/nms/v1_12_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_12_R1/EntityNMSArmorStand.java index c7d00156..1a8920f6 100644 --- a/nms/v1_12_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_12_R1/EntityNMSArmorStand.java +++ b/nms/v1_12_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_12_R1/EntityNMSArmorStand.java @@ -9,7 +9,6 @@ import me.filoghost.fcommons.Preconditions; import me.filoghost.fcommons.Strings; import me.filoghost.fcommons.reflection.ReflectField; import me.filoghost.holographicdisplays.core.DebugLogger; -import me.filoghost.holographicdisplays.core.Utils; import me.filoghost.holographicdisplays.core.hologram.StandardHologramLine; import me.filoghost.holographicdisplays.core.nms.ProtocolPacketSettings; import me.filoghost.holographicdisplays.core.nms.entity.NMSArmorStand; @@ -19,7 +18,6 @@ import net.minecraft.server.v1_12_R1.DamageSource; import net.minecraft.server.v1_12_R1.Entity; import net.minecraft.server.v1_12_R1.EntityArmorStand; import net.minecraft.server.v1_12_R1.EntityHuman; -import net.minecraft.server.v1_12_R1.EntityPlayer; import net.minecraft.server.v1_12_R1.EnumHand; import net.minecraft.server.v1_12_R1.EnumInteractionResult; import net.minecraft.server.v1_12_R1.EnumItemSlot; @@ -39,12 +37,14 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta private final StandardHologramLine parentHologramLine; private final ProtocolPacketSettings protocolPacketSettings; + private final VersionNMSEntityHelper helper; private String customName; public EntityNMSArmorStand(World world, StandardHologramLine parentHologramLine, ProtocolPacketSettings protocolPacketSettings) { super(world); this.parentHologramLine = parentHologramLine; this.protocolPacketSettings = protocolPacketSettings; + this.helper = new VersionNMSEntityHelper(this); super.setInvisible(true); super.setSmall(true); @@ -208,22 +208,7 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta public void setLocationNMS(double x, double y, double z) { super.setPosition(x, y, z); if (protocolPacketSettings.sendAccurateLocationPackets()) { - broadcastLocationPacketNMS(); - } - } - - private void broadcastLocationPacketNMS() { - PacketPlayOutEntityTeleport teleportPacket = new PacketPlayOutEntityTeleport(this); - - for (EntityHuman humanEntity : super.world.players) { - if (humanEntity instanceof EntityPlayer) { - EntityPlayer nmsPlayer = (EntityPlayer) humanEntity; - - double distanceSquared = Utils.distanceSquared(nmsPlayer.locX, super.locX, nmsPlayer.locZ, super.locZ); - if (distanceSquared < 64 * 64 * 2 && nmsPlayer.playerConnection != null) { - nmsPlayer.playerConnection.sendPacket(teleportPacket); - } - } + helper.broadcastPacket(new PacketPlayOutEntityTeleport(this)); } } diff --git a/nms/v1_12_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_12_R1/VersionNMSEntityHelper.java b/nms/v1_12_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_12_R1/VersionNMSEntityHelper.java new file mode 100644 index 00000000..0e5b4e47 --- /dev/null +++ b/nms/v1_12_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_12_R1/VersionNMSEntityHelper.java @@ -0,0 +1,34 @@ +/* + * Copyright (C) filoghost and contributors + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ +package me.filoghost.holographicdisplays.nms.v1_12_R1; + +import me.filoghost.holographicdisplays.core.nms.entity.NMSEntityHelper; +import net.minecraft.server.v1_12_R1.Entity; +import net.minecraft.server.v1_12_R1.EntityTrackerEntry; +import net.minecraft.server.v1_12_R1.Packet; +import net.minecraft.server.v1_12_R1.WorldServer; + +public class VersionNMSEntityHelper extends NMSEntityHelper { + + private final Entity entity; + + public VersionNMSEntityHelper(Entity entity) { + this.entity = entity; + } + + @Override + protected EntityTrackerEntry getTracker0() { + return ((WorldServer) entity.world).tracker.trackedEntities.get(entity.getId()); + } + + public void broadcastPacket(Packet packet) { + EntityTrackerEntry tracker = getTracker(); + if (tracker != null) { + tracker.broadcast(packet); + } + } + +} diff --git a/nms/v1_13_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R1/EntityNMSArmorStand.java b/nms/v1_13_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R1/EntityNMSArmorStand.java index 835cdb7e..d15af064 100644 --- a/nms/v1_13_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R1/EntityNMSArmorStand.java +++ b/nms/v1_13_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R1/EntityNMSArmorStand.java @@ -9,7 +9,6 @@ import me.filoghost.fcommons.Preconditions; import me.filoghost.fcommons.Strings; import me.filoghost.fcommons.reflection.ReflectField; import me.filoghost.holographicdisplays.core.DebugLogger; -import me.filoghost.holographicdisplays.core.Utils; import me.filoghost.holographicdisplays.core.hologram.StandardHologramLine; import me.filoghost.holographicdisplays.core.nms.ProtocolPacketSettings; import me.filoghost.holographicdisplays.core.nms.entity.NMSArmorStand; @@ -19,7 +18,6 @@ import net.minecraft.server.v1_13_R1.DamageSource; import net.minecraft.server.v1_13_R1.Entity; import net.minecraft.server.v1_13_R1.EntityArmorStand; import net.minecraft.server.v1_13_R1.EntityHuman; -import net.minecraft.server.v1_13_R1.EntityPlayer; import net.minecraft.server.v1_13_R1.EnumHand; import net.minecraft.server.v1_13_R1.EnumInteractionResult; import net.minecraft.server.v1_13_R1.EnumItemSlot; @@ -41,12 +39,14 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta private final StandardHologramLine parentHologramLine; private final ProtocolPacketSettings protocolPacketSettings; + private final VersionNMSEntityHelper helper; private String customName; public EntityNMSArmorStand(World world, StandardHologramLine parentHologramLine, ProtocolPacketSettings protocolPacketSettings) { super(world); this.parentHologramLine = parentHologramLine; this.protocolPacketSettings = protocolPacketSettings; + this.helper = new VersionNMSEntityHelper(this); super.setInvisible(true); super.setSmall(true); @@ -210,22 +210,7 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta public void setLocationNMS(double x, double y, double z) { super.setPosition(x, y, z); if (protocolPacketSettings.sendAccurateLocationPackets()) { - broadcastLocationPacketNMS(); - } - } - - private void broadcastLocationPacketNMS() { - PacketPlayOutEntityTeleport teleportPacket = new PacketPlayOutEntityTeleport(this); - - for (EntityHuman humanEntity : super.world.players) { - if (humanEntity instanceof EntityPlayer) { - EntityPlayer nmsPlayer = (EntityPlayer) humanEntity; - - double distanceSquared = Utils.distanceSquared(nmsPlayer.locX, super.locX, nmsPlayer.locZ, super.locZ); - if (distanceSquared < 64 * 64 * 2 && nmsPlayer.playerConnection != null) { - nmsPlayer.playerConnection.sendPacket(teleportPacket); - } - } + helper.broadcastPacket(new PacketPlayOutEntityTeleport(this)); } } diff --git a/nms/v1_13_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R1/VersionNMSEntityHelper.java b/nms/v1_13_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R1/VersionNMSEntityHelper.java new file mode 100644 index 00000000..d89dc8b9 --- /dev/null +++ b/nms/v1_13_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R1/VersionNMSEntityHelper.java @@ -0,0 +1,34 @@ +/* + * Copyright (C) filoghost and contributors + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ +package me.filoghost.holographicdisplays.nms.v1_13_R1; + +import me.filoghost.holographicdisplays.core.nms.entity.NMSEntityHelper; +import net.minecraft.server.v1_13_R1.Entity; +import net.minecraft.server.v1_13_R1.EntityTrackerEntry; +import net.minecraft.server.v1_13_R1.Packet; +import net.minecraft.server.v1_13_R1.WorldServer; + +public class VersionNMSEntityHelper extends NMSEntityHelper { + + private final Entity entity; + + public VersionNMSEntityHelper(Entity entity) { + this.entity = entity; + } + + @Override + protected EntityTrackerEntry getTracker0() { + return ((WorldServer) entity.world).tracker.trackedEntities.get(entity.getId()); + } + + public void broadcastPacket(Packet packet) { + EntityTrackerEntry tracker = getTracker(); + if (tracker != null) { + tracker.broadcast(packet); + } + } + +} diff --git a/nms/v1_13_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R2/EntityNMSArmorStand.java b/nms/v1_13_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R2/EntityNMSArmorStand.java index a788056c..4920d3e7 100644 --- a/nms/v1_13_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R2/EntityNMSArmorStand.java +++ b/nms/v1_13_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R2/EntityNMSArmorStand.java @@ -9,7 +9,6 @@ import me.filoghost.fcommons.Preconditions; import me.filoghost.fcommons.Strings; import me.filoghost.fcommons.reflection.ReflectField; import me.filoghost.holographicdisplays.core.DebugLogger; -import me.filoghost.holographicdisplays.core.Utils; import me.filoghost.holographicdisplays.core.hologram.StandardHologramLine; import me.filoghost.holographicdisplays.core.nms.ProtocolPacketSettings; import me.filoghost.holographicdisplays.core.nms.entity.NMSArmorStand; @@ -19,7 +18,6 @@ import net.minecraft.server.v1_13_R2.DamageSource; import net.minecraft.server.v1_13_R2.Entity; import net.minecraft.server.v1_13_R2.EntityArmorStand; import net.minecraft.server.v1_13_R2.EntityHuman; -import net.minecraft.server.v1_13_R2.EntityPlayer; import net.minecraft.server.v1_13_R2.EnumHand; import net.minecraft.server.v1_13_R2.EnumInteractionResult; import net.minecraft.server.v1_13_R2.EnumItemSlot; @@ -41,12 +39,14 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta private final StandardHologramLine parentHologramLine; private final ProtocolPacketSettings protocolPacketSettings; + private final VersionNMSEntityHelper helper; private String customName; public EntityNMSArmorStand(World world, StandardHologramLine parentHologramLine, ProtocolPacketSettings protocolPacketSettings) { super(world); this.parentHologramLine = parentHologramLine; this.protocolPacketSettings = protocolPacketSettings; + this.helper = new VersionNMSEntityHelper(this); super.setInvisible(true); super.setSmall(true); @@ -210,22 +210,7 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta public void setLocationNMS(double x, double y, double z) { super.setPosition(x, y, z); if (protocolPacketSettings.sendAccurateLocationPackets()) { - broadcastLocationPacketNMS(); - } - } - - private void broadcastLocationPacketNMS() { - PacketPlayOutEntityTeleport teleportPacket = new PacketPlayOutEntityTeleport(this); - - for (EntityHuman humanEntity : super.world.players) { - if (humanEntity instanceof EntityPlayer) { - EntityPlayer nmsPlayer = (EntityPlayer) humanEntity; - - double distanceSquared = Utils.distanceSquared(nmsPlayer.locX, super.locX, nmsPlayer.locZ, super.locZ); - if (distanceSquared < 64 * 64 * 2 && nmsPlayer.playerConnection != null) { - nmsPlayer.playerConnection.sendPacket(teleportPacket); - } - } + helper.broadcastPacket(new PacketPlayOutEntityTeleport(this)); } } diff --git a/nms/v1_13_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R2/VersionNMSEntityHelper.java b/nms/v1_13_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R2/VersionNMSEntityHelper.java new file mode 100644 index 00000000..c373f41b --- /dev/null +++ b/nms/v1_13_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R2/VersionNMSEntityHelper.java @@ -0,0 +1,34 @@ +/* + * Copyright (C) filoghost and contributors + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ +package me.filoghost.holographicdisplays.nms.v1_13_R2; + +import me.filoghost.holographicdisplays.core.nms.entity.NMSEntityHelper; +import net.minecraft.server.v1_13_R2.Entity; +import net.minecraft.server.v1_13_R2.EntityTrackerEntry; +import net.minecraft.server.v1_13_R2.Packet; +import net.minecraft.server.v1_13_R2.WorldServer; + +public class VersionNMSEntityHelper extends NMSEntityHelper { + + private final Entity entity; + + public VersionNMSEntityHelper(Entity entity) { + this.entity = entity; + } + + @Override + protected EntityTrackerEntry getTracker0() { + return ((WorldServer) entity.world).tracker.trackedEntities.get(entity.getId()); + } + + public void broadcastPacket(Packet packet) { + EntityTrackerEntry tracker = getTracker(); + if (tracker != null) { + tracker.broadcast(packet); + } + } + +} diff --git a/nms/v1_14_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_14_R1/EntityNMSArmorStand.java b/nms/v1_14_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_14_R1/EntityNMSArmorStand.java index 64be79aa..f124b243 100644 --- a/nms/v1_14_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_14_R1/EntityNMSArmorStand.java +++ b/nms/v1_14_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_14_R1/EntityNMSArmorStand.java @@ -9,7 +9,6 @@ import me.filoghost.fcommons.Preconditions; import me.filoghost.fcommons.Strings; import me.filoghost.fcommons.reflection.ReflectField; import me.filoghost.holographicdisplays.core.DebugLogger; -import me.filoghost.holographicdisplays.core.Utils; import me.filoghost.holographicdisplays.core.hologram.StandardHologramLine; import me.filoghost.holographicdisplays.core.nms.ProtocolPacketSettings; import me.filoghost.holographicdisplays.core.nms.entity.NMSArmorStand; @@ -19,7 +18,6 @@ import net.minecraft.server.v1_14_R1.DamageSource; import net.minecraft.server.v1_14_R1.Entity; import net.minecraft.server.v1_14_R1.EntityArmorStand; import net.minecraft.server.v1_14_R1.EntityHuman; -import net.minecraft.server.v1_14_R1.EntityPlayer; import net.minecraft.server.v1_14_R1.EntityTypes; import net.minecraft.server.v1_14_R1.EnumHand; import net.minecraft.server.v1_14_R1.EnumInteractionResult; @@ -42,6 +40,7 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta private final StandardHologramLine parentHologramLine; private final ProtocolPacketSettings protocolPacketSettings; + private final VersionNMSEntityHelper helper; private CraftEntity customBukkitEntity; private String customName; @@ -49,6 +48,7 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta super(EntityTypes.ARMOR_STAND, world); this.parentHologramLine = parentHologramLine; this.protocolPacketSettings = protocolPacketSettings; + this.helper = new VersionNMSEntityHelper(this); super.setInvisible(true); super.setSmall(true); @@ -212,22 +212,7 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta public void setLocationNMS(double x, double y, double z) { super.setPosition(x, y, z); if (protocolPacketSettings.sendAccurateLocationPackets()) { - broadcastLocationPacketNMS(); - } - } - - private void broadcastLocationPacketNMS() { - PacketPlayOutEntityTeleport teleportPacket = new PacketPlayOutEntityTeleport(this); - - for (EntityHuman humanEntity : super.world.getPlayers()) { - if (humanEntity instanceof EntityPlayer) { - EntityPlayer nmsPlayer = (EntityPlayer) humanEntity; - - double distanceSquared = Utils.distanceSquared(nmsPlayer.locX, super.locX, nmsPlayer.locZ, super.locZ); - if (distanceSquared < 64 * 64 * 2 && nmsPlayer.playerConnection != null) { - nmsPlayer.playerConnection.sendPacket(teleportPacket); - } - } + helper.broadcastPacket(new PacketPlayOutEntityTeleport(this)); } } diff --git a/nms/v1_14_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_14_R1/VersionNMSEntityHelper.java b/nms/v1_14_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_14_R1/VersionNMSEntityHelper.java new file mode 100644 index 00000000..c71f653e --- /dev/null +++ b/nms/v1_14_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_14_R1/VersionNMSEntityHelper.java @@ -0,0 +1,34 @@ +/* + * Copyright (C) filoghost and contributors + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ +package me.filoghost.holographicdisplays.nms.v1_14_R1; + +import me.filoghost.holographicdisplays.core.nms.entity.NMSEntityHelper; +import net.minecraft.server.v1_14_R1.Entity; +import net.minecraft.server.v1_14_R1.Packet; +import net.minecraft.server.v1_14_R1.PlayerChunkMap.EntityTracker; +import net.minecraft.server.v1_14_R1.WorldServer; + +public class VersionNMSEntityHelper extends NMSEntityHelper { + + private final Entity entity; + + public VersionNMSEntityHelper(Entity entity) { + this.entity = entity; + } + + @Override + protected EntityTracker getTracker0() { + return ((WorldServer) entity.world).getChunkProvider().playerChunkMap.trackedEntities.get(entity.getId()); + } + + public void broadcastPacket(Packet packet) { + EntityTracker tracker = getTracker(); + if (tracker != null) { + tracker.broadcast(packet); + } + } + +} diff --git a/nms/v1_15_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_15_R1/EntityNMSArmorStand.java b/nms/v1_15_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_15_R1/EntityNMSArmorStand.java index be735eab..8c9850a9 100644 --- a/nms/v1_15_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_15_R1/EntityNMSArmorStand.java +++ b/nms/v1_15_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_15_R1/EntityNMSArmorStand.java @@ -9,7 +9,6 @@ import me.filoghost.fcommons.Preconditions; import me.filoghost.fcommons.Strings; import me.filoghost.fcommons.reflection.ReflectField; import me.filoghost.holographicdisplays.core.DebugLogger; -import me.filoghost.holographicdisplays.core.Utils; import me.filoghost.holographicdisplays.core.hologram.StandardHologramLine; import me.filoghost.holographicdisplays.core.nms.ProtocolPacketSettings; import me.filoghost.holographicdisplays.core.nms.entity.NMSArmorStand; @@ -19,7 +18,6 @@ import net.minecraft.server.v1_15_R1.DamageSource; import net.minecraft.server.v1_15_R1.Entity; import net.minecraft.server.v1_15_R1.EntityArmorStand; import net.minecraft.server.v1_15_R1.EntityHuman; -import net.minecraft.server.v1_15_R1.EntityPlayer; import net.minecraft.server.v1_15_R1.EntityTypes; import net.minecraft.server.v1_15_R1.EnumHand; import net.minecraft.server.v1_15_R1.EnumInteractionResult; @@ -42,6 +40,7 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta private final StandardHologramLine parentHologramLine; private final ProtocolPacketSettings protocolPacketSettings; + private final VersionNMSEntityHelper helper; private CraftEntity customBukkitEntity; private String customName; @@ -49,6 +48,7 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta super(EntityTypes.ARMOR_STAND, world); this.parentHologramLine = parentHologramLine; this.protocolPacketSettings = protocolPacketSettings; + this.helper = new VersionNMSEntityHelper(this); super.setInvisible(true); super.setSmall(true); @@ -212,22 +212,7 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta public void setLocationNMS(double x, double y, double z) { super.setPosition(x, y, z); if (protocolPacketSettings.sendAccurateLocationPackets()) { - broadcastLocationPacketNMS(); - } - } - - private void broadcastLocationPacketNMS() { - PacketPlayOutEntityTeleport teleportPacket = new PacketPlayOutEntityTeleport(this); - - for (EntityHuman humanEntity : super.world.getPlayers()) { - if (humanEntity instanceof EntityPlayer) { - EntityPlayer nmsPlayer = (EntityPlayer) humanEntity; - - double distanceSquared = Utils.distanceSquared(nmsPlayer.locX(), super.locX(), nmsPlayer.locZ(), super.locZ()); - if (distanceSquared < 64 * 64 * 2 && nmsPlayer.playerConnection != null) { - nmsPlayer.playerConnection.sendPacket(teleportPacket); - } - } + helper.broadcastPacket(new PacketPlayOutEntityTeleport(this)); } } diff --git a/nms/v1_15_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_15_R1/VersionNMSEntityHelper.java b/nms/v1_15_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_15_R1/VersionNMSEntityHelper.java new file mode 100644 index 00000000..e19a09fd --- /dev/null +++ b/nms/v1_15_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_15_R1/VersionNMSEntityHelper.java @@ -0,0 +1,34 @@ +/* + * Copyright (C) filoghost and contributors + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ +package me.filoghost.holographicdisplays.nms.v1_15_R1; + +import me.filoghost.holographicdisplays.core.nms.entity.NMSEntityHelper; +import net.minecraft.server.v1_15_R1.Entity; +import net.minecraft.server.v1_15_R1.Packet; +import net.minecraft.server.v1_15_R1.PlayerChunkMap.EntityTracker; +import net.minecraft.server.v1_15_R1.WorldServer; + +public class VersionNMSEntityHelper extends NMSEntityHelper { + + private final Entity entity; + + public VersionNMSEntityHelper(Entity entity) { + this.entity = entity; + } + + @Override + protected EntityTracker getTracker0() { + return ((WorldServer) entity.world).getChunkProvider().playerChunkMap.trackedEntities.get(entity.getId()); + } + + public void broadcastPacket(Packet packet) { + EntityTracker tracker = getTracker(); + if (tracker != null) { + tracker.broadcast(packet); + } + } + +} diff --git a/nms/v1_16_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R1/EntityNMSArmorStand.java b/nms/v1_16_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R1/EntityNMSArmorStand.java index 79145b8b..d2c545c2 100644 --- a/nms/v1_16_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R1/EntityNMSArmorStand.java +++ b/nms/v1_16_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R1/EntityNMSArmorStand.java @@ -9,7 +9,6 @@ import me.filoghost.fcommons.Preconditions; import me.filoghost.fcommons.Strings; import me.filoghost.fcommons.reflection.ReflectField; import me.filoghost.holographicdisplays.core.DebugLogger; -import me.filoghost.holographicdisplays.core.Utils; import me.filoghost.holographicdisplays.core.hologram.StandardHologramLine; import me.filoghost.holographicdisplays.core.nms.ProtocolPacketSettings; import me.filoghost.holographicdisplays.core.nms.entity.NMSArmorStand; @@ -19,7 +18,6 @@ import net.minecraft.server.v1_16_R1.DamageSource; import net.minecraft.server.v1_16_R1.Entity; import net.minecraft.server.v1_16_R1.EntityArmorStand; import net.minecraft.server.v1_16_R1.EntityHuman; -import net.minecraft.server.v1_16_R1.EntityPlayer; import net.minecraft.server.v1_16_R1.EntityTypes; import net.minecraft.server.v1_16_R1.EnumHand; import net.minecraft.server.v1_16_R1.EnumInteractionResult; @@ -42,6 +40,7 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta private final StandardHologramLine parentHologramLine; private final ProtocolPacketSettings protocolPacketSettings; + private final VersionNMSEntityHelper helper; private CraftEntity customBukkitEntity; private String customName; @@ -49,6 +48,7 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta super(EntityTypes.ARMOR_STAND, world); this.parentHologramLine = parentHologramLine; this.protocolPacketSettings = protocolPacketSettings; + this.helper = new VersionNMSEntityHelper(this); super.setInvisible(true); super.setSmall(true); @@ -212,22 +212,7 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta public void setLocationNMS(double x, double y, double z) { super.setPosition(x, y, z); if (protocolPacketSettings.sendAccurateLocationPackets()) { - broadcastLocationPacketNMS(); - } - } - - private void broadcastLocationPacketNMS() { - PacketPlayOutEntityTeleport teleportPacket = new PacketPlayOutEntityTeleport(this); - - for (EntityHuman humanEntity : super.world.getPlayers()) { - if (humanEntity instanceof EntityPlayer) { - EntityPlayer nmsPlayer = (EntityPlayer) humanEntity; - - double distanceSquared = Utils.distanceSquared(nmsPlayer.locX(), super.locX(), nmsPlayer.locZ(), super.locZ()); - if (distanceSquared < 64 * 64 * 2 && nmsPlayer.playerConnection != null) { - nmsPlayer.playerConnection.sendPacket(teleportPacket); - } - } + helper.broadcastPacket(new PacketPlayOutEntityTeleport(this)); } } diff --git a/nms/v1_16_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R1/VersionNMSEntityHelper.java b/nms/v1_16_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R1/VersionNMSEntityHelper.java new file mode 100644 index 00000000..44a98ed5 --- /dev/null +++ b/nms/v1_16_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R1/VersionNMSEntityHelper.java @@ -0,0 +1,34 @@ +/* + * Copyright (C) filoghost and contributors + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ +package me.filoghost.holographicdisplays.nms.v1_16_R1; + +import me.filoghost.holographicdisplays.core.nms.entity.NMSEntityHelper; +import net.minecraft.server.v1_16_R1.Entity; +import net.minecraft.server.v1_16_R1.Packet; +import net.minecraft.server.v1_16_R1.PlayerChunkMap.EntityTracker; +import net.minecraft.server.v1_16_R1.WorldServer; + +public class VersionNMSEntityHelper extends NMSEntityHelper { + + private final Entity entity; + + public VersionNMSEntityHelper(Entity entity) { + this.entity = entity; + } + + @Override + protected EntityTracker getTracker0() { + return ((WorldServer) entity.world).getChunkProvider().playerChunkMap.trackedEntities.get(entity.getId()); + } + + public void broadcastPacket(Packet packet) { + EntityTracker tracker = getTracker(); + if (tracker != null) { + tracker.broadcast(packet); + } + } + +} diff --git a/nms/v1_16_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R2/EntityNMSArmorStand.java b/nms/v1_16_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R2/EntityNMSArmorStand.java index 6a408668..158c15b2 100644 --- a/nms/v1_16_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R2/EntityNMSArmorStand.java +++ b/nms/v1_16_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R2/EntityNMSArmorStand.java @@ -9,7 +9,6 @@ import me.filoghost.fcommons.Preconditions; import me.filoghost.fcommons.Strings; import me.filoghost.fcommons.reflection.ReflectField; import me.filoghost.holographicdisplays.core.DebugLogger; -import me.filoghost.holographicdisplays.core.Utils; import me.filoghost.holographicdisplays.core.hologram.StandardHologramLine; import me.filoghost.holographicdisplays.core.nms.ProtocolPacketSettings; import me.filoghost.holographicdisplays.core.nms.entity.NMSArmorStand; @@ -19,7 +18,6 @@ import net.minecraft.server.v1_16_R2.DamageSource; import net.minecraft.server.v1_16_R2.Entity; import net.minecraft.server.v1_16_R2.EntityArmorStand; import net.minecraft.server.v1_16_R2.EntityHuman; -import net.minecraft.server.v1_16_R2.EntityPlayer; import net.minecraft.server.v1_16_R2.EntityTypes; import net.minecraft.server.v1_16_R2.EnumHand; import net.minecraft.server.v1_16_R2.EnumInteractionResult; @@ -42,6 +40,7 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta private final StandardHologramLine parentHologramLine; private final ProtocolPacketSettings protocolPacketSettings; + private final VersionNMSEntityHelper helper; private CraftEntity customBukkitEntity; private String customName; @@ -49,6 +48,7 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta super(EntityTypes.ARMOR_STAND, world); this.parentHologramLine = parentHologramLine; this.protocolPacketSettings = protocolPacketSettings; + this.helper = new VersionNMSEntityHelper(this); super.setInvisible(true); super.setSmall(true); @@ -212,22 +212,7 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta public void setLocationNMS(double x, double y, double z) { super.setPosition(x, y, z); if (protocolPacketSettings.sendAccurateLocationPackets()) { - broadcastLocationPacketNMS(); - } - } - - private void broadcastLocationPacketNMS() { - PacketPlayOutEntityTeleport teleportPacket = new PacketPlayOutEntityTeleport(this); - - for (EntityHuman humanEntity : super.world.getPlayers()) { - if (humanEntity instanceof EntityPlayer) { - EntityPlayer nmsPlayer = (EntityPlayer) humanEntity; - - double distanceSquared = Utils.distanceSquared(nmsPlayer.locX(), super.locX(), nmsPlayer.locZ(), super.locZ()); - if (distanceSquared < 64 * 64 * 2 && nmsPlayer.playerConnection != null) { - nmsPlayer.playerConnection.sendPacket(teleportPacket); - } - } + helper.broadcastPacket(new PacketPlayOutEntityTeleport(this)); } } diff --git a/nms/v1_16_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R2/VersionNMSEntityHelper.java b/nms/v1_16_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R2/VersionNMSEntityHelper.java new file mode 100644 index 00000000..760a8e73 --- /dev/null +++ b/nms/v1_16_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R2/VersionNMSEntityHelper.java @@ -0,0 +1,34 @@ +/* + * Copyright (C) filoghost and contributors + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ +package me.filoghost.holographicdisplays.nms.v1_16_R2; + +import me.filoghost.holographicdisplays.core.nms.entity.NMSEntityHelper; +import net.minecraft.server.v1_16_R2.Entity; +import net.minecraft.server.v1_16_R2.Packet; +import net.minecraft.server.v1_16_R2.PlayerChunkMap.EntityTracker; +import net.minecraft.server.v1_16_R2.WorldServer; + +public class VersionNMSEntityHelper extends NMSEntityHelper { + + private final Entity entity; + + public VersionNMSEntityHelper(Entity entity) { + this.entity = entity; + } + + @Override + protected EntityTracker getTracker0() { + return ((WorldServer) entity.world).getChunkProvider().playerChunkMap.trackedEntities.get(entity.getId()); + } + + public void broadcastPacket(Packet packet) { + EntityTracker tracker = getTracker(); + if (tracker != null) { + tracker.broadcast(packet); + } + } + +} diff --git a/nms/v1_16_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R3/EntityNMSArmorStand.java b/nms/v1_16_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R3/EntityNMSArmorStand.java index 6a2a329c..714ff291 100644 --- a/nms/v1_16_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R3/EntityNMSArmorStand.java +++ b/nms/v1_16_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R3/EntityNMSArmorStand.java @@ -9,7 +9,6 @@ import me.filoghost.fcommons.Preconditions; import me.filoghost.fcommons.Strings; import me.filoghost.fcommons.reflection.ReflectField; import me.filoghost.holographicdisplays.core.DebugLogger; -import me.filoghost.holographicdisplays.core.Utils; import me.filoghost.holographicdisplays.core.hologram.StandardHologramLine; import me.filoghost.holographicdisplays.core.nms.ProtocolPacketSettings; import me.filoghost.holographicdisplays.core.nms.entity.NMSArmorStand; @@ -19,7 +18,6 @@ import net.minecraft.server.v1_16_R3.DamageSource; import net.minecraft.server.v1_16_R3.Entity; import net.minecraft.server.v1_16_R3.EntityArmorStand; import net.minecraft.server.v1_16_R3.EntityHuman; -import net.minecraft.server.v1_16_R3.EntityPlayer; import net.minecraft.server.v1_16_R3.EntityTypes; import net.minecraft.server.v1_16_R3.EnumHand; import net.minecraft.server.v1_16_R3.EnumInteractionResult; @@ -42,6 +40,7 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta private final StandardHologramLine parentHologramLine; private final ProtocolPacketSettings protocolPacketSettings; + private final VersionNMSEntityHelper helper; private CraftEntity customBukkitEntity; private String customName; @@ -49,6 +48,7 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta super(EntityTypes.ARMOR_STAND, world); this.parentHologramLine = parentHologramLine; this.protocolPacketSettings = protocolPacketSettings; + this.helper = new VersionNMSEntityHelper(this); super.setInvisible(true); super.setSmall(true); @@ -212,22 +212,7 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta public void setLocationNMS(double x, double y, double z) { super.setPosition(x, y, z); if (protocolPacketSettings.sendAccurateLocationPackets()) { - broadcastLocationPacketNMS(); - } - } - - private void broadcastLocationPacketNMS() { - PacketPlayOutEntityTeleport teleportPacket = new PacketPlayOutEntityTeleport(this); - - for (EntityHuman humanEntity : super.world.getPlayers()) { - if (humanEntity instanceof EntityPlayer) { - EntityPlayer nmsPlayer = (EntityPlayer) humanEntity; - - double distanceSquared = Utils.distanceSquared(nmsPlayer.locX(), super.locX(), nmsPlayer.locZ(), super.locZ()); - if (distanceSquared < 64 * 64 * 2 && nmsPlayer.playerConnection != null) { - nmsPlayer.playerConnection.sendPacket(teleportPacket); - } - } + helper.broadcastPacket(new PacketPlayOutEntityTeleport(this)); } } diff --git a/nms/v1_16_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R3/VersionNMSEntityHelper.java b/nms/v1_16_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R3/VersionNMSEntityHelper.java new file mode 100644 index 00000000..4713ec7c --- /dev/null +++ b/nms/v1_16_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R3/VersionNMSEntityHelper.java @@ -0,0 +1,34 @@ +/* + * Copyright (C) filoghost and contributors + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ +package me.filoghost.holographicdisplays.nms.v1_16_R3; + +import me.filoghost.holographicdisplays.core.nms.entity.NMSEntityHelper; +import net.minecraft.server.v1_16_R3.Entity; +import net.minecraft.server.v1_16_R3.Packet; +import net.minecraft.server.v1_16_R3.PlayerChunkMap.EntityTracker; +import net.minecraft.server.v1_16_R3.WorldServer; + +public class VersionNMSEntityHelper extends NMSEntityHelper { + + private final Entity entity; + + public VersionNMSEntityHelper(Entity entity) { + this.entity = entity; + } + + @Override + protected EntityTracker getTracker0() { + return ((WorldServer) entity.world).getChunkProvider().playerChunkMap.trackedEntities.get(entity.getId()); + } + + public void broadcastPacket(Packet packet) { + EntityTracker tracker = getTracker(); + if (tracker != null) { + tracker.broadcast(packet); + } + } + +} diff --git a/nms/v1_8_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R2/EntityNMSArmorStand.java b/nms/v1_8_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R2/EntityNMSArmorStand.java index 1ea10d09..63ba4c16 100644 --- a/nms/v1_8_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R2/EntityNMSArmorStand.java +++ b/nms/v1_8_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R2/EntityNMSArmorStand.java @@ -10,7 +10,6 @@ import me.filoghost.fcommons.Strings; import me.filoghost.fcommons.reflection.ReflectField; import me.filoghost.fcommons.reflection.ReflectMethod; import me.filoghost.holographicdisplays.core.DebugLogger; -import me.filoghost.holographicdisplays.core.Utils; import me.filoghost.holographicdisplays.core.hologram.StandardHologramLine; import me.filoghost.holographicdisplays.core.nms.ProtocolPacketSettings; import me.filoghost.holographicdisplays.core.nms.entity.NMSArmorStand; @@ -20,7 +19,6 @@ import net.minecraft.server.v1_8_R2.DamageSource; import net.minecraft.server.v1_8_R2.Entity; import net.minecraft.server.v1_8_R2.EntityArmorStand; import net.minecraft.server.v1_8_R2.EntityHuman; -import net.minecraft.server.v1_8_R2.EntityPlayer; import net.minecraft.server.v1_8_R2.ItemStack; import net.minecraft.server.v1_8_R2.NBTTagCompound; import net.minecraft.server.v1_8_R2.PacketPlayOutEntityTeleport; @@ -38,12 +36,14 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta private final StandardHologramLine parentHologramLine; private final ProtocolPacketSettings protocolPacketSettings; + private final VersionNMSEntityHelper helper; private String customName; - + public EntityNMSArmorStand(World world, StandardHologramLine parentHologramLine, ProtocolPacketSettings protocolPacketSettings) { super(world); this.parentHologramLine = parentHologramLine; this.protocolPacketSettings = protocolPacketSettings; + this.helper = new VersionNMSEntityHelper(this); super.setInvisible(true); super.setSmall(true); @@ -197,22 +197,7 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta public void setLocationNMS(double x, double y, double z) { super.setPosition(x, y, z); if (protocolPacketSettings.sendAccurateLocationPackets()) { - broadcastLocationPacketNMS(); - } - } - - private void broadcastLocationPacketNMS() { - PacketPlayOutEntityTeleport teleportPacket = new PacketPlayOutEntityTeleport(this); - - for (EntityHuman humanEntity : super.world.players) { - if (humanEntity instanceof EntityPlayer) { - EntityPlayer nmsPlayer = (EntityPlayer) humanEntity; - - double distanceSquared = Utils.distanceSquared(nmsPlayer.locX, super.locX, nmsPlayer.locZ, super.locZ); - if (distanceSquared < 64 * 64 * 2 && nmsPlayer.playerConnection != null) { - nmsPlayer.playerConnection.sendPacket(teleportPacket); - } - } + helper.broadcastPacket(new PacketPlayOutEntityTeleport(this)); } } diff --git a/nms/v1_8_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R2/VersionNMSEntityHelper.java b/nms/v1_8_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R2/VersionNMSEntityHelper.java new file mode 100644 index 00000000..8dc1afc8 --- /dev/null +++ b/nms/v1_8_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R2/VersionNMSEntityHelper.java @@ -0,0 +1,34 @@ +/* + * Copyright (C) filoghost and contributors + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ +package me.filoghost.holographicdisplays.nms.v1_8_R2; + +import me.filoghost.holographicdisplays.core.nms.entity.NMSEntityHelper; +import net.minecraft.server.v1_8_R2.Entity; +import net.minecraft.server.v1_8_R2.EntityTrackerEntry; +import net.minecraft.server.v1_8_R2.Packet; +import net.minecraft.server.v1_8_R2.WorldServer; + +public class VersionNMSEntityHelper extends NMSEntityHelper { + + private final Entity entity; + + public VersionNMSEntityHelper(Entity entity) { + this.entity = entity; + } + + @Override + protected EntityTrackerEntry getTracker0() { + return ((WorldServer) entity.world).tracker.trackedEntities.get(entity.getId()); + } + + public void broadcastPacket(Packet packet) { + EntityTrackerEntry tracker = getTracker(); + if (tracker != null) { + tracker.broadcast(packet); + } + } + +} diff --git a/nms/v1_8_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R3/EntityNMSArmorStand.java b/nms/v1_8_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R3/EntityNMSArmorStand.java index 56e34fe9..66a16a4c 100644 --- a/nms/v1_8_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R3/EntityNMSArmorStand.java +++ b/nms/v1_8_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R3/EntityNMSArmorStand.java @@ -10,7 +10,6 @@ import me.filoghost.fcommons.Strings; import me.filoghost.fcommons.reflection.ReflectField; import me.filoghost.fcommons.reflection.ReflectMethod; import me.filoghost.holographicdisplays.core.DebugLogger; -import me.filoghost.holographicdisplays.core.Utils; import me.filoghost.holographicdisplays.core.hologram.StandardHologramLine; import me.filoghost.holographicdisplays.core.nms.ProtocolPacketSettings; import me.filoghost.holographicdisplays.core.nms.entity.NMSArmorStand; @@ -20,7 +19,6 @@ import net.minecraft.server.v1_8_R3.DamageSource; import net.minecraft.server.v1_8_R3.Entity; import net.minecraft.server.v1_8_R3.EntityArmorStand; import net.minecraft.server.v1_8_R3.EntityHuman; -import net.minecraft.server.v1_8_R3.EntityPlayer; import net.minecraft.server.v1_8_R3.ItemStack; import net.minecraft.server.v1_8_R3.NBTTagCompound; import net.minecraft.server.v1_8_R3.PacketPlayOutEntityTeleport; @@ -38,12 +36,14 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta private final StandardHologramLine parentHologramLine; private final ProtocolPacketSettings protocolPacketSettings; + private final VersionNMSEntityHelper helper; private String customName; public EntityNMSArmorStand(World world, StandardHologramLine parentHologramLine, ProtocolPacketSettings protocolPacketSettings) { super(world); this.parentHologramLine = parentHologramLine; this.protocolPacketSettings = protocolPacketSettings; + this.helper = new VersionNMSEntityHelper(this); super.setInvisible(true); super.setSmall(true); @@ -197,22 +197,7 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta public void setLocationNMS(double x, double y, double z) { super.setPosition(x, y, z); if (protocolPacketSettings.sendAccurateLocationPackets()) { - broadcastLocationPacketNMS(); - } - } - - private void broadcastLocationPacketNMS() { - PacketPlayOutEntityTeleport teleportPacket = new PacketPlayOutEntityTeleport(this); - - for (EntityHuman humanEntity : super.world.players) { - if (humanEntity instanceof EntityPlayer) { - EntityPlayer nmsPlayer = (EntityPlayer) humanEntity; - - double distanceSquared = Utils.distanceSquared(nmsPlayer.locX, super.locX, nmsPlayer.locZ, super.locZ); - if (distanceSquared < 64 * 64 * 2 && nmsPlayer.playerConnection != null) { - nmsPlayer.playerConnection.sendPacket(teleportPacket); - } - } + helper.broadcastPacket(new PacketPlayOutEntityTeleport(this)); } } diff --git a/nms/v1_8_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R3/VersionNMSEntityHelper.java b/nms/v1_8_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R3/VersionNMSEntityHelper.java new file mode 100644 index 00000000..04f4ff76 --- /dev/null +++ b/nms/v1_8_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R3/VersionNMSEntityHelper.java @@ -0,0 +1,34 @@ +/* + * Copyright (C) filoghost and contributors + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ +package me.filoghost.holographicdisplays.nms.v1_8_R3; + +import me.filoghost.holographicdisplays.core.nms.entity.NMSEntityHelper; +import net.minecraft.server.v1_8_R3.Entity; +import net.minecraft.server.v1_8_R3.EntityTrackerEntry; +import net.minecraft.server.v1_8_R3.Packet; +import net.minecraft.server.v1_8_R3.WorldServer; + +public class VersionNMSEntityHelper extends NMSEntityHelper { + + private final Entity entity; + + public VersionNMSEntityHelper(Entity entity) { + this.entity = entity; + } + + @Override + protected EntityTrackerEntry getTracker0() { + return ((WorldServer) entity.world).tracker.trackedEntities.get(entity.getId()); + } + + public void broadcastPacket(Packet packet) { + EntityTrackerEntry tracker = getTracker(); + if (tracker != null) { + tracker.broadcast(packet); + } + } + +} diff --git a/nms/v1_9_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R1/EntityNMSArmorStand.java b/nms/v1_9_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R1/EntityNMSArmorStand.java index 9c65cd2f..37956a80 100644 --- a/nms/v1_9_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R1/EntityNMSArmorStand.java +++ b/nms/v1_9_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R1/EntityNMSArmorStand.java @@ -9,7 +9,6 @@ import me.filoghost.fcommons.Preconditions; import me.filoghost.fcommons.Strings; import me.filoghost.fcommons.reflection.ReflectField; import me.filoghost.holographicdisplays.core.DebugLogger; -import me.filoghost.holographicdisplays.core.Utils; import me.filoghost.holographicdisplays.core.hologram.StandardHologramLine; import me.filoghost.holographicdisplays.core.nms.ProtocolPacketSettings; import me.filoghost.holographicdisplays.core.nms.entity.NMSArmorStand; @@ -19,7 +18,6 @@ import net.minecraft.server.v1_9_R1.DamageSource; import net.minecraft.server.v1_9_R1.Entity; import net.minecraft.server.v1_9_R1.EntityArmorStand; import net.minecraft.server.v1_9_R1.EntityHuman; -import net.minecraft.server.v1_9_R1.EntityPlayer; import net.minecraft.server.v1_9_R1.EnumHand; import net.minecraft.server.v1_9_R1.EnumInteractionResult; import net.minecraft.server.v1_9_R1.EnumItemSlot; @@ -39,6 +37,7 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta private final StandardHologramLine parentHologramLine; private final ProtocolPacketSettings protocolPacketSettings; + private final VersionNMSEntityHelper helper; private String customName; @@ -46,6 +45,7 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta super(world); this.parentHologramLine = parentHologramLine; this.protocolPacketSettings = protocolPacketSettings; + this.helper = new VersionNMSEntityHelper(this); super.setInvisible(true); super.setSmall(true); @@ -209,22 +209,7 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta public void setLocationNMS(double x, double y, double z) { super.setPosition(x, y, z); if (protocolPacketSettings.sendAccurateLocationPackets()) { - broadcastLocationPacketNMS(); - } - } - - private void broadcastLocationPacketNMS() { - PacketPlayOutEntityTeleport teleportPacket = new PacketPlayOutEntityTeleport(this); - - for (EntityHuman humanEntity : super.world.players) { - if (humanEntity instanceof EntityPlayer) { - EntityPlayer nmsPlayer = (EntityPlayer) humanEntity; - - double distanceSquared = Utils.distanceSquared(nmsPlayer.locX, super.locX, nmsPlayer.locZ, super.locZ); - if (distanceSquared < 64 * 64 * 2 && nmsPlayer.playerConnection != null) { - nmsPlayer.playerConnection.sendPacket(teleportPacket); - } - } + helper.broadcastPacket(new PacketPlayOutEntityTeleport(this)); } } diff --git a/nms/v1_9_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R1/EntityNMSItem.java b/nms/v1_9_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R1/EntityNMSItem.java index bb60d74e..0914d014 100644 --- a/nms/v1_9_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R1/EntityNMSItem.java +++ b/nms/v1_9_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R1/EntityNMSItem.java @@ -5,7 +5,6 @@ */ package me.filoghost.holographicdisplays.nms.v1_9_R1; -import me.filoghost.holographicdisplays.core.Utils; import me.filoghost.holographicdisplays.core.hologram.StandardHologramLine; import me.filoghost.holographicdisplays.core.hologram.StandardItemLine; import me.filoghost.holographicdisplays.core.nms.NMSCommons; @@ -28,12 +27,14 @@ import org.bukkit.craftbukkit.v1_9_R1.inventory.CraftItemStack; public class EntityNMSItem extends EntityItem implements NMSItem { private final StandardItemLine parentHologramLine; + private final VersionNMSEntityHelper helper; private int resendMountPacketTicks; public EntityNMSItem(World world, StandardItemLine parentHologramLine) { super(world); this.parentHologramLine = parentHologramLine; + this.helper = new VersionNMSEntityHelper(this); super.pickupDelay = Integer.MAX_VALUE; } @@ -51,18 +52,7 @@ public class EntityNMSItem extends EntityItem implements NMSItem { Entity vehicle = by(); if (vehicle != null) { // Send a packet near to "remind" players that the item is riding the armor stand (Spigot bug or client bug) - PacketPlayOutMount mountPacket = new PacketPlayOutMount(vehicle); - - for (EntityHuman humanEntity : super.world.players) { - if (humanEntity instanceof EntityPlayer) { - EntityPlayer nmsPlayer = (EntityPlayer) humanEntity; - - double distanceSquared = Utils.distanceSquared(nmsPlayer.locX, super.locX, nmsPlayer.locZ, super.locZ); - if (distanceSquared < 32 * 32 && nmsPlayer.playerConnection != null) { - nmsPlayer.playerConnection.sendPacket(mountPacket); - } - } - } + helper.broadcastPacket(new PacketPlayOutMount(vehicle)); } } } diff --git a/nms/v1_9_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R1/EntityNMSSlime.java b/nms/v1_9_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R1/EntityNMSSlime.java index 5a2b3665..75fe1673 100644 --- a/nms/v1_9_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R1/EntityNMSSlime.java +++ b/nms/v1_9_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R1/EntityNMSSlime.java @@ -5,14 +5,12 @@ */ package me.filoghost.holographicdisplays.nms.v1_9_R1; -import me.filoghost.holographicdisplays.core.Utils; import me.filoghost.holographicdisplays.core.hologram.StandardHologramLine; import me.filoghost.holographicdisplays.core.nms.entity.NMSSlime; import net.minecraft.server.v1_9_R1.AxisAlignedBB; import net.minecraft.server.v1_9_R1.DamageSource; import net.minecraft.server.v1_9_R1.Entity; import net.minecraft.server.v1_9_R1.EntityDamageSource; -import net.minecraft.server.v1_9_R1.EntityHuman; import net.minecraft.server.v1_9_R1.EntityPlayer; import net.minecraft.server.v1_9_R1.EntitySlime; import net.minecraft.server.v1_9_R1.NBTTagCompound; @@ -26,12 +24,14 @@ import org.bukkit.event.player.PlayerInteractEntityEvent; public class EntityNMSSlime extends EntitySlime implements NMSSlime { private final StandardHologramLine parentHologramLine; + private final VersionNMSEntityHelper helper; private int resendMountPacketTicks; public EntityNMSSlime(World world, StandardHologramLine parentHologramLine) { super(world); this.parentHologramLine = parentHologramLine; + this.helper = new VersionNMSEntityHelper(this); super.persistent = true; super.collides = false; @@ -54,18 +54,7 @@ public class EntityNMSSlime extends EntitySlime implements NMSSlime { Entity vehicle = by(); if (vehicle != null) { // Send a packet near to "remind" players that the slime is riding the armor stand (Spigot bug or client bug) - PacketPlayOutMount mountPacket = new PacketPlayOutMount(vehicle); - - for (EntityHuman humanEntity : super.world.players) { - if (humanEntity instanceof EntityPlayer) { - EntityPlayer nmsPlayer = (EntityPlayer) humanEntity; - - double distanceSquared = Utils.distanceSquared(nmsPlayer.locX, super.locX, nmsPlayer.locZ, super.locZ); - if (distanceSquared < 32 * 32 && nmsPlayer.playerConnection != null) { - nmsPlayer.playerConnection.sendPacket(mountPacket); - } - } - } + helper.broadcastPacket(new PacketPlayOutMount(vehicle)); } } } diff --git a/nms/v1_9_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R1/VersionNMSEntityHelper.java b/nms/v1_9_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R1/VersionNMSEntityHelper.java new file mode 100644 index 00000000..4616fd0e --- /dev/null +++ b/nms/v1_9_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R1/VersionNMSEntityHelper.java @@ -0,0 +1,34 @@ +/* + * Copyright (C) filoghost and contributors + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ +package me.filoghost.holographicdisplays.nms.v1_9_R1; + +import me.filoghost.holographicdisplays.core.nms.entity.NMSEntityHelper; +import net.minecraft.server.v1_9_R1.Entity; +import net.minecraft.server.v1_9_R1.EntityTrackerEntry; +import net.minecraft.server.v1_9_R1.Packet; +import net.minecraft.server.v1_9_R1.WorldServer; + +public class VersionNMSEntityHelper extends NMSEntityHelper { + + private final Entity entity; + + public VersionNMSEntityHelper(Entity entity) { + this.entity = entity; + } + + @Override + protected EntityTrackerEntry getTracker0() { + return ((WorldServer) entity.world).tracker.trackedEntities.get(entity.getId()); + } + + public void broadcastPacket(Packet packet) { + EntityTrackerEntry tracker = getTracker(); + if (tracker != null) { + tracker.broadcast(packet); + } + } + +} diff --git a/nms/v1_9_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R2/EntityNMSArmorStand.java b/nms/v1_9_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R2/EntityNMSArmorStand.java index f80ef612..e95008f3 100644 --- a/nms/v1_9_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R2/EntityNMSArmorStand.java +++ b/nms/v1_9_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R2/EntityNMSArmorStand.java @@ -9,7 +9,6 @@ import me.filoghost.fcommons.Preconditions; import me.filoghost.fcommons.Strings; import me.filoghost.fcommons.reflection.ReflectField; import me.filoghost.holographicdisplays.core.DebugLogger; -import me.filoghost.holographicdisplays.core.Utils; import me.filoghost.holographicdisplays.core.hologram.StandardHologramLine; import me.filoghost.holographicdisplays.core.nms.ProtocolPacketSettings; import me.filoghost.holographicdisplays.core.nms.entity.NMSArmorStand; @@ -19,7 +18,6 @@ import net.minecraft.server.v1_9_R2.DamageSource; import net.minecraft.server.v1_9_R2.Entity; import net.minecraft.server.v1_9_R2.EntityArmorStand; import net.minecraft.server.v1_9_R2.EntityHuman; -import net.minecraft.server.v1_9_R2.EntityPlayer; import net.minecraft.server.v1_9_R2.EnumHand; import net.minecraft.server.v1_9_R2.EnumInteractionResult; import net.minecraft.server.v1_9_R2.EnumItemSlot; @@ -39,12 +37,14 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta private final StandardHologramLine parentHologramLine; private final ProtocolPacketSettings protocolPacketSettings; + private final VersionNMSEntityHelper helper; private String customName; public EntityNMSArmorStand(World world, StandardHologramLine parentHologramLine, ProtocolPacketSettings protocolPacketSettings) { super(world); this.parentHologramLine = parentHologramLine; this.protocolPacketSettings = protocolPacketSettings; + this.helper = new VersionNMSEntityHelper(this); super.setInvisible(true); super.setSmall(true); @@ -209,22 +209,7 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta public void setLocationNMS(double x, double y, double z) { super.setPosition(x, y, z); if (protocolPacketSettings.sendAccurateLocationPackets()) { - broadcastLocationPacketNMS(); - } - } - - private void broadcastLocationPacketNMS() { - PacketPlayOutEntityTeleport teleportPacket = new PacketPlayOutEntityTeleport(this); - - for (EntityHuman humanEntity : super.world.players) { - if (humanEntity instanceof EntityPlayer) { - EntityPlayer nmsPlayer = (EntityPlayer) humanEntity; - - double distanceSquared = Utils.distanceSquared(nmsPlayer.locX, super.locX, nmsPlayer.locZ, super.locZ); - if (distanceSquared < 64 * 64 * 2 && nmsPlayer.playerConnection != null) { - nmsPlayer.playerConnection.sendPacket(teleportPacket); - } - } + helper.broadcastPacket(new PacketPlayOutEntityTeleport(this)); } } diff --git a/nms/v1_9_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R2/EntityNMSItem.java b/nms/v1_9_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R2/EntityNMSItem.java index 2fa867ac..66edb21d 100644 --- a/nms/v1_9_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R2/EntityNMSItem.java +++ b/nms/v1_9_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R2/EntityNMSItem.java @@ -5,7 +5,6 @@ */ package me.filoghost.holographicdisplays.nms.v1_9_R2; -import me.filoghost.holographicdisplays.core.Utils; import me.filoghost.holographicdisplays.core.hologram.StandardHologramLine; import me.filoghost.holographicdisplays.core.hologram.StandardItemLine; import me.filoghost.holographicdisplays.core.nms.NMSCommons; @@ -28,12 +27,14 @@ import org.bukkit.craftbukkit.v1_9_R2.inventory.CraftItemStack; public class EntityNMSItem extends EntityItem implements NMSItem { private final StandardItemLine parentHologramLine; + private final VersionNMSEntityHelper helper; private int resendMountPacketTicks; public EntityNMSItem(World world, StandardItemLine parentHologramLine) { super(world); this.parentHologramLine = parentHologramLine; + this.helper = new VersionNMSEntityHelper(this); super.pickupDelay = Integer.MAX_VALUE; } @@ -51,18 +52,7 @@ public class EntityNMSItem extends EntityItem implements NMSItem { Entity vehicle = bz(); if (vehicle != null) { // Send a packet near to "remind" players that the item is riding the armor stand (Spigot bug or client bug) - PacketPlayOutMount mountPacket = new PacketPlayOutMount(vehicle); - - for (EntityHuman humanEntity : super.world.players) { - if (humanEntity instanceof EntityPlayer) { - EntityPlayer nmsPlayer = (EntityPlayer) humanEntity; - - double distanceSquared = Utils.distanceSquared(nmsPlayer.locX, super.locX, nmsPlayer.locZ, super.locZ); - if (distanceSquared < 32 * 32 && nmsPlayer.playerConnection != null) { - nmsPlayer.playerConnection.sendPacket(mountPacket); - } - } - } + helper.broadcastPacket(new PacketPlayOutMount(vehicle)); } } } diff --git a/nms/v1_9_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R2/EntityNMSSlime.java b/nms/v1_9_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R2/EntityNMSSlime.java index 15c7b1e4..fda2dee6 100644 --- a/nms/v1_9_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R2/EntityNMSSlime.java +++ b/nms/v1_9_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R2/EntityNMSSlime.java @@ -5,14 +5,12 @@ */ package me.filoghost.holographicdisplays.nms.v1_9_R2; -import me.filoghost.holographicdisplays.core.Utils; import me.filoghost.holographicdisplays.core.hologram.StandardHologramLine; import me.filoghost.holographicdisplays.core.nms.entity.NMSSlime; import net.minecraft.server.v1_9_R2.AxisAlignedBB; import net.minecraft.server.v1_9_R2.DamageSource; import net.minecraft.server.v1_9_R2.Entity; import net.minecraft.server.v1_9_R2.EntityDamageSource; -import net.minecraft.server.v1_9_R2.EntityHuman; import net.minecraft.server.v1_9_R2.EntityPlayer; import net.minecraft.server.v1_9_R2.EntitySlime; import net.minecraft.server.v1_9_R2.NBTTagCompound; @@ -26,12 +24,14 @@ import org.bukkit.event.player.PlayerInteractEntityEvent; public class EntityNMSSlime extends EntitySlime implements NMSSlime { private final StandardHologramLine parentHologramLine; + private final VersionNMSEntityHelper helper; private int resendMountPacketTicks; public EntityNMSSlime(World world, StandardHologramLine parentHologramLine) { super(world); this.parentHologramLine = parentHologramLine; + this.helper = new VersionNMSEntityHelper(this); super.persistent = true; super.collides = false; @@ -54,18 +54,7 @@ public class EntityNMSSlime extends EntitySlime implements NMSSlime { Entity vehicle = bz(); if (vehicle != null) { // Send a packet near to "remind" players that the slime is riding the armor stand (Spigot bug or client bug) - PacketPlayOutMount mountPacket = new PacketPlayOutMount(vehicle); - - for (EntityHuman humanEntity : super.world.players) { - if (humanEntity instanceof EntityPlayer) { - EntityPlayer nmsPlayer = (EntityPlayer) humanEntity; - - double distanceSquared = Utils.distanceSquared(nmsPlayer.locX, super.locX, nmsPlayer.locZ, super.locZ); - if (distanceSquared < 32 * 32 && nmsPlayer.playerConnection != null) { - nmsPlayer.playerConnection.sendPacket(mountPacket); - } - } - } + helper.broadcastPacket(new PacketPlayOutMount(vehicle)); } } } diff --git a/nms/v1_9_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R2/VersionNMSEntityHelper.java b/nms/v1_9_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R2/VersionNMSEntityHelper.java new file mode 100644 index 00000000..6ef43582 --- /dev/null +++ b/nms/v1_9_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R2/VersionNMSEntityHelper.java @@ -0,0 +1,34 @@ +/* + * Copyright (C) filoghost and contributors + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ +package me.filoghost.holographicdisplays.nms.v1_9_R2; + +import me.filoghost.holographicdisplays.core.nms.entity.NMSEntityHelper; +import net.minecraft.server.v1_9_R2.Entity; +import net.minecraft.server.v1_9_R2.EntityTrackerEntry; +import net.minecraft.server.v1_9_R2.Packet; +import net.minecraft.server.v1_9_R2.WorldServer; + +public class VersionNMSEntityHelper extends NMSEntityHelper { + + private final Entity entity; + + public VersionNMSEntityHelper(Entity entity) { + this.entity = entity; + } + + @Override + protected EntityTrackerEntry getTracker0() { + return ((WorldServer) entity.world).tracker.trackedEntities.get(entity.getId()); + } + + public void broadcastPacket(Packet packet) { + EntityTrackerEntry tracker = getTracker(); + if (tracker != null) { + tracker.broadcast(packet); + } + } + +}