implement config re-loading
This commit is contained in:
52
src/main/java/gg/malloc/defense/config/Configuration.java
Normal file
52
src/main/java/gg/malloc/defense/config/Configuration.java
Normal 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);
|
||||
}
|
||||
}
|
||||
27
src/main/java/gg/malloc/defense/config/MemoryArena.java
Normal file
27
src/main/java/gg/malloc/defense/config/MemoryArena.java
Normal 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user