191 lines
5.7 KiB
Java
191 lines
5.7 KiB
Java
package ru.prisonlife.api.template;
|
|
|
|
import org.bukkit.Bukkit;
|
|
import org.bukkit.Location;
|
|
import org.bukkit.configuration.file.FileConfiguration;
|
|
import org.bukkit.configuration.file.YamlConfiguration;
|
|
import ru.prisonlife.api.PrisonAPI;
|
|
|
|
import java.io.File;
|
|
import java.io.IOException;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.Objects;
|
|
|
|
public class Manager {
|
|
|
|
private File file;
|
|
private FileConfiguration fileConfiguration;
|
|
|
|
public Manager(String id) {
|
|
file = new File(PrisonAPI.PLUGIN_MANAGER_PATH + "/", "PRISON_" + id + ".yml");
|
|
fileConfiguration = YamlConfiguration.loadConfiguration(file);
|
|
}
|
|
|
|
public boolean contains() {
|
|
return file.exists();
|
|
}
|
|
|
|
public String getName() {
|
|
return file.getName().replace("PRISON_", "").replace(".yml", "");
|
|
}
|
|
|
|
public String getWorld() {
|
|
return fileConfiguration.getString("WORLD");
|
|
}
|
|
|
|
public void setWorld(String name) {
|
|
String p = "WORLD";
|
|
fileConfiguration.set(p, null);
|
|
fileConfiguration.set(p, name);
|
|
try {
|
|
fileConfiguration.save(file);
|
|
} catch (IOException e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
|
|
public boolean getRebootStatus() {
|
|
return fileConfiguration.getBoolean("REBOOT_STATUS");
|
|
}
|
|
|
|
public void setRebootStatus(boolean status) {
|
|
fileConfiguration.set("REBOOT_STATUS", status);
|
|
try {
|
|
fileConfiguration.save(file);
|
|
} catch (IOException e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
|
|
public List<Integer> getSpawnCords(int faction) {
|
|
return fileConfiguration.getIntegerList("FACTIONS." + PrisonAPI.Factions.valueOf(faction) + ".CORDS");
|
|
}
|
|
|
|
public void setSpawnCords(int faction, List<Integer> data) {
|
|
String p = "FACTIONS." + selectFactType(faction) + ".CORDS";
|
|
fileConfiguration.set(p, null);
|
|
fileConfiguration.set(p, data);
|
|
try {
|
|
fileConfiguration.save(file);
|
|
} catch (IOException e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
|
|
public List<Integer> getDiagonal() {
|
|
return fileConfiguration.getIntegerList("DIAGONAL_POINTS");
|
|
}
|
|
|
|
public void setDiagonal(List<Integer> data) {
|
|
if (data.size() == 6) {
|
|
String dp = "DIAGONAL_POINTS";
|
|
fileConfiguration.set(dp, null);
|
|
fileConfiguration.set(dp, data);
|
|
try {
|
|
fileConfiguration.save(file);
|
|
} catch (IOException e) {
|
|
e.printStackTrace();
|
|
}
|
|
} else {
|
|
throw new RuntimeException("data.size() != 6");
|
|
}
|
|
}
|
|
|
|
public int getGlobalNumTerr(int faction) {
|
|
int num = 0;
|
|
for (File prison : Objects.requireNonNull(file.getParentFile().listFiles())) {
|
|
Manager mng = new Manager(prison.getName());
|
|
num += mng.getNumTerr(faction);
|
|
}
|
|
return num;
|
|
}
|
|
|
|
public int getNumTerr(int faction) {
|
|
return fileConfiguration.getInt("FACTIONS." + selectFactType(faction) + ".NUM_TERR");
|
|
}
|
|
|
|
public void setNumTerr(int faction, int value) {
|
|
String p = "FACTIONS." + selectFactType(faction) + ".NUM_TERR";
|
|
fileConfiguration.set(p, null);
|
|
fileConfiguration.set(p, value);
|
|
try {
|
|
fileConfiguration.save(file);
|
|
} catch (IOException e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
|
|
public String getTerrOwner(String name) {
|
|
return fileConfiguration.getString("TERRITORIES." + name + ".OWNER");
|
|
}
|
|
|
|
public void setTerrOwner(String name, String owner) {
|
|
fileConfiguration.set("TERRITORIES." + name + ".OWNER", owner);
|
|
try {
|
|
fileConfiguration.save(file);
|
|
} catch (IOException e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
|
|
public String getTerrConqurer(String name) {
|
|
return fileConfiguration.getString("TERRITORIES." + name + ".CAPTURED");
|
|
}
|
|
|
|
public void setTerrConqurer(String name, String status) {
|
|
fileConfiguration.set("TERRITORIES." + name + ".CAPTURED", status);
|
|
try {
|
|
fileConfiguration.save(file);
|
|
} catch (IOException e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
|
|
public List<String> getAllTerrs() {
|
|
try {
|
|
List<String> terrs = new ArrayList<>();
|
|
for (String t : fileConfiguration.getConfigurationSection("TERRITORIES").getKeys(false))
|
|
terrs.add(t);
|
|
return terrs;
|
|
} catch(NullPointerException z) {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public List<String> getCages() {
|
|
try {
|
|
List<String> cages = new ArrayList<>();
|
|
for (String c : fileConfiguration.getConfigurationSection("CAGES").getKeys(false))
|
|
cages.add(c);
|
|
return cages;
|
|
} catch(NullPointerException z) {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public List<Integer> getPointCage(String cage) {
|
|
return new ArrayList<>(fileConfiguration.getIntegerList("CAGES." + cage));
|
|
}
|
|
|
|
public Location getLocationCage(String cage) {
|
|
List<Integer> point = getPointCage(cage);
|
|
return new Location(Bukkit.getWorld(getWorld()), point.get(0) + 0.5, point.get(1), point.get(2) + 0.5);
|
|
}
|
|
|
|
public void teleportInToCage(Prisoner prs, String cage) {
|
|
List<Integer> data = fileConfiguration.getIntegerList("CAGES." + cage);
|
|
Location loc = new Location(Bukkit.getWorld(getWorld()),
|
|
data.get(0) + 0.5, data.get(1), data.get(2) + 0.5);
|
|
prs.getPlayer().teleport(loc);
|
|
}
|
|
|
|
public String selectFactType(int id) {
|
|
return PrisonAPI.Factions.values()[id].name();
|
|
}
|
|
|
|
public int selectFactId(String faction) {
|
|
return PrisonAPI.Factions.valueOf(faction).ordinal();
|
|
}
|
|
}
|