Advertisement
mattibijnens

Untitled

Jul 24th, 2015
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.03 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.Arrays;
  3. import java.util.List;
  4.  
  5. import net.minecraft.server.v1_8_R3.EntityHorse;
  6. import net.minecraft.server.v1_8_R3.EntityPlayer;
  7. import net.minecraft.server.v1_8_R3.EntityWitherSkull;
  8. import net.minecraft.server.v1_8_R3.PacketPlayOutAttachEntity;
  9. import net.minecraft.server.v1_8_R3.PacketPlayOutEntityDestroy;
  10. import net.minecraft.server.v1_8_R3.PacketPlayOutSpawnEntityLiving;
  11. import net.minecraft.server.v1_8_R3.WorldServer;
  12.  
  13. import org.bukkit.Bukkit;
  14. import org.bukkit.Location;
  15. import org.bukkit.craftbukkit.v1_8_R3.CraftWorld;
  16. import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
  17. import org.bukkit.entity.Player;
  18.  
  19. public class Hologram {
  20. private static final double distance = 0.23;
  21. private List<String> lines = new ArrayList<String>();
  22. private List<Integer> ids = new ArrayList<Integer>();
  23. private boolean showing = false;
  24. private Location location;
  25.  
  26. public Hologram(String... lines) {
  27.     this.lines.addAll(Arrays.asList(lines));
  28. }
  29.  
  30. public void show(Player p, Location loc) {
  31.     if (showing == true) {
  32.       try {
  33.           throw new Exception("Is already showing!");
  34.       } catch (Exception e) {
  35.           e.printStackTrace();
  36.       }
  37.     }
  38.     Location first = loc.clone().add(0, (this.lines.size() / 2) * distance, 0);
  39.     for (int i = 0; i < this.lines.size(); i++) {
  40.       ids.addAll(showLine(p, first.clone(), this.lines.get(i)));
  41.       first.subtract(0, distance, 0);
  42.     }
  43.     showing = true;
  44.     this.location = loc;
  45. }
  46.  
  47. public void destroy() {
  48.     if (showing == false) {
  49.       try {
  50.           throw new Exception("Isn't showing!");
  51.       } catch (Exception e) {
  52.           e.printStackTrace();
  53.       }
  54.     }
  55.     int[] ints = new int[this.ids.size()];
  56.     for (int j = 0; j < ints.length; j++) {
  57.       ints[j] = ids.get(j);
  58.     }
  59.     PacketPlayOutEntityDestroy packet = new PacketPlayOutEntityDestroy(ints);
  60.     for (Player player : Bukkit.getOnlinePlayers()) {
  61.       ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
  62.     }
  63.     showing = false;
  64.     this.location = null;
  65. }
  66.  
  67. private static List<Integer> showLine(Player p, Location loc, String text) {
  68.     WorldServer world = ((CraftWorld) loc.getWorld()).getHandle();
  69.     EntityWitherSkull skull = new EntityWitherSkull(world);
  70.     skull.setLocation(loc.getX(), loc.getY() + 1 + 55, loc.getZ(), 0, 0);
  71.     ((CraftWorld) loc.getWorld()).getHandle().addEntity(skull);
  72.  
  73.     EntityHorse horse = new EntityHorse(world);
  74.     horse.setLocation(loc.getX(), loc.getY() + 55, loc.getZ(), 0, 0);
  75.     horse.setAge(-1700000);
  76.     horse.setCustomName(text);
  77.     horse.setCustomNameVisible(true);
  78.     PacketPlayOutSpawnEntityLiving packedt = new PacketPlayOutSpawnEntityLiving(horse);
  79.       EntityPlayer nmsPlayer = ((CraftPlayer) p).getHandle();
  80.       nmsPlayer.playerConnection.sendPacket(packedt);
  81.  
  82.       PacketPlayOutAttachEntity pa = new PacketPlayOutAttachEntity(0, horse, skull);
  83.       nmsPlayer.playerConnection.sendPacket(pa);
  84.     return Arrays.asList(skull.getId(), horse.getId());
  85. }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement