From 4027cf7268c09205a67d2e0234a7f94dd93925d1 Mon Sep 17 00:00:00 2001 From: Dico200 Date: Thu, 26 Nov 2015 17:41:47 +0100 Subject: Fix most of wrapper_command --- main.py | 13 +++++++------ wrapper_command.py | 38 ++++++++++++++++++++++---------------- wrapper_player.py | 14 +++++++------- 3 files changed, 36 insertions(+), 29 deletions(-) diff --git a/main.py b/main.py index 08ab182..5e2e0a0 100644 --- a/main.py +++ b/main.py @@ -11,12 +11,10 @@ sys.path += ['', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-linux2', '/usr/l try: # Library that adds a bunch of re-usable methods which are used in nearly all other modules from helpers import * - from wrapper import * + #from wrapper import * except: - print("[RedstonerUtils] ERROR: Failed to import Wrapper:") - print(print_traceback()) - - + error("[RedstonerUtils] ERROR: Failed to import Wrapper:") + error(print_traceback()) @hook.enable def on_enable(): @@ -34,7 +32,10 @@ info("Loading RedstonerUtils...") # Import all modules, in this order -shared["load_modules"] = ["test", "login"] +shared["load_modules"] = [ + "test", +# "login", +] shared["modules"] = {} for module in shared["load_modules"]: diff --git a/wrapper_command.py b/wrapper_command.py index 41c7932..d630a5d 100644 --- a/wrapper_command.py +++ b/wrapper_command.py @@ -1,8 +1,6 @@ from wrapper_player import * from helpers import * -root_commands = Command_dict() # {"command": command_object} - class Command(object): """ # Documentation to come.s @@ -20,18 +18,17 @@ class Command(object): def __init__(self, command, parent = None, - aliases = (), + aliases = tuple(), permission = None, description = "Description", - type = Command.SENDER_ANY, - no_arg_action = Command.ACTION_IGNORE, - help_request_action = Command.ACTION_IGNORE, - arguments = (), - ): + type = 0, + no_arg_action = 3, + help_request_action = 3, + arguments = tuple(), + ): self.command = command.lower() self.aliases = tuple(alias.lower() for alias in aliases) - self.permission = self.command if permission == None else permission self.description = description self.type = type self.no_arg_action = no_arg_action @@ -52,7 +49,8 @@ class Command(object): prev_arg = arg_info - # ---- Add self to parent sub_commands ---- + # ---- Add self to parent sub_commands and set permission node ---- + perm_builder = "utils" if self.parent == None: root_commands[self.command] = self else: @@ -69,6 +67,8 @@ class Command(object): except KeyError as e: raise Argument_exception("Error occurred while setting up command hierarchy: " + e.message + "\n" + trace()) + perm_builder += "." + (permission if permission else command).lower() + def __call__(self, handler): """ # To clarify: This function is called when you 'call' an instance of a class. @@ -77,8 +77,8 @@ class Command(object): """ self.handler = handler - if parent == None: - @hook.command(self.command, self.aliases) + if self.parent == None: + @hook.command(self.command, aliases = self.aliases) def run(sender, command, label, args): """ # This function will take care of prefixing and colouring of messages in the future. @@ -88,6 +88,8 @@ class Command(object): message = self.execute(sender, command, label, args) except Command_exception as e: message = e.message + except Argument_exception as e: + message = e.message except Exception: error(trace()) return True @@ -101,14 +103,14 @@ class Command(object): try: return self.sub_commands[args[0].lower()].execute(sender, command, label, args[1:]) except (KeyError, IndexError): - self.execute_checks(sender, command, label, args) + return self.execute_checks(sender, command, label, args) def execute_checks(self, sender, command, label, args): # ---- Check sender type ---- if is_player(sender): Validate.is_true(self.type != Command.SENDER_CONSOLE, "That command can only be used by the console") - sender = py_players[sender] + #sender = py_players.__getattr__(sender) else: Validate.is_true(self.type != Command.SENDER_PLAYER, "That command can only be used by players") @@ -134,7 +136,8 @@ class Command(object): # ---- Set up passed arguments, prepare for handler call ---- scape = Command_scape(args, self.arguments, command, label) if is_player(sender): - sender = py_players[sender] + #sender = py_players[sender] + pass return self.handler(sender, self, scape) # @Command("hello") def on_hello_command(sender, command, scape/args) @@ -234,6 +237,8 @@ class Command_dict(dict): return cmd_obj raise KeyError("Subcommand '%s' was not found" % alias) +root_commands = Command_dict() # {"command": command_object} + class Command_exception(Exception): def __init__(self, message): @@ -284,7 +289,8 @@ class Command_scape(list): target = server.getPlayer(given_arg) if target == None: raise Argument_exception("The %s has to be an online player" % arg_info.name) - self.append(py_players[target]) + self.append(target) + #self.append(py_players[target]) elif arg_type == Argument.OFFLINE_PLAYER: try: diff --git a/wrapper_player.py b/wrapper_player.py index 07eca8b..f69d4be 100644 --- a/wrapper_player.py +++ b/wrapper_player.py @@ -3,7 +3,7 @@ import mysqlhack from mysql_utils import * from util_events import fire_event from thread_utils import * -from players_secret import * +#from players_secret import * from datetime import datetime from com.ziclix.python.sql import zxJDBC from traceback import format_exc as print_traceback @@ -113,7 +113,6 @@ py_players = Py_players() @async(daemon=True) def fetch_player(player): - properties = [] keys = [] for key, value in player.props.iteritems(): @@ -163,9 +162,10 @@ blocked_events = ["block.BlockBreakEvent", "block.BlockPlaceEvent", "player.Play for event in blocked_events: @hook.event(event,"highest") def on_blocked_event(event): - player = py_players[event.getPlayer()] - if player.logging_in: - event.setCancelled(True) + """player = py_players[event.getPlayer()] + if player.logging_in: + event.setCancelled(True)""" + pass @@ -174,11 +174,11 @@ def on_join(event): try: player = py_player(event.getPlayer()) except: - print(print_traceback()) + error(print_traceback()) time.sleep(10) py_players.append(player) player.msg("Your input will be blocked for a short while") - fetch_player(player) + #fetch_player(player) @hook.event("player.PlayerQuitEvent","highest") -- cgit v1.2.3