Action Manager
View the Action Manager for CIYFLib.
We've created an easy yet modular action management system allowing server owners to configure certain actions easily via code - useful when players are redeeming 'rewards' and would rather broadcast a message directly than require another plugin to do so.
1. Configuring your manager.
You'll first want to create your manager object like so.
ActionManager actionManager = new ActionManager();
2. Adding the default actions.
Then you can optionally add the default actions if you so desire.
actionManager.addDefaults();
These will add the following actions:
[CONSOLE] <console command>.
[PLAYER] <player command>.
[BROADCAST] <message to everyone>.
[MESSAGE] <message to target player>.
[CHAT] <make the player send a message>.
[CLOSE] <close the players inventory>.
You may use %player% to get the players username for these.
3. Creating custom actions.
You can create actions by specifing its ID, alongside the code you wish to execute for this particular action. In our example, "sendmessage" will correlate to [SENDMESSAGE] for our player actions.
actionManager.addAction("sendmessage", (player, data) -> Bukkit.dispatchCommand(Bukkit.getConsoleSender(), data));
4. Executing your actions.
In the below example, we've created a list of various actions we wish to execute and then ran our action manager on them.
List<String> someActions = Arrays.asList(
"[console] tell %player% You clicked a " + swordType + " sword!",
"[chat] I love my new sword! :o"
);
actionManager.runActions(player, someActions);
It's THAT easy!
Last updated