Package net.wesjd.anvilgui
Class AnvilGUI.Builder
java.lang.Object
net.wesjd.anvilgui.AnvilGUI.Builder
- Enclosing class:
AnvilGUI
A builder class for an
AnvilGUI object-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionBy default, theasync click handlerwill not run concurrently and instead wait for the previousCompletableFutureto finish before executing it again.Disables compatibility with Geyser softwareinteractableSlots(int... slots) Permit the user to modify (take items in and out) the slot numbers provided.itemLeft(org.bukkit.inventory.ItemStack item) Sets theItemStackto be put in the first slotitemOutput(org.bukkit.inventory.ItemStack item) Sets theItemStackto be put in the output slotitemRight(org.bukkit.inventory.ItemStack item) Sets theItemStackto be put in the second slotSets the AnvilGUI title that is to be displayed to the user.mainThreadExecutor(Executor executor) Set a custom main server thread executor.onClick(BiFunction<Integer, AnvilGUI.StateSnapshot, List<AnvilGUI.ResponseAction>> clickHandler) Do an action when a slot is clicked in the inventoryonClickAsync(AnvilGUI.ClickHandler clickHandler) Do an action when a slot is clicked in the inventoryonClose(Consumer<AnvilGUI.StateSnapshot> closeListener) Listens for when the inventory is closedopen(org.bukkit.entity.Player player) Creates the anvil GUI and opens it for the playerplugin(org.bukkit.plugin.Plugin plugin) Sets the plugin for theAnvilGUIPrevents the closing of the anvil GUI by the userSets the initial item-text that is displayed to the user.Sets the AnvilGUI title that is to be displayed to the user.
-
Constructor Details
-
Builder
public Builder()
-
-
Method Details
-
mainThreadExecutor
Set a custom main server thread executor. Useful for plugins targeting Folia.- Parameters:
executor- The executor to run tasks on- Returns:
- The
AnvilGUI.Builderinstance - Throws:
IllegalArgumentException- when the executor is null
-
preventClose
Prevents the closing of the anvil GUI by the user- Returns:
- The
AnvilGUI.Builderinstance
-
disableGeyserCompat
Disables compatibility with Geyser software -
interactableSlots
Permit the user to modify (take items in and out) the slot numbers provided.- Parameters:
slots- A varags param for the slot numbers. You can avoid relying on magic constants by using theAnvilGUI.Slotclass.- Returns:
- The
AnvilGUI.Builderinstance
-
onClose
Listens for when the inventory is closed- Parameters:
closeListener- AnConsumerthat is called when the anvil GUI is closed- Returns:
- The
AnvilGUI.Builderinstance - Throws:
IllegalArgumentException- when the closeListener is null
-
onClickAsync
Do an action when a slot is clicked in the inventoryThe ClickHandler is only called when the previous execution of the ClickHandler has finished. To alter this behaviour use
allowConcurrentClickHandlerExecution()- Parameters:
clickHandler- AAnvilGUI.ClickHandlerthat is called when the user clicks a slot. TheIntegeris the slot number corresponding toAnvilGUI.Slot, theAnvilGUI.StateSnapshotcontains information about the current state of the anvil, and the response is aCompletableFuturethat will eventually return a list ofAnvilGUI.ResponseActionto execute in the order that they are supplied.- Returns:
- The
AnvilGUI.Builderinstance - Throws:
IllegalArgumentException- when the function supplied is null
-
allowConcurrentClickHandlerExecution
By default, theasync click handlerwill not run concurrently and instead wait for the previousCompletableFutureto finish before executing it again.If this trait is desired, it can be enabled by calling this method but may lead to inconsistent behaviour if not handled properly.
- Returns:
- The
AnvilGUI.Builderinstance
-
onClick
public AnvilGUI.Builder onClick(BiFunction<Integer, AnvilGUI.StateSnapshot, List<AnvilGUI.ResponseAction>> clickHandler) Do an action when a slot is clicked in the inventory- Parameters:
clickHandler- ABiFunctionthat is called when the user clicks a slot. TheIntegeris the slot number corresponding toAnvilGUI.Slot, theAnvilGUI.StateSnapshotcontains information about the current state of the anvil, and the response is a list ofAnvilGUI.ResponseActionto execute in the order that they are supplied.- Returns:
- The
AnvilGUI.Builderinstance - Throws:
IllegalArgumentException- when the function supplied is null
-
plugin
Sets the plugin for theAnvilGUI- Parameters:
plugin- ThePluginthis anvil GUI is associated with- Returns:
- The
AnvilGUI.Builderinstance - Throws:
IllegalArgumentException- if the plugin is null
-
text
Sets the initial item-text that is displayed to the user.
If the usage of Adventure Components is desired, you must create an item, set the displayname of it and put it into the AnvilGUI viaitemLeft(ItemStack)manually.- Parameters:
text- The initial name of the item in the anvil- Returns:
- The
AnvilGUI.Builderinstance - Throws:
IllegalArgumentException- if the text is null
-
title
Sets the AnvilGUI title that is to be displayed to the user.
The provided title will be treated as literal text.- Parameters:
title- The title that is to be displayed to the user- Returns:
- The
AnvilGUI.Builderinstance - Throws:
IllegalArgumentException- if the title is null
-
jsonTitle
Sets the AnvilGUI title that is to be displayed to the user.
The provided json will be parsed into rich chat components.- Parameters:
json- The title that is to be displayed to the user- Returns:
- The
AnvilGUI.Builderinstance - Throws:
IllegalArgumentException- if the title is null- See Also:
-
itemLeft
Sets theItemStackto be put in the first slot- Parameters:
item- TheItemStackto be put in the first slot- Returns:
- The
AnvilGUI.Builderinstance - Throws:
IllegalArgumentException- if theItemStackis null
-
itemRight
Sets theItemStackto be put in the second slot- Parameters:
item- TheItemStackto be put in the second slot- Returns:
- The
AnvilGUI.Builderinstance
-
itemOutput
Sets theItemStackto be put in the output slot- Parameters:
item- TheItemStackto be put in the output slot- Returns:
- The
AnvilGUI.Builderinstance
-
open
Creates the anvil GUI and opens it for the player- Parameters:
player- ThePlayerthe anvil GUI should open for- Returns:
- The
AnvilGUIinstance from this builder - Throws:
IllegalArgumentException- when the onClick function, plugin, or player is null
-