Java Code Examples for org.bukkit.inventory.meta.ItemMeta#setUnbreakable()

The following examples show how to use org.bukkit.inventory.meta.ItemMeta#setUnbreakable() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Reinforced.java    From MineTinker with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean applyMod(Player player, ItemStack tool, boolean isCommand) {
	ItemMeta meta = tool.getItemMeta();

	if (meta != null) {
		meta.addEnchant(Enchantment.DURABILITY, modManager.getModLevel(tool, this), true);

		if (modManager.getModLevel(tool, this) == this.getMaxLvl() && this.applyUnbreakableOnMaxLevel) {
			meta.setUnbreakable(true);
			if (hideUnbreakableFlag) {
				meta.addItemFlags(ItemFlag.HIDE_UNBREAKABLE);
			}
		}

		tool.setItemMeta(meta);
	}

	return true;
}
 
Example 2
Source File: Reinforced.java    From MineTinker with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void removeMod(ItemStack tool) {
	ItemMeta meta = tool.getItemMeta();

	if (meta != null) {
		meta.removeEnchant(Enchantment.DURABILITY);
		if (this.applyUnbreakableOnMaxLevel) {
			meta.setUnbreakable(false);
			meta.removeItemFlags(ItemFlag.HIDE_UNBREAKABLE);
		}

		tool.setItemMeta(meta);
	}
}
 
Example 3
Source File: ItemService.java    From Transport-Pipes with MIT License 5 votes vote down vote up
public ItemStack createModelledItem(int damage) {
    ItemStack woodenPickage = new ItemStack(Material.WOODEN_PICKAXE);
    ItemMeta meta = woodenPickage.getItemMeta();

    ((Damageable) meta).setDamage(damage);
    meta.setUnbreakable(true);
    woodenPickage.setItemMeta(meta);

    return woodenPickage;
}
 
Example 4
Source File: ItemDisguise.java    From iDisguise with Creative Commons Attribution Share Alike 4.0 International 5 votes vote down vote up
/**
 * @since 5.8.1
 */
public void setUnbreakable(boolean unbreakable) {
	if(!VersionHelper.require1_11()) return;
	ItemMeta meta = itemStack.getItemMeta();
	meta.setUnbreakable(unbreakable);
	itemStack.setItemMeta(meta);
}
 
Example 5
Source File: CustomGunItem.java    From QualityArmory with GNU General Public License v3.0 4 votes vote down vote up
@Override
	public ItemStack getItem(MaterialStorage ms) {
	CustomBaseObject base = QualityArmory.getCustomItem(ms);
	if(base==null)
		return null;
	String displayname = base.getDisplayName();
	if (ms == null || ms.getMat() == null)
		return new ItemStack(Material.AIR);

	ItemStack is = new ItemStack(ms.getMat(),1,(short)ms.getData());
	if (ms.getData() < 0)
		is.setDurability((short) 0);
	ItemMeta im = is.getItemMeta();
	if (im == null)
		im = Bukkit.getServer().getItemFactory().getItemMeta(ms.getMat());
	if (im != null) {
		im.setDisplayName(displayname);
		List<String> lore = base.getCustomLore()!=null?new ArrayList<>(base.getCustomLore()):new ArrayList<>();

		if(base instanceof Gun)
			lore.addAll(Gun.getGunLore((Gun) base, null, ((Gun) base).getMaxBullets()));
		if(base instanceof AttachmentBase)
			lore.addAll(Gun.getGunLore(((AttachmentBase) base).getBaseGun(), null, ((AttachmentBase) base).getMaxBullets()));
		if (base instanceof ArmorObject)
			lore.addAll(OLD_ItemFact.getArmorLore((ArmorObject) base));

		OLD_ItemFact.addVariantData(im,lore,base);

		im.setLore(lore);
		if (QAMain.ITEM_enableUnbreakable) {
			try {
				im.setUnbreakable(true);
			} catch (Error | Exception e34) {
				/*try {
					im.spigot().setUnbreakable(true);
				} catch (Error | Exception e344) {
				}*/
				//TODO: Readd Unbreakable support for 1.9
			}
		}
		try {
			if (QAMain.ITEM_enableUnbreakable) {
				im.addItemFlags(org.bukkit.inventory.ItemFlag.HIDE_UNBREAKABLE);
			}
			im.addItemFlags(org.bukkit.inventory.ItemFlag.HIDE_ATTRIBUTES);
			im.addItemFlags(org.bukkit.inventory.ItemFlag.HIDE_DESTROYS);
		} catch (Error e) {

		}

		if (ms.getVariant() != 0) {
			OLD_ItemFact.addVariantData(im, im.getLore(), ms.getVariant());
		}
		is.setItemMeta(im);
	} else {
		// Item meta is still null. Catch and report.
		QAMain.getInstance().getLogger()
				.warning(QAMain.prefix + " ItemMeta is null for " + base.getName() + ". I have");
	}
	is.setAmount(1);
	return is;
}
 
Example 6
Source File: CustomGunItem.java    From QualityArmory with GNU General Public License v3.0 4 votes vote down vote up
@Override
public ItemStack getItem(MaterialStorage ms) {
	CustomBaseObject base = QualityArmory.getCustomItem(ms);
	if(base==null)
		return null;
	String displayname = base.getDisplayName();
	if (ms == null || ms.getMat() == null)
		return new ItemStack(Material.AIR);

	ItemStack is = new ItemStack(ms.getMat());
	if (ms.getData() < 0)
		is.setDurability((short) 0);


	ItemMeta im = is.getItemMeta();
	if (im == null)
		im = Bukkit.getServer().getItemFactory().getItemMeta(ms.getMat());
	if (im != null) {
		im.setDisplayName(displayname);
		List<String> lore = base.getCustomLore()!=null?new ArrayList<>(base.getCustomLore()):new ArrayList<>();

		if (base instanceof Ammo) {
			boolean setSkull = false;
			if (((Ammo) base).isSkull() && ((Ammo) base).hasCustomSkin()) {
				setSkull = true;
				is = SkullHandler.getCustomSkull64(((Ammo) base).getCustomSkin().getBytes());
			}
			if (((Ammo) base).isSkull() && !setSkull) {
				((SkullMeta) im).setOwner(((Ammo) base).getSkullOwner());
			}
		}


		if(base instanceof Gun)
			lore.addAll(Gun.getGunLore((Gun) base, null, ((Gun) base).getMaxBullets()));
		if (base instanceof ArmorObject)
			lore.addAll(OLD_ItemFact.getArmorLore((ArmorObject) base));

		im.setLore(lore);
		if (QAMain.ITEM_enableUnbreakable) {
			try {
				im.setUnbreakable(true);
			} catch (Error | Exception e34) {
			}
		}
		try {
			if (QAMain.ITEM_enableUnbreakable) {
				im.addItemFlags(org.bukkit.inventory.ItemFlag.HIDE_UNBREAKABLE);
			}
			im.addItemFlags(org.bukkit.inventory.ItemFlag.HIDE_ATTRIBUTES);
			im.addItemFlags(org.bukkit.inventory.ItemFlag.HIDE_DESTROYS);
		} catch (Error e) {

		}
		if (ms.getData() >= 0)
			im.setCustomModelData(ms.getData());

		if (is.getType() == Material.CROSSBOW) {
			//Now the player will hold the crossbow like a gun
		//	CrossbowMeta im2 = (CrossbowMeta) im;
		//	im2.addChargedProjectile(new ItemStack(Material.VOID_AIR));
		}
		is.setItemMeta(im);
	} else {
		QAMain.getInstance().getLogger()
				.warning(QAMain.prefix + " ItemMeta is null for " + base.getName() + ". I have");
	}
	is.setAmount(1);
	return is;
}
 
Example 7
Source File: CustomGunItem.java    From QualityArmory with GNU General Public License v3.0 4 votes vote down vote up
@Override
public ItemStack getItem(MaterialStorage ms) {
	CustomBaseObject base = QualityArmory.getCustomItem(ms);
	if(base==null)
		return null;
	String displayname = base.getDisplayName();
	if (ms == null || ms.getMat() == null)
		return new ItemStack(Material.AIR);

	ItemStack is = new ItemStack(ms.getMat(),1,(short)ms.getData());
	if (ms.getData() < 0)
		is.setDurability((short) 0);
	ItemMeta im = is.getItemMeta();
	if (im == null)
		im = Bukkit.getServer().getItemFactory().getItemMeta(ms.getMat());
	if (im != null) {
		im.setDisplayName(displayname);
		List<String> lore = base.getCustomLore()!=null?new ArrayList<>(base.getCustomLore()):new ArrayList<>();

		if(base instanceof Gun)
			lore.addAll(Gun.getGunLore((Gun) base, null, ((Gun) base).getMaxBullets()));
		if (base instanceof ArmorObject)
			lore.addAll(OLD_ItemFact.getArmorLore((ArmorObject) base));

		OLD_ItemFact.addVariantData(im,lore,base);
		im.setLore(lore);
		if (QAMain.ITEM_enableUnbreakable) {
			try {
				im.setUnbreakable(true);
			} catch (Error | Exception e34) {
			}
		}
		try {
			if (QAMain.ITEM_enableUnbreakable) {
				im.addItemFlags(org.bukkit.inventory.ItemFlag.HIDE_UNBREAKABLE);
			}
			im.addItemFlags(org.bukkit.inventory.ItemFlag.HIDE_ATTRIBUTES);
			im.addItemFlags(org.bukkit.inventory.ItemFlag.HIDE_DESTROYS);
		} catch (Error e) {

		}
		if(ms.getVariant()!=0) {
			OLD_ItemFact.addVariantData(im, im.getLore(), ms.getVariant());
		}
		is.setItemMeta(im);
	} else {
		// Item meta is still null. Catch and report.
		QAMain.getInstance().getLogger()
				.warning(QAMain.prefix + " ItemMeta is null for " + base.getName() + ". I have");
	}
	is.setAmount(1);
	return is;

}
 
Example 8
Source File: VersionUtils_1_13.java    From UhcCore with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void setItemUnbreakable(ItemMeta meta, boolean b){
    meta.setUnbreakable(b);
}
 
Example 9
Source File: VersionUtils_1_12.java    From UhcCore with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void setItemUnbreakable(ItemMeta meta, boolean b){
    meta.setUnbreakable(b);
}
 
Example 10
Source File: CustomItemStack.java    From AdditionsAPI with MIT License 4 votes vote down vote up
@SuppressWarnings("deprecation")
private static ItemStack getItemStack(CustomItem cItem, short durability) {
	if (AdditionsAPI.getAllCustomItemStacks() != null)
		for (CustomItemStack cStack : AdditionsAPI.getAllCustomItemStacks())
			if (cStack.getCustomItem().getIdName().equalsIgnoreCase(cItem.getIdName()))
				return cStack.getItemStack();
	// Material, amount and durability
	ItemStack item = NbtFactory
			.getCraftItemStack(new ItemStack(cItem.getMaterial(), cItem.getAmount(), durability));

	// Store data in the nbt data of the ItemStack about the CustomItem's ID
	NbtCompound nbt = NbtFactory.fromItemTag(item);
	nbt.put("CustomItem.IdName", cItem.getIdName());

	ItemMeta meta = item.getItemMeta();

	// Unbreakable
	meta.setUnbreakable(cItem.isUnbreakable());

	// Display Name
	meta.setDisplayName(cItem.getDisplayName());

	// Enchantments
	for (Enchantment e : cItem.getEnchantmnets().keySet())
		meta.addEnchant(e, cItem.getEnchantmnets().get(e), true);

	// Lore
	meta.setLore(cItem.getFullLore(cItem.getEnchantmnets(), cItem.getFakeDurability(), null));

	// ItemFlags
	for (ItemFlag flag : cItem.getItemFlags())
		meta.addItemFlags(flag);

	// Set the lore and return the item
	item.setItemMeta(meta);

	// Add Attributes
	for (Attributes.Attribute attribute : cItem.getAttributes()) {
		Attributes attributes = new Attributes(item);
		attributes.add(attribute);
		item = attributes.getStack();
	}

	// Leather Armor stuff
	if (cItem instanceof CustomLeatherArmor) {
		LeatherArmorMeta leatherMeta = (LeatherArmorMeta) item.getItemMeta();

		leatherMeta.setColor(((CustomLeatherArmor) cItem).getColor());

		item.setItemMeta(leatherMeta);
	}
	return item;
}