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

The following examples show how to use org.bukkit.inventory.meta.ItemMeta#setCustomModelData() . 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: ExprCustomModelData.java    From Skript with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void change(Event e, @Nullable Object[] delta, Changer.ChangeMode mode) {
	long data = delta == null ? 0 : ((Number) delta[0]).intValue();
	if (data > 99999999 || data < 0) data = 0;
	for (ItemType item : getExpr().getArray(e)) {
		long oldData = 0;
		ItemMeta meta = item.getItemMeta();
		if (meta.hasCustomModelData())
			oldData = meta.getCustomModelData();
		switch (mode) {
			case ADD:
				data = oldData + data;
				break;
			case REMOVE:
				data = oldData - data;
				break;
			case DELETE:
			case RESET:
			case REMOVE_ALL:
				data = 0;
		}
		meta.setCustomModelData((int) data);
		item.setItemMeta(meta);
	}
}
 
Example 2
Source File: Modifier.java    From MineTinker with GNU General Public License v3.0 5 votes vote down vote up
/**
 * changes the core settings of the Modifier (like a secondary constructor)
 */
protected void init(Material m) {
	FileConfiguration config = getConfig();

	try {
		this.color = ChatWriter.getColor(config.getString("Color", "%WHITE%"));
	} catch (IllegalArgumentException | ArrayIndexOutOfBoundsException ignored) {
		this.color = ChatColor.WHITE;
		ChatWriter.logError("Illegal Color detected for Modifier " + this.getKey());
	}

	this.maxLvl = config.getInt("MaxLevel");
	this.slotCost = config.getInt("SlotCost", 1);

	if (source.equals(MineTinker.getPlugin())) { //normal Languagesystem-Integration
		String langStart = "Modifier." + getKey();

		this.name = LanguageManager.getString(langStart + ".Name");
		this.description = LanguageManager.getString(langStart + ".Description");

		this.modItem = modManager.createModifierItem(m, this.color + LanguageManager.getString(langStart + ".ModifierItemName"),
				ChatColor.WHITE + LanguageManager.getString(langStart + ".DescriptionModifierItem"), this);
	} else { //use the config values instead
		this.name = config.getString("Name", "");
		this.description = ChatWriter.addColors(config.getString("Description", ""));

		this.modItem = modManager.createModifierItem(m, this.color + config.getString("ModifierItemName", ""),
				ChatWriter.addColors(config.getString("DescriptionModifierItem", "")), this);
	}

	ItemMeta itemMeta = this.modItem.getItemMeta();
	if (itemMeta != null) itemMeta.setCustomModelData(this.customModelData);
	this.modItem.setItemMeta(itemMeta);
	if (ConfigurationManager.getConfig("Modifiers.yml").getBoolean("UseCustomModelData", false)) {
		this.modItem.setType(Material.STICK);
	}
}
 
Example 3
Source File: QualityArmory.java    From QualityArmory with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
public static boolean isCustomItem(ItemStack is, int dataOffset) {
	if (is == null)
		return false;
	ItemStack itemstack = is.clone();
	if(dataOffset!=0) {
		try {
			ItemMeta im = itemstack.getItemMeta();
			int modeldata = 0;
			if(im.hasCustomModelData()) {
				modeldata = im.getCustomModelData();
			}else if (modeldata+dataOffset >0){
				return false;
			}
			im.setCustomModelData(modeldata + dataOffset);
			itemstack.setItemMeta(im);
		} catch (Error | Exception ed4) {
			itemstack.setDurability((short) (is.getDurability() + dataOffset));
		}
	}
	if(isIronSights(itemstack))
		return true;
	if(isGun(itemstack))
		return true;
	if(isAmmo(itemstack))
		return true;
	if(isMisc(itemstack))
		return true;
	if(isArmor(itemstack))
		return true;
	if(QAMain.expansionPacks.contains(MaterialStorage.getMS(is)))
		return true;
	return false;
}
 
Example 4
Source File: CustomTextureService.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
public void setTexture(ItemMeta im, String id) {
    int data = getModelData(id);

    if (SlimefunPlugin.getMinecraftVersion().isAtLeast(MinecraftVersion.MINECRAFT_1_14)) {
        im.setCustomModelData(data == 0 ? null : data);
    }
}
 
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());
	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 6
Source File: ItemUtils1_14.java    From TradePlus with GNU General Public License v3.0 4 votes vote down vote up
public static void applyCustomModelData(ItemMeta meta, int customModelData) {
  meta.setCustomModelData(customModelData);
}