diff options
author | Dico200 <dico.karssiens@gmail.com> | 2015-10-20 01:02:16 +0200 |
---|---|---|
committer | Dico200 <dico.karssiens@gmail.com> | 2015-10-20 01:02:16 +0200 |
commit | 5e593e0f5c692a0cd9ef001bed8f401cd2cd5221 (patch) | |
tree | baf82e7d143173d7e53f4986119a41eb468234d4 | |
parent | 0676c535ad34373740c7ca7e88874965ff9b4883 (diff) | |
parent | fbbbad1853ac7bd377fa68b374bf40caa72e7432 (diff) |
Merge branch 'dev' of https://github.com/RedstonerServer/redstoner-utils into dev
-rwxr-xr-x | chatalias.py | 106 | ||||
-rw-r--r-- | helpers.py | 25 | ||||
-rw-r--r-- | iptracker.py | 95 | ||||
-rw-r--r-- | main.py | 2 | ||||
-rw-r--r-- | mentio.py | 6 | ||||
-rw-r--r-- | misc.py | 3 |
6 files changed, 232 insertions, 5 deletions
diff --git a/chatalias.py b/chatalias.py new file mode 100755 index 0000000..69ac343 --- /dev/null +++ b/chatalias.py @@ -0,0 +1,106 @@ +# Chat Aliasing plugin by Curs3d # +################################## +# Allows users to alias words, +# so that when they send a +# message in chat, it gets +# replaced by their specified +# word. Configuration of this +# plugin is in the "gnl" +# (general) tag of the JSON +# file named "aliases". The +# file is generated if not +# present. Set values to -1 +# for "unlimited" setting. + +from helpers import * + + +def safe_open_json(): + data = open_json_file("aliases") + if data is None: + data = {"gnl":{"max_len":"35","max_entries":"10"}} + save_json_file("aliases", data) + return data + + +@hook.command("alias", usage = "/<command> [to_alias] [alias...]", desc = "Aliases words in chat") +def on_alias_command(sender, cmd, label, args): + + if not is_player(sender): + msg(sender, "Sorry, Console cannot alias words") + return True + + if not sender.hasPermission("utils.alias.allowed"): + plugin_header(recipient = sender, name = "Chat Alias") + noperm(sender) + return True + + if len(args) == 0: + plugin_header(recipient = sender, name = "Chat Alias") + msg(sender, "This is a plugin that allows you to type in chat and have words replaced by other ones automatically!") + msg(sender, "\nCommands:") + msg(sender, "/alias <word>: removes <word> from aliased words. Use * to remove all aliased words.") + msg(sender, "/alias <word> <others...>: Will change <word> to <others...> in chat") + msg(sender, "\nYour Aliases:") + data = safe_open_json() + try: + for alias, value in data[str(sender.getUniqueId())].items(): + msg(sender, "%s ==> %s" % (alias, value)) + except KeyError: + pass + return True + + elif len(args) == 1: + data = safe_open_json() + if args[0] == "*": + del data[str(sender.getUniqueId())] + save_json_file("aliases", data) + plugin_header(recipient = sender, name = "Chat Alias") + msg(sender, "ALL alias data successfuly removed!") + return True + + if data[str(sender.getUniqueId())].pop(args[0], None) is None: + plugin_header(recipient = sender, name = "Chat Alias") + msg(sender, "Could not remove: alias not present!") + return True + + save_json_file("aliases", data) + plugin_header(recipient = sender, name = "Chat Alias") + msg(sender, "Alias for %s successfuly removed" % args[0]) + return True + + elif len(args) >= 2: + data = safe_open_json() + alias = " ".join(args[1:]) + try: + if len(alias) > int(data["gnl"]["max_len"]) and int(data["gnl"]["max_len"]) >= 0: + plugin_header(recipient = sender, name = "Chat Alias") + msg(sender, "Please do not alias long words/sentences.") + return True + + if len(data[str(sender.getUniqueId())]) >= int(data["gnl"]["max_entries"]) and int(data["gnl"]["max_entries"]) >= 0: + plugin_header(recipient = sender, name = "Chat Alias") + msg(sender, "You have reached the maximum amount of alias entries! Sorry!") + return True + except KeyError: + data[str(sender.getUniqueId())] = {} + + data[str(sender.getUniqueId())][args[0]] = alias + save_json_file("aliases", data) + plugin_header(recipient = sender, name = "Chat Alias") + msg(sender, "Chat Alias %s ==> %s successfully created!" % (args[0], alias)) + return True + + else: + return False + + + +@hook.event("player.AsyncPlayerChatEvent", "High") +def on_player_chat(event): + if event.isCancelled(): + return + + data = safe_open_json() + for alias, value in data[str(event.getPlayer().getUniqueId())].items(): + event.setMessage(event.getMessage().replace(alias, value)) @@ -255,4 +255,27 @@ def toggle(player, ls, name = "Toggle", add = None): msg(player, "&a%s turned off!" % name) elif add != False: ls.append(pid) - msg(player, "&a%s turned on!" % name)
\ No newline at end of file + msg(player, "&a%s turned on!" % name) + +def send_JSON_message(playername, message): + bukkit.Bukkit.getServer().dispatchCommand(bukkit.Bukkit.getServer().getConsoleSender(), "tellraw " + playername + " " + message) + + +def isIP(tocheck): + subsets = ["","","",""] + i = 0 + for j in range(0,len(tocheck)): + if not (tocheck[j] in "0123456789."): + return False + elif tocheck[j] == ".": + i += 1 + if (i >= 4): + return False + else: + subsets[i] += tocheck[j] + if not (i == 3): + return False + for j in range(0,3): + if not ((int(subsets[j]) >= 0) & (int(subsets[j]) <= 255)): + return False + return True diff --git a/iptracker.py b/iptracker.py new file mode 100644 index 0000000..a25dcce --- /dev/null +++ b/iptracker.py @@ -0,0 +1,95 @@ +import mysqlhack +import org.bukkit as bukkit +import json +from java.util import UUID as UUID +from helpers import * +from org.bukkit import * +from traceback import format_exc as trace + +iptrack_permission = "utils.iptrack" + + +@hook.event("player.PlayerJoinEvent", "low") +def on_player_join(event): + player = event.getPlayer() + ip = player.getAddress().getHostString() + uuid = uid(player) + conn = zxJDBC.connect(mysql_database, mysql_user, mysql_pass, "com.mysql.jdbc.Driver") + curs = conn.cursor() + curs.execute("SELECT ips FROM iptrack_uuidtoips WHERE uuid = ?", (uuid, )) + results = curs.fetchall() + if len(results) == 0: + ips = [] + else: + ips = json.loads(results[0][0]) + curs.execute("SELECT uuids FROM iptrack_iptouuids WHERE ip = ?", (ip, )) + results = curs.fetchall() + if len(results) == 0: + uuids = [] + else: + uuids = json.loads(results[0][0]) + new_ip_entry = (len(ips) == 0) + new_uuid_entry = (len(uuids) == 0) + if ip not in ips: + ips.append(ip) + if new_ip_entry: + curs.execute("INSERT INTO iptrack_uuidtoips VALUES (?,?)", (uuid, json.dumps(ips), )) + else: + curs.execute("UPDATE iptrack_uuidtoips SET ips = ? WHERE uuid = ?", (uuid, json.dumps(ips), )) + if uuid not in uuids: + uuids.append(uuid) + if new_uuid_entry: + curs.execute("INSERT INTO iptrack_iptouuids VALUES (?,?)", (ip, json.dumps(uuids), )) + else: + curs.execute("UPDATE iptrack_iptouuids SET uuids = ? WHERE uuid = ?", (ip, json.dumps(uuids), )) + conn.commit() + curs.close() + conn.close() + + +@hook.command("getinfo") +def on_getinfo_command(sender, args): + if(sender.hasPermission(iptrack_permission)): + if not checkargs(sender, args, 1, 1): + return false + else: + if isIP(args[0]): + conn = zxJDBC.connect(mysql_database, mysql_user, mysql_pass, "com.mysql.jdbc.Driver") + curs = conn.cursor() + curs.execute("SELECT uuids FROM iptrack_iptouuids WHERE ip = ?", (args[0], )) + results = curs.fetchall() + curs.close() + conn.close() + if len(results) == 0: + msg(sender, "IP " + args[0] + " is not registered in the database, maybe you got a number wrong?") + else: + uuids = json.loads(results[0][0]) + msg(sender, "IP " + args[0] + " was seen with " + str(len(uuids)) + " different Accounts:") + for i in range(0, len(uuids)): + p=Bukkit.getOfflinePlayer(UUID.fromString(uuids[i])) + if is_player(sender): + send_JSON_message(sender.getName(), '["",{"text":"' + p.getName() + ' - (uuid: ' + uuids[i] + '","color":"gold","clickEvent":{"action":"run_command","value":"/getinfo ' + p.getName() + '"},"hoverEvent":{"action":"show_text","value":{"text":"","extra":[{"text":"To search for ' + p.getName() + ' in the database, simply click the name!","color":"gold"}]}}}]') + else: + msg(sender,p.getName() + " - (uuid: " + uuids[i] + ")") + else: + target = Bukkit.getOfflinePlayer(args[0]) + uuid = target.getUniqueId() + conn = zxJDBC.connect(mysql_database, mysql_user, mysql_pass, "com.mysql.jdbc.Driver") + curs = conn.cursor() + curs.execute("SELECT ips FROM iptrack_uuidtoips WHERE uuid = ?", (uuid.toString(), )) + results = curs.fetchall() + curs.close() + conn.close() + if len(results) == 0: + msg(sender, "Player " + args[0] + " is not registered in the database, maybe you misspelled the name?") + else: + ips = json.loads(results[0][0]) + msg(sender, "Player " + args[0] + " was seen with " + str(len(ips)) + " different IPs:") + for i in range(0, len(ips)): + if is_player(sender): + send_JSON_message(sender.getName(), '["",{"text":"' + ips[i] + '","color":"gold","clickEvent":{"action":"run_command","value":"/getinfo ' + ips[i] + '"},"hoverEvent":{"action":"show_text","value":{"text":"","extra":[{"text":"To search for the IP ' + ips[i] + ' in the database, simply click the IP!","color":"gold"}]}}}]') + else: + msg(sender,ips[i]) + else: + noperm(sender) + return True @@ -42,6 +42,8 @@ shared["load_modules"] = [ "blockplacemods", # Adds /calc, toggles automatic solving of Math expressions in chat "calc", + # Adds aliasing of chat words + "chatalias", # Plugin to locate laggy chunks. /lc <n> lists chunks with more than n entities "lagchunks", # Adds /report and /rp, Stores reports with time and location @@ -4,7 +4,7 @@ from traceback import format_exc as print_traceback mentions = open_json_file("mentio", {}) # contains a list of keywords for each player (uuid) -max_amount = 3 +max_amount = -1 arrow = colorify(u"&r&7\u2192&r") colors_reg = reg_compile(u"\u00A7[\\da-fk-or]") # finds color codes @@ -70,7 +70,7 @@ def add_keyword(sender, args): keywords = get_keywords(sender) new_word = stripcolors(args[1].lower()) - if len(keywords) >= max_amount: + if (len(keywords) >= max_amount) and (max_amount >= 0): msg(sender, "&cYou are already listening for %s words! Try &6/mentio del <word>" % max_amount) return True @@ -146,4 +146,4 @@ def onListenCommand(sender, command, label, args): show_help(sender) else: show_help(sender) - return True
\ No newline at end of file + return True @@ -298,7 +298,8 @@ def eval_thread(sender, code): pythoners = [ "e452e012-2c82-456d-853b-3ac8e6b581f5", # Nemes "ae795aa8-6327-408e-92ab-25c8a59f3ba1", # jomo -"305ccbd7-0589-403e-a45b-d791dcfdee7d" # PanFritz +"305ccbd7-0589-403e-a45b-d791dcfdee7d", # PanFritz +"51f2ad3c-6cc8-40ea-aa2b-f25970316921" # Dico ] @simplecommand("pyeval", |