implement config re-loading

This commit is contained in:
2022-05-11 20:14:10 +02:00
parent a4b110773e
commit 793b25251c
9 changed files with 145 additions and 96 deletions

View File

@@ -0,0 +1,52 @@
package gg.malloc.defense.config;
import java.util.List;
import java.util.Map;
import java.util.ArrayList;
import java.util.Collection;
import gg.malloc.defense.model.Arena;
import gg.malloc.defense.model.Waypoint;
import org.bukkit.configuration.ConfigurationSection;
public class Configuration {
ConfigurationSection m_root;
public Configuration(ConfigurationSection rootConfig) {
m_root = rootConfig;
}
public Collection<String> getMapNames() {
ConfigurationSection mapList = m_root.getConfigurationSection("maps");
return mapList.getKeys(false);
}
public Arena getArenaForMap(String name) {
ConfigurationSection mapList = m_root.getConfigurationSection("maps");
return makeArena(mapList.getConfigurationSection(name));
}
MemoryArena makeArena(ConfigurationSection mapConfig) {
List<Map<?, ?>> spawnpointList = mapConfig.getMapList("spawnpoints");
ArrayList<Waypoint> spawnpoints = new ArrayList<>();
for(Map<?, ?> spawnerObj : spawnpointList) {
Map<String, Double> thisSpawner = (Map<String, Double>)spawnerObj;
double x = thisSpawner.get("x");
double y = thisSpawner.get("y");
double z = thisSpawner.get("z");
spawnpoints.add(new Waypoint(x, y, z));
}
ConfigurationSection targetConfig = mapConfig.getConfigurationSection("target");
double x = targetConfig.getDouble("x");
double y = targetConfig.getDouble("y");
double z = targetConfig.getDouble("z");
Waypoint bombTarget = new Waypoint(x, y, z);
Waypoint[] spawnArray = new Waypoint[spawnpoints.size()];
spawnpoints.toArray(spawnArray);
return new MemoryArena(spawnArray, bombTarget);
}
}

View File

@@ -0,0 +1,27 @@
package gg.malloc.defense.config;
import gg.malloc.defense.model.Arena;
import gg.malloc.defense.model.Waypoint;
import org.bukkit.configuration.ConfigurationSection;
public class MemoryArena implements Arena {
Waypoint[] m_spawnpoints;
Waypoint m_bombTarget;
public MemoryArena(Waypoint[] spawnpoints, Waypoint bombTarget) {
m_spawnpoints = spawnpoints;
m_bombTarget = bombTarget;
}
@Override
public Waypoint[] spawnpoints() {
return m_spawnpoints;
}
@Override
public Waypoint bombTarget() {
return m_bombTarget;
}
}