-
-
Notifications
You must be signed in to change notification settings - Fork 4
4. Using the Action API
Foxikle edited this page Sep 13, 2023
·
2 revisions
The Action API is what sets CustomNPCs apart from the competition.
To get started, pick out the action type you want to create. A full list of action types can be found here. For this guide, we will be using SEND_MESSAGE. The arguments for SEND_MESSAGE are the words of the message. So lets first start by creating an list of the words in our message.
List<String> args = new ArrayList<>(List.of("&aI'm", "a", "message!"));
Since this tutorial doesn't cover conditions we won't be using them. The third parameter determines if all conditions should be met. The fourth parameter is the list of serialized conditions.
Action action = new Action(ActionType.SEND_MESSAGE, args, Conditional.SelectionMode.ONE, new ArrayList<>());
To add the action to our NPC we can use the NPC#setActions
method.
npc.setActions(Collections.singleton(action));
You have now added an action to an NPC.