54 lines
1.2 KiB
Java
54 lines
1.2 KiB
Java
package me.loganb1max.minions.util;
|
|
|
|
import org.bukkit.Material;
|
|
import org.bukkit.inventory.ItemStack;
|
|
import org.bukkit.inventory.meta.ItemMeta;
|
|
import java.util.List;
|
|
import java.util.stream.Collectors;
|
|
|
|
public class ItemBuilder {
|
|
|
|
private ItemStack itemStack;
|
|
|
|
public ItemBuilder(final Material material) {
|
|
this.itemStack = new ItemStack(material);
|
|
}
|
|
|
|
public static ItemBuilder of(final Material material) {
|
|
return new ItemBuilder(material);
|
|
}
|
|
|
|
public ItemBuilder amount(final int amount) {
|
|
itemStack.setAmount(amount);
|
|
return this;
|
|
}
|
|
|
|
public ItemBuilder name(final String name) {
|
|
ItemMeta meta = itemStack.getItemMeta();
|
|
meta.setDisplayName(Text.color(name));
|
|
itemStack.setItemMeta(meta);
|
|
return this;
|
|
}
|
|
|
|
public ItemBuilder lore(final String lore) {
|
|
ItemMeta meta = itemStack.getItemMeta();
|
|
List<String> loreList = meta.getLore();
|
|
loreList.add(Text.color(lore));
|
|
meta.setLore(loreList);
|
|
itemStack.setItemMeta(meta);
|
|
return this;
|
|
}
|
|
|
|
public ItemBuilder lore(final List<String> lore) {
|
|
ItemMeta meta = itemStack.getItemMeta();
|
|
meta.setLore(lore.stream().map(Text::color).collect(Collectors.toList()));
|
|
itemStack.setItemMeta(meta);
|
|
return this;
|
|
}
|
|
|
|
public ItemStack build() {
|
|
return itemStack.clone();
|
|
}
|
|
|
|
}
|