Fix holograms not following players in 1.9+

This commit is contained in:
Graphica 2017-05-27 17:29:48 -05:00 committed by cnr
parent 98929f043f
commit a61c4cd816
2 changed files with 51 additions and 27 deletions

View File

@ -34,7 +34,7 @@ public class Hologram {
/**
* 1.7 packets uses both EntityIDs while 1.8 uses only the first.
*/
private ArrayList<Integer> _entityIds = new ArrayList<Integer>();
private ArrayList<Integer> _entityIds = new ArrayList<>();
private Entity _followEntity;
private HologramManager _hologramManager;
private String[] _hologramText = new String[0];
@ -50,7 +50,7 @@ public class Hologram {
private Packet[] _packets1_8;
private Packet[] _packets1_9;
private HashSet<UUID> _playersInList = new HashSet<>();
private ArrayList<Player> _playersTracking = new ArrayList<Player>();
private ArrayList<Player> _playersTracking = new ArrayList<>();
private boolean _removeEntityDeath;
private HologramTarget _target = HologramTarget.BLACKLIST;
private int _viewDistance = 70;
@ -70,7 +70,7 @@ public class Hologram {
*/
public Hologram(HologramManager hologramManager, Location location, String... text)
{
this(hologramManager, location, false, -1l, text);
this(hologramManager, location, false, -1L, text);
}
/**
@ -83,7 +83,7 @@ public class Hologram {
*/
public Hologram(HologramManager hologramManager, Location location, boolean hideBoundingBox, String... text)
{
this(hologramManager, location, hideBoundingBox, -1l, text);
this(hologramManager, location, hideBoundingBox, -1L, text);
}
/**
@ -431,9 +431,14 @@ public class Hologram {
*
* @return the original hologram object.
*/
public Hologram setFollowEntity(Entity entityToFollow) {
public Hologram setFollowEntity(Entity entityToFollow)
{
_followEntity = entityToFollow;
relativeToEntity = entityToFollow == null ? null : _location.clone().subtract(entityToFollow.getLocation()).toVector();
if (entityToFollow != null)
{
relativeToEntity = _location.clone().subtract(entityToFollow.getLocation()).toVector();
}
return this;
}
@ -447,7 +452,8 @@ public class Hologram {
*
* @retuen the original hologram object.
*/
public Hologram setHologramTarget(HologramTarget newTarget) {
public Hologram setHologramTarget(HologramTarget newTarget)
{
_target = newTarget;
return this;
}
@ -516,9 +522,32 @@ public class Hologram {
int z = (int) Math.floor(32 * _lastMovement.getZ());
Packet[] packets1_8 = new Packet[_hologramText.length];
Packet[] packets1_9 = new Packet[_hologramText.length];
int i = 0;
// Generate packets for 1.9 clients
x = (int) Math.floor(32 * newLocation.getX());
z = (int) Math.floor(32 * newLocation.getZ());
_lastMovement = new Vector(newLocation.getX() - (x / 32D), 0, newLocation.getZ() - (z / 32D));
for (Integer entityId : _entityIds)
{
PacketPlayOutEntityTeleport teleportPacket = new PacketPlayOutEntityTeleport();
teleportPacket.a = entityId;
teleportPacket.b = x;
teleportPacket.c = (int) Math.floor((oldLocation.getY() + (-2.1) + ((double) i * 0.285)) * 32);
teleportPacket.d = z;
packets1_9[i] = teleportPacket;
i++;
}
i = 0;
// Generate move packets for 1.8 clients if the move is small enough.
if (x >= -128 && x <= 127 && y >= -128 && y <= 127 && z >= -128 && z <= 127)
{
_lastMovement.subtract(new Vector(x / 32D, y / 32D, z / 32D));
@ -536,32 +565,26 @@ public class Hologram {
i++;
}
}
else
else // Use teleport packets
{
x = (int) Math.floor(32 * newLocation.getX());
z = (int) Math.floor(32 * newLocation.getZ());
_lastMovement = new Vector(newLocation.getX() - (x / 32D), 0, newLocation.getZ() - (z / 32D));
for (Integer entityId : _entityIds)
{
PacketPlayOutEntityTeleport teleportPacket = new PacketPlayOutEntityTeleport();
teleportPacket.a = entityId;
teleportPacket.b = x;
teleportPacket.c = (int) Math.floor((oldLocation.getY() + (-2.1) + ((double) i * 0.285)) * 32);
teleportPacket.d = z;
packets1_8[i] = teleportPacket;
i++;
}
packets1_8 = packets1_9;
}
for (Player player : canSee)
{
for (Packet packet : packets1_8)
if (UtilPlayer.is1_9(player))
{
UtilPlayer.sendPacket(player, packet);
for (Packet packet : packets1_9)
{
UtilPlayer.sendPacket(player, packet);
}
}
else
{
for (Packet packet : packets1_8)
{
UtilPlayer.sendPacket(player, packet);
}
}
}
}

View File

@ -81,6 +81,7 @@ public class HologramManager extends MiniPlugin implements IPacketHandler
hologram.stop();
continue;
}
if (!hologram.relativeToEntity.equals(following.getLocation().subtract(hologram.getLocation()).toVector()))
{
// And we do this so in the rare offchance it changes by a decimal. It doesn't start turning wonky.