Advertisement
Guest User

Untitled

a guest
Jan 17th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.78 KB | None | 0 0
  1.  
  2. import de.bytevalue.gameapi.GameAPI;
  3. import java.util.ArrayList;
  4. import java.util.HashMap;
  5. import java.util.UUID;
  6. import net.minecraft.server.v1_8_R3.EntityArmorStand;
  7. import net.minecraft.server.v1_8_R3.PacketPlayOutEntityDestroy;
  8. import net.minecraft.server.v1_8_R3.PacketPlayOutSpawnEntityLiving;
  9. import org.bukkit.Bukkit;
  10. import org.bukkit.Location;
  11. import org.bukkit.craftbukkit.v1_8_R3.CraftWorld;
  12. import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
  13. import org.bukkit.entity.EntityType;
  14. import org.bukkit.entity.Player;
  15.  
  16. public class HologramAPI {
  17.  
  18. private static HashMap<UUID, ArrayList> caches = new HashMap<>();
  19. private final UUID uuid;
  20. private final Location location;
  21. private final String[] lore;
  22.  
  23. public HologramAPI(UUID uuid, String[] lore, Location location){
  24. this.uuid = uuid;
  25. this.lore = lore;
  26. this.location = location;
  27. ArrayList<EntityArmorStand> armorStands = new ArrayList<>();
  28. caches.put(this.uuid, armorStands);
  29. }
  30. public void createHologram()
  31. {
  32. ArrayList<EntityArmorStand> armorStands = caches.get(this.uuid);
  33. for(String line : lore)
  34. {
  35. EntityArmorStand entity = new EntityArmorStand(((CraftWorld) this.location.getWorld()).getHandle(),this.location.getX(), this.location.getY(),this.location.getZ());
  36. entity.setCustomNameVisible(true);
  37. entity.setCustomName(line);
  38. entity.setInvisible(true);
  39. entity.setGravity(false);
  40. this.location.subtract(0, 0.25D, 0);
  41. armorStands.add(entity);
  42.  
  43. }
  44. caches.replace(this.uuid, armorStands);
  45. }
  46. public void showHologram()
  47. {
  48. Player player = Bukkit.getPlayer(this.uuid);
  49. ArrayList<EntityArmorStand> armorStands = caches.get(this.uuid);
  50. armorStands.forEach((armor ->
  51. {
  52. PacketPlayOutSpawnEntityLiving entityLiving = new PacketPlayOutSpawnEntityLiving(armor);
  53. ((CraftPlayer)player).getHandle().playerConnection.sendPacket(entityLiving);
  54.  
  55. }));
  56. }
  57. public void hideHologram() {
  58. Player player = Bukkit.getPlayer(this.uuid);
  59. ArrayList<EntityArmorStand> armorStands = caches.get(this.uuid);
  60. armorStands.forEach((armor ->{
  61. PacketPlayOutEntityDestroy destroy = new PacketPlayOutEntityDestroy(armor.getId());
  62. ((CraftPlayer)player).getHandle().playerConnection.sendPacket(destroy);
  63. }));
  64. armorStands.clear();
  65. caches.remove(this.uuid);
  66. }
  67. public void hideHologram(Integer time) {
  68. Bukkit.getScheduler().runTaskLaterAsynchronously(GameAPI.getInstance(), () -> {
  69. this.hideHologram();
  70.  
  71. }, time);
  72. }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement