/**
* Helper method for loading a single class.
*/
private ArenaClass loadClass(String classname) {
ConfigurationSection section = config.getConfigurationSection("classes." + classname);
String lowercase = classname.toLowerCase();
// If the section doesn't exist, the class doesn't either.
if (section == null) {
Messenger.severe("Failed to load class '" + classname + "'.");
return null;
}
// Check if weapons and armor for this class should be unbreakable
boolean weps = section.getBoolean("unbreakable-weapons", true);
boolean arms = section.getBoolean("unbreakable-armor", true);
// Grab the class price, if any
double price = -1D;
String priceString = section.getString("price", null);
if (priceString != null) {
ItemStack priceItem = ItemParser.parseItem(priceString);
if (priceItem != null && priceItem.getTypeId() == MobArena.ECONOMY_MONEY_ID) {
price = (priceItem.getAmount() + (priceItem.getDurability() / 100D));
} else {
Messenger.warning("The price for class '" + classname + "' could not be parsed!");
Messenger.warning("- expected e.g. '$10', found '" + priceString + "'");
}
}
// Create an ArenaClass with the config-file name.
ArenaClass arenaClass = new ArenaClass(classname, price, weps, arms);
// Parse the items-node
List<String> items = section.getStringList("items");
if (items == null || items.isEmpty()) {
String str = section.getString("items", "");
List<ItemStack> stacks = ItemParser.parseItems(str);
arenaClass.setItems(stacks);
} else {
List<ItemStack> stacks = new ArrayList<ItemStack>();
for (String item : items) {
ItemStack stack = ItemParser.parseItem(item);
if (stack != null) {
stacks.add(stack);
}
}
arenaClass.setItems(stacks);
}
// And the legacy armor-node
String armor = section.getString("armor", "");
if (!armor.equals("")) {
List<ItemStack> stacks = ItemParser.parseItems(armor);
arenaClass.setArmor(stacks);
}
// Get armor strings
String head = section.getString("helmet", null);
String chest = section.getString("chestplate", null);
String legs = section.getString("leggings", null);
String feet = section.getString("boots", null);
// Parse to ItemStacks
ItemStack helmet = ItemParser.parseItem(head);
ItemStack chestplate = ItemParser.parseItem(chest);
ItemStack leggings = ItemParser.parseItem(legs);