Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package auki.commands.holographic;
- import auki.commands.user;
- import auki.config.chologram;
- import org.bukkit.Bukkit;
- import org.bukkit.ChatColor;
- import org.bukkit.Location;
- import org.bukkit.World;
- import org.bukkit.entity.ArmorStand;
- import org.bukkit.entity.EntityType;
- import java.util.ArrayList;
- import java.util.List;
- public class Hologram {
- public String name;
- public List<ArmorStand> physicalEntities;
- private List<String> content, commands;
- private Location hologramLocation;
- public static String format(String string) {
- return ChatColor.translateAlternateColorCodes('&', string);
- }
- public static String format(List<String> list) {
- String str = "";
- for (String content : list) {
- if (str.equals("")) {
- str = content;
- } else {
- str = str + ", " + content;
- }
- }
- return str;
- }
- public Hologram(String name, Location location, String content) {
- this.name = name;
- this.content = new ArrayList<>();
- this.physicalEntities = new ArrayList<>();
- this.commands = new ArrayList<>();
- this.content.add(content);
- spawn(location);
- }
- public Hologram(String name) {
- this.name = name;
- this.physicalEntities = new ArrayList<>();
- this.commands = new ArrayList<>();
- this.commands = chologram.get.getFile().getStringList("holograms." + name + ".commands");
- this.content = new ArrayList<>();
- for (String key : chologram.get.getFile().getConfigurationSection("holograms." + name + ".content").getKeys(false)) {
- this.content.add(format(chologram.get.getFile().getString("holograms." + name + ".content." + key)));
- }
- World world = Bukkit.getWorld(chologram.get.getFile().getString("holograms." + name + ".location.world"));
- double x = chologram.get.getFile().getDouble("holograms." + name + ".location.x"), y = chologram.get.getFile().getDouble("holograms." + name + ".location.y"), z = chologram.get.getFile().getDouble("holograms." + name + ".location.z");
- float yaw = Float.parseFloat(chologram.get.getFile().getString("holograms." + name + ".location.yaw")), pitch = Float.parseFloat(chologram.get.getFile().getString("holograms." + name + ".location.pitch"));
- if (world == null) return;
- Location location = new Location(world, x, y, z, yaw, pitch);
- spawn(location);
- }
- private void spawn(Location location) {
- this.hologramLocation = location;
- int cycle = 0;
- for (String str : content) {
- cycle++;
- location.subtract(0, 0.3, 0);
- ArmorStand physicalEntity = (ArmorStand) location.getWorld().spawnEntity(location, EntityType.ARMOR_STAND);
- physicalEntity.setVisible(false);
- physicalEntity.setGravity(false);
- physicalEntity.setCustomNameVisible(true);
- physicalEntity.setCustomName(format(str));
- physicalEntity.setInvulnerable(true);
- physicalEntities.add(physicalEntity);
- }
- }
- public boolean isTouchscreen() {
- return commands != null && commands.size() > 0;
- }
- public void executeCommands(user user) {
- if (isTouchscreen()) {
- return;
- }
- for (String command : commands) {
- if (user.isplayer()) {
- boolean status = user.access().performCommand("/" + command.replaceAll("player%", user.access().getName()));
- if (!status) {
- user.send("Failed to run command " + command);
- }
- }
- }
- }
- public void addCommand(String command) {
- commands.add(command);
- }
- public void remove() {
- for(ArmorStand armorStand : physicalEntities) {
- armorStand.remove();
- }
- }
- public void addline(String line) {
- content.add(format(line));
- this.remove();
- this.spawn(hologramLocation);
- }
- public void serialize() {
- Location location = this.hologramLocation;
- chologram.get.setPath("holograms." + name + ".location.world", location.getWorld().getName());
- chologram.get.setPath("holograms." + name + ".location.x", location.getX());
- chologram.get.setPath("holograms." + name + ".location.y", location.getY());
- chologram.get.setPath("holograms." + name + ".location.z", location.getZ());
- chologram.get.setPath("holograms." + name + ".location.yaw", location.getYaw());
- chologram.get.setPath("holograms." + name + ".location.pitch", location.getPitch());
- chologram.get.setPath("holograms." + name + ".commands", commands);
- for (int x = 0; x < content.size(); x++) {
- chologram.get.setDefault("holograms." + name + ".content." + x, String.valueOf(content.get(x)));
- }
- for (ArmorStand armorStand : physicalEntities) {
- armorStand.remove();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement