# Protection

# 1 Rules explained

You can use [regions](https://kingdomcraft.be/wiki/premium/regions) to protect your area. Every region allows you to setup multiple rules, these rules decide who can or can’t do something. You can also add rules to a kingdom, these rules will apply to all regions claimed by that kingdom.


:::info
**NB.** Most of the time you want to allow or deny an action by a player based on their **relation** with your kingdom. Therefore it is necessary that a region is **claimed by a kingdom**.

:::


:::info
**NB.** Don’t forget to disable the protection of **WorldGuard** with `/rg flags add <region> build allow`.

:::


# 2 Rules

## 2.1 Rule format

This is the format of rules:

```javascript
<type> <state> <relation> (<target>)
```

[type](https://kingdomcraft.be/wiki/premium/protection#rule-types): This is the rule type (building, teleporting, opening chests...)

[state](https://kingdomcraft.be/wiki/premium/protection#state): This can be any of **ALLOW** or **DENY**.

[relation](https://kingdomcraft.be/wiki/premium/protection#relations): This decides who the rule applies to (kingdom members, enemies, allies...)

[target](https://kingdomcraft.be/wiki/premium/protection#target): This is an optional argument for some rule types (e.g. block type for the BUILD rule)


## 2.2 Rule types

* **BUILD**: Place and break blocks
* **INTERACT**: Interact with blocks (door, button, gate, armor stand...)
* **CONTAINER**: Open containers (chest, beacon, barrel...)
* **NEUTRAL_MOBS**: Kill or ride on neutral animals
* **HOSTILE_MOBS**: Kill monsters
* **PVP**: Fight with players
* **DAMAGE_OWNER**: Fight with members of this region’s kingdom
* **PICKUP_ITEMS**: Pick up items from the ground
* **TELEPORT**: Teleport to or from this region
* **FLY**: Fly in this region
* **DESTROY**: More destructive breaking like TNT cannons
* **COMMAND**: Execute (specific) commands
* **ENTRANCE**: Enter this region
* **MINING_REGION**: Break respawing blocks in this [Mining Region](https://kingdomcraft.be/wiki/premium/miningregion).


## 2.3 Rule state

This allows (**ALLOW**) or denies (**DENY**) actions defined by the rule type. In case of an overlap, rules with the ALLOW state will have priority.


## 2.4 Rule relation

This decides for whom the rule applies. A relation with a higher priority will be checked first (the following list is sorted from low to high).

* **ANY**: Everyone
* **NEUTRAL**: Neutral kingdoms or players without a kingdom
* **ALLY**: Allies
* **ENEMY**: Enemies
* **KINGDOM**: Kingdom members
* **VISITOR**: Visitors ([more info](https://kingdomcraft.be/wiki/premium/visitor))
* **ATTACKER**: Enemy team during an event ([more info](https://kingdomcraft.be/wiki/premium/events))
* **DEFENDER**: Team members during an event ([more info](https://kingdomcraft.be/wiki/premium/events))
* **ANARCHY**: Members of a kingdom in anarchy ([more info](https://kingdomcraft.be/wiki/premium/events))


You can also add more relations that are applicable if the player has the following permission: `kingdom.regions.protection.relation.NAME`. 

```javascript
protection:
  permission-relations:
  - ROLEPLAY_CHARACTER
  - DONATOR
```

This allows you to e.g. give donators access to a protected region.


## 2.5 Target

### 2.5.1 Blocks

This is applicable to the rule types `BUILD`,`INTERACT` and `CONTAINER`. If you enter the type name of a block, this rule only applies if the action happens on a block of this type.

```javascript
/k rules add BUILD DENY ENEMY CHEST
```

### 1.5.2 Commands

This is applicable to the rule types `COMMAND`. If you enter a command without the `/`, this rule only applies if that command is executed.

```javascript
/k rules add COMMAND DENY ENEMY tp
```

You can also add commands with subcommands such as  `k warp`. Extra aliases such as `tp`,  `teleport`, `essentials:tp`... etc. will automatically be detected in most cases. However, this only applies to the root command, for subcommands you must add rules for all possible aliases.

## 1.6 Examples

If nobody is allowed to build except members of the kingdom

```yaml
BUILD DENY ANY
BUILD ALLOW KINGDOM
```

If nobody is allowed to place blocks of TNT.

```yaml
BUILD DENY ANY TNT
```

If enemies are not allowed to build. Except during an event, if they are attacking, they are allowed to place water.

```yaml
BUILD DENY ENEMY
BUILD ALLOW ATTACKER WATER
```

If nobody is allowed to open chests, barrels, … except kingdom members and allies.

```yaml
CONTAINER DENY ANY
CONTAINER ALLOW ALLY,KINGDOM
```

If attackers are not allowed to build during an event except water but is may not flow.

```yaml
BUILD DENY ATTACKER
BUILD ALLOW ATTACKER WATER
BUILD DENY ATTACKER WATER_FLOW
```

If only members of your kingdom are allowed to execute `/k spawn` and aliases such as `/kdc spawn`.

```yaml
COMMAND DENY ANY k spawn
COMMAND ALLOW KINGDOM k spawn
```


## 1.7 Admin bypass

In admin mode you can bypass protection of a specific type if you have the following permission:

```javascript
kingdom.admin.regions.protection.REGELTYPE
```


# 2 Kingdom rule commands

Kingdom rules are applicable to **all** regions of this kingdom.

## 2.1 Add rule

You can also use `ALL` for the `<kingdom>` argument to add this rule to all existing kingdoms.

| /k rules add <rule> | kingdom.rules.add.<type><br>kingdom.rules.add.all |
|---------------------|------------------------------------------------|
| /k rules add <kingdom> <rule> | kingdom.rules.add.other                        |


:::tip
**HINT:** You can add rules to the **template** kingdom, these will be copied to newly created kingdoms.

:::


## 2.2 Copy rules

| /k rules copy <from-kingdom> <to-kingdom> | kingdom.rules.copy |
|-------------------------------------------|--------------------|


## 2.3 Remove rules

You can also use `ALL` for the `<kingdom>` argument to remove this rule from all existing kingdoms.

| /k rules remove <rule> | kingdom.rules.remove.<type><br>kingdom.rules.remove.all |
|------------------------|------------------------------------------------------|
| /k rules remove <kingdom> <rule> | kingdom.rules.remove.other                           |


## 2.4 Remove all rules

| /k rules clear | kingdom.rules.clear |
|----------------|---------------------|
| /k rules clear <kingdom> | kingdom.rules.clear.other |


## 2.5 List rules

| /k rules list | kingdom.rules.list |
|---------------|--------------------|
| /k rules list <kingdom> | kingdom.rules.list.other |


# 3 Region rules


:::tip
It is **recommended** to use the commands above to add rules to kingdoms instead of regions.

:::

## 3.1 Add rules

| /k regions rules add <region> <rule> | kingdom.regions.rules.add |
|--------------------------------------|---------------------------|


## 3.2 Copy rules

| /k regions rules copy <from-region> <to-region> | kingdom.regions.rules.copy |
|-------------------------------------------------|----------------------------|


## 3.3 Remove rules

| /k regions rules remove <region> <rule> | kingdom.regions.rules.remove |
|-----------------------------------------|------------------------------|


## 3.4 Remove all rules

| /k regions rules clear <region> | kingdom.regions.rules.clear |
|---------------------------------|-----------------------------|


## 3.5 List rules

| /k regions rules list <region> | kingdom.regions.rules.list |
|--------------------------------|----------------------------|

---

**Documents**

- [Getting started](https://wiki.guflimc.com/s/kingdomcraft-premium/doc/getting-started-DMncr30uhG)
- [Sidebar](https://wiki.guflimc.com/s/kingdomcraft-premium/doc/sidebar-wJTtc1tlZN)
- [Tablist & Nametags](https://wiki.guflimc.com/s/kingdomcraft-premium/doc/tablist-nametags-25sz4eqfq9)
- [Kingdom selector](https://wiki.guflimc.com/s/kingdomcraft-premium/doc/kingdom-selector-ebmkGONWFM)
- [Regions](https://wiki.guflimc.com/s/kingdomcraft-premium/doc/regions-rhNS90NSIy)
- [Claims](https://wiki.guflimc.com/s/kingdomcraft-premium/doc/claims-jABwG0Svr8)
- [Power](https://wiki.guflimc.com/s/kingdomcraft-premium/doc/power-70rbbejmW6)
- [Protection](https://wiki.guflimc.com/s/kingdomcraft-premium/doc/protection-rcHugSsHwR)
- [Visitors](https://wiki.guflimc.com/s/kingdomcraft-premium/doc/visitors-aQMHQCji0M)
- [Modifiers](https://wiki.guflimc.com/s/kingdomcraft-premium/doc/modifiers-NIQaQ4ARa6)
- [Resource regions](https://wiki.guflimc.com/s/kingdomcraft-premium/doc/resource-regions-7K2ig0IKqh)
- [Dynmap/Bluemap](https://wiki.guflimc.com/s/kingdomcraft-premium/doc/dynmapbluemap-7cM99zhpRW)
- [Channel mutes](https://wiki.guflimc.com/s/kingdomcraft-premium/doc/channel-mutes-FsmJfHOIYs)
- [Placeholders](https://wiki.guflimc.com/s/kingdomcraft-premium/doc/placeholders-9gQgGoKMAB)
- [Warps](https://wiki.guflimc.com/s/kingdomcraft-premium/doc/warps-h3YmTSSZ1C)
- [Elections](https://wiki.guflimc.com/s/kingdomcraft-premium/doc/elections-IXZCGc3Cuq)
- [Admin mode](https://wiki.guflimc.com/s/kingdomcraft-premium/doc/admin-mode-ALQQSdUm9H)
- [All permissions](https://wiki.guflimc.com/s/kingdomcraft-premium/doc/all-permissions-WdNzOBeqCA)
- [Events - NL](https://wiki.guflimc.com/s/kingdomcraft-premium/doc/events-nl-mOImzefI5b)