ActionLib is used to easily implement JSON based data-driven actions, e.g. setting a players health or saturation, or showing a random inventory.
Better documentation can be found
here
Default Actions:
trip: Drops the player's entire inventory onto the ground
teleport_player: Allows teleporting the player
spawn_entity: Spawns the specified entity randomly within a radius
smite: Strikes the player with lightning
show_screen: Shows the player a specified screen (Currently only supports the demo screen)
set_saturation: Sets the player's saturation level
set_player_armor: Sets the player's armor
set_level: Sets the player's xp level
set_health: Sets the player's health
set_gamemode: Sets the player's gamemode
set_food_level: Sets the player's food level
set_fire: Sets the player on fire
send_title: Sends a title to the player
send_message: Sends a message to the player
potion_effect: Allows adding, removing, and clearing the player's potion effects
player_chat: Has the player send the specified message
play_sound: Plays a specific sound to the player
open_inventory: Causes the player to open a random or specified inventory (Different than show_screen)
launch_entity: Allows launching all entities (or just the player) into the air
kick_player: Kicks the player
give_item: Gives the player a specified item
flip_player: Flips the player 180 degrees
drop_item: Drops the item in either the player's main hand or the player's off hand
Adding custom actions:
Custom actions are added by extending the "AbstractAction" class and using the "ActionType" annotation
Code (Text):
@ActionType(value = "name_of_action")
public class CustomAction extends AbstractAction {
public CustomAction(JavaPlugin plugin) {
super(plugin);
}
// Optional loadFromJson to load from the action's json object
@Override
public void execute(Player target, String[] args) {
// Execution code is here
}
}
Registering custom actions:
Code (Text):
ActionRegistry.registerActionsFromPackage("com.example.package", javaPluginInstance);
Using actions:
Code (Text):
ActionObjectManager manager = new ActionObjectManager();
JsonObject jsonObject = JsonParser.parseReader(new FileReader(file)).getAsJsonObject();
ActionObject newAction = new ActionObject(plugin, jsonObject);
manager.addActionObject(newAction);
ActionObject action = manager.getEnabledActionObjectByName(args[1]);
action.execute(target, Arrays.copyOfRange(args, 2, args.length));