diff --git a/chatalias.py b/chatalias.py index 5560c5f..449a68f 100644 --- a/chatalias.py +++ b/chatalias.py @@ -55,12 +55,6 @@ permission_FINFO = "utils.alias.finfo" # CODE # ######## -# OnEnable -enabled = helpers_version in helpers_versions -if not enabled: - error = colorify("&6Incompatible versions detected (&chelpers.py&6)") - - def safe_open_json(uuid): if not os.path.exists("plugins/redstoner-utils.py.dir/files/aliases"): os.makedirs("plugins/redstoner-utils.py.dir/files/aliases") @@ -179,8 +173,9 @@ def add(sender, args): msg(sender, "&cCould not create alias: Max_limit reached!") return True args = [args[0]] + [" ".join(args[1:])] - data[str(uid(sender))][str(args[0])] = args[1] - save_data(uid(sender)) + if not add_alias_data(uid(sender), str(args[0]), args[1]): + msg(sender, colorify("&c") + "Could not add this alias because it would cause some sequences to be replaced multiple times", usecolor = False) + return True msg(sender, colorify("&7Alias: ") + args[0] + colorify("&7 -> " + args[1] + colorify("&7 was succesfully created!")), usecolor=sender.hasPermission("essentials.chat.color")) return True @@ -196,6 +191,8 @@ def radd(sender, args): if args[3].lower() == "false": plugin_header(target, "Alias") msg(target, "&cPlayer " + sender_name + " &cis creating an alias for you!") + elif args[3].lower() != "true": + args[2] += " " + args[3] if not sender.hasPermission(permission_ALL) and len(data[uid(sender)]) >= int(get_permission_content(target, permission_AMOUNT)): msg(sender, "&cCould not create alias: Max_limit reached!") if args[3].lower() == "false": @@ -203,14 +200,37 @@ def radd(sender, args): return True if len(args) == 3: args += ["true"] - data[str(uid(target))][str(args[1])] = str(args[2]) - save_data(uid(target)) + if not add_alias_data(uid(target), str(args[1]), str(args[2])): + message = colorify("&c") + "Could not add this alias because it would cause some sequences to be replaced multiple times" + msg(sender, message) + if args[3].lower() == "false": + msg(target, message) + return True msg(sender, colorify("&7Alias: ") + args[1] + colorify("&7 -> " + args[2] + colorify("&7 was succesfully created!")), usecolor=target.hasPermission("essentials.chat.color")) if args[3].lower() == "false": msg(target, colorify("&7Alias: ") + args[1] + colorify("&7 -> " + args[2] + colorify("&7 was succesfully created!")), usecolor=target.hasPermission("essentials.chat.color")) return True +def add_alias_data(puuid, aliased, new_alias): + prior = data[puuid] + + # prevent 2 -> 3 if there is 1 -> 2 + if aliased not in prior: + for alias in prior.values(): + if aliased in alias: + return False + + # prevent 1 -> 2 if there is 2 -> 3 + for sequence in prior: + if sequence in new_alias: + return False + + prior[aliased] = new_alias + save_data(puuid) + return True + + def remove(sender, args): plugin_header(sender, "Alias") try: @@ -256,7 +276,7 @@ def rlist_alias(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 len(args) == 1: @@ -264,11 +284,9 @@ def rlist_alias(sender, args): msg(sender, "Player " + args[0] + " has following aliases (" + str(len(data[uid(target)])) + " in total):") if args[1].lower() == "false": plugin_header(target, "Alias") - msg(target, "&cPlayer " + sender_name + " &cis listing your aliases (" + str(len(data[uid(target)])) + " in total):") + msg(target, "&cPlayer " + sender_name + " &cis listing your aliases") for word, alias in data[str(uid(target))].items(): msg(sender, colorify("&7") + word + colorify("&7 -> ") + alias, usecolor=target.hasPermission("essentials.chat.color")) - if args[1].lower() == "false": - msg(target, colorify("&7") + word + colorify("&7 -> ") + alias, usecolor=target.hasPermission("essentials.chat.color")) return True @@ -323,16 +341,34 @@ def save_data_thread(uuid): # Subcommands: subcommands = { "help": help, + "?": help, "add": add, "remove": remove, + "del": remove, + "delete": remove, "player": remote, + "remote": remote, "list": list_alias } remotes = { "add": radd, "remove": rremove, + "del": rremove, + "delete": rremove, "list": rlist_alias, } -Status API Training Shop Blog About -© 2016 GitHub, Inc. Terms Privacy Security Contact Help \ No newline at end of file + +# OnModuleLoad + +enabled = helpers_version in helpers_versions +if not enabled: + error = colorify("&6Incompatible versions detected (&chelpers.py&6)") +for player in server.getOnlinePlayers(): + if enabled: + t = threading.Thread(target=load_data, args=(uid(player), )) + t.daemon = True + t.start() + else: + if player.hasPermission(permission_FINFO): + disabled_fallback(player)