91 lines
2.6 KiB
Java
91 lines
2.6 KiB
Java
package com.gigazelensky.antispoof.gui;
|
|
|
|
import com.gigazelensky.antispoof.util.TextUtil;
|
|
import java.util.ArrayList;
|
|
import java.util.Arrays;
|
|
import java.util.List;
|
|
import net.kyori.adventure.text.Component;
|
|
import org.bukkit.Material;
|
|
import org.bukkit.OfflinePlayer;
|
|
import org.bukkit.enchantments.Enchantment;
|
|
import org.bukkit.inventory.ItemFlag;
|
|
import org.bukkit.inventory.ItemStack;
|
|
import org.bukkit.inventory.meta.ItemMeta;
|
|
import org.bukkit.inventory.meta.SkullMeta;
|
|
|
|
/**
|
|
* Fluent ItemStack builder for AntiSpoof management GUIs (reconstructed from IIIllIIlIIllIlI).
|
|
*/
|
|
public final class ItemBuilder {
|
|
private final ItemStack stack;
|
|
|
|
public ItemBuilder(Material material) {
|
|
this.stack = new ItemStack(material == null ? Material.STONE : material);
|
|
}
|
|
|
|
public ItemBuilder(ItemStack base) {
|
|
this.stack = base == null ? new ItemStack(Material.STONE) : base.clone();
|
|
}
|
|
|
|
public ItemBuilder name(String name) {
|
|
ItemMeta meta = stack.getItemMeta();
|
|
if (meta != null && name != null) {
|
|
meta.displayName(TextUtil.toComponent(name));
|
|
stack.setItemMeta(meta);
|
|
}
|
|
return this;
|
|
}
|
|
|
|
public ItemBuilder lore(String... lines) {
|
|
return lore(Arrays.asList(lines));
|
|
}
|
|
|
|
public ItemBuilder lore(List<String> lines) {
|
|
ItemMeta meta = stack.getItemMeta();
|
|
if (meta != null && lines != null) {
|
|
List<Component> comps = new ArrayList<>(lines.size());
|
|
for (String line : lines) {
|
|
comps.add(TextUtil.toComponent(line));
|
|
}
|
|
meta.lore(comps);
|
|
stack.setItemMeta(meta);
|
|
}
|
|
return this;
|
|
}
|
|
|
|
public ItemBuilder glow(boolean enabled) {
|
|
if (!enabled) {
|
|
return this;
|
|
}
|
|
ItemMeta meta = stack.getItemMeta();
|
|
if (meta != null) {
|
|
meta.addEnchant(Enchantment.UNBREAKING, 1, true);
|
|
meta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
|
|
stack.setItemMeta(meta);
|
|
}
|
|
return this;
|
|
}
|
|
|
|
public ItemBuilder hideAttributes() {
|
|
ItemMeta meta = stack.getItemMeta();
|
|
if (meta != null) {
|
|
meta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
|
|
stack.setItemMeta(meta);
|
|
}
|
|
return this;
|
|
}
|
|
|
|
public ItemBuilder skullOwner(OfflinePlayer owner) {
|
|
ItemMeta meta = stack.getItemMeta();
|
|
if (meta instanceof SkullMeta skull && owner != null) {
|
|
skull.setOwningPlayer(owner);
|
|
stack.setItemMeta(skull);
|
|
}
|
|
return this;
|
|
}
|
|
|
|
public ItemStack build() {
|
|
return stack;
|
|
}
|
|
}
|