Skip to content

Commit 8d2f9fd

Browse files
committed
refactor: update to new plugin api
1 parent b0d0494 commit 8d2f9fd

6 files changed

Lines changed: 80 additions & 55 deletions

File tree

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "endstone-example-plugin"
7-
version = "0.2.0"
7+
version = "0.3.0"
88
dependencies = []
99
authors = [
1010
{ name = "Endstone Developers", email = "hello@endstone.dev" },
@@ -18,4 +18,4 @@ keywords = ["endstone", "plugin"]
1818
Homepage = "https://github.com/EndstoneMC/python-example-plugin"
1919

2020
[project.entry-points."endstone"]
21-
example-plugin = "endstone_example_plugin:ExamplePlugin"
21+
example = "endstone_example:ExamplePlugin"

src/endstone_example/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from endstone_example.example_plugin import ExamplePlugin
2+
3+
__all__ = ["ExamplePlugin"]
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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
File renamed without changes.

src/endstone_example_plugin/__init__.py

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/endstone_example_plugin/example_plugin.py

Lines changed: 0 additions & 50 deletions
This file was deleted.

0 commit comments

Comments
 (0)