Fix most of wrapper_command

This commit is contained in:
Dico200
2015-11-26 17:41:47 +01:00
parent c76f8373ef
commit 4027cf7268
3 changed files with 36 additions and 29 deletions

13
main.py
View File

@@ -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"]:

View File

@@ -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:

View File

@@ -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()]
"""player = py_players[event.getPlayer()]
if player.logging_in:
event.setCancelled(True)
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")