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 Essentials by drtshock.
the class UserData method _getKitTimestamps.
private Map<String, Long> _getKitTimestamps() {
if (config.isConfigurationSection("timestamps.kits")) {
final ConfigurationSection section = config.getConfigurationSection("timestamps.kits");
final Map<String, Long> timestamps = new HashMap<String, Long>();
for (String command : section.getKeys(false)) {
if (section.isLong(command)) {
timestamps.put(command.toLowerCase(Locale.ENGLISH), section.getLong(command));
} else if (section.isInt(command)) {
timestamps.put(command.toLowerCase(Locale.ENGLISH), (long) section.getInt(command));
}
}
return timestamps;
}
return new HashMap<String, Long>();
}
use of org.bukkit.configuration.ConfigurationSection in project Essentials by drtshock.
the class Settings method _getCommandCosts.
private ConfigurationSection _getCommandCosts() {
if (config.isConfigurationSection("command-costs")) {
final ConfigurationSection section = config.getConfigurationSection("command-costs");
final ConfigurationSection newSection = new MemoryConfiguration();
for (String command : section.getKeys(false)) {
if (command.charAt(0) == '/') {
ess.getLogger().warning("Invalid command cost. '" + command + "' should not start with '/'.");
}
if (section.isDouble(command)) {
newSection.set(command.toLowerCase(Locale.ENGLISH), section.getDouble(command));
} else if (section.isInt(command)) {
newSection.set(command.toLowerCase(Locale.ENGLISH), (double) section.getInt(command));
} else if (section.isString(command)) {
String costString = section.getString(command);
try {
double cost = Double.parseDouble(costString.trim().replace(getCurrencySymbol(), "").replaceAll("\\W", ""));
newSection.set(command.toLowerCase(Locale.ENGLISH), cost);
} catch (NumberFormatException ex) {
ess.getLogger().warning("Invalid command cost for: " + command + " (" + costString + ")");
}
} else {
ess.getLogger().warning("Invalid command cost for: " + command);
}
}
return newSection;
}
return null;
}
use of org.bukkit.configuration.ConfigurationSection in project Essentials by drtshock.
the class Kit method listKits.
//TODO: Convert this to use one of the new text classes?
public static String listKits(final IEssentials ess, final User user) throws Exception {
try {
final ConfigurationSection kits = ess.getSettings().getKits();
final StringBuilder list = new StringBuilder();
for (String kitItem : kits.getKeys(false)) {
if (user == null) {
list.append(" ").append(capitalCase(kitItem));
} else if (user.isAuthorized("essentials.kits." + kitItem.toLowerCase(Locale.ENGLISH))) {
String cost = "";
String name = capitalCase(kitItem);
BigDecimal costPrice = new Trade("kit-" + kitItem.toLowerCase(Locale.ENGLISH), ess).getCommandCost(user);
if (costPrice.signum() > 0) {
cost = tl("kitCost", NumberUtil.displayCurrency(costPrice, ess));
}
Kit kit = new Kit(kitItem, ess);
double nextUse = kit.getNextUse(user);
if (nextUse == -1 && ess.getSettings().isSkippingUsedOneTimeKitsFromKitList()) {
continue;
} else if (nextUse != 0) {
name = tl("kitDelay", name);
}
list.append(" ").append(name).append(cost);
}
}
return list.toString().trim();
} catch (Exception ex) {
throw new Exception(tl("kitError"), ex);
}
}
use of org.bukkit.configuration.ConfigurationSection in project acidisland by tastybento.
the class ControlPanel method loadShop.
// The first parameter, is the inventory owner. I make it null to let
// everyone use it.
// The second parameter, is the slots in a inventory. Must be a multiple of
// 9. Can be up to 54.
// The third parameter, is the inventory name. This will accept chat colors.
/**
* This loads the minishop from the minishop.yml file
*/
public static void loadShop() {
// The first parameter is the Material, then the durability (if wanted),
// slot, descriptions
// Minishop
store.clear();
miniShopFile = Util.loadYamlFile("minishop.yml");
allowSelling = miniShopFile.getBoolean("config.allowselling", false);
ConfigurationSection items = miniShopFile.getConfigurationSection("items");
ASkyBlock plugin = ASkyBlock.getPlugin();
if (DEBUG)
plugin.getLogger().info("DEBUG: loading the shop. items = " + items.toString());
if (items != null) {
// Create the store
// Get how many the store should be
int size = items.getKeys(false).size() + 8;
size -= (size % 9);
miniShop = Bukkit.createInventory(null, size, plugin.myLocale().islandMiniShopTitle);
// Run through items
int slot = 0;
for (String item : items.getKeys(false)) {
try {
String m = items.getString(item + ".material");
// plugin.getLogger().info("Material = " + m);
Material material = Material.matchMaterial(m);
int quantity = items.getInt(item + ".quantity", 0);
String extra = items.getString(item + ".extra", "");
double price = items.getDouble(item + ".price", -1D);
double sellPrice = items.getDouble(item + ".sellprice", -1D);
if (!allowSelling) {
sellPrice = -1;
}
String description = ChatColor.translateAlternateColorCodes('&', items.getString(item + ".description", ""));
MiniShopItem shopItem = new MiniShopItem(material, extra, slot, description, quantity, price, sellPrice);
store.put(slot, shopItem);
miniShop.setItem(slot, shopItem.getItem());
slot++;
} catch (Exception e) {
plugin.getLogger().warning("Problem loading minishop item #" + slot);
plugin.getLogger().warning(e.getMessage());
e.printStackTrace();
}
}
}
}
Aggregations