Implementation of Mojang's brigadier in Python
Project description
brigadier.py
Implementation of Mojang/brigadier in Python.
Installing
Requires Python 3.7 or higher
# For Windows
py -3 -m pip install brigadier.py
# For linux or macOS
python3 -m pip install brigadier.py
Examples
Registering a simple command
from brigadier import CommandDispatcher
from brigadier.builder import literal, argument
from brigadier.arguments import integer
def pow2_command(ctx):
number = ctx.get_argument("number")
return pow(number, 2)
def pow_command(ctx):
number = ctx.get_argument("number")
power = ctx.get_argument("power")
return pow(number, power)
# Register the command
dispatcher = CommandDispatcher()
dispatcher.register(
literal("pow2").then(
argument("number", integer).executes(power_command)
)
)
dispatcher.register(
literal("pow").then(
argument("number", integer).then(
argument("power", integer).executes(pow_command)
)
)
)
# Execute the command
print(dispatcher.execute("pow2 2", {}))
print(dispatcher.execute("pow 3 4", {}))
Using a custom argument type
from brigadier import CommandDispatcher
from brigadier.builder import literal, argument
from brigadier.suggestion import empty_suggestion
class Vector3:
def parse(self, reader):
self.x = reader.read_int()
reader.skip()
self.y = reader.read_int()
reader.skip()
self.z = reader.read_int()
return self
def list_suggestions(self, builder):
return empty_suggestion()
def get_examples(self):
return ["2 3 1", "0 5 0"]
def teleport_command(ctx):
location = ctx.get_argument("location")
x = location.x
y = location.y
z = location.z
print(f"You've been teleported to {x}, {y}, {z}")
return 1
dispatcher = CommandDispatcher()
dispatcher.register(
literal("teleport").then(
argument("location", Vector3()).executes(teleport_command)
)
)
dispatcher.execute("teleport 24 51 -632", {})
License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
brigadier.py-1.1.0.tar.gz
(17.1 kB
view details)
Built Distribution
File details
Details for the file brigadier.py-1.1.0.tar.gz
.
File metadata
- Download URL: brigadier.py-1.1.0.tar.gz
- Upload date:
- Size: 17.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8d0df5b588307ba7377ec2c981304a622dc941844eae3e8a2ebbbc1e6bed9593 |
|
MD5 | 3cfe19a0a05ebe5ae417edd3bd6e5d7a |
|
BLAKE2b-256 | 48d4dbebf31464e099c22c8465438674783294b39fe7c6a3b56f1ca3c4351895 |
File details
Details for the file brigadier.py-1.1.0-py3-none-any.whl
.
File metadata
- Download URL: brigadier.py-1.1.0-py3-none-any.whl
- Upload date:
- Size: 27.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 092f22dd68f33edd7410a4425f22f778390451ef2333270f01ee5c5e8cc529ea |
|
MD5 | fe802fa94324f62fe98f6a0273bb570d |
|
BLAKE2b-256 | 59a490f4ecb20225a64e50a28d6dde794e0388d6728f6982805f937590659cc6 |