NextLib 1.0.2
Short Description
NextLib 1.0.2 adds an extensible GUI action registry that allows third-party plugins to register their own click handlers via the API. The update includes thread-safe logging and improved diagnostics when loading YAML menus.
Major changes:
- Added the thread-safe Actions.registerAction registry, which allows you to map identifiers and arguments from YAML to GuiAction factories.
- The functional interface of the GuiActionFactory is presented, which simplifies the creation of actions to which the GUIManager and the argument string are passed.
- GuiLoader now builds actions through the registry and logs unknown identifiers, which makes debugging configurations easier.
How to use
Code (Java):
import
io.github.chi2l3s.nextlib.api.gui.Actions
;
import
io.github.chi2l3s.nextlib.api.gui.GuiManager
;
import
org.bukkit.Location
;
import
org.bukkit.plugin.java.JavaPlugin
;
public
final
class CustomActionsPlugin
extends JavaPlugin
{
@Override
public
void onLoad
(
)
{
// Registration can take place in onLoad or OnEnable before loading the YAML menu.
}
@Override
public
void onEnable
(
)
{
Actions.
registerAction
(
"teleport",
(manager, args
)
->
{
String
[
] parts
= args.
split
(
" "
)
;
if
(parts.
length
<
3
)
{
throw
new
IllegalArgumentException
(
"Usage: teleport <x> <y> <z>"
)
;
}
double x
=
Double.
parseDouble
(parts
[
0
]
)
;
double y
=
Double.
parseDouble
(parts
[
1
]
)
;
double z
=
Double.
parseDouble
(parts
[
2
]
)
;
return player
-> player.
teleport
(
new Location
(player.
getWorld
(
), x, y, z
)
)
;
}
)
;
}
}
After registering an action, you can call it in the YAML menu.:
Code (YAML):
items:
tp-button:
material
: ENDER_PEARL
slot
: 13
name
:
"&bTeleport"
on_left_click
:
-
"teleport 0 80 0"
If you try to use a non-existent action in the menu, a warning will be sent to the plugin's log indicating the problematic element and the type of click.