Skip to content

Commit

Permalink
Internal changes in ItemUtils
Browse files Browse the repository at this point in the history
  • Loading branch information
DenaryDev committed Nov 24, 2023
1 parent 521579c commit ee909aa
Showing 1 changed file with 17 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,12 @@ public static ItemStack getCustomHead(final String signature, final String textu
* Builder for {@link ItemStack}
*/
public static class Builder {
private ItemStack item;

private Material type;
private String texture;
private ItemStack itemStack;
private int amount;
private Component displayname;
private List<Component> lore;
private List<? extends Component> lore;
private final Map<Enchantment, Integer> enchantments = new HashMap<>();
private ItemFlag[] itemFlags;
private boolean unbreakable;
Expand All @@ -115,13 +114,13 @@ public Builder texture(String texture) {
return this;
}

public Builder itemStack(ItemStack item) {
this.item = item;
public Builder itemStack(ItemStack itemStack) {
this.itemStack = itemStack;
return this;
}

public Builder amount(int amount) {
this.amount = amount;
this.amount = Math.max(Math.min(amount, 64), 1);
return this;
}

Expand Down Expand Up @@ -151,7 +150,7 @@ public Builder loreRich(List<String> lore, TagResolver... tags) {
}

public Builder lorePlain(List<String> lore) {
this.lore = new ArrayList<>(lore.stream().map(s -> PlainTextComponentSerializer.plainText().deserialize(s)).toList());
this.lore = lore.stream().map(s -> PlainTextComponentSerializer.plainText().deserialize(s)).toList();
return this;
}

Expand Down Expand Up @@ -203,12 +202,20 @@ public Builder persistentData(NamespacedKey key, Object value) {
}

public ItemStack build() {
if (item == null) {
amount = Math.max(Math.min(amount, 64), 1);
final ItemStack item;
if (itemStack != null) {
item = itemStack;
if (type != null) {
item.setType(type);
}
} else {
if (texture != null) {
item = getCustomHead(texture, amount);
} else if (type != null) {
item = new ItemStack(type, amount);
} else {
throw new IllegalArgumentException("The ItemStack type or texture must be present!");
}
item = new ItemStack(type, amount);
}

if (metaEditor != null)
Expand Down

0 comments on commit ee909aa

Please sign in to comment.