Advertisement
Guest User

Untitled

a guest
Jul 10th, 2015
310
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.34 KB | None | 0 0
  1. package test;
  2.  
  3. import java.util.LinkedList;
  4. import java.util.List;
  5. import java.util.UUID;
  6.  
  7. import net.minecraft.server.v1_8_R1.EntityArmorStand;
  8. import net.minecraft.server.v1_8_R1.PacketPlayOutEntityDestroy;
  9. import net.minecraft.server.v1_8_R1.PacketPlayOutSpawnEntityLiving;
  10.  
  11. import org.bukkit.Bukkit;
  12. import org.bukkit.Location;
  13. import org.bukkit.craftbukkit.v1_8_R1.CraftWorld;
  14. import org.bukkit.craftbukkit.v1_8_R1.entity.CraftPlayer;
  15. import org.bukkit.entity.Player;
  16. import org.bukkit.event.EventHandler;
  17. import org.bukkit.event.Listener;
  18. import org.bukkit.event.player.PlayerJoinEvent;
  19. import org.bukkit.event.player.PlayerQuitEvent;
  20.  
  21. public class Hologram implements Listener {
  22.  
  23. private static final Double DISTANCE = 0.2D;
  24. private String text;
  25. private Location loc;
  26. private EntityArmorStand e;
  27. private PacketPlayOutSpawnEntityLiving ps;
  28. private PacketPlayOutEntityDestroy pd;
  29. private List<UUID> s;
  30. private List<UUID> q;
  31. private MainClass i;
  32. private boolean dod;
  33. private boolean soj;
  34.  
  35. public Hologram(Location l, String text, MainClass instance){
  36. this.text = text;
  37. this.loc = l;
  38. this.e = new EntityArmorStand(((CraftWorld) l.getWorld()).getHandle(), l.getX(), l.getY() + DISTANCE, l.getZ());
  39. this.e.setGravity(false);
  40. this.e.setInvisible(true);
  41. this.e.setCustomNameVisible(true);
  42. this.e.setCustomName(text);
  43. this.ps = new PacketPlayOutSpawnEntityLiving(e);
  44. this.pd = new PacketPlayOutEntityDestroy(new int[] {e.getId()});
  45. this.s = new LinkedList<UUID>();
  46. this.q = new LinkedList<UUID>();
  47. this.i = instance;
  48. Bukkit.getPluginManager().registerEvents(this, i);
  49.  
  50. }
  51.  
  52.  
  53.  
  54. /**
  55. * @param p The player, who shall recieve the Hologram.
  56. */
  57. public void showPlayer(Player p){
  58. if(s.contains(p.getUniqueId())) return;
  59. ((CraftPlayer) p).getHandle().playerConnection.sendPacket(ps);
  60. s.add(p.getUniqueId());
  61. }
  62.  
  63. /**
  64. * @param p The player, who shall recieve the destroy of the Hologram.
  65. */
  66. public void hidePlayer(Player p){
  67. if(!s.contains(p.getUniqueId())) return;
  68. ((CraftPlayer) p).getHandle().playerConnection.sendPacket(pd);
  69. s.remove(p.getUniqueId());
  70. }
  71.  
  72. /**
  73. * @see The Hologram will appear for everyone.
  74. */
  75. @SuppressWarnings("deprecation")
  76. public void showAllPlayers(){
  77. for(Player all : Bukkit.getOnlinePlayers()){
  78. if(s.contains(all.getUniqueId())) continue;
  79. ((CraftPlayer) all).getHandle().playerConnection.sendPacket(ps);
  80. s.add(all.getUniqueId());
  81. }
  82. }
  83.  
  84. /**
  85. * @see The Hologram will disappear for everyone.
  86. */
  87. @SuppressWarnings("deprecation")
  88. public void hideAllPlayers(){
  89. for(Player all : Bukkit.getOnlinePlayers()){
  90. if(!s.contains(all.getUniqueId())) continue;
  91. ((CraftPlayer) all).getHandle().playerConnection.sendPacket(pd);
  92. s.remove(all.getUniqueId());
  93. }
  94. }
  95.  
  96. /**
  97. * @param l The location, where it shall appear.
  98. */
  99. public void setLocation(Location l) {
  100. this.loc = l;
  101. this.e.teleportTo(l, true);
  102. }
  103.  
  104. /**
  105. * @return The location, where it is.
  106. */
  107. public Location getLocation() {
  108. return loc;
  109. }
  110.  
  111. /**
  112. * @param text The text, which shall appears in the hologram.
  113. */
  114. public void setText(String text) {
  115. this.text = text;
  116. this.e.setCustomName(text);
  117. }
  118.  
  119. /**
  120. * @return The text, which appears in the hologram.
  121. */
  122. public String getText() {
  123. return text;
  124. }
  125.  
  126. /**
  127. * @return A List with UUID's from all players, which can see the Hologram.
  128. */
  129. public List<UUID> getShowingPlayers() {
  130. return s;
  131. }
  132.  
  133. /**
  134. * @param s A List with UUID's from all players, which shall can see the Hologram.
  135. */
  136. public void setShowingPlayers(List<UUID> s) {
  137. for(UUID uuid : this.s){
  138. if(Bukkit.getPlayer(uuid) == null){
  139. q.add(uuid);
  140. continue;
  141. }
  142. ((CraftPlayer) Bukkit.getPlayer(uuid)).getHandle().playerConnection.sendPacket(pd);
  143. }
  144. this.s = s;
  145. for(UUID uuid : s){
  146. if(Bukkit.getPlayer(uuid) == null) continue;
  147. ((CraftPlayer) Bukkit.getPlayer(uuid)).getHandle().playerConnection.sendPacket(ps);
  148. }
  149. }
  150.  
  151. /**
  152. * @param b Shall the Hologram disappear for the players when they disconnect?
  153. */
  154. public void setDestroyOnDisconnect(boolean b){
  155. this.dod = b;
  156. }
  157.  
  158. /**
  159. * @return A Boolean value which shows if the hologram disappears when a player disconnect.
  160. */
  161. public boolean getDestroyOnDisconnect(){
  162. return dod;
  163. }
  164.  
  165. /**
  166. * @param b Shall the Hologram appear when a player join?
  167. */
  168. public void setShowOnJoin(boolean b){
  169. this.soj = b;
  170. }
  171.  
  172. /**
  173. * @return A Boolean value which shows if the hologram appears when a player join.
  174. */
  175. public boolean getShowOnJoin(){
  176. return soj;
  177. }
  178.  
  179. /**
  180. * @see Destroys Destroys the Hologram.
  181. */
  182. public void destroy(){
  183. for(UUID uuid : s){
  184. if(Bukkit.getPlayer(uuid) == null) continue;
  185. ((CraftPlayer) Bukkit.getPlayer(uuid)).getHandle().playerConnection.sendPacket(pd);
  186. }
  187.  
  188. e.setHealth(0.0F);
  189.  
  190. }
  191.  
  192. @EventHandler
  193. public void onPlayerJoin(PlayerJoinEvent e){
  194. if(!s.contains(e.getPlayer().getUniqueId()) && soj){
  195. ((CraftPlayer) e.getPlayer()).getHandle().playerConnection.sendPacket(ps);
  196. s.add(e.getPlayer().getUniqueId());
  197. }
  198. if(this.q.contains(e.getPlayer().getUniqueId())) {
  199. ((CraftPlayer) e.getPlayer()).getHandle().playerConnection.sendPacket(pd);
  200. q.remove(e.getPlayer().getUniqueId());
  201. }
  202. }
  203.  
  204.  
  205. @EventHandler
  206. public void onquit(PlayerQuitEvent e){
  207. if(dod && s.contains(e.getPlayer().getUniqueId())){
  208. ((CraftPlayer) e.getPlayer()).getHandle().playerConnection.sendPacket(pd);
  209. s.remove(e.getPlayer().getUniqueId());
  210. }
  211. }
  212.  
  213. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement