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