Search in sources :

Example 11 with ConfigurationSection

use of org.bukkit.configuration.ConfigurationSection in project Glowstone by GlowstoneMC.

the class BuiltinMaterialValueManager method registerBuiltins.

private void registerBuiltins(ConfigurationSection mainSection) {
    ConfigurationSection valuesSection = mainSection.getConfigurationSection("values");
    Set<String> materials = valuesSection.getKeys(false);
    for (String strMaterial : materials) {
        Material material = Material.matchMaterial(strMaterial);
        if (material == null) {
            throw new RuntimeException("Invalid builtin/materialValues.yml: Couldn't found material: " + strMaterial);
        }
        ConfigurationSection materialSection = valuesSection.getConfigurationSection(strMaterial);
        values.put(material, new BuiltinValueCollection(materialSection));
    }
}
Also used : Material(org.bukkit.Material) ConfigurationSection(org.bukkit.configuration.ConfigurationSection)

Example 12 with ConfigurationSection

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>();
}
Also used : ConfigurationSection(org.bukkit.configuration.ConfigurationSection)

Example 13 with ConfigurationSection

use of org.bukkit.configuration.ConfigurationSection in project Essentials by drtshock.

the class Worth method getPrice.

public BigDecimal getPrice(ItemStack itemStack) {
    String itemname = itemStack.getType().toString().toLowerCase(Locale.ENGLISH).replace("_", "");
    BigDecimal result;
    //First check for matches with item name
    result = config.getBigDecimal("worth." + itemname + "." + itemStack.getDurability(), BigDecimal.ONE.negate());
    if (result.signum() < 0) {
        final ConfigurationSection itemNameMatch = config.getConfigurationSection("worth." + itemname);
        if (itemNameMatch != null && itemNameMatch.getKeys(false).size() == 1) {
            result = config.getBigDecimal("worth." + itemname + ".0", BigDecimal.ONE.negate());
        }
    }
    if (result.signum() < 0) {
        result = config.getBigDecimal("worth." + itemname + ".*", BigDecimal.ONE.negate());
    }
    if (result.signum() < 0) {
        result = config.getBigDecimal("worth." + itemname, BigDecimal.ONE.negate());
    }
    //Now we should check for item ID
    if (result.signum() < 0) {
        result = config.getBigDecimal("worth." + itemStack.getTypeId() + "." + itemStack.getDurability(), BigDecimal.ONE.negate());
    }
    if (result.signum() < 0) {
        final ConfigurationSection itemNumberMatch = config.getConfigurationSection("worth." + itemStack.getTypeId());
        if (itemNumberMatch != null && itemNumberMatch.getKeys(false).size() == 1) {
            result = config.getBigDecimal("worth." + itemStack.getTypeId() + ".0", BigDecimal.ONE.negate());
        }
    }
    if (result.signum() < 0) {
        result = config.getBigDecimal("worth." + itemStack.getTypeId() + ".*", BigDecimal.ONE.negate());
    }
    if (result.signum() < 0) {
        result = config.getBigDecimal("worth." + itemStack.getTypeId(), BigDecimal.ONE.negate());
    }
    //This is to match the old worth syntax
    if (result.signum() < 0) {
        result = config.getBigDecimal("worth-" + itemStack.getTypeId(), BigDecimal.ONE.negate());
    }
    if (result.signum() < 0) {
        return null;
    }
    return result;
}
Also used : BigDecimal(java.math.BigDecimal) ConfigurationSection(org.bukkit.configuration.ConfigurationSection)

Example 14 with ConfigurationSection

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;
}
Also used : MemoryConfiguration(org.bukkit.configuration.MemoryConfiguration) ConfigurationSection(org.bukkit.configuration.ConfigurationSection)

Example 15 with ConfigurationSection

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);
    }
}
Also used : BigDecimal(java.math.BigDecimal) NoChargeException(com.earth2me.essentials.commands.NoChargeException) ConfigurationSection(org.bukkit.configuration.ConfigurationSection)

Aggregations

ConfigurationSection (org.bukkit.configuration.ConfigurationSection)49 ItemStack (org.bukkit.inventory.ItemStack)7 IOException (java.io.IOException)6 Material (org.bukkit.Material)6 YamlConfiguration (org.bukkit.configuration.file.YamlConfiguration)6 File (java.io.File)5 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)3 MemoryConfiguration (org.bukkit.configuration.MemoryConfiguration)3 EntityType (org.bukkit.entity.EntityType)3 Rewards (au.com.mineauz.minigames.minigame.reward.Rewards)2 ChatColor (com.gamingmesh.jobs.util.ChatColor)2 ASkyBlock (com.wasteofplastic.acidisland.ASkyBlock)2 BigDecimal (java.math.BigDecimal)2 Enchantment (org.bukkit.enchantments.Enchantment)2 SQLiteBackend (au.com.mineauz.minigames.backend.sqlite.SQLiteBackend)1 MenuItemRewardGroup (au.com.mineauz.minigames.menu.MenuItemRewardGroup)1 LoadoutAddon (au.com.mineauz.minigames.minigame.modules.LoadoutModule.LoadoutAddon)1 StandardRewardScheme (au.com.mineauz.minigames.minigame.reward.scheme.StandardRewardScheme)1 NoChargeException (com.earth2me.essentials.commands.NoChargeException)1