Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.61 KB | None | 0 0
  1. package me.activated.uhc.holograms;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.Arrays;
  5. import java.util.List;
  6.  
  7. import org.bukkit.Bukkit;
  8. import org.bukkit.Location;
  9. import org.bukkit.craftbukkit.v1_7_R4.CraftWorld;
  10. import org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer;
  11. import org.bukkit.entity.Player;
  12. import org.bukkit.scheduler.BukkitRunnable;
  13.  
  14. import me.activated.uhc.UHCPlugin;
  15. import net.minecraft.server.v1_7_R4.EntityHorse;
  16. import net.minecraft.server.v1_7_R4.EntityPlayer;
  17. import net.minecraft.server.v1_7_R4.EntityWitherSkull;
  18. import net.minecraft.server.v1_7_R4.PacketPlayOutAttachEntity;
  19. import net.minecraft.server.v1_7_R4.PacketPlayOutEntityDestroy;
  20. import net.minecraft.server.v1_7_R4.PacketPlayOutSpawnEntity;
  21. import net.minecraft.server.v1_7_R4.PacketPlayOutSpawnEntityLiving;
  22. import net.minecraft.server.v1_7_R4.WorldServer;
  23.  
  24. @SuppressWarnings("all")
  25. public class Hologram {
  26. private static final double distance = 0.23;
  27. private List<String> lines = new ArrayList<String>();
  28. private List<Integer> ids = new ArrayList<Integer>();
  29. private boolean showing = false;
  30. private Location location;
  31. public static Hologram get;
  32.  
  33. public Hologram(String... lines) {
  34. this.lines.addAll(Arrays.asList(lines));
  35. get = this;
  36. }
  37.  
  38. public void change(String... lines) {
  39. destroy();
  40. this.lines = Arrays.asList(lines);
  41. show(this.location);
  42. }
  43.  
  44. public void show(Location loc) {
  45. if (showing == true) {
  46. try {
  47. throw new Exception("Is already showing!");
  48. } catch (Exception e) {
  49. e.printStackTrace();
  50. }
  51. }
  52. Location first = loc.clone().add(0, (this.lines.size() / 2) * distance, 0);
  53. for (int i = 0; i < this.lines.size(); i++) {
  54. ids.addAll(showLine(first.clone(), this.lines.get(i)));
  55. first.subtract(0, distance, 0);
  56. }
  57. showing = true;
  58. this.location = loc;
  59. }
  60.  
  61. public void show(Location loc, long ticks) {
  62. show(loc);
  63. new BukkitRunnable() {
  64. @Override
  65. public void run() {
  66. destroy();
  67. }
  68. }.runTaskLater(UHCPlugin.getInstance(), ticks);
  69. }
  70.  
  71. public void destroy() {
  72. if (showing == false) {
  73. try {
  74. throw new Exception("Isn't showing!");
  75. } catch (Exception e) {
  76. e.printStackTrace();
  77. }
  78. }
  79. int[] ints = new int[this.ids.size()];
  80. for (int j = 0; j < ints.length; j++) {
  81. ints[j] = ids.get(j);
  82. }
  83. PacketPlayOutEntityDestroy packet = new PacketPlayOutEntityDestroy(ints);
  84. for (Player player : Bukkit.getOnlinePlayers()) {
  85. ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
  86. }
  87. showing = false;
  88. this.location = null;
  89. }
  90.  
  91. private static List<Integer> showLine(Location loc, String text) {
  92. WorldServer world = ((CraftWorld) loc.getWorld()).getHandle();
  93. EntityWitherSkull skull = new EntityWitherSkull(world);
  94. skull.setLocation(loc.getX(), loc.getY() + 1 + 55, loc.getZ(), 0, 0);
  95. PacketPlayOutSpawnEntity skull_packet = new PacketPlayOutSpawnEntity(skull, 0, 0);
  96.  
  97. EntityHorse horse = new EntityHorse(world);
  98. horse.setLocation(loc.getX(), loc.getY() + 55, loc.getZ(), 0, 0);
  99. horse.setAge(-1700000);
  100. horse.setCustomName(text);
  101. horse.setCustomNameVisible(true);
  102. PacketPlayOutSpawnEntityLiving packedt = new PacketPlayOutSpawnEntityLiving(horse);
  103. for (Player player : loc.getWorld().getPlayers()) {
  104. EntityPlayer nmsPlayer = ((CraftPlayer) player).getHandle();
  105. nmsPlayer.playerConnection.sendPacket(packedt);
  106. nmsPlayer.playerConnection.sendPacket(skull_packet);
  107.  
  108. PacketPlayOutAttachEntity pa = new PacketPlayOutAttachEntity(0, horse, skull);
  109. nmsPlayer.playerConnection.sendPacket(pa);
  110. }
  111. return Arrays.asList(skull.getId(), horse.getId());
  112. }
  113.  
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement