102 lines
3.2 KiB
Java
102 lines
3.2 KiB
Java
package eu.univento.lobby.utils;
|
|
|
|
import eu.univento.lobby.Lobby;
|
|
import org.bukkit.Bukkit;
|
|
import org.bukkit.Location;
|
|
import org.bukkit.configuration.file.FileConfiguration;
|
|
import org.bukkit.configuration.file.YamlConfiguration;
|
|
import org.bukkit.scheduler.BukkitRunnable;
|
|
|
|
import java.io.File;
|
|
import java.io.IOException;
|
|
import java.util.ArrayList;
|
|
|
|
/**
|
|
* @author joethei
|
|
* @version 0.1
|
|
*/
|
|
public class StatusSignManager {
|
|
|
|
static File file = new File("plugins/Core", "signs.yml");
|
|
static FileConfiguration cfg = YamlConfiguration.loadConfiguration(file);
|
|
|
|
static ArrayList<StatusSign> signs = new ArrayList<>();
|
|
|
|
public static StatusSign getSign(String name) {
|
|
for(StatusSign sign : signs) {
|
|
if(sign.getServerName().equals(name)) {
|
|
return sign;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public static StatusSign getSign(Location loc) {
|
|
for(StatusSign sign : signs) {
|
|
if(sign.getLocation().equals(loc)) {
|
|
return sign;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public static boolean isStatusSign(Location loc) {
|
|
return getSign(loc) != null;
|
|
}
|
|
|
|
public static void addSign(String name, Location loc) {
|
|
StatusSign sign = new StatusSign(name, loc);
|
|
signs.add(sign);
|
|
}
|
|
|
|
public static void removeSign(String name) {
|
|
signs.remove(getSign(name));
|
|
}
|
|
|
|
public static void updateSigns() {
|
|
Bukkit.getScheduler().scheduleSyncRepeatingTask(Lobby.getInstance(), () -> signs.forEach(StatusSign::update), 20 * 20L, 5L);
|
|
}
|
|
|
|
public static void saveSigns() {
|
|
for(String key : cfg.getKeys(false)){
|
|
cfg.set(key,null);
|
|
}
|
|
for(StatusSign sign : signs) {
|
|
cfg.set("Sign." + sign.getServerName() + ".World", sign.getLocation().getWorld().getName());
|
|
cfg.set("Sign." + sign.getServerName() + ".X", sign.getLocation().getX());
|
|
cfg.set("Sign." + sign.getServerName() + ".Y", sign.getLocation().getY());
|
|
cfg.set("Sign." + sign.getServerName() + ".Z", sign.getLocation().getZ());
|
|
}
|
|
try {
|
|
cfg.save(file);
|
|
} catch (IOException e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
|
|
public static void loadSigns() {
|
|
for(String key : cfg.getConfigurationSection("Sign").getKeys(false)) {
|
|
String world = cfg.getString("Sign." + key + ".World");
|
|
double x = cfg.getDouble("Sign." + key + ".X");
|
|
double y = cfg.getDouble("Sign." + key + ".Y");
|
|
double z = cfg.getDouble("Sign." + key + ".Z");
|
|
Location loc = new Location(Bukkit.getWorld(world), x, y, z);
|
|
addSign(key, loc);
|
|
}
|
|
}
|
|
|
|
public void loadSign(String name) {
|
|
if(cfg.contains("Sign." + name)) {
|
|
String world = cfg.getString("Sign." + name + ".World");
|
|
double x = cfg.getDouble("Sign." + name + ".X");
|
|
double y = cfg.getDouble("Sign." + name + ".Y");
|
|
double z = cfg.getDouble("Sign." + name + ".Z");
|
|
Location loc = new Location(Bukkit.getWorld(world), x, y, z);
|
|
if(!isStatusSign(loc)) {
|
|
addSign(name, loc);
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
} |