Skip to content

Commit 8428eba

Browse files
committed
feat: add papi command
1 parent 85bb72c commit 8428eba

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed

endstone_papi/plugin.py

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,28 @@
1+
from endstone import Player
12
from endstone.plugin import Plugin, ServicePriority
2-
3+
from endstone.command import Command, CommandSender
34
from .pypapi import PlaceholderAPI
45

56

67
class PlaceholderAPIPlugin(Plugin):
78
api_version = "0.6"
89

910
commands = {
11+
"papi": {
12+
"description": "PlaceholderAPI command",
13+
"usage": [
14+
"/papi parse <str: text> [player: player]",
15+
"/papi list",
16+
],
17+
"permission": "papi.command.papi",
18+
}
19+
}
1020

21+
permissions = {
22+
"papi.command.papi": {
23+
"description": "Allows users to use the /papi command",
24+
"default": "op",
25+
}
1126
}
1227

1328
def __init__(self):
@@ -19,3 +34,23 @@ def on_load(self):
1934

2035
def on_disable(self):
2136
self.server.service_manager.unregister_all(self)
37+
38+
def on_command(self, sender: CommandSender, command: Command, args: list[str]) -> bool:
39+
match args[0]:
40+
case "parse":
41+
text: str = args[1]
42+
player: Player | None = None
43+
if len(args) == 3:
44+
player_name: str = args[2]
45+
player = self.server.get_player(player_name)
46+
if player is None:
47+
sender.send_error_message(f"Could not find player {player_name}!")
48+
return False
49+
50+
sender.send_message(self._api.set_placeholder(player, text))
51+
case "list":
52+
sender.send_message("Available placeholders:")
53+
for identifier in self._api.get_registered_identifiers():
54+
sender.send_message(f"- {identifier}")
55+
56+
return True

0 commit comments

Comments
 (0)