Replaced /sudo and /me with @simplecommand hook
Also improved simplecommand a little bit. Don't ask me why it doesn't work in its own file as I have no clue, it wasn't tracing the errors.
This commit is contained in:
15
helpers.py
15
helpers.py
@@ -239,10 +239,13 @@ Information about some arguments:
|
||||
- sender_limit: Defines what sendertype can use the command. Leave blank for console & player, 0 for player only, 1 for console only.
|
||||
- min_args: The least arguments for the command.
|
||||
- max_args: You guessed it right. Defaults to infinity (-1).
|
||||
- help_noargs: Whether to send help if no arguments are given
|
||||
- help_subcmd: Whether to send help upon '/<cmd> help'
|
||||
|
||||
*** DISCLAIMER ***
|
||||
|
||||
Your command function must take four arguments: sender, command, label, args.
|
||||
Your command function must take four arguments: sender, command, label, args and help_msg.
|
||||
help_msg is a function which can be called like 'return help_msg(sender)' to send them information about the command.
|
||||
|
||||
Your function must also not return a boolean like before, but a String instead. The string returned will be sent to the player (&-codes supported).
|
||||
Use None or "" for no message.
|
||||
@@ -252,12 +255,10 @@ Feel free to edit or give suggestions (but don't break existing commands)
|
||||
See below for an example command.
|
||||
"""
|
||||
|
||||
def simplecommand(cmd_name, aliases = [], permission = None, usage = None, description = None, sender_limit = -1, min_args = 0, max_args = -1):
|
||||
def simplecommand(cmd_name, aliases = [], permission = None, usage = "[args...]", description = None, sender_limit = -1, min_args = 0, max_args = -1, help_noargs = False, help_subcmd = False):
|
||||
cmd_name = cmd_name.lower()
|
||||
if not permission:
|
||||
permission = "utils." + cmd_name
|
||||
if not usage:
|
||||
usage = "[args...]"
|
||||
if not description:
|
||||
description = "Handles " + cmd_name
|
||||
|
||||
@@ -278,9 +279,11 @@ def simplecommand(cmd_name, aliases = [], permission = None, usage = None, descr
|
||||
return "&cThis command can only be run from the console" if isplayer else "&cThis command can only be run by players"
|
||||
if not sender.hasPermission(permission):
|
||||
return "&cYou do not have permission to use this command"
|
||||
if ((not args) and help_noargs) or (help_subcmd and args and args[0].lower() == "help"):
|
||||
return help_message(sender)
|
||||
if not checkargs(sender, args, min_args, max_args):
|
||||
return None
|
||||
return help_message(sender) if args and args[0].lower() == "help" else function(sender, command, label, args)
|
||||
return function(sender, command, label, args, help_message)
|
||||
|
||||
return __call_func__
|
||||
|
||||
@@ -298,7 +301,7 @@ def simplecommand(cmd_name, aliases = [], permission = None, usage = None, descr
|
||||
"""
|
||||
try:
|
||||
help_msg = "&aInformation about command /%s:\n &9%s" % (cmd_name, description.replace("\n", "\n "))
|
||||
help_msg += "\n\n&aSyntax: &o/%s %s" % (cmd_name, usage)
|
||||
help_msg += "\n \n&aSyntax: /%s %s" % (cmd_name, usage)
|
||||
if aliases:
|
||||
help_msg += ("\n&6Aliases: " + "".join([(alias + ", ") for alias in aliases]))[:-2]
|
||||
return help_msg
|
||||
|
||||
54
misc.py
54
misc.py
@@ -37,13 +37,13 @@ def on_join(event):
|
||||
msg(player, "&6You can use /back if you &nreally&6 want to go back")
|
||||
player.teleport(player.getWorld().getSpawnLocation())
|
||||
|
||||
|
||||
"""
|
||||
@hook.command("sudo")
|
||||
def on_sudo_command(sender, command, label, args):
|
||||
"""
|
||||
"
|
||||
/sudo
|
||||
execute command/chat *as* a player/console
|
||||
"""
|
||||
"
|
||||
if sender.hasPermission("utils.sudo"):
|
||||
if not checkargs(sender, args, 2, -1):
|
||||
return True
|
||||
@@ -65,24 +65,38 @@ def on_sudo_command(sender, command, label, args):
|
||||
else:
|
||||
noperm(sender)
|
||||
return True
|
||||
"""
|
||||
|
||||
#Temporary solution for /me
|
||||
@hook.command("me")
|
||||
def on_me_command(sender, command, label, args):
|
||||
if not sender.hasPermission("essentials.me"):
|
||||
noperm(sender)
|
||||
return True
|
||||
if not is_player(sender):
|
||||
return True
|
||||
sender = server.getPlayer(sender.getName())
|
||||
if not checkargs(sender, args, 1, -1):
|
||||
return True
|
||||
msg = " ".join(args)
|
||||
event = PlayerChatEvent(sender, msg)
|
||||
server.getPluginManager().callEvent(event)
|
||||
if not event.isCancelled():
|
||||
broadcast("essentials.me", "&7- %s &7%s %s" % (sender.getDisplayName(), u"\u21E6", msg))
|
||||
return True
|
||||
@simplecommand("sudo",
|
||||
permission = "utils.sudo",
|
||||
usage = "<player> [cmd..]",
|
||||
description = "Makes <player> write [cmd..] in chat",
|
||||
min_args = 2,
|
||||
help_noargs = True)
|
||||
def on_sudo_command(sender, command, label, args, help_msg):
|
||||
target = args[0]
|
||||
cmd = " ".join(args[1:])
|
||||
msg(sender, "&2[SUDO] &rRunning '&e%s&r' as &3%s" % (cmd, target))
|
||||
is_cmd = cmd[0] == "/"
|
||||
is_console = target.lower() == "server" or target.lower() == "console"
|
||||
if is_console:
|
||||
server.dispatchCommand(server.getConsoleSender(), cmd[1:] if is_cmd else cmd)
|
||||
return None
|
||||
target_player = server.getPlayer(target)
|
||||
if target_player:
|
||||
target_player.chat(cmd)
|
||||
return None
|
||||
return "&cPlayer %s not found!" % target
|
||||
|
||||
|
||||
@simplecommand("me",
|
||||
permission = "utils.me",
|
||||
usage = "[message..]",
|
||||
description = "Sends a message in third person",
|
||||
help_noargs = True)
|
||||
def on_me_command(sender, command, label, args, help_msg):
|
||||
broadcast("utils.me", "&7- %s &7%s %s" % (sender.getDisplayName() if isinstance(sender, Player) else "&9CONSOLE", u"\u21E6", " ".join(args)))
|
||||
return None
|
||||
|
||||
|
||||
#@hook.command("gm")
|
||||
|
||||
@@ -176,7 +176,7 @@ def reports_reminder(): # needs 2 args for unknown reason
|
||||
thread.exit()
|
||||
targeted_reports = get_reports(False)
|
||||
if len(targeted_reports) > 0:
|
||||
broadcast(rp_permission, "&2--=[ Reports ]=--\n&aThere are %s open reports!" % len(targeted_reports))
|
||||
broadcast(rp_permission, "&aThere are %s open reports!" % len(targeted_reports))
|
||||
|
||||
|
||||
def stop_reporting():
|
||||
|
||||
Reference in New Issue
Block a user