-
Notifications
You must be signed in to change notification settings - Fork 0
05 action system
github-actions[bot] edited this page May 5, 2026
·
1 revision
The Action System provides a streamlined way to execute defined behaviors for players dynamically.
KLibrary typically provides out-of-the-box standard actions:
-
[message] <text>: Sends a MiniMessage parsed text to the player. -
[console] <command>: Executes a command as the console. -
[player] <command>: Forces the player to execute a command. -
[sound] <sound>;<volume>;<pitch>: Plays a sound to the player. -
[close]: Closes the player's active inventory.
You can execute actions programmatically:
List<String> rawActions = Arrays.asList(
"[message] <green>Action executed!",
"[sound] BLOCK_NOTE_BLOCK_PLING;1.0;2.0"
);
List<Action> actions = actionFactory.deserializeActions(rawActions);
for (Action action : actions) {
action.execute(player);
}Creating a new Action involves extending the base Action abstraction.
import io.github.kaivian.klibrary.action.api.Action;
import org.bukkit.entity.Player;
public class HealAction extends Action {
private final double amount;
public HealAction(String rawData) {
// rawData is the string after the tag: e.g. "10.0" from "[heal] 10.0"
try {
this.amount = Double.parseDouble(rawData.trim());
} catch (NumberFormatException e) {
this.amount = 20.0; // Fallback
}
}
@Override
public void execute(Player player) {
double newHealth = Math.min(20.0, player.getHealth() + amount);
player.setHealth(newHealth);
}
}Register your custom action using the ActionFactory you instantiated on plugin start.
// Registering the "[heal]" tag to map to HealAction
actionFactory.register("heal", HealAction.class);Now, anywhere in your configuration, [heal] 5.0 will resolve to your custom class and heal the player when executed!
KLibrary by Kaivian © 2026. All rights reserved.