Java 类org.bukkit.attribute.ItemAttributeModifier 实例源码

项目:ProjectAres    文件:XMLUtils.java   
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
        )
    );
}
项目:Cardinal    文件:DocumentItems.java   
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;
}
项目:Cardinal    文件:DocumentItems.java   
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;
}
项目:CardinalPGM    文件:Parser.java   
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;
}
项目:Cardinal    文件:DocumentItems.java   
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"))));
}
项目:CardinalPGM    文件:Parser.java   
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"))));
}