> For the complete documentation index, see [llms.txt](https://walksy.gitbook.io/walksylib-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://walksy.gitbook.io/walksylib-docs/walksylibservermanager/developers/installing-the-api.md).

# Installing the API

Other plugins can control WalksyLib mods through WalksyLibControl's API. For example, a pvp plugin can apply a rule set when a player joins an arena.

{% stepper %}
{% step %}

## Add the dependency

```groovy
repositories {
    maven { url = "https://api.modrinth.com/maven" }
}

dependencies {
    compileOnly "maven.modrinth:walksylibcontrol:<version>"
}
```

{% endstep %}

{% step %}

## Depend on it in `plugin.yml`

```yaml
depend: [WalksyLibControl]
```

Use `softdepend: [WalksyLibControl]` if your plugin should also work without it. In that case, check that it's enabled before using the API.
{% endstep %}

{% step %}

## Get `ModControl`

```java
import main.walksy.lib.control.api.ModControl;

ModControl control = ModControl.get();
```

`ModControl` is the entry point for everything:

| Method                 | Returns                                                |
| ---------------------- | ------------------------------------------------------ |
| `global()`             | The global rule set (applies to everyone)              |
| `ruleSet(id)`          | The rule set with this ID, created if it doesn't exist |
| `findRuleSet(id)`      | `Optional` of an existing rule set                     |
| `ruleSets()`           | All rule sets                                          |
| `deleteRuleSet(id)`    | Deletes a rule set, returns whether it existed         |
| `player(Player)`       | The player's `PlayerControl`                           |
| `client(Player)`       | `Optional<ClientInfo>` with the player's client report |
| `hasWalksyLib(Player)` | Whether the player runs WalksyLib                      |
| {% endstep %}          |                                                        |
| {% endstepper %}       |                                                        |

## Restrictions

A `Restriction` is a mod, or a mod feature:

```java
Restriction whole = Restriction.mod("shieldstatus");
Restriction feature = Restriction.feature("shieldstatus", "other-player-shields");
Restriction parsed = Restriction.parse("shieldstatus:other-player-shields");
```

IDs are lower-cased automatically. Invalid IDs throw `IllegalArgumentException`. Check them first with `Restriction.isValidId(id)`.

Most methods also have `String` overloads, such as `disable(modId)` and `disableFeature(modId, feature)`, so you rarely need to build `Restriction`s yourself.

## Quick example

```java
public void onArenaJoin(Player player) {
    ModControl.get().player(player).apply("uhc");
}

public void onArenaLeave(Player player) {
    ModControl.get().player(player).remove("uhc");
}
```
