Guest User

Untitled

a guest
May 6th, 2019
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.59 KB | None | 0 0
  1. package com.outlook.tehbrian.tfcplugin.utils;
  2.  
  3. import org.bukkit.Material;
  4. import org.bukkit.enchantments.Enchantment;
  5. import org.bukkit.inventory.ItemFlag;
  6. import org.bukkit.inventory.ItemStack;
  7. import org.bukkit.inventory.meta.ItemMeta;
  8.  
  9. import java.util.List;
  10. import java.util.Map;
  11.  
  12. public class ItemBuilder {
  13.  
  14. private Material material;
  15. private Integer amount = null;
  16. private Short durability = null;
  17. private Map<Enchantment, Integer> enchantments = null;
  18. private List<ItemFlag> flags = null;
  19. private List<String> lore = null;
  20. private String name = null;
  21. private Boolean unbreakable = null;
  22.  
  23. public ItemBuilder(Material material) {
  24. this.material = material;
  25. }
  26.  
  27. public ItemBuilder amount(Integer amount) {
  28. this.amount = amount;
  29. return this;
  30. }
  31.  
  32. public ItemBuilder durability(Short durability) {
  33. this.durability = durability;
  34. return this;
  35. }
  36.  
  37. public ItemBuilder enchantments(Map<Enchantment, Integer> enchantments) {
  38. this.enchantments = enchantments;
  39. return this;
  40. }
  41.  
  42. public ItemBuilder flags(List<ItemFlag> flags) {
  43. this.flags = flags;
  44. return this;
  45. }
  46.  
  47. public ItemBuilder lore(List<String> lore) {
  48. this.lore = lore;
  49. return this;
  50. }
  51.  
  52. public ItemBuilder name(String name) {
  53. this.name = name;
  54. return this;
  55. }
  56.  
  57. public ItemBuilder unbreakable(Boolean unbreakable) {
  58. this.unbreakable = unbreakable;
  59. return this;
  60. }
  61.  
  62. public ItemStack build() {
  63.  
  64. ItemStack itemStack = new ItemStack(material);
  65. ItemMeta itemMeta = itemStack.getItemMeta();
  66.  
  67. if (amount != null) {
  68. itemStack.setAmount(amount);
  69. }
  70. if (durability != null) {
  71. itemStack.setDurability(durability);
  72. }
  73. if (enchantments != null) {
  74. itemStack.addUnsafeEnchantments(enchantments);
  75. }
  76. if (flags != null) {
  77. for (ItemFlag flag : flags) {
  78. itemStack.addItemFlags(flag);
  79. }
  80. }
  81. if (lore != null) {
  82. for (int i = 0; i < lore.size(); i++) {
  83. lore.set(i, TextUtils.color(lore.get(i)));
  84. }
  85. itemStack.setLore(lore);
  86. }
  87. if (name != null) {
  88. itemMeta.setDisplayName(TextUtils.color(name));
  89. }
  90. if (unbreakable != null) {
  91. itemMeta.setUnbreakable(unbreakable);
  92. }
  93.  
  94. itemStack.setItemMeta(itemMeta);
  95.  
  96. return itemStack;
  97. }
  98. }
Add Comment
Please, Sign In to add comment