|
| 1 | +from endstone.command import Command, CommandSender |
| 2 | +from endstone.plugin import Plugin |
| 3 | + |
| 4 | +from endstone_example.python_command import PythonCommandExecutor |
| 5 | + |
| 6 | + |
| 7 | +class ExamplePlugin(Plugin): |
| 8 | + name = "PythonExamplePlugin" |
| 9 | + version = "0.3.0" |
| 10 | + description = "Python example plugin for Endstone servers" |
| 11 | + authors = ["Endstone Developers <hello@endstone.dev>"] |
| 12 | + website = "https://github.com/EndstoneMC/python-example-plugin" |
| 13 | + load = "POSTWORLD" |
| 14 | + |
| 15 | + commands = { |
| 16 | + "python": { |
| 17 | + "description": "Zen of python", |
| 18 | + "usages": ["/python"], |
| 19 | + "aliases": ["py"], |
| 20 | + "permissions": ["python_example.command.python"], |
| 21 | + }, |
| 22 | + "test": { |
| 23 | + "description": "This is a test command from python", |
| 24 | + "usages": [ |
| 25 | + "/test", |
| 26 | + "/test [value: int]", |
| 27 | + "/test [value: float]", |
| 28 | + ], |
| 29 | + "permissions": ["python_example.command.test"], |
| 30 | + }, |
| 31 | + } |
| 32 | + |
| 33 | + permissions = { |
| 34 | + "python_example.command": { |
| 35 | + "description": "Allow users to use all commands provided by this plugin.", |
| 36 | + "default": True, |
| 37 | + "children": {"python_example.command.python": True, "python_example.command.test": True}, |
| 38 | + }, |
| 39 | + "python_example.command.python": { |
| 40 | + "description": "Allow users to use the /python command.", |
| 41 | + "default": "op", |
| 42 | + }, |
| 43 | + "python_example.command.test": { |
| 44 | + "description": "Allow users to use the /test command.", |
| 45 | + "default": True, |
| 46 | + }, |
| 47 | + } |
| 48 | + |
| 49 | + def on_load(self) -> None: |
| 50 | + self.logger.info("on_load is called!") |
| 51 | + |
| 52 | + def on_enable(self) -> None: |
| 53 | + self.logger.info("on_enable is called!") |
| 54 | + self.get_command("python").executor = PythonCommandExecutor() |
| 55 | + |
| 56 | + def on_disable(self) -> None: |
| 57 | + self.logger.info("on_disable is called!") |
| 58 | + |
| 59 | + def on_command(self, sender: CommandSender, command: Command, args: list[str]) -> bool: |
| 60 | + # You can also handle commands here instead of setting an executor in on_enable if you prefer |
| 61 | + match command.name, args: |
| 62 | + case "test", []: |
| 63 | + # handle /test |
| 64 | + sender.send_message("Test!!") |
| 65 | + case "test", [n]: |
| 66 | + # handle /test n |
| 67 | + sender.send_message(f"Test with number: {n}!") |
| 68 | + case _, []: |
| 69 | + # handle /* (wildcard) |
| 70 | + sender.send_message(f"/{command.name} is executed from Python!") |
| 71 | + case _, *args: |
| 72 | + # handle /* args... (wildcard) |
| 73 | + sender.send_message(f"/{command.name} is executed from Python with arguments {args}!") |
| 74 | + |
| 75 | + return True |
0 commit comments