Package eu.xap3y.xagui.models
Class GuiButton
Object
GuiButton
- All Implemented Interfaces:
GuiButtonInterface
Represents a button in a GUI.
A GuiButton wraps an ItemStack and optional click behavior. It supports:
- Setting item metadata (name, lore, amount, flags)
- Adding/removing enchantments
- A click listener
- An optional redirect to another menu after click
- An optional click sound
this for fluent chaining.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddEnchantment(Enchantment enchantment) Add an unsafe enchantment at level 1.addEnchantment(Enchantment enchantment, int level) Add an unsafe enchantment with a custom level.addItemFlag(ItemFlag flag) Add an item flag to the icon.Append multiple lore lines from varargs, translating color codes with &.addLoreArray(String[] array) Append multiple lore lines from an array, translating color codes with &.addLoreLine(String line) Append a single lore line, translating color codes with &.addLoreList(List<String> lines) Append multiple lore lines, translating color codes with &.voidcallRedirect(Player p) If a redirect is configured, open that menu for the given player.Clear all lore from the item.clone()Create a shallow copy of this button.Get the configured click listener for this button, if any.SoundGet the sound configured to play on click, if any.floatGet the volume configured for the click sound.MaterialgetIcon()Get the material type of this button's icon.ItemStackgetItem()Get this button's ItemStack.Remove all enchantments from the icon.removeEnchantment(Enchantment enchantment) Remove a specific enchantment from the icon.removeItemFlag(ItemFlag flag) Remove an item flag from the icon.setAmount(int amount) Set the stack amount of the icon.setDurability(short durability) Set the durability (damage) value of the icon.voidsetItem(ItemStack item) Replace this button's ItemStack.Set the lore lines from varargs, translating color codes with &.setLoreArray(String[] array) Set the lore lines from an array, translating color codes with &.setLoreList(List<String> newLore) Set the lore lines of the button, translating color codes with &.Set the display name of the button, supporting color codes with &.withClickSound(Sound sound, float volume) Configure a sound to play when this button is clicked.withListener(GuiClickInterface newListener) Set the click listener for this button.withRedirect(Supplier<GuiMenuInterface> menu) Configure a redirect menu supplier to be opened after this button is clicked.Methods inherited from class Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface GuiButtonInterface
withClickSound
-
Constructor Details
-
GuiButton
public GuiButton(ItemStack item) Create a new GuiButton from an ItemStack.- Parameters:
item- the backing ItemStack
-
GuiButton
public GuiButton(Material material) Create a new GuiButton with a Material (amount 1).- Parameters:
material- the material to use
-
GuiButton
public GuiButton(XMaterial xmaterial) Create a new GuiButton with a XMaterial (amount 1).- Parameters:
xmaterial- the material to use
-
-
Method Details
-
getIcon
public Material getIcon()Get the material type of this button's icon.- Specified by:
getIconin interfaceGuiButtonInterface- Returns:
- the Material of the icon
-
getItem
public ItemStack getItem()Get this button's ItemStack.- Specified by:
getItemin interfaceGuiButtonInterface- Returns:
- the ItemStack reference
-
setItem
public void setItem(ItemStack item) Replace this button's ItemStack.- Specified by:
setItemin interfaceGuiButtonInterface- Parameters:
item- the new ItemStack
-
withListener
Set the click listener for this button.- Specified by:
withListenerin interfaceGuiButtonInterface- Parameters:
newListener- the listener to invoke on click- Returns:
- this button for chaining
-
setName
Set the display name of the button, supporting color codes with &.- Specified by:
setNamein interfaceGuiButtonInterface- Parameters:
name- the new display name- Returns:
- this button for chaining
-
setLoreList
Set the lore lines of the button, translating color codes with &.- Specified by:
setLoreListin interfaceGuiButtonInterface- Parameters:
newLore- list of lore lines- Returns:
- this button for chaining
-
setLore
Set the lore lines from varargs, translating color codes with &.- Specified by:
setLorein interfaceGuiButtonInterface- Parameters:
args- lore lines- Returns:
- this button for chaining
-
setLoreArray
Set the lore lines from an array, translating color codes with &.- Specified by:
setLoreArrayin interfaceGuiButtonInterface- Parameters:
array- lore lines- Returns:
- this button for chaining
-
addLoreLine
Append a single lore line, translating color codes with &.- Specified by:
addLoreLinein interfaceGuiButtonInterface- Parameters:
line- the lore line to add- Returns:
- this button for chaining
-
addLoreList
Append multiple lore lines, translating color codes with &.- Specified by:
addLoreListin interfaceGuiButtonInterface- Parameters:
lines- list of lore lines to add- Returns:
- this button for chaining
-
addLore
Append multiple lore lines from varargs, translating color codes with &.- Specified by:
addLorein interfaceGuiButtonInterface- Parameters:
args- lore lines- Returns:
- this button for chaining
-
addLoreArray
Append multiple lore lines from an array, translating color codes with &.- Specified by:
addLoreArrayin interfaceGuiButtonInterface- Parameters:
array- lore lines- Returns:
- this button for chaining
-
clearLore
Clear all lore from the item.- Specified by:
clearLorein interfaceGuiButtonInterface- Returns:
- this button for chaining
-
addItemFlag
Add an item flag to the icon.- Specified by:
addItemFlagin interfaceGuiButtonInterface- Parameters:
flag- the item flag to add- Returns:
- this button for chaining
-
removeItemFlag
Remove an item flag from the icon.- Specified by:
removeItemFlagin interfaceGuiButtonInterface- Parameters:
flag- the item flag to remove- Returns:
- this button for chaining
-
setAmount
Set the stack amount of the icon.- Specified by:
setAmountin interfaceGuiButtonInterface- Parameters:
amount- new amount- Returns:
- this button for chaining
-
addEnchantment
Add an unsafe enchantment at level 1.- Specified by:
addEnchantmentin interfaceGuiButtonInterface- Parameters:
enchantment- the enchantment to add- Returns:
- this button for chaining
-
addEnchantment
Add an unsafe enchantment with a custom level.- Specified by:
addEnchantmentin interfaceGuiButtonInterface- Parameters:
enchantment- the enchantment to addlevel- the level to apply- Returns:
- this button for chaining
-
removeEnchantment
Remove a specific enchantment from the icon.- Specified by:
removeEnchantmentin interfaceGuiButtonInterface- Parameters:
enchantment- the enchantment to remove- Returns:
- this button for chaining
-
removeAllEnchantments
Remove all enchantments from the icon.- Specified by:
removeAllEnchantmentsin interfaceGuiButtonInterface- Returns:
- this button for chaining
-
setDurability
Set the durability (damage) value of the icon. Note: durability is deprecated for modern versions in favor of Damageable meta.- Specified by:
setDurabilityin interfaceGuiButtonInterface- Parameters:
durability- the durability value- Returns:
- this button for chaining
-
getClickListener
Get the configured click listener for this button, if any.- Specified by:
getClickListenerin interfaceGuiButtonInterface- Returns:
- the listener or null
-
getClickSound
public Sound getClickSound()Get the sound configured to play on click, if any.- Specified by:
getClickSoundin interfaceGuiButtonInterface- Returns:
- the click sound or null
-
getClickSoundVolume
public float getClickSoundVolume()Get the volume configured for the click sound.- Specified by:
getClickSoundVolumein interfaceGuiButtonInterface- Returns:
- the click sound volume
-
clone
Create a shallow copy of this button.The copy contains a cloned ItemStack and copies over listener, redirect, and sound references.
- Specified by:
clonein interfaceGuiButtonInterface- Overrides:
clonein classObject- Returns:
- a cloned GuiButton
-
withRedirect
Configure a redirect menu supplier to be opened after this button is clicked.- Specified by:
withRedirectin interfaceGuiButtonInterface- Parameters:
menu- supplier that returns a target GuiMenuInterface- Returns:
- this button for chaining
-
withClickSound
Configure a sound to play when this button is clicked. Use null to disable.- Specified by:
withClickSoundin interfaceGuiButtonInterface- Parameters:
sound- the sound to play, or nullvolume- the volume to play the sound at- Returns:
- this button for chaining
-
callRedirect
public void callRedirect(Player p) If a redirect is configured, open that menu for the given player. Also plays the global redirect sound if configured via XaGui.- Specified by:
callRedirectin interfaceGuiButtonInterface- Parameters:
p- the player to redirect
-