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