SHARE
TWEET

Untitled

a guest Jan 24th, 2020 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.  
  3. import org.bukkit.Color;
  4. import org.bukkit.DyeColor;
  5. import org.bukkit.Material;
  6. import org.bukkit.enchantments.Enchantment;
  7. import org.bukkit.inventory.ItemFlag;
  8. import org.bukkit.inventory.ItemStack;
  9. import org.bukkit.inventory.meta.ItemMeta;
  10. import org.bukkit.inventory.meta.LeatherArmorMeta;
  11. import org.bukkit.inventory.meta.SkullMeta;
  12.  
  13. import java.util.Arrays;
  14.  
  15. public class ItemBuilder {
  16.     private ItemStack is;
  17.  
  18.     public ItemBuilder(Material m) {
  19.         this(m, 1);
  20.     }
  21.  
  22.     public ItemBuilder(ItemStack is) {
  23.         this.is = is;
  24.     }
  25.  
  26.     public ItemBuilder(Material m, int amount) {
  27.         is = new ItemStack(m, amount);
  28.     }
  29.  
  30.     public ItemBuilder(Material m, int amount, short meta){
  31.         is = new ItemStack(m, amount, meta);
  32.     }
  33.  
  34.     public ItemBuilder clone() {
  35.         return new ItemBuilder(is);
  36.     }
  37.  
  38.     public ItemBuilder setDurability(short dur) {
  39.         is.setDurability(dur);
  40.         return this;
  41.     }
  42.  
  43.     public ItemBuilder setName(String name) {
  44.         ItemMeta im = is.getItemMeta();
  45.         im.setDisplayName(name);
  46.         is.setItemMeta(im);
  47.         return this;
  48.     }
  49.  
  50.     public ItemBuilder addUnsafeEnchantment(Enchantment ench, int level) {
  51.         is.addUnsafeEnchantment(ench, level);
  52.         return this;
  53.     }
  54.  
  55.     public ItemBuilder removeEnchantment(Enchantment ench) {
  56.         is.removeEnchantment(ench);
  57.         return this;
  58.     }
  59.  
  60.     public ItemBuilder setSkullOwner(String owner) {
  61.         try {
  62.             SkullMeta im = (SkullMeta) is.getItemMeta();
  63.             im.setOwner(owner);
  64.             is.setItemMeta(im);
  65.         } catch (ClassCastException expected) {
  66.         }
  67.         return this;
  68.     }
  69.  
  70.     public ItemBuilder addEnchant(Enchantment ench, int level) {
  71.         ItemMeta im = is.getItemMeta();
  72.         im.addEnchant(ench, level, true);
  73.         is.setItemMeta(im);
  74.         return this;
  75.     }
  76.  
  77.     public ItemBuilder setInfinityDurability() {
  78.         is.setDurability(Short.MAX_VALUE);
  79.         return this;
  80.     }
  81.  
  82.     public ItemBuilder setLore(String... lore) {
  83.         ItemMeta im = is.getItemMeta();
  84.         im.setLore(Arrays.asList(lore));
  85.         is.setItemMeta(im);
  86.         return this;
  87.     }
  88.  
  89.     @SuppressWarnings("deprecation")
  90.     public ItemBuilder setWoolColor(DyeColor color) {
  91.         if (!is.getType().equals(Material.WOOL))
  92.             return this;
  93.         this.is.setDurability(color.getData());
  94.         return this;
  95.     }
  96.  
  97.     public ItemBuilder setLeatherArmorColor(Color color) {
  98.         try {
  99.             LeatherArmorMeta im = (LeatherArmorMeta) is.getItemMeta();
  100.             im.setColor(color);
  101.             is.setItemMeta(im);
  102.         } catch (ClassCastException expected) {
  103.         }
  104.         return this;
  105.     }
  106.  
  107.     public ItemStack toItemStack() {
  108.         return is;
  109.     }
  110. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top