2016-11-20 20:18:04 +00:00
|
|
|
package me.mrCookieSlime.Slimefun.holograms;
|
|
|
|
|
2016-11-20 20:35:24 +00:00
|
|
|
import org.bukkit.Bukkit;
|
2017-06-14 10:35:25 +00:00
|
|
|
import org.bukkit.ChatColor;
|
2016-11-20 20:18:04 +00:00
|
|
|
import org.bukkit.Location;
|
|
|
|
import org.bukkit.entity.ArmorStand;
|
|
|
|
import org.bukkit.entity.Entity;
|
|
|
|
|
2017-06-14 10:35:25 +00:00
|
|
|
import me.mrCookieSlime.CSCoreLibPlugin.general.World.ArmorStandFactory;
|
2016-11-20 20:35:24 +00:00
|
|
|
import me.mrCookieSlime.Slimefun.SlimefunStartup;
|
|
|
|
|
|
|
|
|
2016-11-20 20:18:04 +00:00
|
|
|
public class ReactorHologram {
|
|
|
|
|
|
|
|
public static ArmorStand getArmorStand(Location reactor) {
|
2019-06-19 14:26:30 +00:00
|
|
|
Location l = new Location(reactor.getWorld(), reactor.getX() + 0.5, reactor.getY() + 0.7, reactor.getZ() + 0.5);
|
2016-11-20 20:18:04 +00:00
|
|
|
|
|
|
|
for (Entity n : l.getChunk().getEntities()) {
|
2019-08-29 20:04:31 +00:00
|
|
|
if (n instanceof ArmorStand && l.distanceSquared(n.getLocation()) < 0.4D) return (ArmorStand) n;
|
2016-11-20 20:18:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ArmorStand hologram = ArmorStandFactory.createHidden(l);
|
2016-11-23 17:21:19 +00:00
|
|
|
hologram.setCustomNameVisible(false);
|
2016-11-20 20:18:04 +00:00
|
|
|
hologram.setCustomName(null);
|
|
|
|
return hologram;
|
|
|
|
}
|
2016-11-20 20:35:24 +00:00
|
|
|
|
|
|
|
public static void update(final Location l, final String name) {
|
2019-03-30 12:32:13 +00:00
|
|
|
Bukkit.getScheduler().scheduleSyncDelayedTask(SlimefunStartup.instance, () -> {
|
|
|
|
ArmorStand hologram = getArmorStand(l);
|
|
|
|
if (!hologram.isCustomNameVisible()) hologram.setCustomNameVisible(true);
|
|
|
|
hologram.setCustomName(ChatColor.translateAlternateColorCodes('&', name));
|
2016-11-20 20:35:24 +00:00
|
|
|
});
|
|
|
|
}
|
2016-11-20 20:18:04 +00:00
|
|
|
|
|
|
|
public static void remove(Location l) {
|
|
|
|
ArmorStand hologram = getArmorStand(l);
|
|
|
|
hologram.remove();
|
|
|
|
}
|
|
|
|
}
|