Delete src/main/java/de/lasertec/arena/ArenaManager.java via Git Manager GUI
This commit is contained in:
@@ -1,163 +0,0 @@
|
||||
package de.lasertec.arena;
|
||||
|
||||
import de.lasertec.LasertecPlugin;
|
||||
import de.lasertec.game.Team;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
public class ArenaManager {
|
||||
|
||||
private final LasertecPlugin plugin;
|
||||
private final Map<String, Arena> arenas = new LinkedHashMap<>();
|
||||
private File file;
|
||||
private FileConfiguration cfg;
|
||||
|
||||
public ArenaManager(LasertecPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
load();
|
||||
}
|
||||
|
||||
// ─── CRUD ────────────────────────────────────────────────────────────────
|
||||
|
||||
public Arena createArena(String name) {
|
||||
String key = name.toLowerCase();
|
||||
if (arenas.containsKey(key)) return null;
|
||||
Arena arena = new Arena(name);
|
||||
arenas.put(key, arena);
|
||||
save();
|
||||
return arena;
|
||||
}
|
||||
|
||||
public Arena getArena(String name) {
|
||||
return arenas.get(name.toLowerCase());
|
||||
}
|
||||
|
||||
public boolean deleteArena(String name) {
|
||||
if (arenas.remove(name.toLowerCase()) == null) return false;
|
||||
save();
|
||||
return true;
|
||||
}
|
||||
|
||||
public Collection<Arena> getAll() { return Collections.unmodifiableCollection(arenas.values()); }
|
||||
|
||||
public List<Arena> getReady() {
|
||||
List<Arena> list = new ArrayList<>();
|
||||
for (Arena a : arenas.values())
|
||||
if (a.isReady() && a.isEnabled()) list.add(a);
|
||||
return list;
|
||||
}
|
||||
|
||||
// ─── Persistence ─────────────────────────────────────────────────────────
|
||||
|
||||
private void load() {
|
||||
file = new File(plugin.getDataFolder(), "arenas.yml");
|
||||
if (!file.exists()) {
|
||||
try { plugin.getDataFolder().mkdirs(); file.createNewFile(); }
|
||||
catch (IOException ex) { ex.printStackTrace(); return; }
|
||||
}
|
||||
cfg = YamlConfiguration.loadConfiguration(file);
|
||||
|
||||
ConfigurationSection root = cfg.getConfigurationSection("arenas");
|
||||
if (root == null) return;
|
||||
|
||||
for (String key : root.getKeys(false)) {
|
||||
ConfigurationSection sec = root.getConfigurationSection(key);
|
||||
if (sec == null) continue;
|
||||
|
||||
Arena arena = new Arena(sec.getString("display-name", key));
|
||||
arena.setEnabled(sec.getBoolean("enabled", false));
|
||||
|
||||
// Lobby
|
||||
if (sec.contains("lobby"))
|
||||
arena.setLobbyLocation(sec.getLocation("lobby"));
|
||||
|
||||
// Corners
|
||||
if (sec.contains("corner1")) arena.setCorner1(sec.getLocation("corner1"));
|
||||
if (sec.contains("corner2")) arena.setCorner2(sec.getLocation("corner2"));
|
||||
|
||||
// Team spawns
|
||||
ConfigurationSection spawnsSec = sec.getConfigurationSection("spawns");
|
||||
if (spawnsSec != null) {
|
||||
for (Team t : Team.values()) {
|
||||
List<Map<?,?>> locs = spawnsSec.getMapList(t.name());
|
||||
for (Map<?,?> m : locs) {
|
||||
Location loc = deserializeLoc(m);
|
||||
if (loc != null) arena.addSpawn(t, loc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Team bases
|
||||
ConfigurationSection basesSec = sec.getConfigurationSection("bases");
|
||||
if (basesSec != null) {
|
||||
for (Team t : Team.values()) {
|
||||
if (basesSec.contains(t.name())) {
|
||||
Location loc = basesSec.getLocation(t.name());
|
||||
if (loc != null) arena.setBase(t, loc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
arenas.put(key.toLowerCase(), arena);
|
||||
plugin.getLogger().info("Arena geladen: §e" + key + (arena.isReady() ? " §a[OK]" : " §c[Setup unvollständig]"));
|
||||
}
|
||||
}
|
||||
|
||||
public void save() {
|
||||
cfg.set("arenas", null);
|
||||
for (Map.Entry<String, Arena> entry : arenas.entrySet()) {
|
||||
Arena a = entry.getValue();
|
||||
String path = "arenas." + entry.getKey() + ".";
|
||||
|
||||
cfg.set(path + "display-name", a.getDisplayName());
|
||||
cfg.set(path + "enabled", a.isEnabled());
|
||||
|
||||
if (a.getLobbyLocation() != null)
|
||||
cfg.set(path + "lobby", a.getLobbyLocation());
|
||||
if (a.getCorner1() != null) cfg.set(path + "corner1", a.getCorner1());
|
||||
if (a.getCorner2() != null) cfg.set(path + "corner2", a.getCorner2());
|
||||
|
||||
// Spawns
|
||||
for (Team t : Team.values()) {
|
||||
List<Map<String, Object>> list = new ArrayList<>();
|
||||
for (Location loc : a.getSpawns(t)) list.add(serializeLoc(loc));
|
||||
cfg.set(path + "spawns." + t.name(), list);
|
||||
}
|
||||
|
||||
// Bases
|
||||
for (Map.Entry<Team, Location> be : a.getAllBases().entrySet()) {
|
||||
cfg.set(path + "bases." + be.getKey().name(), be.getValue());
|
||||
}
|
||||
}
|
||||
try { cfg.save(file); } catch (IOException ex) { ex.printStackTrace(); }
|
||||
}
|
||||
|
||||
// ─── Location serialization (compatible without external libs) ───────────
|
||||
|
||||
private Map<String, Object> serializeLoc(Location loc) {
|
||||
Map<String, Object> m = new LinkedHashMap<>();
|
||||
m.put("world", loc.getWorld().getName());
|
||||
m.put("x", loc.getX()); m.put("y", loc.getY()); m.put("z", loc.getZ());
|
||||
m.put("yaw", (double) loc.getYaw());
|
||||
m.put("pitch", (double) loc.getPitch());
|
||||
return m;
|
||||
}
|
||||
|
||||
private Location deserializeLoc(Map<?,?> m) {
|
||||
try {
|
||||
String world = (String) m.get("world");
|
||||
double x = ((Number) m.get("x")).doubleValue();
|
||||
double y = ((Number) m.get("y")).doubleValue();
|
||||
double z = ((Number) m.get("z")).doubleValue();
|
||||
float yaw = m.containsKey("yaw") ? ((Number)m.get("yaw")).floatValue() : 0f;
|
||||
float pitch = m.containsKey("pitch") ? ((Number)m.get("pitch")).floatValue() : 0f;
|
||||
return new Location(plugin.getServer().getWorld(world), x, y, z, yaw, pitch);
|
||||
} catch (Exception ex) { return null; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user