State dependent modules

This page describes the setup to create state dependent modules. These modules can be used to dynamically show/hide staff items by activating other staff items. Example and use cases below.

custom module config

Each custom module can configure these 3 optional configuration parameters:

Modes config

In the modes config we can specify which states should be active when entering the mode:

modes:
  default:
    ...
    initial-item-states:
    - nightvision-off

Using this system we can create modules which are enabled only on certain states. Because state changes can be done by staff modules themselves we can create some flexible configurations.

Examples

Nightvision modules

We defined 2 modules. 1 for toggling night mode on. And one for turning it off. The first module switches the state to nightvision-on This state change makes it so that the second module will be enabled and shown inside the player's inventory. Vice versa the second module triggers the state to nightvision-off

custom-modules.yml
custom-modules:
  - name: TurnOnNightVisionModule
    enabled: true
    enabled-on-state: nightvision-off
    enable-state: nightvision-on
    disable-state: nightvision-off
    type: COMMAND_STATIC
    item: 
      type: OBSIDIAN
      name: '&bEnables night vision'
      lore: '&7Click to enable night vision'
    commands: 
       - "nightvision on"
  - name: TurnOffNightVisionModule
    enabled: true
    enabled-on-state: nightvision-on
    enable-state: nightvision-off
    disable-state: nightvision-on
    type: COMMAND_STATIC
    item: 
      type: DIAMOND
      name: '&bDisables night vision'
      lore: '&7Click to disable night vision'
    commands: 
       - "nightvision off"

Modes config

To configure the mode I did the following:

  • disable the default night vision of staff mode

  • Disable night vision when exiting staff mode

  • Set initial state to night vision off. So when you enter staff mode the obsidian block will be in your inventory

  • We defined the module on the same inventory location. Due to the state only one will be shown at a time.

modes:
  default:
    # other config here
    ...
    night-vision: false
    disable-commands:
    - command: nightvision off %staff%
    initial-item-states:
    - nightvision-off
    gui:
    - TurnOnNightVisionModule:1
    - TurnOffNightVisionModule:1

Last updated