Module graph

Source
Expand description

§Command graph implementation

This is the core of the command system. It is a graph of CommandNodes that are connected by the CommandEdgeType. The graph is used to determine what command to run when a command is entered. The graph is also used to generate the command tree that is sent to the client.

§The graph is a directed graph with 3 types of nodes:

  • Root node (NodeData::Root) - This is the root of the graph. It is used to connect all the other nodes to the graph. It is always present and there should only be one.
  • Literal node (NodeData::Literal) - This is a literal part of a command. It is a string that must be matched exactly by the client to trigger the validity of the node. For example, the command /teleport would have a literal node with the name teleport which is a child of the root node.
  • Argument node (NodeData::Argument) - This is a node that represents an argument in a command. It is a string that is matched by the client and checked by the server. For example, the command /teleport 0 0 0 would have 1 argument node with the name “destination:location” and the parser Parser::Vec3 which is a child of the literal node with the name teleport.
§and 2 types of edges:
  • Child edge (CommandEdgeType::Child) - This is an edge that connects a parent node to a child node. It is used to determine what nodes are valid children of a parent node. for example, the literal node with the name teleport would have a child edge to the argument node with the name “destination:location”. This means that the argument node is a valid child of the literal node.
  • Redirect edge (CommandEdgeType::Redirect) - This edge is special. It is used to redirect the client to another node. For example, the literal node with the name tp would have a Redirect edge to the literal node with the name teleport. This means that if the client enters the command /tp the server will redirect the client to the literal node with the name teleport. Making the command /tp functionally equivalent to /teleport.

§Cool Example Graph For Possible Implementation Of Teleport Command (made with graphviz)

                                              ┌────────────────────────────────┐
                                              │              Root              │ ─┐
                                              └────────────────────────────────┘  │
                                                │                                 │
                                                │ Child                           │
                                                ▼                                 │
                                              ┌────────────────────────────────┐  │
                                              │          Literal: tp           │  │
                                              └────────────────────────────────┘  │
                                                │                                 │
                                                │ Redirect                        │ Child
                                                ▼                                 ▼
┌──────────────────────────────────┐  Child   ┌──────────────────────────────────────────────────────────────────────────────┐
│  Argument: <destination:entity>  │ ◀─────── │                              Literal: teleport                               │
└──────────────────────────────────┘          └──────────────────────────────────────────────────────────────────────────────┘
                                                │                                           │
                                                │ Child                                     │ Child
                                                ▼                                           ▼
┌──────────────────────────────────┐  Child   ┌────────────────────────────────┐          ┌──────────────────────────────────┐
│ Argument: <destination:location> │ ◀─────── │   Argument: <target:entity>    │          │ Argument: <destination:location> │
└──────────────────────────────────┘          └────────────────────────────────┘          └──────────────────────────────────┘
                                                │
                                                │ Child
                                                ▼
                                              ┌────────────────────────────────┐
                                              │ Argument: <destination:entity> │
                                              └────────────────────────────────┘

If you want a cool graph of your own command graph you can use the display trait on the CommandGraph struct. Then you can use a tool like Graphviz Online to look at the graph.

Structs§

CommandGraph
This struct is used to store the command graph. (see module level docs for more info)
CommandGraphBuilder
Ergonomic builder pattern for adding executables, literals and arguments to a command graph. See the derive macro for a more ergonomic way of doing this for a basic command with an enum or struct.
CommandNode
Data for the nodes in the graph (see module level docs for more info)

Enums§

CommandEdgeType