ItemStack item = new Item(Material).setDisplayName("Name").build());
package de.flowcode.serversystem.util;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.SkullMeta;
import java.util.Arrays;
import java.util.List;
public class Item {
private ItemStack itemStack;
private ItemMeta itemMeta;
public Item(ItemStack itemStack) {
this.itemStack = itemStack;
this.itemMeta = itemStack.getItemMeta();
}
public Item(Material material) {
this.itemStack = new ItemStack(material);
this.itemMeta = itemStack.getItemMeta();
}
public Item(Material material, int id) {
this.itemStack = new ItemStack(material, 1, (short) id);
this.itemMeta = itemStack.getItemMeta();
}
public Item setDisplayName(String name) {
itemMeta.setDisplayName(ChatColor.translateAlternateColorCodes('&', name));
return this;
}
@SuppressWarnings("deprecation")
public Item setMetaID(byte metaID) {
itemStack.getData().setData(metaID);
return this;
}
public Item setOwner(String name) {
SkullMeta m = (SkullMeta) itemMeta;
m.setOwner(name);
itemStack.setItemMeta(m);
return this;
}
public Item setAmount(int amount) {
this.itemStack.setAmount(amount);
return this;
}
public Item setDurability(short durability) {
this.itemStack.setDurability(durability);
return this;
}
public Item addEnchantment(Enchantment enchantment, int lvl) {
this.itemMeta.addEnchant(enchantment, lvl, false);
return this;
}
public Item clearEnchantments() {
this.itemMeta.getEnchants().forEach((enchantment, integer) -> this.itemMeta.removeEnchant(enchantment));
return this;
}
public Item removeEnchantment(Enchantment enchantment) {
if (this.itemMeta.getEnchants().containsKey(enchantment))
this.itemMeta.removeEnchant(enchantment);
return this;
}
public Item setLore(List<String> lines) {
this.itemMeta.setLore(lines);
return this;
}
public Item setLore(String... lines) {
this.itemMeta.setLore(Arrays.asList(lines));
return this;
}
public Item resetLore() {
this.itemMeta.getLore().clear();
return this;
}
public ItemStack build() {
itemStack.setItemMeta(itemMeta);
return itemStack;
}
}Similar projects
Plugin →Let Me Despawn
Improves performance by tweaking mob despawn rules. Say bye to pesky unintentional persistent mobs.
25MSueta
JourneyMap
Real-time map used for mapping in-game or your browser as you explore.
14.7MSueta
Emotecraft
Create your own emotes in Minecraft.
7.5MSueta
Simple Tpa
A simple tpa plugin which sends requests
5.4MSueta
Common Network
Forge and Fabric Unified Networking Solution
3.9MSueta
Set Home
A lightweight plugin for players to set their homes.
3.8MSueta