Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package fr.hydozia.api.hologram;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Random;
- import java.util.UUID;
- import org.bukkit.Location;
- import org.bukkit.World;
- import org.bukkit.entity.ArmorStand;
- import org.bukkit.entity.Entity;
- import org.bukkit.entity.EntityType;
- import org.bukkit.metadata.FixedMetadataValue;
- import org.bukkit.metadata.MetadataValue;
- import org.bukkit.scheduler.BukkitRunnable;
- import fr.hydozia.api.HydoziaAPI;
- /**
- * @author Tarkod,
- * @link github/tarkodev && gitlab/tarkod.
- */
- public class HologramManager {
- final private String name;
- final private UUID metaData;
- public HologramManager(final String name) {
- this.name = name;
- this.metaData = UUID.randomUUID();
- }
- public void spawn(final Location location) {
- ArmorStand armorStand = (ArmorStand) location.getWorld().spawnEntity(location, EntityType.ARMOR_STAND);
- armorStand.setVisible(false);
- armorStand.setGravity(false);
- armorStand.setBasePlate(false);
- armorStand.setSmall(true);
- armorStand.setCustomNameVisible(true);
- armorStand.setCustomName(name);
- armorStand.setMetadata("UUID", new FixedMetadataValue(HydoziaAPI.getInstance(), metaData));
- }
- public void spawn(final Location location, final double rangeX, final double rangeY, final double rangeZ) {
- Location loc = location;
- double xMin = loc.getX()-rangeX;
- double xMax = loc.getX()+rangeX;
- double x = xMin + (new Random().nextDouble() * (xMax - xMin));
- double yMin = loc.getY()-rangeY;
- double yMax = loc.getY()+rangeY;
- double y = yMin + (new Random().nextDouble() * (yMax - yMin));
- double zMin = loc.getZ()-rangeZ;
- double zMax = loc.getZ()+rangeZ;
- double z = zMin + (new Random().nextDouble() * (zMax - zMin));
- Location result = new Location(loc.getWorld(), x, y, z);
- spawn(result);
- }
- public void spawn(final Location location, final double rangeX, final double rangeY, final double rangeZ, final int ticks) {
- spawn(location, rangeX, rangeY, rangeZ);
- new BukkitRunnable() {
- int ticksRemaining = ticks;
- @Override
- public void run() {
- if (ticksRemaining <= 0) {
- killAll(location.getWorld());
- cancel();
- }
- ticksRemaining--;
- }
- }.runTaskTimer(HydoziaAPI.getInstance(), 1, 1);
- }
- public void spawn(final Location location, final double range) {
- spawn(location, range, range, range);
- }
- /**
- * Spawn a hologram.
- * @param location the location of hologram.
- * @param range that's a random range
- * @param ticks the ticks was for the duration of hologram and the ticks in minecraft was 20 per seconds | 20 = 1 seconde.
- */
- public void spawn(final Location location, final double range, final int ticks) {
- spawn(location, range, range, range, ticks);
- }
- public List<ArmorStand> find(final World world) {
- List<ArmorStand> armorStandList = new ArrayList<ArmorStand>();
- for (Entity entity : world.getEntities()) {
- if (entity instanceof ArmorStand) {
- ArmorStand armorStand = (ArmorStand) entity;
- for(MetadataValue values : armorStand.getMetadata("UUID")) {
- if(values.value().equals(metaData)) {
- armorStandList.add(armorStand);
- }
- }
- }
- }
- return armorStandList;
- }
- public void killAll(final World world) {
- for (ArmorStand armorStands : find(world)) {
- armorStands.remove();
- }
- }
- public UUID getUUID() {
- return metaData;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement