public static Pair<org.bukkit.attribute.Attribute, ItemAttributeModifier> parseItemAttributeModifier(Element el) throws InvalidXMLException { return Pair.create( parseAttribute(new Node(el)), new ItemAttributeModifier( parseEquipmentSlot(Node.fromAttr(el, "slot"), null), parseAttributeModifier(el).second ) ); }
public static ItemStack applyMeta(ItemStack itemStack, Element element) { for (Element enchant : element.getChildren("enchantment")) { String ench = enchant.getText(); Enchantment enchantment = Enchantment.getByName(Strings.getTechnicalName(ench)); int lvl = Numbers.parseInteger(enchant.getAttributeValue("level"), 1); if (enchantment == null) { //TODO: NMS name check } else { itemStack.addUnsafeEnchantment(enchantment, lvl); } } ItemMeta meta = itemStack.getItemMeta(); for (Element effect : element.getChildren("effect")) { PotionEffect potionEffect = getPotion(effect); if (!((PotionMeta) meta).getCustomEffects().contains(potionEffect)) { ((PotionMeta) meta).addCustomEffect(potionEffect, true); } } for (Element attribute : element.getChildren("attribute")) { ItemAttributeModifier itemAttribute = getAttribute(attribute); if (!meta.getModifiedAttributes().contains(attribute.getText())) { meta.addAttributeModifier(attribute.getText(), itemAttribute); } } /* TODO: can-destroy & can-place-on, and all attributes * @link https://docs.oc.tc/modules/item_mods#itemmeta */ itemStack.setItemMeta(meta); return itemStack; }
private static List<ItemAttributeModifier> parseAttributes(String attributes) { List<ItemAttributeModifier> list = Lists.newArrayList(); for (String attribute : attributes.split(";")) { String[] attr = attribute.split(":"); list.add(new ItemAttributeModifier(null, new AttributeModifier(UUID.randomUUID(), attr[0], Numbers.parseDouble(attr[2]), getOperation(attr[1])))); } return list; }
private static List<ItemAttributeModifier> parseAttributes(String attributes) { List<ItemAttributeModifier> list = new ArrayList<>(); for (String attribute : attributes.split(";")) { String[] attr = attribute.split(":"); list.add(new ItemAttributeModifier(null, new AttributeModifier(UUID.randomUUID(), attr[0], Double.parseDouble(attr[2]), getOperation(attr[1])))); } return list; }
private static ItemAttributeModifier getAttribute(Element attribute) { return new ItemAttributeModifier(getEquipmentSlot(attribute.getAttributeValue("slot", "")), new AttributeModifier(UUID.randomUUID(), attribute.getText(), Double.parseDouble(attribute.getAttributeValue("amount", "0.0")), getOperation(attribute.getAttributeValue("operation", "add")))); }
public static ItemAttributeModifier getAttribute(Element attribute) { return new ItemAttributeModifier(getEquipmentSlot(attribute.getAttributeValue("slot", "")), new AttributeModifier(UUID.randomUUID(), attribute.getText(), Double.parseDouble(attribute.getAttributeValue("amount", "0.0")), getOperation(attribute.getAttributeValue("operation", "add")))); }