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));
}
}
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 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;
}
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);
}
}
Aggregations