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.
|
- 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.
|
- min_args: The least arguments for the command.
|
||||||
- max_args: You guessed it right. Defaults to infinity (-1).
|
- 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 ***
|
*** 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).
|
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.
|
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.
|
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()
|
cmd_name = cmd_name.lower()
|
||||||
if not permission:
|
if not permission:
|
||||||
permission = "utils." + cmd_name
|
permission = "utils." + cmd_name
|
||||||
if not usage:
|
|
||||||
usage = "[args...]"
|
|
||||||
if not description:
|
if not description:
|
||||||
description = "Handles " + cmd_name
|
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"
|
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):
|
if not sender.hasPermission(permission):
|
||||||
return "&cYou do not have permission to use this command"
|
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):
|
if not checkargs(sender, args, min_args, max_args):
|
||||||
return None
|
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__
|
return __call_func__
|
||||||
|
|
||||||
@@ -298,7 +301,7 @@ def simplecommand(cmd_name, aliases = [], permission = None, usage = None, descr
|
|||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
help_msg = "&aInformation about command /%s:\n &9%s" % (cmd_name, description.replace("\n", "\n "))
|
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:
|
if aliases:
|
||||||
help_msg += ("\n&6Aliases: " + "".join([(alias + ", ") for alias in aliases]))[:-2]
|
help_msg += ("\n&6Aliases: " + "".join([(alias + ", ") for alias in aliases]))[:-2]
|
||||||
return help_msg
|
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")
|
msg(player, "&6You can use /back if you &nreally&6 want to go back")
|
||||||
player.teleport(player.getWorld().getSpawnLocation())
|
player.teleport(player.getWorld().getSpawnLocation())
|
||||||
|
|
||||||
|
"""
|
||||||
@hook.command("sudo")
|
@hook.command("sudo")
|
||||||
def on_sudo_command(sender, command, label, args):
|
def on_sudo_command(sender, command, label, args):
|
||||||
"""
|
"
|
||||||
/sudo
|
/sudo
|
||||||
execute command/chat *as* a player/console
|
execute command/chat *as* a player/console
|
||||||
"""
|
"
|
||||||
if sender.hasPermission("utils.sudo"):
|
if sender.hasPermission("utils.sudo"):
|
||||||
if not checkargs(sender, args, 2, -1):
|
if not checkargs(sender, args, 2, -1):
|
||||||
return True
|
return True
|
||||||
@@ -65,24 +65,38 @@ def on_sudo_command(sender, command, label, args):
|
|||||||
else:
|
else:
|
||||||
noperm(sender)
|
noperm(sender)
|
||||||
return True
|
return True
|
||||||
|
"""
|
||||||
|
|
||||||
#Temporary solution for /me
|
@simplecommand("sudo",
|
||||||
@hook.command("me")
|
permission = "utils.sudo",
|
||||||
def on_me_command(sender, command, label, args):
|
usage = "<player> [cmd..]",
|
||||||
if not sender.hasPermission("essentials.me"):
|
description = "Makes <player> write [cmd..] in chat",
|
||||||
noperm(sender)
|
min_args = 2,
|
||||||
return True
|
help_noargs = True)
|
||||||
if not is_player(sender):
|
def on_sudo_command(sender, command, label, args, help_msg):
|
||||||
return True
|
target = args[0]
|
||||||
sender = server.getPlayer(sender.getName())
|
cmd = " ".join(args[1:])
|
||||||
if not checkargs(sender, args, 1, -1):
|
msg(sender, "&2[SUDO] &rRunning '&e%s&r' as &3%s" % (cmd, target))
|
||||||
return True
|
is_cmd = cmd[0] == "/"
|
||||||
msg = " ".join(args)
|
is_console = target.lower() == "server" or target.lower() == "console"
|
||||||
event = PlayerChatEvent(sender, msg)
|
if is_console:
|
||||||
server.getPluginManager().callEvent(event)
|
server.dispatchCommand(server.getConsoleSender(), cmd[1:] if is_cmd else cmd)
|
||||||
if not event.isCancelled():
|
return None
|
||||||
broadcast("essentials.me", "&7- %s &7%s %s" % (sender.getDisplayName(), u"\u21E6", msg))
|
target_player = server.getPlayer(target)
|
||||||
return True
|
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")
|
#@hook.command("gm")
|
||||||
|
|||||||
@@ -176,7 +176,7 @@ def reports_reminder(): # needs 2 args for unknown reason
|
|||||||
thread.exit()
|
thread.exit()
|
||||||
targeted_reports = get_reports(False)
|
targeted_reports = get_reports(False)
|
||||||
if len(targeted_reports) > 0:
|
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():
|
def stop_reporting():
|
||||||
|
|||||||
Reference in New Issue
Block a user