diff options
author | Dico200 <dico.karssiens@gmail.com> | 2015-05-14 04:10:04 +0200 |
---|---|---|
committer | Dico200 <dico.karssiens@gmail.com> | 2015-05-14 04:10:04 +0200 |
commit | dd1f0b8356408bc2ac01652365d9ecaacfec31ba (patch) | |
tree | a6bf44932d2501aa03cbed7c6bec62516451f79f /basecommands.py | |
parent | 4599ae89e9e261130d18668147b1ce289777fc68 (diff) |
Steps towards even easier command handling.
See issue #4
Diffstat (limited to 'basecommands.py')
-rw-r--r-- | basecommands.py | 49 |
1 files changed, 47 insertions, 2 deletions
diff --git a/basecommands.py b/basecommands.py index 5e23bcc..9517485 100644 --- a/basecommands.py +++ b/basecommands.py @@ -19,7 +19,6 @@ def helpMsg(sender, cmd, description, usage, aliases, permission): return help_msg - def simplecommand(cmd, aliases = [], usage = "[args...]", @@ -60,6 +59,52 @@ def simplecommand(cmd, return getHelp(sender) if not checkargs(sender, args, amin, amax): return None - return function(sender, command, label, args) + + try: + return function(sender, command, label, args) + except CommandException, e: + return e.message + except Exception, e: + error(e.message, trace()) + return "&cAn internal error occurred while attempting to perform this command" + return call return decorator + + +class CommandException(Exception): + pass + + +class Validate(): + @staticmethod + def notNone(obj, msg): + if obj == null: + raise Exception(msg) + + @staticmethod + def isPlayer(sender): + if not is_player(sender): + raise CommandException("&cThat command can only be run by players") + + @staticmethod + def isConsole(sender): + if is_player(sender): + raise CommandException("&cThat command can only be run from the console") + + @staticmethod + def isAuthorized(sender, permission): + if not sender.hasPermission(permission): + raise CommandException("&cYou do not have permission to use that command") + + @staticmethod + def isTrue(obj, msg): + if obj != True: + raise CommandException(msg) + + @staticmethod + def checkArgs(sender, args, amin, amax): + if not checkargs(sender, args, amin, amax): + raise CommandException("") + + |