1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-21 20:25:54 +00:00
Slimefun4/src/me/mrCookieSlime/Slimefun/holograms/ReactorHologram.java

43 lines
1.4 KiB
Java
Raw Normal View History

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) {
Location l = new Location(reactor.getWorld(), reactor.getX() + 0.5, reactor.getY(), reactor.getZ() + 0.5);
for (Entity n : l.getChunk().getEntities()) {
if (n instanceof ArmorStand) {
2016-11-20 21:27:52 +00:00
if (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();
}
}