Skip to content

Commit

Permalink
Improved ItemStackBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
anjoismysign committed Oct 7, 2023
1 parent 9804bf4 commit fd77505
Showing 1 changed file with 16 additions and 23 deletions.
39 changes: 16 additions & 23 deletions src/main/java/us/mytheria/bloblib/itemstack/ItemStackBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,10 @@
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.LeatherArmorMeta;
import us.mytheria.bloblib.entities.Rep;
import us.mytheria.bloblib.utilities.TextColor;

import java.util.*;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.logging.Level;

public final class ItemStackBuilder {
Expand Down Expand Up @@ -100,35 +98,40 @@ public ItemStackBuilder unflag(Collection<ItemFlag> flags) {
return unflag(flags.toArray(new ItemFlag[0]));
}

public ItemStackBuilder displayName(String name, char translateColorChar) {
return itemMeta(itemMeta -> itemMeta.setDisplayName(TextColor.CUSTOM_PARSE(translateColorChar, name)));
public ItemStackBuilder displayName(String name, char colorChar) {
return itemMeta(itemMeta -> itemMeta.setDisplayName(TextColor.CUSTOM_PARSE(colorChar, name)));
}

public ItemStackBuilder displayName(String name) {
return displayName(name, '&');
}

public ItemStackBuilder lore(String line, char colorChar) {
return lore(List.of(line), colorChar);
}

public ItemStackBuilder lore(String line) {
return lore(List.of(TextColor.PARSE(line)));
return lore(line, '&');
}

public ItemStackBuilder lore(String... lore) {
public ItemStackBuilder lore(char colorChar, String... lore) {
List<String> list = List.of(lore);
List<String> dupe = new ArrayList<>();
list.forEach(s -> dupe.add(TextColor.PARSE(s)));
list.forEach(s -> dupe.add(TextColor.CUSTOM_PARSE(colorChar, s)));
return itemMeta(itemMeta -> itemMeta.setLore(dupe));
}

public ItemStackBuilder lore(List<String> lore) {
return itemMeta(itemMeta -> itemMeta.setLore(lore));
public ItemStackBuilder lore(String... lore) {
return lore('&', lore);
}

public ItemStackBuilder lore(Function<List<String>, List<String>> lore) {
return itemMeta(itemMeta -> itemMeta.setLore(lore.apply(itemMeta.getLore())));
public ItemStackBuilder lore(List<String> lore, char colorChar) {
List<String> list = lore.stream().map(s -> TextColor.CUSTOM_PARSE(colorChar, s)).toList();
return itemMeta(itemMeta -> itemMeta.setLore(list));
}

public ItemStackBuilder lore(List<String> lore, Rep... reps) {
return lore(Rep.lace(lore, reps));
public ItemStackBuilder lore(List<String> lore) {
return lore(lore, '&');
}

private List<String> getLore() {
Expand All @@ -137,16 +140,6 @@ private List<String> getLore() {
return meta.getLore();
}

public ItemStackBuilder lore(Rep... reps) {
List<String> lore = getLore();
if (lore == null) return this;
return lore(Rep.lace(lore, reps));
}

public ItemStackBuilder lore(Collection<Rep> reps) {
return lore(reps.toArray(new Rep[0]));
}

/**
* Clears the lore of the item.
*/
Expand Down

0 comments on commit fd77505

Please sign in to comment.