1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-21 12:15:50 +00:00
Slimefun4/src/me/mrCookieSlime/Slimefun/holograms/CargoHologram.java

39 lines
1.2 KiB
Java
Raw Normal View History

2016-04-14 16:24:03 +00:00
package me.mrCookieSlime.Slimefun.holograms;
import org.bukkit.Bukkit;
2017-06-14 10:35:25 +00:00
import org.bukkit.ChatColor;
2016-04-14 16:24:03 +00:00
import org.bukkit.Location;
import org.bukkit.block.Block;
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;
import me.mrCookieSlime.Slimefun.SlimefunStartup;
2016-04-14 16:24:03 +00:00
public class CargoHologram {
public static void update(final Block b, final String name) {
2019-03-30 12:32:13 +00:00
Bukkit.getScheduler().scheduleSyncDelayedTask(SlimefunStartup.instance, () -> {
ArmorStand hologram = getArmorStand(b);
hologram.setCustomName(ChatColor.translateAlternateColorCodes('&', name));
2016-04-14 16:24:03 +00:00
});
}
public static void remove(Block b) {
ArmorStand hologram = getArmorStand(b);
hologram.remove();
}
private static ArmorStand getArmorStand(Block b) {
2019-06-19 13:32:18 +00:00
Location l = new Location(b.getWorld(), b.getX() + 0.5, b.getY() + 0.7F, b.getZ() + 0.5);
2016-04-14 16:24:03 +00:00
2019-03-30 12:32:13 +00:00
for (Entity n : l.getChunk().getEntities()) {
2019-08-29 20:04:31 +00:00
if (n instanceof ArmorStand && n.getCustomName() != null && l.distanceSquared(n.getLocation()) < 0.4D) return (ArmorStand) n;
2016-04-14 16:24:03 +00:00
}
ArmorStand hologram = ArmorStandFactory.createHidden(l);
return hologram;
}
}