Installation command
!!MCDR plugin install dict_command_registration
Author
Repository
Synced at
...
Last update
...
Latest version
Total downloads
1347
Back to catalogue
Dict Command Registration
Register your command with a python dict.
MCDReforged implements a command system like brigadier, but it is too difficult to use and not intuitive enough. When the tree becomes large, maintainability and readability become extremely poor. Then you have to split it into multiple child nodes, but when the child nodes become large you need to keep splitting them and end up in an infinite loop.
This plugin provides an API that allows you to register MCDR command trees with python dict, which is also a tree structure - a more intuitive structure, isn't it? It takes the python dict you provide, generates the MCDR Command Node, then register it. You do not have to bother with the huge code tree, just maintain your dict tree.
Incidentally, it can register the help message for you.
Quick Start
Let's register this example command in MCDR doc:
Literal('!!email'). \
then(Literal('list')). \
then(Literal('remove'). \
then(Integer('email_id'))
). \
then(Literal('send'). \
then(Text('player'). \
then(GreedyText('message'))
)
)
Write the command dict and call register method.
from dict_command_registration import NodeType, register
command = {
"name": "!!email",
"children": [
{
"name": "list"
},
{
"name": "remove",
"children": [
{
"name": "email_id",
"type": NodeType.INTEGER
}
]
},
{
"name": "send",
"children": [
{
"name": "player",
"type": NodeType.TEXT,
"children": [
{
"name": "email_id",
"type": NodeType.GREEDY_TEXT
}
]
}
]
}
]
}
def on_load(server, prev_module):
register(server, command)
All done!
If you want register help message together:
register(server, command, "Email command")
Concepts
Node
In this plugin, Node
means a dict which contains data of a MCDR
command node.
See also: Node
API Reference
Exceptions
MissingRequiredAttribute
Raise when missing required attribute in Node.
NodeType
MCDR Origin Command Nodes.
Key | Class |
---|---|
LITERAL | Literal |
NUMBER | Number |
INTEGER | Integer |
FLOAT | Float |
TEXT | Text |
QUOTABLE_TEXT | QuotableText |
GREEDY_TEXT | GreedyText |
BOOLEAN | Boolean |
ENUMERATION | Enumeration |
Node (class)
Parse a Node (dict), and can cast to MCDR node.
init(data: Dict[str, Any])
Accept a dict.
literal: Union[str, Iterable[str]]
Get literal string or Iterable.
to_mcdr_node() -> Union[Literal, ArgumentNode]
To MCDR Node.
Node (dict)
name
Name of the node.
- Type:
str
This value is required.
node
MCDR node if you want use exist node.
- Type: Literal or ArgumentNode
literal
Text of a literal node.
- Type:
str
orIterable[str]
- Default: name value
You have to set this value if you want use multiple literals (Iterable).
type
Type of this node.
- Type: NodeType or ArgumentNode
- Default: NodeType.LITERAL
enumeration
Value of Enumeration node.
- Type:
Dict[str, Any]
- Default:
[]
args
Args to create Node if using customize node.
- Type:
List[Any]
- Default:
[]
kwargs
Kwargs to create Node if using customize node.
- Type:
Dict[str, Any]
- Default:
{}
runs
Set the callback function of this node.
- Type:
Callable
See also: AbstractNode.runs().
requires
Set the requirement tester callback of the node.
- Type:
Union[Callable, List[Callable]]
See also: AbstractNode.requires().
redirects
Redirect all further child nodes command parsing to another given node.
- Type: AbstractNode
See also: AbstractNode.redirects().
suggests
Set the provider for command suggestions of this node.
- Type:
Callable
See also: AbstractNode.suggests().
on_error
When a command error occurs, the given will invoke the given handler to handle with the error.
- Type:
Dict[str, Any]
See also: AbstractNode.on_error().
Accept three keys in the dict, which are three arguments listed in the doc.
on_child_error
Similar to
on_error()
, but it gets triggered only when the node receives a command error from one of the node’s direct or indirect child.
- Type:
Dict[str, Any]
See also: AbstractNode.on_child_error().
Accept three keys in the dict, which are three arguments listed in the doc.
children
Children of this node.
- Type:
List[Dict[str, Any]]
- Default:
[]
You can put node in the array to add a child node.
register
Method to register command.
Params:
- PluginServerInterface server: the PluginServerInterface instance of your plugin, to ensure that this command is registered by your plugin.
- dict command: Command, please find more information in the document.
- str help_message: Provide a string value if you want register
- int help_message_permission: The minimum permission level to see this help message. See also in MCDReforged document.
README source: src/dict_command_registration/readme.md