Complete Stage 0: Project scaffold
- Fix build.gradle.kts: Java 21, Paper 1.20.6, ProtocolLib 5.3.0 - Add permissions to paper-plugin.yml - Add ConfigManager with safe yaml loading (no overwrite) - Add LocationsConfig for all game object coordinates - Add GameConfig with all balance values - Update mdbd.java with onEnable/onDisable + ConfigManager - Mark Stage 0 complete in PLAN.md
This commit is contained in:
parent
32da611c63
commit
53f3f6e9da
7 changed files with 443 additions and 15 deletions
159
src/main/java/dev/loki/config/LocationsConfig.java
Normal file
159
src/main/java/dev/loki/config/LocationsConfig.java
Normal file
|
|
@ -0,0 +1,159 @@
|
|||
package dev.loki.config;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class LocationsConfig {
|
||||
private final FileConfiguration config;
|
||||
|
||||
public LocationsConfig(FileConfiguration config) {
|
||||
this.config = config;
|
||||
setDefaults();
|
||||
}
|
||||
|
||||
private void setDefaults() {
|
||||
if (!config.contains("lobby")) {
|
||||
config.set("lobby.world", "world");
|
||||
config.set("lobby.x", 0.0);
|
||||
config.set("lobby.y", 100.0);
|
||||
config.set("lobby.z", 0.0);
|
||||
config.set("lobby.yaw", 0.0);
|
||||
config.set("lobby.pitch", 0.0);
|
||||
}
|
||||
if (!config.contains("generators")) {
|
||||
config.set("generators", new ArrayList<>());
|
||||
}
|
||||
if (!config.contains("hooks")) {
|
||||
config.set("hooks", new ArrayList<>());
|
||||
}
|
||||
if (!config.contains("pallets")) {
|
||||
config.set("pallets", new ArrayList<>());
|
||||
}
|
||||
if (!config.contains("windows")) {
|
||||
config.set("windows", new ArrayList<>());
|
||||
}
|
||||
if (!config.contains("chests")) {
|
||||
config.set("chests", new ArrayList<>());
|
||||
}
|
||||
if (!config.contains("totems")) {
|
||||
config.set("totems", new ArrayList<>());
|
||||
}
|
||||
if (!config.contains("exitgates")) {
|
||||
config.set("exitgates", new ArrayList<>());
|
||||
}
|
||||
if (!config.contains("killer-spawn")) {
|
||||
config.set("killer-spawn", new ArrayList<>());
|
||||
}
|
||||
if (!config.contains("survivor-spawns")) {
|
||||
config.set("survivor-spawns", new ArrayList<>());
|
||||
}
|
||||
}
|
||||
|
||||
public Location getLobby() {
|
||||
World world = Bukkit.getWorld(config.getString("lobby.world", "world"));
|
||||
if (world == null) return null;
|
||||
return new Location(
|
||||
world,
|
||||
config.getDouble("lobby.x", 0.0),
|
||||
config.getDouble("lobby.y", 100.0),
|
||||
config.getDouble("lobby.z", 0.0),
|
||||
(float) config.getDouble("lobby.yaw", 0.0),
|
||||
(float) config.getDouble("lobby.pitch", 0.0)
|
||||
);
|
||||
}
|
||||
|
||||
public void setLobby(Location loc) {
|
||||
config.set("lobby.world", loc.getWorld().getName());
|
||||
config.set("lobby.x", loc.getX());
|
||||
config.set("lobby.y", loc.getY());
|
||||
config.set("lobby.z", loc.getZ());
|
||||
config.set("lobby.yaw", loc.getYaw());
|
||||
config.set("lobby.pitch", loc.getPitch());
|
||||
}
|
||||
|
||||
public List<Location> getGenerators() {
|
||||
return loadLocationList("generators");
|
||||
}
|
||||
|
||||
public List<Location> getHooks() {
|
||||
return loadLocationList("hooks");
|
||||
}
|
||||
|
||||
public List<Location> getPallets() {
|
||||
return loadLocationList("pallets");
|
||||
}
|
||||
|
||||
public List<Location> getWindows() {
|
||||
return loadLocationList("windows");
|
||||
}
|
||||
|
||||
public List<Location> getChests() {
|
||||
return loadLocationList("chests");
|
||||
}
|
||||
|
||||
public List<Location> getTotems() {
|
||||
return loadLocationList("totems");
|
||||
}
|
||||
|
||||
public List<Location> getExitGates() {
|
||||
return loadLocationList("exitgates");
|
||||
}
|
||||
|
||||
public Location getKillerSpawn() {
|
||||
List<Location> spawns = loadLocationList("killer-spawn");
|
||||
return spawns.isEmpty() ? null : spawns.get(0);
|
||||
}
|
||||
|
||||
public List<Location> getSurvivorSpawns() {
|
||||
return loadLocationList("survivor-spawns");
|
||||
}
|
||||
|
||||
private List<Location> loadLocationList(String path) {
|
||||
List<Location> locations = new ArrayList<>();
|
||||
List<?> list = config.getList(path);
|
||||
if (list == null) return locations;
|
||||
|
||||
for (Object obj : list) {
|
||||
if (obj instanceof String) {
|
||||
Location loc = parseLocation((String) obj);
|
||||
if (loc != null) locations.add(loc);
|
||||
}
|
||||
}
|
||||
return locations;
|
||||
}
|
||||
|
||||
private Location parseLocation(String str) {
|
||||
String[] parts = str.split(",");
|
||||
if (parts.length < 4) return null;
|
||||
World world = Bukkit.getWorld(parts[0].trim());
|
||||
if (world == null) return null;
|
||||
try {
|
||||
double x = Double.parseDouble(parts[1].trim());
|
||||
double y = Double.parseDouble(parts[2].trim());
|
||||
double z = Double.parseDouble(parts[3].trim());
|
||||
float yaw = parts.length > 4 ? Float.parseFloat(parts[4].trim()) : 0f;
|
||||
float pitch = parts.length > 5 ? Float.parseFloat(parts[5].trim()) : 0f;
|
||||
return new Location(world, x, y, z, yaw, pitch);
|
||||
} catch (NumberFormatException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void addLocation(String path, Location loc) {
|
||||
List<String> list = config.getStringList(path);
|
||||
list.add(String.format("%s,%.2f,%.2f,%.2f,%.1f,%.1f",
|
||||
loc.getWorld().getName(),
|
||||
loc.getX(), loc.getY(), loc.getZ(),
|
||||
loc.getYaw(), loc.getPitch()));
|
||||
config.set(path, list);
|
||||
}
|
||||
|
||||
public FileConfiguration getConfig() {
|
||||
return config;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue