Skip to content

Command Custom (0.7.0)

Yao Chung Hu edited this page Jul 5, 2022 · 12 revisions

Command Custom

Prerequisites

Introduction

With the new release of 0.7.0 and later, we can finally store values and this will allow us to create a lot of new custom commands.

Let's take a look at what new features were included.

  • New database commands and compute commands
  • New function processor
  • A simple implementation of the Permission API that you can use alongside LuckPerms
  • The child component now has a list of unsuccessfulActions which allows running those actions if the command fails
  • The child component also has 2 new fields for successfulMessage and unsuccessfulMessage which allows for messages depending on if the command failed or not

Let's get started.

Recapping a format with new features

  {
    "commandMode": "COMMAND_CUSTOM", // Required | Custom Command Format
    "customCommand": {
      "parent": "hello", // Required | Parent command 
      "type": "literal", // Redundant | Type of command
      "permission": 0, // Optional | If LuckPerms is not installed will fallback to these permission level
      "message": "hello parent commnad", // Optional | Executor gets a local message if parent command is executed
      "children": [ // Optional | List of sub commands
        {
          "child": "name", // Required | Sub command placeholder
          "type": "argument", // Required | Type of sub command literal or argument
          "argumentType": "minecraft:word", // Required | Argument Type
          "permission": 0, // Optional | If LuckPerms is not installed will fallback to these permission level
          "message": "Hello name sub command", // Optional | Executor gets a local message if child command is executed
          "children": [ // Optional | List of sub commands
            // Child component
          ],
          "actions": [ // Optional | List of actions
            {
              "command": "say Hello {{name}}", // Optional | Command to execute will be processed to map variables and process functions
              "commandType": "SERVER", // Optional | Required if command is present
              "message": "We tried said hello {{name}}", // Optional | Executor gets a local message
              "successfulMessage": "We said hello {{name}}",  // Optional | Executor gets a local message if command success
              "unsuccessfulMessage": "We failed to say hello {{name}} somehow", // Optional | Executor gets a local message if command fails
              "requireSuccess": true, // Optional | Default: false |  If set to true prevents the execution of the next action if this action command fails
              "sleep": "1000", // Optional | Default: None
              "unsuccesfulActions": [ // Optional | This set of actions gets executed if command fails
                // Action Component
              ]
            }
          ]
        }
      ],
      "actions": [
        // Action Component
      ]
    }
  }

Database and Compute commands

Database

We are using a key-value database. You can read more about key-value databases on Wikipedia.

  • commandaliases database put <key> <value>
    • Stores entry of a key-value into the database of the world directory, there is no user output
  • commandaliases database delete <key>
    • Deletes entry of a key from the database of the world directory, there is no user output
  • commandaliases database contains <key>
    • Returns success internally if the database of the world directory contains a key, there is no user output
  • commandaliases database get <key>
    • Prints key if the key exists with the database of world directory, meant for debugging purposes

Compute

These commands are simple mathematical operations for storing them in the database.

  • commandaliases compute equals <value1> <value2>
    • Returns 1(all successful commands will return 1 by default this is how requireSuccess works by checking the the command was executed successfully) internally if value1 is equal to value2
  • commandaliases compute addition <key> <value1> <value2>
    • Stores the value of value1 + value2 into database of key
  • commandaliases compute subtraction <key> <value1> <value2>
    • Stores the value of value1 - value2 into database of key
  • commandaliases compute multiplication <key> <value1> <value2>
    • Stores the value of value1 * value2 into database of key
  • commandaliases compute division <key> <value1> <value2>
    • Stores the value of value1 / value2 into database of key
  • commandaliases compute modulus <key> <value1> <value2>
    • Stores the value of value1 % value2 into database of key

Function Processor

As of 0.7.0

  • $executor_name()
    • Returns the player name of the command executor.
  • $get_database_value(key)
    • Returns the value of key from the database if it exists. Example: commandaliases database put hello.key world.value then say $get_database_value(hello.key) and it will say in chat world.value
  • $get_dimension(player)
    • Returns the dimension registry key of the player in the argument. Example: say $get_dimension(jeb_) and it will say in chat minecraft:overworld
  • $get_pos_x(player)
    • Returns player position x in the argument. Example: say $get_pos_x(jeb_) and it will say in chat 10.25
  • $get_pos_y(player)
    • Returns player position y in the argument. Example: say $get_pos_y(jeb_) and it will say in chat 64.5
  • $get_pos_z(player)
    • Returns player position z in the argument. Example: say $get_pos_z(jeb_) and it will say in chat -10.25
  • $get_yaw(player)
    • Returns player yaw in the argument. Example: say $get_yaw(jeb_) and it will say in chat 0
  • $get_pitch(player)
    • Returns player pitch in the argument. Example: say $get_pitch(jeb_) and it will say in chat 90
  • $get_block_pos_x(player)
    • Returns player block position x in the argument. Example: say $get_block_pos_x(jeb_) and it will say in chat 10
  • $get_block_pos_y(player)
    • Returns player block position y in the argument. Example: say $get_block_pos_y(jeb_) and it will say in chat 64
  • $get_block_pos_z(player)
    • Returns player block position z in the argument. Example: say $get_block_pos_z(jeb_) and it will say in chat -10

Permission API

When you have LuckPerms installed the default permission key will be <parent_name>.<child_name_if_any>.<child_name_of_child_if_any> recursively.

TLDR Video

Wiki Explanation and Home commands

IMAGE ALT TEXT

TPA commands

IMAGE ALT TEXT

Gist for commands

Clone this wiki locally