Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/main/java/com/cosimo/utilities/item/ItemBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@
* A proxy class (rather than a true builder) that wraps around an {@link ItemStack}, allowing easier, more fluent and
* chained modifications of the item.
*/
@SuppressWarnings("unused")
public class ItemBuilder implements Cloneable {

/**
* Mutable {@link ItemStack}.
*/
private final ItemStack itemStack;
private ItemMeta itemMeta;

/**
* Creates a new {@link ItemBuilder} from an item stored in a given configuration file's path or a default provided
Expand Down Expand Up @@ -131,6 +133,7 @@ public ItemBuilder(@NonNull Material material) {
*/
public ItemBuilder(@NonNull ItemStack itemStack) {
this.itemStack = itemStack;
this.itemMeta = itemStack.getItemMeta();
}

/**
Expand Down Expand Up @@ -245,7 +248,9 @@ public ItemBuilder loreAt(@Nullable String line, final int @NonNull ... indices)
*/
@NonNull
public ItemBuilder with(@NonNull Consumer<ItemStack> itemConsumer) {
this.itemStack.setItemMeta(this.itemMeta);
itemConsumer.accept(this.itemStack);
this.itemMeta = this.itemStack.getItemMeta();
return this;
}

Expand Down Expand Up @@ -473,7 +478,7 @@ public ItemBuilder clearLore() {
*/
@NonNull
public Optional<ItemMeta> getItemMeta() {
return Optional.ofNullable(this.itemStack.getItemMeta());
return Optional.ofNullable(this.itemMeta);
}

/**
Expand Down Expand Up @@ -502,9 +507,11 @@ public boolean isBreakable() {
*/
@NonNull
public ItemStack build() {
this.itemStack.setItemMeta(this.itemMeta);
return this.itemStack;
}

@SuppressWarnings("MethodDoesntCallSuperMethod")
@Override
public ItemBuilder clone() {
return new ItemBuilder(this.itemStack.clone());
Expand Down
Loading