Skip to content

Commit 30176a3

Browse files
committed
feat: add /kickme command
1 parent 4895ea3 commit 30176a3

File tree

1 file changed

+31
-14
lines changed

1 file changed

+31
-14
lines changed

src/endstone_example/example_plugin.py

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,22 @@ class ExamplePlugin(Plugin):
3333
],
3434
"permissions": ["python_example.command.test"],
3535
},
36+
"kickme": {
37+
"description": "Ask the server to kick you with a custom message",
38+
"usages": ["/kickme [reason: message]"],
39+
"permissions": ["python_example.command.kickme"],
40+
},
3641
}
3742

3843
permissions = {
3944
"python_example.command": {
4045
"description": "Allow users to use all commands provided by this plugin.",
4146
"default": True,
42-
"children": {"python_example.command.python": True, "python_example.command.test": True},
47+
"children": {
48+
"python_example.command.python": True,
49+
"python_example.command.test": True,
50+
"python_example.command.kickme": True,
51+
},
4352
},
4453
"python_example.command.python": {
4554
"description": "Allow users to use the /python command.",
@@ -49,6 +58,10 @@ class ExamplePlugin(Plugin):
4958
"description": "Allow users to use the /test command.",
5059
"default": True,
5160
},
61+
"python_example.command.kickme": {
62+
"description": "Allow users to use the /kickme command.",
63+
"default": True,
64+
},
5265
}
5366

5467
def on_load(self) -> None:
@@ -69,19 +82,23 @@ def on_disable(self) -> None:
6982

7083
def on_command(self, sender: CommandSender, command: Command, args: list[str]) -> bool:
7184
# You can also handle commands here instead of setting an executor in on_enable if you prefer
72-
match command.name, args:
73-
case "test", []:
74-
# handle /test
75-
sender.send_message("Test!!")
76-
case "test", [n]:
77-
# handle /test n
78-
sender.send_message(f"Test with number: {n}!")
79-
case _, []:
80-
# handle /* (wildcard)
81-
sender.send_message(f"/{command.name} is executed from Python!")
82-
case _, *args:
83-
# handle /* args... (wildcard)
84-
sender.send_message(f"/{command.name} is executed from Python with arguments {args}!")
85+
86+
match command.name:
87+
case "test":
88+
if len(args) > 0:
89+
sender.send_message(f"Test with number: {args[0]}!")
90+
else:
91+
sender.send_message("Test!!")
92+
case "kickme":
93+
player = sender.as_player()
94+
if player is None:
95+
sender.send_error_message("You must be a player to execute this command.")
96+
return False
97+
98+
if len(args) > 0:
99+
player.kick(args[0])
100+
else:
101+
player.kick("You asked for it!")
85102

86103
return True
87104

0 commit comments

Comments
 (0)