Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package de.max.lobby.utils;
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.List;
- import org.bukkit.Color;
- import org.bukkit.Material;
- import org.bukkit.SkullType;
- import org.bukkit.enchantments.Enchantment;
- import org.bukkit.inventory.ItemFlag;
- import org.bukkit.inventory.ItemStack;
- import org.bukkit.inventory.meta.ItemMeta;
- import org.bukkit.inventory.meta.LeatherArmorMeta;
- import org.bukkit.inventory.meta.SkullMeta;
- public class ItemsBuilder {
- private ItemStack stack;
- public ItemsBuilder(Material material) {
- this.stack = new ItemStack(material);
- }
- public ItemsBuilder(Material material, int data) {
- this.stack = new ItemStack(material, 1, (short) data);
- }
- public ItemsBuilder setAmount(int amount) {
- this.stack.setAmount(amount);
- return this;
- }
- public ItemsBuilder setDisplayname(String name) {
- ItemMeta meta = this.stack.getItemMeta();
- meta.setDisplayName(name);
- this.stack.setItemMeta(meta);
- return this;
- }
- public ItemsBuilder setUnbreakable(boolean unbreakable) {
- ItemMeta meta = this.stack.getItemMeta();
- meta.spigot().setUnbreakable(unbreakable);
- return this;
- }
- public ItemsBuilder setLore(List<String> list) {
- ItemMeta meta = this.stack.getItemMeta();
- meta.setLore(list);
- this.stack.setItemMeta(meta);
- return this;
- }
- public ItemsBuilder addLore(String lore) {
- ItemMeta meta = this.stack.getItemMeta();
- if (!meta.hasLore()) {
- List<String> newLore = new ArrayList<>();
- newLore.add(lore);
- meta.setLore(newLore);
- } else {
- List<String> itemLore = meta.getLore();
- itemLore.add(lore);
- meta.setLore(itemLore);
- }
- this.stack.setItemMeta(meta);
- return this;
- }
- public ItemsBuilder addEnchantment(Enchantment enchantment, int level) {
- this.stack.addEnchantment(enchantment, level);
- return this;
- }
- public ItemsBuilder addUnsafeEnchantment(Enchantment enchantment, int level) {
- this.stack.addUnsafeEnchantment(enchantment, level);
- return this;
- }
- public ItemsBuilder setColor(Color color) {
- LeatherArmorMeta meta = (LeatherArmorMeta) this.stack.getItemMeta();
- meta.setColor(color);
- this.stack.setItemMeta(meta);
- return this;
- }
- public ItemsBuilder hideEnchantment() {
- ItemMeta meta = this.stack.getItemMeta();
- meta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
- this.stack.setItemMeta(meta);
- return this;
- }
- public ItemsBuilder hideAttributes() {
- ItemMeta meta = this.stack.getItemMeta();
- meta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
- this.stack.setItemMeta(meta);
- return this;
- }
- public ItemsBuilder hidePlaceOn() {
- ItemMeta meta = this.stack.getItemMeta();
- meta.addItemFlags(ItemFlag.HIDE_PLACED_ON);
- this.stack.setItemMeta(meta);
- return this;
- }
- public ItemsBuilder setGlowing() {
- ItemMeta meta = this.stack.getItemMeta();
- meta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
- meta.addEnchant(Enchantment.DURABILITY, 1, false);
- this.stack.setItemMeta(meta);
- return this;
- }
- public static ItemStack SkullBuilder(String name, String owner) {
- ItemStack skull = new ItemStack(Material.SKULL_ITEM, 1, (short) SkullType.PLAYER.ordinal());
- SkullMeta meta = (SkullMeta) skull.getItemMeta();
- meta.setDisplayName(name);
- meta.setOwner(owner);
- skull.setItemMeta(meta);
- return skull;
- }
- public static ItemStack SkullBuilder(String name, String owner, String... lore) {
- ItemStack skull = new ItemStack(Material.SKULL_ITEM, 1, (short) SkullType.PLAYER.ordinal());
- SkullMeta meta = (SkullMeta) skull.getItemMeta();
- meta.setDisplayName(name);
- meta.setOwner(owner);
- if (lore != null) {
- meta.setLore(Arrays.asList(lore));
- }
- skull.setItemMeta(meta);
- return skull;
- }
- public ItemStack PotionBuilder(String name, int amount, int potionid) {
- ItemStack stack = new ItemStack(Material.POTION, amount, (short) potionid);
- ItemMeta meta = stack.getItemMeta();
- meta.setDisplayName(name);
- stack.setItemMeta(meta);
- return stack;
- }
- public ItemStack PotionBuilder(String name, int amount, int potionid, String... lore) {
- ItemStack stack = new ItemStack(Material.POTION, amount, (short) potionid);
- ItemMeta meta = stack.getItemMeta();
- meta.setDisplayName(name);
- if (lore != null) {
- meta.setLore(Arrays.asList(lore));
- }
- stack.setItemMeta(meta);
- return stack;
- }
- public ItemStack create() {
- return this.stack;
- }
- public ItemMeta getMeta() {
- return this.stack.getItemMeta();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement