-
Notifications
You must be signed in to change notification settings - Fork 2
/
command.py
36 lines (25 loc) · 1.21 KB
/
command.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from org.bukkit.command import Command
from org.bukkit import Bukkit
from org.bukkit.plugin import SimplePluginManager
from org.bukkit.command import Command
from bukkit_helpers import chatcolor
_commandmap_field = SimplePluginManager.getDeclaredField("commandMap")
_commandmap_field.setAccessible(True)
commandmap = _commandmap_field.get(Bukkit.getPluginManager())
class PythonCommand(Command):
def __init__(self, func, name, description, usage, aliases, tab_complete):
super(Command, self).__init__(name, description, usage, aliases)
self.func = func
self.tab_complete = tab_complete
def execute(self, sender, label, args):
if not self.testPermission(sender):
return
if self.func(sender, label, args) is False:
sender.sendMessage(chatcolor.RED + "Usage: " + self.getUsage().replace("<command>", label))
def tabComplete(self, sender, alias, args):
if self.tab_complete:
return self.tab_complete(sender, alias, args)
def register_command(func, command_name, tab_complete=None, description="", usage="/<command>", permission=None, aliases=[]):
command = PythonCommand(func, command_name, description, usage, aliases, tab_complete)
command.setPermission(permission)
commandmap.register("/", command)