Advertisement
Guest User

Untitled

a guest
Apr 24th, 2019
434
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.40 KB | None | 0 0
  1. package fr.hydozia.api.hologram;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.List;
  5. import java.util.Random;
  6. import java.util.UUID;
  7.  
  8. import org.bukkit.Location;
  9. import org.bukkit.World;
  10. import org.bukkit.entity.ArmorStand;
  11. import org.bukkit.entity.Entity;
  12. import org.bukkit.entity.EntityType;
  13. import org.bukkit.metadata.FixedMetadataValue;
  14. import org.bukkit.metadata.MetadataValue;
  15. import org.bukkit.scheduler.BukkitRunnable;
  16.  
  17. import fr.hydozia.api.HydoziaAPI;
  18.  
  19. /**
  20. * @author Tarkod,
  21. * @link github/tarkodev && gitlab/tarkod.
  22. */
  23. public class HologramManager {
  24.  
  25. final private String name;
  26. final private UUID metaData;
  27.  
  28. public HologramManager(final String name) {
  29. this.name = name;
  30. this.metaData = UUID.randomUUID();
  31. }
  32.  
  33.  
  34. public void spawn(final Location location) {
  35. ArmorStand armorStand = (ArmorStand) location.getWorld().spawnEntity(location, EntityType.ARMOR_STAND);
  36. armorStand.setVisible(false);
  37. armorStand.setGravity(false);
  38. armorStand.setBasePlate(false);
  39. armorStand.setSmall(true);
  40. armorStand.setCustomNameVisible(true);
  41. armorStand.setCustomName(name);
  42. armorStand.setMetadata("UUID", new FixedMetadataValue(HydoziaAPI.getInstance(), metaData));
  43. }
  44.  
  45. public void spawn(final Location location, final double rangeX, final double rangeY, final double rangeZ) {
  46. Location loc = location;
  47.  
  48. double xMin = loc.getX()-rangeX;
  49. double xMax = loc.getX()+rangeX;
  50. double x = xMin + (new Random().nextDouble() * (xMax - xMin));
  51.  
  52. double yMin = loc.getY()-rangeY;
  53. double yMax = loc.getY()+rangeY;
  54. double y = yMin + (new Random().nextDouble() * (yMax - yMin));
  55.  
  56. double zMin = loc.getZ()-rangeZ;
  57. double zMax = loc.getZ()+rangeZ;
  58. double z = zMin + (new Random().nextDouble() * (zMax - zMin));
  59.  
  60. Location result = new Location(loc.getWorld(), x, y, z);
  61. spawn(result);
  62. }
  63.  
  64. public void spawn(final Location location, final double rangeX, final double rangeY, final double rangeZ, final int ticks) {
  65. spawn(location, rangeX, rangeY, rangeZ);
  66.  
  67. new BukkitRunnable() {
  68. int ticksRemaining = ticks;
  69.  
  70. @Override
  71. public void run() {
  72. if (ticksRemaining <= 0) {
  73. killAll(location.getWorld());
  74. cancel();
  75. }
  76. ticksRemaining--;
  77. }
  78. }.runTaskTimer(HydoziaAPI.getInstance(), 1, 1);
  79. }
  80.  
  81. public void spawn(final Location location, final double range) {
  82. spawn(location, range, range, range);
  83. }
  84.  
  85. /**
  86. * Spawn a hologram.
  87. * @param location the location of hologram.
  88. * @param range that's a random range
  89. * @param ticks the ticks was for the duration of hologram and the ticks in minecraft was 20 per seconds | 20 = 1 seconde.
  90. */
  91. public void spawn(final Location location, final double range, final int ticks) {
  92. spawn(location, range, range, range, ticks);
  93. }
  94.  
  95. public List<ArmorStand> find(final World world) {
  96. List<ArmorStand> armorStandList = new ArrayList<ArmorStand>();
  97. for (Entity entity : world.getEntities()) {
  98. if (entity instanceof ArmorStand) {
  99. ArmorStand armorStand = (ArmorStand) entity;
  100. for(MetadataValue values : armorStand.getMetadata("UUID")) {
  101. if(values.value().equals(metaData)) {
  102. armorStandList.add(armorStand);
  103. }
  104. }
  105. }
  106. }
  107. return armorStandList;
  108. }
  109.  
  110.  
  111. public void killAll(final World world) {
  112. for (ArmorStand armorStands : find(world)) {
  113. armorStands.remove();
  114. }
  115. }
  116.  
  117. public UUID getUUID() {
  118. return metaData;
  119. }
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement