Add follow entity to holograms
This commit is contained in:
parent
f5533dbce2
commit
b160822260
@ -19,6 +19,7 @@ import net.minecraft.server.v1_7_R4.PacketPlayOutSpawnEntityLiving;
|
|||||||
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer;
|
import org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer;
|
||||||
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
@ -40,6 +41,8 @@ public class Hologram
|
|||||||
* 1.7 packets uses both EntityIDs while 1.8 uses only the first.
|
* 1.7 packets uses both EntityIDs while 1.8 uses only the first.
|
||||||
*/
|
*/
|
||||||
private ArrayList<Entry<Integer, Integer>> _entityIds = new ArrayList<Entry<Integer, Integer>>();
|
private ArrayList<Entry<Integer, Integer>> _entityIds = new ArrayList<Entry<Integer, Integer>>();
|
||||||
|
private Entity _followEntity;
|
||||||
|
private HologramManager _hologramManager;
|
||||||
private boolean _isWitherSkull;
|
private boolean _isWitherSkull;
|
||||||
/**
|
/**
|
||||||
* Keeps track of the holograms movements. This fixes offset that occasionally happens when moving a hologram around.
|
* Keeps track of the holograms movements. This fixes offset that occasionally happens when moving a hologram around.
|
||||||
@ -54,7 +57,7 @@ public class Hologram
|
|||||||
private HologramTarget _target = HologramTarget.BLACKLIST;
|
private HologramTarget _target = HologramTarget.BLACKLIST;
|
||||||
private String[] _text = new String[0];
|
private String[] _text = new String[0];
|
||||||
private int _viewDistance = 70;
|
private int _viewDistance = 70;
|
||||||
private HologramManager _hologramManager;
|
protected Vector relativeToEntity;
|
||||||
|
|
||||||
public Hologram(HologramManager hologramManager, Location location, String... text)
|
public Hologram(HologramManager hologramManager, Location location, String... text)
|
||||||
{
|
{
|
||||||
@ -106,6 +109,11 @@ public class Hologram
|
|||||||
return UtilPlayer.is1_8(player) ? _destroy1_8 : _destroy1_7;
|
return UtilPlayer.is1_8(player) ? _destroy1_8 : _destroy1_7;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Entity getEntityFollowing()
|
||||||
|
{
|
||||||
|
return _followEntity;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get who can see the hologram
|
* Get who can see the hologram
|
||||||
*
|
*
|
||||||
@ -138,6 +146,11 @@ public class Hologram
|
|||||||
return nearbyPlayers;
|
return nearbyPlayers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected ArrayList<Player> getPlayersTracking()
|
||||||
|
{
|
||||||
|
return _playersTracking;
|
||||||
|
}
|
||||||
|
|
||||||
protected Packet[] getSpawnPackets(Player player)
|
protected Packet[] getSpawnPackets(Player player)
|
||||||
{
|
{
|
||||||
if (_makePackets)
|
if (_makePackets)
|
||||||
@ -348,6 +361,19 @@ public class Hologram
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If the entity moves, the hologram will update its position to appear relative to the movement.
|
||||||
|
*
|
||||||
|
* @Please note the hologram updates every tick.
|
||||||
|
*/
|
||||||
|
public Hologram setFollowEntity(Entity entityToFollow)
|
||||||
|
{
|
||||||
|
_followEntity = entityToFollow;
|
||||||
|
relativeToEntity = entityToFollow == null ? null : this._location.clone().subtract(entityToFollow.getLocation())
|
||||||
|
.toVector();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set who can see the hologram
|
* Set who can see the hologram
|
||||||
*
|
*
|
||||||
@ -368,6 +394,11 @@ public class Hologram
|
|||||||
_makePackets = true;
|
_makePackets = true;
|
||||||
Location oldLocation = getLocation();
|
Location oldLocation = getLocation();
|
||||||
_location = newLocation.clone();
|
_location = newLocation.clone();
|
||||||
|
// TODO Needs to set the new relativeToEntity
|
||||||
|
if (getEntityFollowing() != null)
|
||||||
|
{
|
||||||
|
relativeToEntity = _location.clone().subtract(getEntityFollowing().getLocation()).toVector();
|
||||||
|
}
|
||||||
if (isInUse())
|
if (isInUse())
|
||||||
{
|
{
|
||||||
ArrayList<Player> canSee = getNearbyPlayers();
|
ArrayList<Player> canSee = getNearbyPlayers();
|
||||||
@ -571,11 +602,6 @@ public class Hologram
|
|||||||
return setLocation(getLocation());
|
return setLocation(getLocation());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ArrayList<Player> getPlayersTracking()
|
|
||||||
{
|
|
||||||
return _playersTracking;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Start the hologram
|
* Start the hologram
|
||||||
*/
|
*/
|
||||||
|
@ -11,11 +11,13 @@ import net.minecraft.server.v1_7_R4.Packet;
|
|||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer;
|
import org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer;
|
||||||
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
public class HologramManager implements Listener
|
public class HologramManager implements Listener
|
||||||
{
|
{
|
||||||
@ -53,6 +55,18 @@ public class HologramManager implements Listener
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
if (hologram.getEntityFollowing() != null)
|
||||||
|
{
|
||||||
|
Entity following = hologram.getEntityFollowing();
|
||||||
|
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.
|
||||||
|
Vector vec = hologram.relativeToEntity.clone();
|
||||||
|
hologram.setLocation(following.getLocation().add(hologram.relativeToEntity));
|
||||||
|
hologram.relativeToEntity = vec;
|
||||||
|
continue; // No need to do the rest of the code as setLocation does it.
|
||||||
|
}
|
||||||
|
}
|
||||||
ArrayList<Player> canSee = hologram.getNearbyPlayers();
|
ArrayList<Player> canSee = hologram.getNearbyPlayers();
|
||||||
Iterator<Player> itel2 = hologram.getPlayersTracking().iterator();
|
Iterator<Player> itel2 = hologram.getPlayersTracking().iterator();
|
||||||
while (itel2.hasNext())
|
while (itel2.hasNext())
|
||||||
|
Loading…
Reference in New Issue
Block a user