use of org.bukkit.configuration.ConfigurationSection in project Minigames by AddstarMC.
the class RewardGroup method load.
public static RewardGroup load(ConfigurationSection section, Rewards container) {
RewardRarity rarity = RewardRarity.valueOf(section.getString("rarity"));
RewardGroup group = new RewardGroup(section.getName(), rarity);
// Load contents
for (String key : section.getKeys(false)) {
if (key.equals("rarity")) {
continue;
}
ConfigurationSection itemSection = section.getConfigurationSection(key);
// TODO: Remove after 1.7 release
if (!itemSection.contains("data")) {
ItemStack item = itemSection.getItemStack("item");
if (item != null) {
RewardType it = RewardTypes.getRewardType("ITEM", container);
it.loadReward("item", itemSection);
group.addItem(it);
} else {
RewardType it = RewardTypes.getRewardType("MONEY", container);
it.loadReward("money", itemSection);
group.addItem(it);
}
} else {
RewardType rew = RewardTypes.getRewardType(itemSection.getString("type"), container);
rew.loadReward("data", itemSection);
group.addItem(rew);
}
}
return group;
}
use of org.bukkit.configuration.ConfigurationSection in project Denizen-For-Bukkit by DenizenScript.
the class Denizen method updateSaves.
public void updateSaves() {
int saves_version = 1;
if (savesConfig.contains("a_saves.version")) {
saves_version = savesConfig.getInt("a_saves.version");
}
if (saves_version == 1) {
dB.log("Updating saves from v1 to v2...");
ConfigurationSection section = savesConfig.getConfigurationSection("Players");
if (section != null) {
ArrayList<String> keyList = new ArrayList<String>(section.getKeys(false));
// Remove UPPERCASE cooldown saves from the list - handled manually
for (int i = 0; i < keyList.size(); i++) {
String key = keyList.get(i);
if (!key.equals(key.toUpperCase()) && keyList.contains(key.toUpperCase())) {
keyList.remove(key.toUpperCase());
}
}
// Handle all actual player saves
for (int i = 0; i < keyList.size(); i++) {
String key = keyList.get(i);
try {
// Flags
ConfigurationSection playerSection = savesConfig.getConfigurationSection("Players." + key);
if (playerSection == null) {
dB.echoError("Can't update saves for player '" + key + "' - broken YAML section!");
continue;
}
Map<String, Object> keys = playerSection.getValues(true);
if (!key.equals(key.toUpperCase()) && savesConfig.contains("Players." + key.toUpperCase())) {
// Cooldowns
keys.putAll(savesConfig.getConfigurationSection("Players." + key.toUpperCase()).getValues(true));
savesConfig.set("Players." + key.toUpperCase(), null);
}
dPlayer player = dPlayer.valueOf(key);
if (player == null) {
dB.echoError("Can't update saves for player '" + key + "' - invalid name!");
savesConfig.createSection("PlayersBACKUP." + key, keys);
// TODO: READ FROM BACKUP AT LOG IN
} else {
savesConfig.createSection("Players." + player.getSaveName(), keys);
}
savesConfig.set("Players." + key, null);
} catch (Exception ex) {
dB.echoError(ex);
}
}
}
section = savesConfig.getConfigurationSection("Listeners");
if (section != null) {
for (String key : section.getKeys(false)) {
try {
dPlayer player = dPlayer.valueOf(key);
if (player == null) {
dB.log("Warning: can't update listeners for player '" + key + "' - invalid name!");
} else // Listeners
{
savesConfig.createSection("Listeners." + player.getSaveName(), savesConfig.getConfigurationSection("Listeners." + key).getValues(true));
}
savesConfig.set("Listeners." + key, null);
} catch (Exception ex) {
dB.echoError(ex);
}
}
}
savesConfig.set("a_saves.version", "2");
dB.log("Done!");
}
}
use of org.bukkit.configuration.ConfigurationSection in project Glowstone by GlowstoneMC.
the class GlowServer method getGenerator.
/**
* Gets the default ChunkGenerator for the given environment and type.
*
* @return The ChunkGenerator.
*/
private ChunkGenerator getGenerator(String name, Environment environment, WorldType type) {
// find generator based on configuration
ConfigurationSection worlds = config.getWorlds();
if (worlds != null) {
String genName = worlds.getString(name + ".generator", null);
ChunkGenerator generator = WorldCreator.getGeneratorForName(name, genName, getConsoleSender());
if (generator != null) {
return generator;
}
}
// find generator based on environment and world type
if (environment == Environment.NETHER) {
return new NetherGenerator();
} else if (environment == Environment.THE_END) {
return new TheEndGenerator();
} else {
if (type == WorldType.FLAT) {
return new SuperflatGenerator();
} else {
return new OverworldGenerator();
}
}
}
use of org.bukkit.configuration.ConfigurationSection in project Glowstone by GlowstoneMC.
the class GlowServer method enablePlugins.
/**
* Enable all plugins of the given load order type.
*
* @param type The type of plugin to enable.
*/
private void enablePlugins(PluginLoadOrder type) {
if (type == PluginLoadOrder.STARTUP) {
helpMap.clear();
helpMap.loadConfig(config.getConfigFile(Key.HELP_FILE));
}
// load all the plugins
Plugin[] plugins = pluginManager.getPlugins();
for (Plugin plugin : plugins) {
if (!plugin.isEnabled() && plugin.getDescription().getLoad() == type) {
List<Permission> perms = plugin.getDescription().getPermissions();
for (Permission perm : perms) {
try {
pluginManager.addPermission(perm);
} catch (IllegalArgumentException ex) {
getLogger().log(Level.WARNING, "Plugin " + plugin.getDescription().getFullName() + " tried to register permission '" + perm.getName() + "' but it's already registered", ex);
}
}
try {
pluginManager.enablePlugin(plugin);
} catch (Throwable ex) {
logger.log(Level.SEVERE, "Error loading " + plugin.getDescription().getFullName(), ex);
}
}
}
if (type == PluginLoadOrder.POSTWORLD) {
commandMap.setFallbackCommands();
commandMap.registerServerAliases();
DefaultPermissions.registerCorePermissions();
helpMap.initializeCommands();
helpMap.amendTopics(config.getConfigFile(Key.HELP_FILE));
// load permissions.yml
ConfigurationSection permConfig = config.getConfigFile(Key.PERMISSIONS_FILE);
Map<String, Map<String, Object>> data = new HashMap<>();
permConfig.getValues(false).forEach((key, value) -> data.put(key, ((MemorySection) value).getValues(false)));
List<Permission> perms = Permission.loadPermissions(data, "Permission node '%s' in permissions config is invalid", PermissionDefault.OP);
for (Permission perm : perms) {
try {
pluginManager.addPermission(perm);
} catch (IllegalArgumentException ex) {
getLogger().log(Level.WARNING, "Permission config tried to register '" + perm.getName() + "' but it's already registered", ex);
}
}
}
}
use of org.bukkit.configuration.ConfigurationSection in project Glowstone by GlowstoneMC.
the class GlowHelpMap method amendTopics.
/**
* Process topic amendments from help.yml.
*
* @param config The configuration to read from.
*/
public void amendTopics(ConfigurationSection config) {
ConfigurationSection amendedTopics = config.getConfigurationSection("amended-topics");
if (amendedTopics != null) {
for (String key : amendedTopics.getKeys(false)) {
HelpTopic target = getHelpTopic(key);
if (target == null) {
continue;
}
ConfigurationSection amend = amendedTopics.getConfigurationSection(key);
if (amend == null) {
continue;
}
target.amendTopic(color(amend.getString("shortText")), color(amend.getString("fullText")));
String perm = amend.getString("permission", null);
if (perm != null) {
// empty string can be specified to remove permission
target.amendCanSee(perm.isEmpty() ? null : perm);
}
}
}
}
Aggregations