По просьбе Димона + mini-update 0.1.2
This commit is contained in:
173
src/main/java/ru/prisonlife/api/template/Manager.java
Normal file
173
src/main/java/ru/prisonlife/api/template/Manager.java
Normal file
@@ -0,0 +1,173 @@
|
||||
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_PATH + "/", "PRISON_" + id + ".yml");
|
||||
fileConfiguration = YamlConfiguration.loadConfiguration(file);
|
||||
}
|
||||
|
||||
public boolean contains() {
|
||||
return file.exists();
|
||||
}
|
||||
|
||||
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." + selectFactType(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() {
|
||||
List<String> terrs = new ArrayList<>();
|
||||
for(String t : fileConfiguration.getConfigurationSection("TERRITORIES").getKeys(false))
|
||||
terrs.add(t);
|
||||
return terrs;
|
||||
}
|
||||
|
||||
public List<String> getCages() {
|
||||
List<String> cages = new ArrayList<>();
|
||||
for(String c : fileConfiguration.getConfigurationSection("CAGES").getKeys(false))
|
||||
cages.add(c);
|
||||
return cages;
|
||||
}
|
||||
|
||||
public List<Integer> getPointCage(String cage) {
|
||||
return new ArrayList<>(fileConfiguration.getIntegerList("CAGES." + cage));
|
||||
}
|
||||
|
||||
public void teleportInToCage(Prisoner prs, String cage) {
|
||||
List<Integer> data =fileConfiguration.getIntegerList("CAGES." + cage);
|
||||
Location loc = new Location(Bukkit.getWorld(fileConfiguration.getString("WORLD")),
|
||||
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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user