# Voting Unit

Voting Unit, later only ***VU***, is a core of the resource. You can also name it **Voting Situation**. Players place votes about these units.

{% hint style="info" %}
Plugin offers **7** predefined VU and you can easily extend or reduce this set.
{% endhint %}

## Creating VotingUnit in the configuration file <a href="#creating-votingunit-in-the-configuration-file" id="creating-votingunit-in-the-configuration-file"></a>

Configuration file `VotingUnits.yml` is located at main folder of the resource.

**Types**

* `GLOBAL` - Only one round can run at one moment.
* `LOCAL` - In each world, round can run independently on round in another world.

> At **Local** type, there is able to run more than one voting round at the same time. E.g. *Day* for Survival world and *Night* for SkyBlock world.

{% hint style="warning" %}
**Global** and **Local** round cannot run at the same time!
{% endhint %}

**Categories**

* `WEATHER` - Allows to change weather using built-in methods. Time change animation is available at this category.
* `CUSTOM` - VotingUnit that fits right for your server.

**PauseCategory**

VotingUnit can be assigned to pause category, if so, pause is applied only to group of VotingUnits with the same category, while another voting round can be started.

More info at <https://wiki.innouniq.com/plugins/voting/configuration/options#pause>

**Immediate initiator's vote**

This flag indicates, that player, initiator, places vote immediately at starting a round.

**Price**

We mentioned above that you can chagre players for placing a vote or starting a voting round.\
Price for *placing a vote* can be different like for *starting* a voting round.

**Required Participation**

Value in percentage range.

* Allowed range: `0 - 100`
* Default value: `100`

Required percentage of participated online players to stop and evaluate the current voting round.

Example: If there are 10 players online and the value is set to 80, then 8 players are required to participate in the current voting round.

**World Restriction**

You can restrict in which world will **not** be able to start voting round.

**Result Commands**

After the end of the round, you can specify commands, which will be invoked.

**Types of commands**

* `Global` - Commands are performed only once. Especially used at custom units.
* `Participant` - Commands are performed for each player separately
  * `Success` - Commands performed when round success
    * `All` - Commands executed for all players. (At Local round, under 'All players' is meant players in that world.)
    * `Voters` - Commands executed only for players which placed a *positive* vote
  * `Failure` - Commands performed when round fails
    * `All` - Commands executed for all players. (At Local round, under 'All players' is meant players in that world.)
    * `Voters` - Commands executed only for players which placed a *negative* vote

**Example of commands**

```yaml
Result:
  Command:
    Global:
      - "kick {target}"
    Participant:
      Success:
        All:
          - "tell {player} Round has succeed."
        Voter:
          - "karma give {player} 5"
      Failure:
        All:
          - "tell {player} Round has failed."
        Voter:
          - "karma take {player} 5"
```

> These commands do not have to be used all. You can choose only that types, which fits your expectations.\
> **E.g.,** If you want to use only global commands, you do not have to use Participant section!

***

### **Weather Category**

At first, let's clarify basic information.

* **1 Minecraft Day = 24000 Ticks = 20 Minutes**
* Tick **0** reprecents **06:00** and tick **13000** reprecents **19:00**
* More information about daylight cycle is avaialable [**here**](https://minecraft.gamepedia.com/Daylight_cycle#24-hour_Minecraft_day)

When round with weather category success, these values are applied:

```yaml
Result:
  Time: <Value> #Value indicates time in a day. Range <0;23999>
  Rain: <Flag> #Flag indicates rainy weather
  Lighting: <Flag> #Flag indicates stormy weather
  Duration: <Value> #Value indicates how long takes result.
```

> These **4** values can be used separately.\
> **E.g.,** In one VU you will use only *Time* value and in another VU, you will use *Rain*, *Lighting* and *Duration* value.

**Example of Weather VU**

```yaml
DAY: #Key of the unit. Used in intern methods, localizations file.
  Name: Day #Readable name of the unit. Used in tab-completer.
  Type: GLOBAL
  Category: WEATHER
  PauseCategory: DAY_LIGHT #Optional
  ImmediateInitiatorVote:
    Active: true
  Price:
    Start: 0
    Vote: 0
  RequiredParticipation: 100
  Restriction:
    World: [ ]
  Result:
    Time: 0 #Sets time to 6 o'clock
```

{% hint style="warning" %}
Do not forget to create new records into localization file!

Path `Alias.Unit.Weather.<VU-Key>`
{% endhint %}

### **Custom Category**

Via this category you can create own situations, which perfectly fits your server.

There is better to explain the whole mechanism with an example. We will create VU which **kicks** player from the server, if round success.

> This category works with parameters typed in command located behind *Name* of the VU.

We need to define **2** parameters. First parameters represents whom to kick and second is a reason.

> Our final command for start this round is **/Voting Kick \<Player> \<Reason>**

**Types of parameters**

* `PLAYER` - Accepts only online player as a parameter.
* `WORLD` - Accepts only name of world.
* `PAYLOAD` - Accepts more than one word. Sentence.
* `WORD` - Accepts one word.
* `INTEGER` - Accepts only Integers from allowed range.
* `DOUBLE` - Accepts only Doubles from allowed range.
* `BOOLEAN` - Accepts only predicate. `true/false`

Our first parameter is named **player**, or target for better meaning.

> Each parameter has to have its name. This name is used as a replacement at localization file and at executed commands after the end of the round.

There can occur situation, you want to **protect** yourself as an initiator of the round or you want to **protect** some players before kicking out from the server at this situation. The whole list can be specified in **Resistance** section.

> The same mechanism is at parameter of type **World**! Except initiator's protection.

Our second parameter is the **reason**, why we want to kick the player.\
Here is the best opportunnity to use type **PAYLOAD**. It allows us to read the whole sentence until the end of input line.

{% hint style="warning" %}
Type **PAYLOAD** has to be the last parameter of the sequence!
{% endhint %}

If you want to make this parameter optional, no problem, set flag Optional to true.

> Then, you need to define **default value**, which will be used instead of missing parameter.

{% hint style="warning" %}
Missing variable **Optional** in the configuration file means that parameter is **Required**!
{% endhint %}

At Number(Integer/Double) Parameters we can restrict allowed range of values.

> Use `MinValue` or `MaxValue` to specify range.

> Also, you can allow only limited values using list of strings `AllowedValueList`.

> Cou can predefine values using list of strings `PredefinedValueList`. These values will be offered at tab completing.

At the end we need to specify command, which will be executed after successful round.

Also, we need to map our values from parameters to command. It's simple, each parameter has name as mentoined above.

We create replacement. It starts with prefix **p\_**. After that prefix we will write **name** of the parameter.

> If we had name of the parameter **player** our final replacement is **p\_player**.\
> The same for the second parameter.

**Our final command**

`kick {p_player} {p_reason}`

**Our created VU for kicking the player**

```yaml
KICK:
  Name: Kick
  Type: GLOBAL
  Category: CUSTOM
  ImmediateInitiatorVote:
    Active: true
  Price:
    Start: 0
    Vote: 0
  RequiredParticipation: 100
  Restriction:
    World: [ ]
  Parameter:
    Target:
      Name: player
      Type: PLAYER
      Resistance:
        Initiator:
          Active: true
        Collection:
          - "player_name"
    Reason:
      Name: reason
      Type: PAYLOAD
      Optional: true
      DefaultValue: "Unknown"
      PredefinedValueList:
        - Spamming
        - Inappropriate behavior
        - Hacking
  Result:
    Command:
      Global:
        - "kick {p_player} {p_reason}"
```

{% hint style="warning" %}
Do not forget to create new records into localization file!
{% endhint %}
