コード例 #1
0
  public ItemStack getOutcome(boolean isFixedDrops) {
    if (Math.random() * 100.0D < percentage && material != null) {
      int dropAmount =
          isFixedDrops
              ? range.getMaximumInteger()
              : range.getMinimumInteger()
                  + random.nextInt(
                      Math.abs(range.getMaximumInteger() - range.getMinimumInteger() + 1));

      if (dropAmount > 0) {
        ItemStack itemStack;
        if (data == null) {
          itemStack = new ItemStack(material, dropAmount);
        } else {
          MaterialData materialData = new MaterialData(material, data);
          itemStack = materialData.toItemStack(dropAmount);
          if (durability != null) {
            itemStack.setDurability(durability);
          }
        }
        itemStack.addEnchantments(ItemEnchantment.getOutcome(enchantments));
        if (itemStack.getAmount() > 0) {
          return itemStack;
        }
      }
    }
    return null;
  }
コード例 #2
0
 /**
  * Enchant.
  *
  * @param item the item
  * @param enchants the enchants
  */
 public void enchant(ItemStack item, Map<Enchantment, Integer> enchants) {
   if (item == null) {
     return;
   }
   for (Enchantment ench : item.getEnchantments().keySet()) {
     item.removeEnchantment(ench);
   }
   item.addEnchantments(enchants);
 }
コード例 #3
0
 public static ItemStack loadItemStack(final ConfigurationSection config) {
   final ItemStack item =
       new MaterialData(config.getInt("id"), (byte) config.getInt("data"))
           .toItemStack(config.getInt("amount", 1));
   if (config.contains("durability")) item.setDurability((short) config.getInt("durability"));
   if (config.contains("enchantments"))
     item.addEnchantments(loadEnchantments(config.getConfigurationSection("enchantments")));
   return item;
 }
コード例 #4
0
ファイル: RPGItem.java プロジェクト: OsipXD/RPG-Items
 public static void updateItem(
     ItemStack item, String locale, RPGMetadata rpgMeta, boolean updateDurability) {
   RPGItem rItem = ItemManager.toRPGItem(item);
   if (rItem == null) return;
   item.setType(rItem.item.getType());
   ItemMeta meta = rItem.getLocaleMeta(locale);
   if (!(meta instanceof LeatherArmorMeta) && updateDurability) {
     item.setDurability(rItem.item.getDurability());
   }
   List<String> lore = meta.getLore();
   rItem.addExtra(rpgMeta, item, lore);
   lore.set(0, meta.getLore().get(0) + rpgMeta.toMCString());
   meta.setLore(lore);
   Map<Enchantment, Integer> enchantments = null;
   if (enchantmentSupport) enchantments = item.getEnchantments();
   item.setItemMeta(meta);
   if (enchantmentSupport) item.addEnchantments(enchantments);
 }