* @param arena
* @param section
* @return
*/
public Cuboid configToCuboid(String arena, String section) {
FileConfiguration conf = SimpleSpleef.getPlugin().getConfig();
arena = arena.toLowerCase();
section = section.toLowerCase();
String confbase = "arenas." + arena + "." + section; // shorten stuff later on
// is arena protected? If not, ignore to save resources
if (!conf.getBoolean("arenas." + arena + ".protectArena", true)) return null;
// get arena cube, if possible
if (!conf.isConfigurationSection(confbase) ||
!conf.getBoolean("arenas." + arena + ".arena.enabled", false)) return null;
// do we have a world guard region here?
if (conf.getString(confbase + ".worldguardRegion") != null && conf.getString(confbase + ".worldguardWorld") != null && SimpleSpleef.getPlugin().getWorldGuard() != null) {
// get world guard region
World world = SimpleSpleef.getPlugin().getServer().getWorld(conf.getString(confbase + ".worldguardWorld"));
// get region manager
RegionManager regionManager = world!=null?SimpleSpleef.getPlugin().getWorldGuard().getRegionManager(world):null;
// error?
if (world == null || regionManager == null) return null;
// get region
ProtectedRegion region = regionManager.getRegion(conf.getString(confbase + ".worldguardRegion"));
if (region == null) return null;
return new CuboidWorldGuard(region, world); // create world guard cuboid - very cool!
} else { // normal, non WorldGuard coordinates
// now, check sane coords
String firstWorldString = conf.getString(confbase + ".a.world");
String secondWorldString = conf.getString(confbase + ".b.world");
World firstWorld = firstWorldString!=null?SimpleSpleef.getPlugin().getServer().getWorld(firstWorldString):null;
World secondWorld = secondWorldString!=null?SimpleSpleef.getPlugin().getServer().getWorld(secondWorldString):null;
if (firstWorld == null || secondWorld == null || firstWorld != secondWorld) return null; // non-sane worlds
int firstX = conf.getInt(confbase + ".a.x", 0);
int firstY = conf.getInt(confbase + ".a.y", 0);
int firstZ = conf.getInt(confbase + ".a.z", 0);
int secondX = conf.getInt(confbase + ".b.x", 0);
int secondY = conf.getInt(confbase + ".b.y", 0);
int secondZ = conf.getInt(confbase + ".b.z", 0);
if (firstX == 0 && firstY == 0 && firstZ == 0 && secondX == 0 && secondY == 0 && secondZ == 0) return null;
// create cube
return new CuboidImpl(firstWorld, (firstX<secondX?firstX:secondX), (firstY<secondY?firstY:secondY), (firstZ<secondZ?firstZ:secondZ),
(firstX>secondX?firstX:secondX), (firstY>secondY?firstY:secondY), (firstZ>secondZ?firstZ:secondZ));
}