55import org .bukkit .Material ;
66import org .bukkit .NamespacedKey ;
77import org .bukkit .enchantments .Enchantment ;
8+ import org .bukkit .entity .Player ;
89import org .bukkit .inventory .ItemStack ;
910import org .bukkit .inventory .meta .ItemMeta ;
1011import org .bukkit .inventory .meta .SkullMeta ;
1112import org .bukkit .persistence .PersistentDataContainer ;
1213import org .bukkit .persistence .PersistentDataType ;
1314
1415import javax .annotation .Nonnull ;
16+ import javax .annotation .Nullable ;
1517import java .util .ArrayList ;
1618import java .util .HashMap ;
1719import java .util .List ;
2426 */
2527public class ItemWrapper {
2628
27- private final ItemStack itemStack ;
28- private ItemMeta itemMeta ;
29- private String displayName = null ;
30- private List <String > lore = new ArrayList <>();
29+ protected final ItemStack itemStack ;
30+ protected ItemMeta itemMeta ;
31+ protected String displayName = null ;
32+ protected List <String > lore = new ArrayList <>();
33+ protected @ Nullable Player owningPlayer = null ;
3134
3235 /**
3336 * Specifies directly what {@link ItemStack} you want to wrap around
3437 * @param stack A {@link ItemStack}
3538 */
36- public ItemWrapper (final ItemStack stack ) {
37- if (stack == null ) throw new IllegalArgumentException ("ItemStack in ItemWrapper cannot be null!" );
39+ public ItemWrapper (@ Nonnull final ItemStack stack ) {
3840 this .itemStack = stack ;
39- if ( this . itemStack . getType () != Material . AIR ) this .itemMeta = this .itemStack .getItemMeta ();
41+ this .itemMeta = this .itemStack .getItemMeta ();
4042 }
4143
4244 /**
@@ -45,7 +47,7 @@ public ItemWrapper(final ItemStack stack) {
4547 */
4648 public ItemWrapper (@ Nonnull final Material material ) {
4749 this .itemStack = new ItemStack (material , 1 );
48- if ( this . itemStack . getType () != Material . AIR ) this .itemMeta = this .itemStack .getItemMeta ();
50+ this .itemMeta = this .itemStack .getItemMeta ();
4951 }
5052
5153 /**
@@ -58,6 +60,49 @@ public ItemWrapper(@Nonnull final Material material, final int amount) {
5860 if (this .itemStack .getType () != Material .AIR ) this .itemMeta = this .itemStack .getItemMeta ();
5961 }
6062
63+ /**
64+ * Specifies directly what {@link ItemStack} you want to wrap around
65+ * <br>
66+ * The {@link Player} argument is for if you want certain support for things like PlaceholderAPI to parse
67+ * placeholders on this item for a specific player
68+ * @param stack An {@link ItemStack} cant be null
69+ * @param player A {@link Player} is nullable
70+ */
71+ public ItemWrapper (final @ Nonnull ItemStack stack , @ Nullable Player player ) {
72+ this .itemStack = stack ;
73+ this .itemMeta = this .itemStack .getItemMeta ();
74+ this .owningPlayer = player ;
75+ }
76+
77+ /**
78+ * Creates a {@link ItemStack} with a {@link Integer} of 1 as the amount
79+ * <br>
80+ * This also allows you to put a {@link Player} as the second argument, to allow PlaceholderAPI parsing.
81+ * @param material A {@link Material} enum
82+ * @param player A nullable {@link Player}
83+ */
84+ public ItemWrapper (@ Nonnull final Material material , @ Nullable final Player player ) {
85+ this .itemStack = new ItemStack (material , 1 );
86+ this .itemMeta = this .itemStack .getItemMeta ();
87+ this .owningPlayer = player ;
88+ }
89+
90+ /**
91+ * Creates a {@link ItemStack} with a specific {@link Material} and {@link Integer} amount
92+ * <br>
93+ * This also allows you to specify a {@link Player} for PlaceholderAPI parsing.
94+ * @param material A {@link Material} enum
95+ * @param amount A {@link Integer} amount, value cant be <= 0
96+ * @param player A nullable {@link Player}
97+ */
98+ public ItemWrapper (@ Nonnull final Material material ,
99+ final int amount ,
100+ @ Nullable final Player player ) {
101+ this .itemStack = new ItemStack (material , amount );
102+ this .itemMeta = this .itemStack .getItemMeta ();
103+ this .owningPlayer = player ;
104+ }
105+
61106 /**
62107 * Might be null
63108 * @return String of display name, or null
@@ -82,7 +127,7 @@ public final List<String> getLore() {
82127 public final ItemWrapper setDisplayName (final String displayName ) {
83128 if (this .itemMeta == null ) return this ;
84129 this .displayName = displayName ;
85- this .itemMeta .setDisplayName (convert (this .displayName ));
130+ this .itemMeta .setDisplayName (convert (this .displayName , null ));
86131 this .itemStack .setItemMeta (this .itemMeta );
87132 return this ;
88133 }
@@ -94,7 +139,7 @@ public final ItemWrapper setDisplayName(final String displayName) {
94139 */
95140 public final ItemWrapper addItemLore (final String ... lore ) {
96141 for (int i = 0 ; i <= lore .length ; i ++) {
97- this .lore .add (convert (lore [i ]));
142+ this .lore .add (convert (lore [i ], null ));
98143 }
99144 this .setItemLore (this .lore );
100145 return this ;
@@ -110,7 +155,7 @@ public final ItemWrapper setItemLore(final List<String> itemLore) {
110155 this .lore = itemLore ;
111156 final List <String > colored = new ArrayList <>();
112157 itemLore .forEach ((loreItem ) -> {
113- colored .add (convert (loreItem ));
158+ colored .add (convert (loreItem , null ));
114159 });
115160 this .itemMeta .setLore (colored );
116161 this .itemStack .setItemMeta (this .itemMeta );
0 commit comments