protected String getOnStartKey(ConfigurationSection section) throws InvalidConfigurationException { if (!section.contains("on start")) return null; if (!section.isString("on start")) throw new InvalidConfigurationException( "Expected a String at `on start` but found something else instead"); return section.getString("on start"); }
protected Map<String, String> getMotdsFromConfig(ConfigurationSection section) throws InvalidConfigurationException { Preconditions.checkArgument( section.isConfigurationSection("motds"), "Configuration missing required section `motds`"); ConfigurationSection motdsSection = section.getConfigurationSection("motds"); Collection<String> keys = motdsSection.getKeys(false); Map<String, String> motds = Maps.newHashMap(); for (String key : keys) { if (!motdsSection.isString(key)) throw new InvalidConfigurationException( "Expected a String at motd `" + key + "` but found something else instead"); motds.put(key, ChatColor.translateAlternateColorCodes('&', motdsSection.getString(key))); } return motds; }
/** * @see * fr.ribesg.bukkit.ncore.config.AbstractConfig#handleValues(org.bukkit.configuration.file.YamlConfiguration) */ @Override protected void handleValues(final YamlConfiguration config) throws InvalidConfigurationException { // ############# // ## General ## // ############# // spawnCommandBehaviour. Default: 1. // Possible values: 0,1 setSpawnCommandBehaviour(config.getInt("spawnCommandBehaviour", 1)); if (getSpawnCommandBehaviour() < 0 || getSpawnCommandBehaviour() > 1) { wrongValue("config.yml", "spawnCommandBehaviour", getSpawnCommandBehaviour(), 0); setSpawnCommandBehaviour(0); } // defaultRequiredPermission. Default: nworld.admin setDefaultRequiredPermission(config.getString("defaultRequiredPermission", "nworld.admin")); // defaultHidden. Default: true setDefaultHidden(config.getBoolean("defaultHidden", true)); // ############## // ## Messages ## // ############## // broadcastOnWorldCreate. Default: 0. // Possible values: 0,1 setBroadcastOnWorldCreate(config.getInt("broadcastOnWorldCreate", 0)); if (getBroadcastOnWorldCreate() < 0 || getBroadcastOnWorldCreate() > 1) { wrongValue("config.yml", "broadcastOnWorldCreate", getBroadcastOnWorldCreate(), 0); setBroadcastOnWorldCreate(0); } // broadcastOnWorldLoad. Default: 0. // Possible values: 0,1 setBroadcastOnWorldLoad(config.getInt("broadcastOnWorldLoad", 0)); if (getBroadcastOnWorldLoad() < 0 || getBroadcastOnWorldLoad() > 1) { wrongValue("config.yml", "broadcastOnWorldLoad", getBroadcastOnWorldLoad(), 0); setBroadcastOnWorldLoad(0); } // broadcastOnWorldUnload. Default: 0. // Possible values: 0,1 setBroadcastOnWorldUnload(config.getInt("broadcastOnWorldUnload", 0)); if (getBroadcastOnWorldUnload() < 0 || getBroadcastOnWorldUnload() > 1) { wrongValue("config.yml", "broadcastOnWorldUnload", getBroadcastOnWorldUnload(), 0); setBroadcastOnWorldUnload(0); } // ############ // ## Worlds ## // ############ final Map<String, GeneralWorld> worldsMap = new HashMap<>(); if (config.isConfigurationSection("stockWorlds")) { final ConfigurationSection stockWorldsSection = config.getConfigurationSection("stockWorlds"); for (final String worldName : stockWorldsSection.getKeys(false)) { final ConfigurationSection worldSection = stockWorldsSection.getConfigurationSection(worldName); final GeneralWorld.WorldType type = worldName.endsWith("_the_end") ? GeneralWorld.WorldType.STOCK_END : worldName.endsWith("_nether") ? GeneralWorld.WorldType.STOCK_NETHER : GeneralWorld.WorldType.STOCK; boolean malformedWorldSection = false; NLocation spawnLocation = null; String requiredPermission = null; final boolean enabled = Bukkit.getWorld(worldName) != null; Boolean hidden = null; if (!worldSection.isConfigurationSection("spawnLocation")) { malformedWorldSection = true; log.severe( "Missing or invalid configuration value: stockWorlds." + worldName + ".spawnLocation"); } else { final ConfigurationSection spawnSection = worldSection.getConfigurationSection("spawnLocation"); if (!spawnSection.isDouble("x")) { malformedWorldSection = true; log.severe( "Missing or invalid configuration value: stockWorlds." + worldName + ".spawnLocation.x"); } else if (!spawnSection.isDouble("y")) { malformedWorldSection = true; log.severe( "Missing or invalid configuration value: stockWorlds." + worldName + ".spawnLocation.y"); } else if (!spawnSection.isDouble("z")) { malformedWorldSection = true; log.severe( "Missing or invalid configuration value: stockWorlds." + worldName + ".spawnLocation.z"); } else if (!spawnSection.isDouble("yaw")) { malformedWorldSection = true; log.severe( "Missing or invalid configuration value: stockWorlds." + worldName + ".spawnLocation.yaw"); } else if (!spawnSection.isDouble("pitch")) { malformedWorldSection = true; log.severe( "Missing or invalid configuration value: stockWorlds." + worldName + ".spawnLocation.pitch"); } else { final double x = spawnSection.getDouble("x"); final double y = spawnSection.getDouble("y"); final double z = spawnSection.getDouble("z"); final float yaw = (float) spawnSection.getDouble("yaw"); final float pitch = (float) spawnSection.getDouble("pitch"); spawnLocation = new NLocation(worldName, x, y, z, yaw, pitch); } } if (!worldSection.isString("requiredPermission")) { malformedWorldSection = true; log.severe( "Missing or invalid configuration value: stockWorlds." + worldName + ".requiredPermission"); } else { requiredPermission = worldSection.getString("requiredPermission"); } if (!worldSection.isBoolean("hidden")) { malformedWorldSection = true; log.severe( "Missing or invalid configuration value: stockWorlds." + worldName + ".hidden"); } else { hidden = worldSection.getBoolean("hidden"); } if (!malformedWorldSection) { worldsMap.put( worldName, new StockWorld( plugin, worldName, type, spawnLocation, requiredPermission, enabled, hidden)); } else { throw new InvalidConfigurationException("Malformed Configuration - Stopping everything"); } } } if (config.isConfigurationSection("additionalWorlds")) { final ConfigurationSection additionalWorldsSection = config.getConfigurationSection("additionalWorlds"); for (final String worldName : additionalWorldsSection.getKeys(false)) { final ConfigurationSection worldSection = additionalWorldsSection.getConfigurationSection(worldName); // If an error is found in the config boolean malformedWorldSection = false; // All variables to build the GeneralWorld objects // Main NLocation spawnLocation = null; Long seed = null; String requiredPermission = null; Boolean enabled = null; Boolean hidden = null; Boolean hasNether = null; Boolean hasEnd = null; // Nether NLocation netherSpawnLocation = null; String netherRequiredPermission = null; Boolean netherEnabled = null; Boolean netherHidden = null; // End NLocation endSpawnLocation = null; String endRequiredPermission = null; Boolean endEnabled = null; Boolean endHidden = null; if (!worldSection.isConfigurationSection("spawnLocation")) { malformedWorldSection = true; log.severe( "Missing or invalid configuration value: additionalWorlds." + worldName + ".spawnLocation"); } else { final ConfigurationSection spawnSection = worldSection.getConfigurationSection("spawnLocation"); if (!spawnSection.isDouble("x")) { malformedWorldSection = true; log.severe( "Missing or invalid configuration value: additionalWorlds." + worldName + ".spawnLocation.x"); } else if (!spawnSection.isDouble("y")) { malformedWorldSection = true; log.severe( "Missing or invalid configuration value: additionalWorlds." + worldName + ".spawnLocation.y"); } else if (!spawnSection.isDouble("z")) { malformedWorldSection = true; log.severe( "Missing or invalid configuration value: additionalWorlds." + worldName + ".spawnLocation.z"); } else if (!spawnSection.isDouble("yaw")) { malformedWorldSection = true; log.severe( "Missing or invalid configuration value: additionalWorlds." + worldName + ".spawnLocation.yaw"); } else if (!spawnSection.isDouble("pitch")) { malformedWorldSection = true; log.severe( "Missing or invalid configuration value: additionalWorlds." + worldName + ".spawnLocation.pitch"); } else { final double x = spawnSection.getDouble("x"); final double y = spawnSection.getDouble("y"); final double z = spawnSection.getDouble("z"); final float yaw = (float) spawnSection.getDouble("yaw"); final float pitch = (float) spawnSection.getDouble("pitch"); spawnLocation = new NLocation(worldName, x, y, z, yaw, pitch); } } if (!worldSection.isLong("seed") && !worldSection.isInt("seed")) { malformedWorldSection = true; log.severe( "Missing or invalid configuration value: additionalWorlds." + worldName + ".seed"); } else { seed = worldSection.getLong("seed"); } if (!worldSection.isString("requiredPermission")) { malformedWorldSection = true; log.severe( "Missing or invalid configuration value: additionalWorlds." + worldName + ".requiredPermission"); } else { requiredPermission = worldSection.getString("requiredPermission"); } if (!worldSection.isBoolean("enabled")) { malformedWorldSection = true; log.severe( "Missing or invalid configuration value: additionalWorlds." + worldName + ".enabled"); } else { enabled = worldSection.getBoolean("enabled"); } if (!worldSection.isBoolean("hidden")) { malformedWorldSection = true; log.severe( "Missing or invalid configuration value: additionalWorlds." + worldName + ".hidden"); } else { hidden = worldSection.getBoolean("hidden"); } if (!worldSection.isBoolean("hasNether")) { malformedWorldSection = true; log.severe( "Missing or invalid configuration value: additionalWorlds." + worldName + ".hasNether"); } else { hasNether = worldSection.getBoolean("hasNether"); } if (!worldSection.isConfigurationSection("netherWorld")) { malformedWorldSection = true; log.severe( "Missing or invalid configuration section: additionalWorlds." + worldName + ".netherWorld"); } else { final ConfigurationSection netherSection = worldSection.getConfigurationSection("netherWorld"); if (!netherSection.isConfigurationSection("spawnLocation")) { malformedWorldSection = true; log.severe( "Missing or invalid configuration value: additionalWorlds." + worldName + ".netherWorld.spawnLocation"); } else { final ConfigurationSection spawnSection = netherSection.getConfigurationSection("spawnLocation"); if (!spawnSection.isDouble("x")) { malformedWorldSection = true; log.severe( "Missing or invalid configuration value: additionalWorlds." + worldName + ".netherWorld.spawnLocation.x"); } else if (!spawnSection.isDouble("y")) { malformedWorldSection = true; log.severe( "Missing or invalid configuration value: additionalWorlds." + worldName + ".netherWorld.spawnLocation.y"); } else if (!spawnSection.isDouble("z")) { malformedWorldSection = true; log.severe( "Missing or invalid configuration value: additionalWorlds." + worldName + ".netherWorld.spawnLocation.z"); } else if (!spawnSection.isDouble("yaw")) { malformedWorldSection = true; log.severe( "Missing or invalid configuration value: additionalWorlds." + worldName + ".netherWorld.spawnLocation.yaw"); } else if (!spawnSection.isDouble("pitch")) { malformedWorldSection = true; log.severe( "Missing or invalid configuration value: additionalWorlds." + worldName + ".netherWorld.spawnLocation.pitch"); } else { final double x = spawnSection.getDouble("x"); final double y = spawnSection.getDouble("y"); final double z = spawnSection.getDouble("z"); final float yaw = (float) spawnSection.getDouble("yaw"); final float pitch = (float) spawnSection.getDouble("pitch"); netherSpawnLocation = new NLocation(worldName + "_nether", x, y, z, yaw, pitch); } } if (!netherSection.isString("requiredPermission")) { malformedWorldSection = true; log.severe( "Missing or invalid configuration value: additionalWorlds." + worldName + ".netherWorld.requiredPermission"); } else { netherRequiredPermission = netherSection.getString("requiredPermission"); } if (!netherSection.isBoolean("enabled")) { malformedWorldSection = true; log.severe( "Missing or invalid configuration value: additionalWorlds." + worldName + ".netherWorld.enabled"); } else { netherEnabled = netherSection.getBoolean("enabled"); } if (!netherSection.isBoolean("hidden")) { malformedWorldSection = true; log.severe( "Missing or invalid configuration value: additionalWorlds." + worldName + ".netherWorld.hidden"); } else { netherHidden = netherSection.getBoolean("hidden"); } } if (!worldSection.isBoolean("hasEnd")) { malformedWorldSection = true; log.severe( "Missing or invalid configuration value: additionalWorlds." + worldName + ".hasEnd"); } else { hasEnd = worldSection.getBoolean("hasEnd"); } if (!worldSection.isConfigurationSection("endWorld")) { malformedWorldSection = true; log.severe( "Missing or invalid configuration section: additionalWorlds." + worldName + ".endWorld"); } else { final ConfigurationSection endSection = worldSection.getConfigurationSection("endWorld"); if (!endSection.isConfigurationSection("spawnLocation")) { malformedWorldSection = true; log.severe( "Missing or invalid configuration value: additionalWorlds." + worldName + ".endWorld.spawnLocation"); } else { final ConfigurationSection spawnSection = endSection.getConfigurationSection("spawnLocation"); if (!spawnSection.isDouble("x")) { malformedWorldSection = true; log.severe( "Missing or invalid configuration value: additionalWorlds." + worldName + ".endWorld.spawnLocation.x"); } else if (!spawnSection.isDouble("y")) { malformedWorldSection = true; log.severe( "Missing or invalid configuration value: additionalWorlds." + worldName + ".endWorld.spawnLocation.y"); } else if (!spawnSection.isDouble("z")) { malformedWorldSection = true; log.severe( "Missing or invalid configuration value: additionalWorlds." + worldName + ".endWorld.spawnLocation.z"); } else if (!spawnSection.isDouble("yaw")) { malformedWorldSection = true; log.severe( "Missing or invalid configuration value: additionalWorlds." + worldName + ".endWorld.spawnLocation.yaw"); } else if (!spawnSection.isDouble("pitch")) { malformedWorldSection = true; log.severe( "Missing or invalid configuration value: additionalWorlds." + worldName + ".endWorld.spawnLocation.pitch"); } else { final double x = spawnSection.getDouble("x"); final double y = spawnSection.getDouble("y"); final double z = spawnSection.getDouble("z"); final float yaw = (float) spawnSection.getDouble("yaw"); final float pitch = (float) spawnSection.getDouble("pitch"); endSpawnLocation = new NLocation(worldName + "_the_end", x, y, z, yaw, pitch); } } if (!endSection.isString("requiredPermission")) { malformedWorldSection = true; log.severe( "Missing or invalid configuration value: additionalWorlds." + worldName + ".endWorld.requiredPermission"); } else { endRequiredPermission = endSection.getString("requiredPermission"); } if (!endSection.isBoolean("enabled")) { malformedWorldSection = true; log.severe( "Missing or invalid configuration value: additionalWorlds." + worldName + ".endWorld.enabled"); } else { endEnabled = endSection.getBoolean("enabled"); } if (!endSection.isBoolean("hidden")) { malformedWorldSection = true; log.severe( "Missing or invalid configuration value: additionalWorlds." + worldName + ".endWorld.hidden"); } else { endHidden = endSection.getBoolean("hidden"); } } if (!malformedWorldSection) { final AdditionalWorld world = new AdditionalWorld( plugin, worldName, seed, spawnLocation, requiredPermission, enabled, hidden, hasNether, hasEnd); worldsMap.put(worldName, world); if (hasNether) { final AdditionalSubWorld nether = new AdditionalSubWorld( plugin, world, netherSpawnLocation, netherRequiredPermission, netherEnabled, netherHidden, World.Environment.NETHER); worldsMap.put(worldName + "_nether", nether); } if (hasEnd) { final AdditionalSubWorld end = new AdditionalSubWorld( plugin, world, endSpawnLocation, endRequiredPermission, endEnabled, endHidden, World.Environment.THE_END); worldsMap.put(worldName + "_the_end", end); } } else { throw new InvalidConfigurationException("Malformed Configuration - Stopping everything"); } } } worlds.putAll(worldsMap); // ########### // ## Warps ## // ########### final Map<String, Warp> warpsMap = new HashMap<>(); if (config.isConfigurationSection("warps")) { final ConfigurationSection warpsSection = config.getConfigurationSection("warps"); for (final String warpName : warpsSection.getKeys(false)) { final ConfigurationSection warpSection = warpsSection.getConfigurationSection(warpName); boolean malformedWarpSection = false; NLocation location = null; String requiredPermission = null; Boolean hidden = null; if (!warpSection.isConfigurationSection("location")) { malformedWarpSection = true; log.severe("Missing or invalid configuration value: warps." + warpName + ".location"); } else { final ConfigurationSection locationSection = warpSection.getConfigurationSection("location"); if (!locationSection.isString("worldName")) { malformedWarpSection = true; log.severe( "Missing or invalid configuration value: warps." + warpName + ".location.worldName"); } if (!locationSection.isDouble("x")) { malformedWarpSection = true; log.severe("Missing or invalid configuration value: warps." + warpName + ".location.x"); } if (!locationSection.isDouble("y")) { malformedWarpSection = true; log.severe("Missing or invalid configuration value: warps." + warpName + ".location.y"); } if (!locationSection.isDouble("z")) { malformedWarpSection = true; log.severe("Missing or invalid configuration value: warps." + warpName + ".location.z"); } if (!locationSection.isDouble("yaw")) { malformedWarpSection = true; log.severe( "Missing or invalid configuration value: warps." + warpName + ".location.yaw"); } if (!locationSection.isDouble("pitch")) { malformedWarpSection = true; log.severe( "Missing or invalid configuration value: warps." + warpName + ".location.pitch"); } if (!malformedWarpSection) { final String worldName = locationSection.getString("worldName"); final double x = locationSection.getDouble("x"); final double y = locationSection.getDouble("y"); final double z = locationSection.getDouble("z"); final float yaw = (float) locationSection.getDouble("yaw"); final float pitch = (float) locationSection.getDouble("pitch"); location = new NLocation(worldName, x, y, z, yaw, pitch); } } if (!warpSection.isString("requiredPermission")) { malformedWarpSection = true; log.severe( "Missing or invalid configuration value: warps." + warpName + ".requiredPermission"); } else { requiredPermission = warpSection.getString("requiredPermission"); } if (!warpSection.isBoolean("hidden")) { malformedWarpSection = true; log.severe("Missing or invalid configuration value: warps." + warpName + ".hidden"); } else { hidden = warpSection.getBoolean("hidden"); } if (!malformedWarpSection) { warpsMap.put(warpName, new Warp(warpName, location, false, requiredPermission, hidden)); } else { throw new InvalidConfigurationException("Malformed Configuration - Stopping everything"); } } } warps.putAll(warpsMap); }