> 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/rule-sets-api.md).

# Rule Sets API

`RuleSet` is the API equivalent of `/wlcontrol ruleset`. Every method that changes something returns the rule set, so calls can be chained. Changes apply to online players right away.

## Creating and editing

```java
RuleSet uhc = ModControl.get().ruleSet("uhc")
    .disable("customhitboxes")
    .disableFeature("shieldstatus", "other-player-shields", "Not in UHC")
    .bindWorld("uhc_1");
```

| Method                                             | Does                              |
| -------------------------------------------------- | --------------------------------- |
| `disable(modId)` / `disable(modId, reason)`        | Switch off a whole mod            |
| `disableFeature(modId, feature)` / `(..., reason)` | Switch off one feature            |
| `disable(Restriction)` / `(Restriction, reason)`   | Same, from a `Restriction`        |
| `disableAll(Collection<Restriction>)`              | Several at once                   |
| `enable(modId)` / `enableFeature(modId, feature)`  | Lift a restriction                |
| `enable(Restriction, reason)`                      | Lift it, and tell players why     |
| `clearMod(modId)`                                  | Lift the mod and all its features |
| `clear()`                                          | Lift everything in this rule set  |

Reasons can be `null` for no reason.

## Where it applies

| Method                                     | Does                                                          |
| ------------------------------------------ | ------------------------------------------------------------- |
| `bindWorld(name)` / `bindWorld(World)`     | In force for everyone in that world                           |
| `unbindWorld(name)` / `unbindWorld(World)` | Removes the world                                             |
| `bindPermission(node)`                     | In force for everyone with this permission (`null` to remove) |
| `applyTo(Player)` / `removeFrom(Player)`   | In force for one player until removed or they leave           |

The global rule set (`ModControl.get().global()`) always applies to everyone, so it can't be bound or applied.

## Reading

| Method                                     | Returns                                                    |
| ------------------------------------------ | ---------------------------------------------------------- |
| `id()`                                     | The rule set's ID                                          |
| `isGlobal()`                               | Whether this is the global rule set                        |
| `restrictions()`                           | Everything it switches off                                 |
| `contains(Restriction)`                    | Whether it switches this off                               |
| `reasonFor(Restriction)`                   | The reason, or `""`                                        |
| `worlds()` / `permission()`                | Its bindings                                               |
| `appliedPlayers()` / `isAppliedTo(Player)` | Players it was applied to directly                         |
| `isInForceFor(Player)`                     | Whether it currently applies to the player, for any reason |

## Saving

Rule sets created through the API are **temporary by default**. They live until the server stops and aren't written to `rules.yml`. This suits minigame plugins that set up their rule sets on startup.

To save one to `rules.yml`, so it can be edited with commands and survives restarts:

```java
ModControl.get().ruleSet("uhc").persistent(true);
```

`isPersistent()` tells you which kind a rule set is.
