/** * Applies the effects of this potion to the given {@link ItemStack}. The * ItemStack must be a potion. * * @param to The itemstack to apply to */ public void apply(ItemStack to) { Validate.notNull(to, "itemstack cannot be null"); Validate.isTrue(to.getType() == Material.POTION, "given itemstack is not a potion"); to.setDurability(toDamageValue()); }
/** * Get a list of all recipes for a given item. The stack size is ignored in comparisons. * If the durability is -1, it will match any data value. * * @param result The item whose recipes you want * @return The list of recipes */ public List<Recipe> getRecipesFor(ItemStack result) { // handling for old-style wildcards if (result.getDurability() == -1) { result = result.clone(); result.setDurability(Short.MAX_VALUE); } List<Recipe> recipes = new LinkedList<>(); for (Recipe recipe : this) { if (matchesWildcard(result, recipe.getResult())) { recipes.add(recipe); } } return recipes; }
@Override public Collection<ItemStack> getDrops(GlowBlock block, ItemStack tool) { GlowBanner state = (GlowBanner) block.getState(); ItemStack drop = new ItemStack(Material.BANNER, 1); BannerMeta meta = (BannerMeta) drop.getItemMeta(); meta.setPatterns(state.getPatterns()); drop.setItemMeta(meta); drop.setDurability(state.getBaseColor().getDyeData()); return Arrays.asList(drop); }
@Override public Collection<ItemStack> getDrops(GlowBlock block, ItemStack tool) { GlowSkull skull = (GlowSkull) block.getState(); ItemStack drop = new ItemStack(Material.SKULL_ITEM, 1); if (skull.hasOwner()) { SkullMeta meta = (SkullMeta) drop.getItemMeta(); meta.setOwner(skull.getOwner()); drop.setItemMeta(meta); } drop.setDurability((short) skull.getSkullType().ordinal()); return Arrays.asList(drop); } }
/** * Inflicts damage to an item. Unbreaking enchantment is applied if present. * * @param player the player holding the item, or null if held by a dispenser * @param holding the item * * @return the updated item stack */ public static ItemStack damageItem(GlowPlayer player, ItemStack holding) { if (player != null && player.getGameMode() == GameMode.CREATIVE) { return holding; } // Apply unbreaking enchantment. // TODO: Armor has a different formula for chance to avoid damage int durability = holding.getEnchantmentLevel(Enchantment.DURABILITY); if (durability > 0 && ThreadLocalRandom.current().nextDouble() < 1 / (durability + 1)) { return holding; } holding.setDurability((short) (holding.getDurability() + 1)); if (holding.getDurability() == holding.getType().getMaxDurability() + 1) { if (player != null) { EventFactory.getInstance() .callEvent(new PlayerItemBreakEvent(player, holding)); } return createEmptyStack(); } return holding; }
hand.setDurability((short) (hand.getDurability() + 1)); player.getInventory().setItem(message.getHandSlot(), hand); } else {
&& player.getGameMode() != GameMode.CREATIVE) { itemInHand.setDurability((short) (itemInHand.getDurability() + durabilityLoss));
&& holding.getDurability() > holding.getType().getMaxDurability()) { holding.setAmount(holding.getAmount() - 1); holding.setDurability((short) 0);
public IconMaker setDurability(short d) { this.item.setDurability(d); return this; }
public ItemBuilder damage(int damage) { itemStack.setDurability((short) damage); return this; }
protected void displayItem(Particle particle, Location center, float offsetX, float offsetY, float offsetZ, float speed, int amount, Material material, byte materialData, double range, List<Player> targetPlayers) { if (material == null || material == Material.AIR) { return; } ItemStack item = new ItemStack(material); item.setDurability(materialData); display(particle, center, offsetX, offsetY, offsetZ, speed, amount, item, range, targetPlayers); }
public static void setMapId(ItemStack mapItem, int id) { if (isCurrentVersion()) { setMetaInt(mapItem, "map", id); } else { mapItem.setDurability((short)id); } } }
@Override public LuaValue call(LuaValue value) { item.setDurability(value.checknumber().toshort()); return NIL; } });
/** * Applies the effects of this potion to the given {@link ItemStack}. The * ItemStack must be a potion. * * @param to The itemstack to apply to */ public void apply(ItemStack to) { Validate.notNull(to, "itemstack cannot be null"); Validate.isTrue(to.getType() == Material.POTION, "given itemstack is not a potion"); to.setDurability(toDamageValue()); }
protected void updateDurability() { int maxDurability = item.getType().getMaxDurability(); if (maxDurability > 0 && effectiveManaMax > 0) { int durability = (short)(getMana() * maxDurability / effectiveManaMax); durability = maxDurability - durability; if (durability >= maxDurability) { durability = maxDurability - 1; } else if (durability < 0) { durability = 0; } item.setDurability((short)durability); } }
public IconMaker setOwner(String username) { if (this.item != null && this.item.getType() == Material.SKULL_ITEM) { this.item.setDurability((short) 3); // 3: Player SkullMeta sm = (SkullMeta) item.getItemMeta(); sm.setOwner(username); item.setItemMeta(sm); } return this; } }
@EventHandler public void onBreak(BlockBreakEvent event) { Player p = event.getPlayer(); if (!p.equals(player)) return; ItemStack tool = p.getInventory().getItemInMainHand(); if (!isTool(tool)) return; event.setCancelled(true); tool.setDurability((short) 0); }
public static ItemStack addDurability(ItemStack i, int d) { i.setDurability((short) (i.getDurability() + d)); int min = i.getDurability(); int max = i.getType().getMaxDurability(); if (min >= max) { i.setType(Material.AIR); } return i; }
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public void onBlockBreak(BlockBreakEvent event) { Player player = event.getPlayer(); WorldConfiguration wcfg = getWorldConfig(player); if (!wcfg.itemDurability) { ItemStack held = player.getItemInHand(); if (held.getType() != Material.AIR) { held.setDurability((short) 0); player.setItemInHand(held); } } }
/** * Transfers the item type, data and enchantments from one item stack to the other * * @param from which Item Stack to read the info * @param to which Item Stack to transfer the info to */ @SuppressWarnings("deprecation") public static void transferInfo(org.bukkit.inventory.ItemStack from, org.bukkit.inventory.ItemStack to) { // Transfer type, durability and any other remaining metadata information to.setTypeId(from.getTypeId()); to.setDurability(from.getDurability()); setMetaTag(to, LogicUtil.clone(getMetaTag(from))); }