package com.viper.PlaceholderSIGN.sign; import com.viper.PlaceholderSIGN.Main; import java.io.File; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Random; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.block.BlockState; import org.bukkit.block.Sign; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Player; public class SignManager { private List ps = new ArrayList<>(); private Random r; public List getSigns() { return this.ps; } public SignManager() { this.r = new Random(); File f = new File(Main.getInstance().getDataFolder(), "signs"); if (!f.exists()) { f.mkdir(); } for (File s : f.listFiles()) { YamlConfiguration yamlConfiguration = YamlConfiguration.loadConfiguration(s); String[] l = yamlConfiguration.getString("location").split(","); String[] q = new String[yamlConfiguration.getStringList("rawLines").size()]; Location signLoc = new Location(Bukkit.getWorld(l[0]), Double.parseDouble(l[1]), Double.parseDouble(l[2]), Double.parseDouble(l[3])); if (signLoc != null && signLoc.getWorld() != null) { BlockState temp = signLoc.getWorld().getBlockAt(signLoc).getState(); if (temp instanceof Sign) { this.ps.add(new PlaceholderSign(s.getName().replace(".yml", ""), yamlConfiguration.getStringList("rawLines").toArray(q), (Sign) temp)); } } } } private String genID() { StringBuilder f = new StringBuilder(); for (int i = 0; i < 14; i++) { f.append(this.r.nextInt(9)); } return f.toString(); } public void createSign(Sign s, List lines) { if (!isPlaceholderSign(s)) { while (lines.size() != 4) { lines.add(""); } this.ps.add(new PlaceholderSign(genID(), lines.toArray(new String[0]), s)); } } public boolean isPlaceholderSign(Sign s) { return (getPlaceholderSign(s) != null); } public PlaceholderSign getPlaceholderSign(Sign s) { for (PlaceholderSign p : this.ps) { if (p.getSign().getLocation().equals(s.getLocation())) { return p; } } return null; } public void saveAll() { for (PlaceholderSign p : this.ps) { p.save(); } } public void isInside(Player p) { for (PlaceholderSign pz : this.ps) { pz.isInside(p); } } public void removeSign(Sign s) { if (isPlaceholderSign(s)) { PlaceholderSign signs = getPlaceholderSign(s); signs.deleted = true; this.ps.remove(signs); File f = new File(Main.getInstance().getDataFolder(), "signs/" + signs.getID() + ".yml"); f.delete(); } } public void forceUpdate(Player p) { for (PlaceholderSign pz : this.ps) { if (pz.isInside(p)) { pz.forceUpdate(p); } } } }