Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package test;
- import java.util.LinkedList;
- import java.util.List;
- import java.util.UUID;
- import net.minecraft.server.v1_8_R1.EntityArmorStand;
- import net.minecraft.server.v1_8_R1.PacketPlayOutEntityDestroy;
- import net.minecraft.server.v1_8_R1.PacketPlayOutSpawnEntityLiving;
- import org.bukkit.Bukkit;
- import org.bukkit.Location;
- import org.bukkit.craftbukkit.v1_8_R1.CraftWorld;
- import org.bukkit.craftbukkit.v1_8_R1.entity.CraftPlayer;
- import org.bukkit.entity.Player;
- import org.bukkit.event.EventHandler;
- import org.bukkit.event.Listener;
- import org.bukkit.event.player.PlayerJoinEvent;
- import org.bukkit.event.player.PlayerQuitEvent;
- public class Hologram implements Listener {
- private static final Double DISTANCE = 0.2D;
- private String text;
- private Location loc;
- private EntityArmorStand e;
- private PacketPlayOutSpawnEntityLiving ps;
- private PacketPlayOutEntityDestroy pd;
- private List<UUID> s;
- private List<UUID> q;
- private MainClass i;
- private boolean dod;
- private boolean soj;
- public Hologram(Location l, String text, MainClass instance){
- this.text = text;
- this.loc = l;
- this.e = new EntityArmorStand(((CraftWorld) l.getWorld()).getHandle(), l.getX(), l.getY() + DISTANCE, l.getZ());
- this.e.setGravity(false);
- this.e.setInvisible(true);
- this.e.setCustomNameVisible(true);
- this.e.setCustomName(text);
- this.ps = new PacketPlayOutSpawnEntityLiving(e);
- this.pd = new PacketPlayOutEntityDestroy(new int[] {e.getId()});
- this.s = new LinkedList<UUID>();
- this.q = new LinkedList<UUID>();
- this.i = instance;
- Bukkit.getPluginManager().registerEvents(this, i);
- }
- /**
- * @param p The player, who shall recieve the Hologram.
- */
- public void showPlayer(Player p){
- if(s.contains(p.getUniqueId())) return;
- ((CraftPlayer) p).getHandle().playerConnection.sendPacket(ps);
- s.add(p.getUniqueId());
- }
- /**
- * @param p The player, who shall recieve the destroy of the Hologram.
- */
- public void hidePlayer(Player p){
- if(!s.contains(p.getUniqueId())) return;
- ((CraftPlayer) p).getHandle().playerConnection.sendPacket(pd);
- s.remove(p.getUniqueId());
- }
- /**
- * @see The Hologram will appear for everyone.
- */
- @SuppressWarnings("deprecation")
- public void showAllPlayers(){
- for(Player all : Bukkit.getOnlinePlayers()){
- if(s.contains(all.getUniqueId())) continue;
- ((CraftPlayer) all).getHandle().playerConnection.sendPacket(ps);
- s.add(all.getUniqueId());
- }
- }
- /**
- * @see The Hologram will disappear for everyone.
- */
- @SuppressWarnings("deprecation")
- public void hideAllPlayers(){
- for(Player all : Bukkit.getOnlinePlayers()){
- if(!s.contains(all.getUniqueId())) continue;
- ((CraftPlayer) all).getHandle().playerConnection.sendPacket(pd);
- s.remove(all.getUniqueId());
- }
- }
- /**
- * @param l The location, where it shall appear.
- */
- public void setLocation(Location l) {
- this.loc = l;
- this.e.teleportTo(l, true);
- }
- /**
- * @return The location, where it is.
- */
- public Location getLocation() {
- return loc;
- }
- /**
- * @param text The text, which shall appears in the hologram.
- */
- public void setText(String text) {
- this.text = text;
- this.e.setCustomName(text);
- }
- /**
- * @return The text, which appears in the hologram.
- */
- public String getText() {
- return text;
- }
- /**
- * @return A List with UUID's from all players, which can see the Hologram.
- */
- public List<UUID> getShowingPlayers() {
- return s;
- }
- /**
- * @param s A List with UUID's from all players, which shall can see the Hologram.
- */
- public void setShowingPlayers(List<UUID> s) {
- for(UUID uuid : this.s){
- if(Bukkit.getPlayer(uuid) == null){
- q.add(uuid);
- continue;
- }
- ((CraftPlayer) Bukkit.getPlayer(uuid)).getHandle().playerConnection.sendPacket(pd);
- }
- this.s = s;
- for(UUID uuid : s){
- if(Bukkit.getPlayer(uuid) == null) continue;
- ((CraftPlayer) Bukkit.getPlayer(uuid)).getHandle().playerConnection.sendPacket(ps);
- }
- }
- /**
- * @param b Shall the Hologram disappear for the players when they disconnect?
- */
- public void setDestroyOnDisconnect(boolean b){
- this.dod = b;
- }
- /**
- * @return A Boolean value which shows if the hologram disappears when a player disconnect.
- */
- public boolean getDestroyOnDisconnect(){
- return dod;
- }
- /**
- * @param b Shall the Hologram appear when a player join?
- */
- public void setShowOnJoin(boolean b){
- this.soj = b;
- }
- /**
- * @return A Boolean value which shows if the hologram appears when a player join.
- */
- public boolean getShowOnJoin(){
- return soj;
- }
- /**
- * @see Destroys Destroys the Hologram.
- */
- public void destroy(){
- for(UUID uuid : s){
- if(Bukkit.getPlayer(uuid) == null) continue;
- ((CraftPlayer) Bukkit.getPlayer(uuid)).getHandle().playerConnection.sendPacket(pd);
- }
- e.setHealth(0.0F);
- }
- @EventHandler
- public void onPlayerJoin(PlayerJoinEvent e){
- if(!s.contains(e.getPlayer().getUniqueId()) && soj){
- ((CraftPlayer) e.getPlayer()).getHandle().playerConnection.sendPacket(ps);
- s.add(e.getPlayer().getUniqueId());
- }
- if(this.q.contains(e.getPlayer().getUniqueId())) {
- ((CraftPlayer) e.getPlayer()).getHandle().playerConnection.sendPacket(pd);
- q.remove(e.getPlayer().getUniqueId());
- }
- }
- @EventHandler
- public void onquit(PlayerQuitEvent e){
- if(dod && s.contains(e.getPlayer().getUniqueId())){
- ((CraftPlayer) e.getPlayer()).getHandle().playerConnection.sendPacket(pd);
- s.remove(e.getPlayer().getUniqueId());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement