From fa1d5e900d13c546ddf069849e14eadafdc79377 Mon Sep 17 00:00:00 2001 From: Pepich Date: Mon, 11 Apr 2016 16:59:42 +0200 Subject: [PATCH 1/3] Fixed player subcommand, removed debug outputs --- chatalias.py | 41 +++++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/chatalias.py b/chatalias.py index a73decb..530cc90 100644 --- a/chatalias.py +++ b/chatalias.py @@ -11,6 +11,7 @@ ############################################ import os +import mysqlhack import org.bukkit as bukkit from org.bukkit import * from helpers import * @@ -26,6 +27,7 @@ error = colorify("&cUnspecified error") commands_per_page = 5 global_aliases = {"./":"/"} data = {} +# DON'T SET THIS TO TRUE! MySQL requestst are NOT async yet! (And for some reason it doesn't want to store any data ._.) use_mysql = False # Permissions: @@ -83,7 +85,6 @@ def on_alias_command(sender, cmd, label, args): return True return subcommands[args[0].lower()](sender, args[1:]) except: - print(trace()) return subcommands["help"](sender, "1") @@ -132,7 +133,7 @@ def on_join(event): if event.getPlayer().hasPermission(permission_FINFO): disabled_fallback(event.getPlayer()) except: - print(trace()) + return @hook.event("player.AsyncPlayerChatEvent", "high") @@ -154,7 +155,7 @@ def on_player_chat(event): else: event.setMessage(event.getMessage().replace(alias, value)) except: - print(trace()) + return def hasPerm(player, permission): return (player.hasPermission(permission)) or (player.hasPermission(permission_ALL)) @@ -186,8 +187,13 @@ def add(sender, args): def radd(sender, args): - args = [args[0:1]] + [" ".join([args[2:len(args)-2]])] + [args[len(args)-1]] plugin_header(sender, "Alias") + args = args[0:2] + [" ".join(args[2:len(args)-1])] + [args[len(args)-1]] + if is_player(sender): + sender_name = colorify(sender.getDisplayName()) + else: + sender_name = colorify("&6Console") + target = get_player(args[0]) if args[3].lower() == "false": plugin_header(target, "Alias") msg(target, "&cPlayer " + sender_name + " &cis creating an alias for you!") @@ -196,12 +202,6 @@ def radd(sender, args): if args[3].lower() == "false": msg(target, "&cCould not create alias: Max_limit reached!") return True - - target = get_player(args[0]) - if is_player(sender): - sender_name = colorify(sender.getDisplayName) - else: - sender_name = colorify("&6Console") if len(args) == 3: args += ["true"] data[str(uid(target))][str(args[1])] = str(args[2]) @@ -226,11 +226,10 @@ def rremove(sender, args): plugin_header(sender, "Alias") target = get_player(args[0]) if is_player(sender): - sender_name = colorify(sender.getDisplayName) + sender_name = colorify(sender.getDisplayName()) else: sender_name = colorify("&6Console") if args[2].lower() == "false": - print("WTF") plugin_header(target, "Alias") msg(target, "&cPlayer " + sender_name + " &cis removing an alias for you!") try: @@ -276,13 +275,18 @@ def rlist_alias(sender, args): def remote(sender, args): try: - return remotes[args[1].lower()](sender, [args[0]] + [args[2:]]) + return remotes[args[1].lower()](sender, [args[0]] + args[2:]) except: - print(trace()) return subcommands["help"](sender, ["2"]) - def load_data(uuid): + load_data_thread(uuid) +# t = threading.Thread(target=load_data_thread, args=(uuid)) +# t.daemon = True +# t.start() + + +def load_data_thread(uuid): if use_mysql: conn = zxJDBC.connect(mysql_database, mysql_user, mysql_pass, "com.mysql.jdbc.Driver") curs = conn.cursor() @@ -295,8 +299,13 @@ def load_data(uuid): else: data[uuid] = safe_open_json(uuid) - def save_data(uuid): + save_data_thread(uuid) +# t = threading.Thread(target=save_data_thread, args=(uuid)) +# t.daemon = True +# t.start() + +def save_data_thread(uuid): if use_mysql: conn = zxJDBC.connect(mysql_database, mysql_user, mysql_pass, "com.mysql.jdbc.Driver") curs = conn.cursor() -- 2.45.2 From 48251e1e520a2f3ad42d30a2ab8e11fd09abee19 Mon Sep 17 00:00:00 2001 From: Pepich Date: Tue, 12 Apr 2016 14:52:16 +0200 Subject: [PATCH 2/3] Cleanup, adding debug outputs back, removing empty try/catch phrases --- chatalias.py | 50 ++++++++++++++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 22 deletions(-) diff --git a/chatalias.py b/chatalias.py index 530cc90..de18f78 100644 --- a/chatalias.py +++ b/chatalias.py @@ -27,7 +27,7 @@ error = colorify("&cUnspecified error") commands_per_page = 5 global_aliases = {"./":"/"} data = {} -# DON'T SET THIS TO TRUE! MySQL requestst are NOT async yet! (And for some reason it doesn't want to store any data ._.) +# DON'T SET THIS TO TRUE! MySQL requestst are NOT ASYNC yet! (And for some reason it doesn't want to store any data ._.) use_mysql = False # Permissions: @@ -55,6 +55,7 @@ permission_FINFO = "utils.alias.finfo" # CODE # ######## +# OnEnable enabled = helpers_version in helpers_versions if not enabled: error = colorify("&6Incompatible versions detected (&chelpers.py&6)") @@ -124,16 +125,13 @@ def help(sender, args): @hook.event("player.PlayerJoinEvent", "high") def on_join(event): - try: - if enabled: - t = threading.Thread(target=load_data, args=(uid(event.getPlayer()), )) - t.daemon = True - t.start() - else: - if event.getPlayer().hasPermission(permission_FINFO): - disabled_fallback(event.getPlayer()) - except: - return + if enabled: + t = threading.Thread(target=load_data, args=(uid(event.getPlayer()), )) + t.daemon = True + t.start() + else: + if event.getPlayer().hasPermission(permission_FINFO): + disabled_fallback(event.getPlayer()) @hook.event("player.AsyncPlayerChatEvent", "high") @@ -155,7 +153,8 @@ def on_player_chat(event): else: event.setMessage(event.getMessage().replace(alias, value)) except: - return + print(trace()) + def hasPerm(player, permission): return (player.hasPermission(permission)) or (player.hasPermission(permission_ALL)) @@ -279,12 +278,15 @@ def remote(sender, args): except: return subcommands["help"](sender, ["2"]) -def load_data(uuid): - load_data_thread(uuid) -# t = threading.Thread(target=load_data_thread, args=(uuid)) -# t.daemon = True -# t.start() +def load_data(uuid): + try: + load_data_thread(uuid) +# t = threading.Thread(target=load_data_thread, args=(uuid)) +# t.daemon = True +# t.start() + except: + print(trace()) def load_data_thread(uuid): if use_mysql: @@ -299,11 +301,15 @@ def load_data_thread(uuid): else: data[uuid] = safe_open_json(uuid) + def save_data(uuid): - save_data_thread(uuid) -# t = threading.Thread(target=save_data_thread, args=(uuid)) -# t.daemon = True -# t.start() + try: + save_data_thread(uuid) +# t = threading.Thread(target=save_data_thread, args=(uuid)) +# t.daemon = True +# t.start() + except: + print(trace()) def save_data_thread(uuid): if use_mysql: @@ -313,8 +319,8 @@ def save_data_thread(uuid): else: save_json_file("aliases/" + uuid, data[uuid]) -# Subcommands: +# Subcommands: subcommands = { "help": help, "add": add, -- 2.45.2 From 07039b3d1601b67056044c45a7ee88d4e0062c97 Mon Sep 17 00:00:00 2001 From: Dico Date: Wed, 25 May 2016 01:37:01 +0200 Subject: [PATCH 3/3] Fix command given for next help page in chatalias.py --- chatalias.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chatalias.py b/chatalias.py index de18f78..da1a657 100644 --- a/chatalias.py +++ b/chatalias.py @@ -119,7 +119,7 @@ def help(sender, args): for message in to_display: msg(sender, message) if page+1 < pages: - msg(sender, colorify("&6To display the next page, type &c/help " + str(page+2))) + msg(sender, colorify("&6To display the next page, type &c/alias help " + str(page+2))) return True -- 2.45.2