An open API service indexing awesome lists of open source software.

https://github.com/maxlego08/playeractionsapi


https://github.com/maxlego08/playeractionsapi

Last synced: 6 months ago
JSON representation

Awesome Lists containing this project

README

          

# PlayerActionsAPI

Player Actions API allows to transform a string list into a list of actions, send a message to the player, execute a
command in the console etc.
This API uses the same syntax as DeluxeMenu.

# Actions

| Action | Description |
|-------------|-----------------------------------------------------------------|
| [broadcast] | Broadcast a message to the server. |
| [chat] | Send a chat message as the player performing the action. |
| [close] | Close the viewers open menu. |
| [console] | Execute a command from the console. |
| [message] | Send a message to the menu viewer. |
| [player] | Execute a command from the player. |

You can add a tick delay to your action by using this: ````
You must set the delay after defining the action to perform.

**Example**
````yml
commands:
- "[console] give %player% diamond"
- "[message] &bAction &f&l� &fExample message"
````

# Developer

JitPack: https://jitpack.io/#Maxlego08/PlayerActionsAPI

## Maven
````xml


jitpack.io
https://jitpack.io

com.github.Maxlego08
PlayerActionsAPI
{version}

````
# Gradle
````kotlin
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
dependencies {
implementation 'com.github.Maxlego08:PlayerActionsAPI:{version}'
}
````

Do not forget to relocate the sources so as not to complicate with other plugin.

## How to use

This configuration allows to execute a command and after a delay of 10 tickets to send a message
````yml
commands:
- "[console] give %player% diamond"
- "[message] &bAction &f&l� &fExample message"
````

### Load Actions
The first step and turn your string list into an action list.
````java
public class Example extends JavaPlugin {

@Override
public void onEnable() {
List commands = getConfig().getStringList("commands");
List actions = ActionsAPI.loadActions(commands);
}
}
````

### Use actions
To use the actions just run the `execute` method. The method requires a plugin and a player.
````java
public class Example extends JavaPlugin {

public void execute(List actions, Player player) {
actions.forEach(command -> command.execute(this, player));
}
}
````

### Register actions
To use the actions just run the `registerAction(JavaPlugin plugin, ActionType type)` method. The method requires a plugin and an action type.

````java
public class CustomAction extends Action {

public CustomAction(int delay) {
super(delay);
}

@Override
protected Runnable getRunnableAction(Plugin plugin, Player player) {
return () -> player.sendMessage("Hello, " + player.getName() + "!");
}
}
````
````java
public class CustomActionType implements ActionType {

@Override
public String getIdentifier() {
return "[custom]";
}

@Override
public Class extends Action> getAction() {
return CustomAction.class;
}
}
````
````java
public class Example extends JavaPlugin {

public void onEnable() {
ActionsAPI.registerAction(this, new CustomActionType());
ActionsAPI.loadActions("[custom] ");
}
}
````

With the method `registerAction(JavaPlugin plugin, ActionType type, Class extends Action> action)` you can override any action type already registered.