use of pl.themolka.arcade.attribute.BoundedItemModifier in project Arcade2 by ShootGame.
the class ItemStackParser method parseTree.
@Override
protected ParserResult<ItemStack> parseTree(Node node, String name) throws ParserException {
Property amountProperty = node.property("amount", "total");
Property durabilityProperty = node.property("durability");
MaterialData type = this.typeParser.parse(node.property(MaterialParser.MATERIAL_ELEMENT_NAMES)).orFail();
int amount = this.amountParser.parse(amountProperty).orDefault(1);
String displayName = this.displayNameParser.parse(node.firstChild("name", "display-name")).orDefaultNull();
List<String> description = this.parseDescription(node);
short durability = this.durabilityParser.parse(durabilityProperty).orDefault((short) 0);
List<ItemEnchantment> enchantments = this.parseEnchantments(node);
List<Material> canDestroy = this.parseDestroy(node);
List<Material> canPlaceOn = this.parseCanPlaceOn(node);
boolean unbreakable = this.unbreakableParser.parse(node.property("unbreakable", "permanent")).orDefault(false);
List<ItemFlag> flags = this.parseFlags(node);
if (amount <= 0) {
throw this.fail(amountProperty, "Amount must be positive (greater than 0)");
} else if (type.getData() != 0 && durability != 0) {
// Notch made a huge mistake here... :(
throw this.fail(durabilityProperty, "Sorry! Durability cannot be combined with material data!");
}
ItemStack itemStack = new ItemStack(type.getItemType());
itemStack.setData(type);
itemStack.setAmount(amount);
itemStack.setDurability(durability);
for (ItemEnchantment enchantment : enchantments) {
enchantment.apply(itemStack);
}
ItemMeta itemMeta = itemStack.getItemMeta();
if (displayName != null) {
itemMeta.setDisplayName(displayName);
}
if (!description.isEmpty()) {
itemMeta.setLore(description);
}
if (!canDestroy.isEmpty()) {
itemMeta.setCanDestroy(canDestroy);
}
if (!canPlaceOn.isEmpty()) {
itemMeta.setCanPlaceOn(canPlaceOn);
}
for (Node modifierNode : node.children("modifier", "attribute-modifier", "attributemodifier", "attribute")) {
BoundedItemModifier modifier = this.modifierParser.parse(modifierNode).orFail();
itemMeta.addAttributeModifier(modifier.getKey().key(), modifier.getItemModifier());
}
itemMeta.setUnbreakable(unbreakable);
itemMeta.addItemFlags(flags.toArray(new ItemFlag[flags.size()]));
itemStack.setItemMeta(this.itemMetaParser.parse(node, itemStack, itemMeta));
return ParserResult.fine(node, name, itemStack);
}
Aggregations