Advertisement
Guest User

Untitled

a guest
Mar 17th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.47 KB | None | 0 0
  1. package de.max.lobby.utils;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.Arrays;
  5. import java.util.List;
  6.  
  7. import org.bukkit.Color;
  8. import org.bukkit.Material;
  9. import org.bukkit.SkullType;
  10. import org.bukkit.enchantments.Enchantment;
  11. import org.bukkit.inventory.ItemFlag;
  12. import org.bukkit.inventory.ItemStack;
  13. import org.bukkit.inventory.meta.ItemMeta;
  14. import org.bukkit.inventory.meta.LeatherArmorMeta;
  15. import org.bukkit.inventory.meta.SkullMeta;
  16.  
  17. public class ItemsBuilder {
  18.  
  19. private ItemStack stack;
  20.  
  21. public ItemsBuilder(Material material) {
  22. this.stack = new ItemStack(material);
  23. }
  24.  
  25. public ItemsBuilder(Material material, int data) {
  26. this.stack = new ItemStack(material, 1, (short) data);
  27. }
  28.  
  29. public ItemsBuilder setAmount(int amount) {
  30. this.stack.setAmount(amount);
  31. return this;
  32. }
  33.  
  34. public ItemsBuilder setDisplayname(String name) {
  35. ItemMeta meta = this.stack.getItemMeta();
  36. meta.setDisplayName(name);
  37. this.stack.setItemMeta(meta);
  38. return this;
  39. }
  40.  
  41. public ItemsBuilder setUnbreakable(boolean unbreakable) {
  42. ItemMeta meta = this.stack.getItemMeta();
  43. meta.spigot().setUnbreakable(unbreakable);
  44. return this;
  45. }
  46.  
  47. public ItemsBuilder setLore(List<String> list) {
  48. ItemMeta meta = this.stack.getItemMeta();
  49. meta.setLore(list);
  50. this.stack.setItemMeta(meta);
  51. return this;
  52. }
  53.  
  54. public ItemsBuilder addLore(String lore) {
  55. ItemMeta meta = this.stack.getItemMeta();
  56. if (!meta.hasLore()) {
  57. List<String> newLore = new ArrayList<>();
  58. newLore.add(lore);
  59. meta.setLore(newLore);
  60. } else {
  61. List<String> itemLore = meta.getLore();
  62. itemLore.add(lore);
  63. meta.setLore(itemLore);
  64. }
  65. this.stack.setItemMeta(meta);
  66. return this;
  67. }
  68.  
  69. public ItemsBuilder addEnchantment(Enchantment enchantment, int level) {
  70. this.stack.addEnchantment(enchantment, level);
  71. return this;
  72. }
  73.  
  74. public ItemsBuilder addUnsafeEnchantment(Enchantment enchantment, int level) {
  75. this.stack.addUnsafeEnchantment(enchantment, level);
  76. return this;
  77. }
  78.  
  79. public ItemsBuilder setColor(Color color) {
  80. LeatherArmorMeta meta = (LeatherArmorMeta) this.stack.getItemMeta();
  81. meta.setColor(color);
  82. this.stack.setItemMeta(meta);
  83. return this;
  84. }
  85.  
  86. public ItemsBuilder hideEnchantment() {
  87. ItemMeta meta = this.stack.getItemMeta();
  88. meta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
  89. this.stack.setItemMeta(meta);
  90. return this;
  91. }
  92.  
  93. public ItemsBuilder hideAttributes() {
  94. ItemMeta meta = this.stack.getItemMeta();
  95. meta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
  96. this.stack.setItemMeta(meta);
  97. return this;
  98. }
  99.  
  100. public ItemsBuilder hidePlaceOn() {
  101. ItemMeta meta = this.stack.getItemMeta();
  102. meta.addItemFlags(ItemFlag.HIDE_PLACED_ON);
  103. this.stack.setItemMeta(meta);
  104. return this;
  105. }
  106.  
  107. public ItemsBuilder setGlowing() {
  108. ItemMeta meta = this.stack.getItemMeta();
  109. meta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
  110. meta.addEnchant(Enchantment.DURABILITY, 1, false);
  111. this.stack.setItemMeta(meta);
  112. return this;
  113. }
  114.  
  115. public static ItemStack SkullBuilder(String name, String owner) {
  116. ItemStack skull = new ItemStack(Material.SKULL_ITEM, 1, (short) SkullType.PLAYER.ordinal());
  117. SkullMeta meta = (SkullMeta) skull.getItemMeta();
  118. meta.setDisplayName(name);
  119. meta.setOwner(owner);
  120. skull.setItemMeta(meta);
  121. return skull;
  122. }
  123.  
  124. public static ItemStack SkullBuilder(String name, String owner, String... lore) {
  125. ItemStack skull = new ItemStack(Material.SKULL_ITEM, 1, (short) SkullType.PLAYER.ordinal());
  126. SkullMeta meta = (SkullMeta) skull.getItemMeta();
  127. meta.setDisplayName(name);
  128. meta.setOwner(owner);
  129. if (lore != null) {
  130. meta.setLore(Arrays.asList(lore));
  131. }
  132. skull.setItemMeta(meta);
  133. return skull;
  134. }
  135.  
  136. public ItemStack PotionBuilder(String name, int amount, int potionid) {
  137.  
  138. ItemStack stack = new ItemStack(Material.POTION, amount, (short) potionid);
  139. ItemMeta meta = stack.getItemMeta();
  140. meta.setDisplayName(name);
  141. stack.setItemMeta(meta);
  142.  
  143. return stack;
  144. }
  145.  
  146. public ItemStack PotionBuilder(String name, int amount, int potionid, String... lore) {
  147.  
  148. ItemStack stack = new ItemStack(Material.POTION, amount, (short) potionid);
  149. ItemMeta meta = stack.getItemMeta();
  150. meta.setDisplayName(name);
  151. if (lore != null) {
  152. meta.setLore(Arrays.asList(lore));
  153. }
  154. stack.setItemMeta(meta);
  155.  
  156. return stack;
  157. }
  158.  
  159. public ItemStack create() {
  160. return this.stack;
  161. }
  162.  
  163. public ItemMeta getMeta() {
  164. return this.stack.getItemMeta();
  165. }
  166.  
  167. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement