2424 * A proxy class (rather than a true builder) that wraps around an {@link ItemStack}, allowing easier, more fluent and
2525 * chained modifications of the item.
2626 */
27+ @ SuppressWarnings ("unused" )
2728public class ItemBuilder implements Cloneable {
2829
2930 /**
3031 * Mutable {@link ItemStack}.
3132 */
3233 private final ItemStack itemStack ;
34+ private ItemMeta itemMeta ;
3335
3436 /**
3537 * Creates a new {@link ItemBuilder} from an item stored in a given configuration file's path or a default provided
@@ -132,6 +134,7 @@ public ItemBuilder(@NonNull Material material) {
132134 */
133135 public ItemBuilder (@ NonNull ItemStack itemStack ) {
134136 this .itemStack = itemStack ;
137+ this .itemMeta = itemStack .getItemMeta ();
135138 }
136139
137140 /**
@@ -246,7 +249,9 @@ public ItemBuilder loreAt(@Nullable String line, final int @NonNull ... indices)
246249 */
247250 @ NonNull
248251 public ItemBuilder with (@ NonNull Consumer <ItemStack > itemConsumer ) {
249- itemConsumer .accept (this .itemStack );
252+ itemConsumer .accept (this .build ());
253+ this .itemMeta = this .itemStack .getItemMeta ();
254+
250255 return this ;
251256 }
252257
@@ -474,7 +479,7 @@ public ItemBuilder clearLore() {
474479 */
475480 @ NonNull
476481 public Optional <ItemMeta > getItemMeta () {
477- return Optional .ofNullable (this .itemStack . getItemMeta () );
482+ return Optional .ofNullable (this .itemMeta );
478483 }
479484
480485 /**
@@ -503,6 +508,7 @@ public boolean isBreakable() {
503508 */
504509 @ NonNull
505510 public ItemStack build () {
511+ this .itemStack .setItemMeta (this .itemMeta );
506512 return this .itemStack ;
507513 }
508514
@@ -514,7 +520,7 @@ public ItemStack build() {
514520 */
515521 @ NonNull
516522 public <E > Button <E > asButton () {
517- return Button .of (this .itemStack );
523+ return Button .of (this .build () );
518524 }
519525
520526 /**
@@ -525,9 +531,10 @@ public <E> Button<E> asButton() {
525531 */
526532 @ NonNull
527533 public <E > Button <E > asButton (E property ) {
528- return Button .of (this .itemStack , property );
534+ return Button .of (this .build () , property );
529535 }
530536
537+ @ SuppressWarnings ("MethodDoesntCallSuperMethod" )
531538 @ Override
532539 public ItemBuilder clone () {
533540 return new ItemBuilder (this .itemStack .clone ());
0 commit comments