start of AI implementation for automatic reports
This commit is contained in:
80
src/main/java/eu/mhsl/craftattack/spawn/util/ConfigUtil.java
Normal file
80
src/main/java/eu/mhsl/craftattack/spawn/util/ConfigUtil.java
Normal file
@@ -0,0 +1,80 @@
|
||||
package eu.mhsl.craftattack.spawn.util;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class ConfigUtil {
|
||||
private static ConfigUtil instance;
|
||||
private final File file;
|
||||
private final FileConfiguration config;
|
||||
|
||||
//loaded config variables
|
||||
private boolean apiSwearWordCheck = false;
|
||||
private String apiToken;
|
||||
|
||||
public static ConfigUtil getConfigUtil() {
|
||||
if (instance == null) instance = new ConfigUtil("config.yml");
|
||||
return instance;
|
||||
}
|
||||
private ConfigUtil(String path) {
|
||||
this.file = new File(Objects.requireNonNull(Bukkit.getPluginManager().getPlugin("spawn")).getDataFolder().getAbsolutePath() + "/" + path);
|
||||
this.config = YamlConfiguration.loadConfiguration(this.file);
|
||||
loadConfig();
|
||||
}
|
||||
|
||||
public boolean save() {
|
||||
try {
|
||||
this.config.save(this.file);
|
||||
return true;
|
||||
}catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private void loadConfig() {
|
||||
apiSwearWordCheck = (boolean) config.get("enableSwearWordCheck");
|
||||
apiToken = (String) config.get("apiToken");
|
||||
}
|
||||
|
||||
public FileConfiguration getConfig() {
|
||||
return this.config;
|
||||
}
|
||||
public Location getVillagerLocation() {
|
||||
List<Double> cordsList = this.config.getDoubleList("villagerLocation");
|
||||
World world = Bukkit.getWorld("world");
|
||||
double x = cordsList.get(0);
|
||||
double y = cordsList.get(1);
|
||||
double z = cordsList.get(2);
|
||||
double yaw = cordsList.get(3);
|
||||
double pitch = cordsList.get(4);
|
||||
Location location = new Location(world, x, y, z);
|
||||
location.setYaw((float) yaw);
|
||||
location.setPitch((float) pitch);
|
||||
|
||||
return location;
|
||||
}
|
||||
|
||||
public Location getSpawnLocation() {
|
||||
List<Double> cordsList = this.config.getDoubleList("spawnLocation");
|
||||
World world = Bukkit.getWorld("world");
|
||||
double x = cordsList.get(0);
|
||||
double y = cordsList.get(1);
|
||||
double z = cordsList.get(2);
|
||||
return new Location(world, x, y, z);
|
||||
}
|
||||
|
||||
public boolean isApiSwearWordCheck() {
|
||||
return apiSwearWordCheck;
|
||||
}
|
||||
|
||||
public String getApiToken() {
|
||||
return apiToken;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user