Skip to content
This repository has been archived by the owner on May 23, 2023. It is now read-only.

Add your own action

GCNT edited this page Feb 23, 2022 · 4 revisions

Overview

On this page, we will be explaining how you can create custom actions for AdditionsPlus that can eventually be used by the end-users after registration. Please make sure that you have set up the dependency correctly. You can read how here.

What is an action?

In AdditionsPlus, you can see actions as some sort of command or executable that is being performed when certain conditions are met. We currently distinguish actions in five different groups:

  • INNER: Action that can have inline arguments. This is often used for condition checking.
    • Example: [delay=50]
  • OUTER: Action that has an opening and closing tag with arguments in between.
    • Example: [math](5 * 5) / (1 / 9)[/math]
  • STANDALONE: Action that does not necessarily require a value to work, and will work without any arguments specified.
    • Example: [close]
  • NORMAL: Action that requires a value to work, and cannot have any inline arguments.
    • Example: [message]&aThis is a chat message
  • COMBINED: Action that has to be combined with a NORMAL or INNER action in order to work. This is often used for condition checking, but without the need for arguments.
    • Example: [return] or [everyone]

Each action is assigned to one of these types and requires a JavaPlugin, identifier, and a java Consumer. Think about what type of action suits your action best, because they are all handled a little differently.
Currently, it is not possible to add custom condition-checking actions.

Add a new action

For this example, you need the AdditionsAPI class as explained here.

For this example, we will be registering the custom action when your plugin is being enabled. If you wish to use this exact code, please put it in your main class. Please note that this code will fail when you run it since we are using default actions in this example, which are already registered.

@Override
public void onEnable() {
    AdditionsPlus additions = (AdditionsPlus) Bukkit.getPluginManager().getPlugin("Additions");
    // creating the action.
    // this sends the value of the action to the sender (player or console), with parsed colors. They can use [message] or [msg].
    AdditionsAction action = additions.getAPI().createCustomAction(this, "message", ActionType.NORMAL, queued -> {
        // everything in here will be executed when the action is being called.
        queued.getSender().sendMessage(queued.getColoredValue());
    }, false, "msg");

    // registering the newly created action.
    boolean registered = additions.getAPI().registerCustomAction(action);
    // check if it was actually registered. This returns false if an action with your identifier already exists.
    if (registered) Bukkit.getLogger().info("Successfully registered the AdditionsPlus action!");
    else Bukkit.getLogger().severe("Failed to register the AdditionsPlus action!");
}