From 782f127b23e6d320338362e9279fd6b399e3d889 Mon Sep 17 00:00:00 2001 From: NEMESIS13cz Date: Mon, 17 Aug 2015 14:44:02 +0200 Subject: [PATCH 001/217] Changed timeout in loginsecurity to 60 seconds --- loginsecurity.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/loginsecurity.py b/loginsecurity.py index 88f5fec..e96edf2 100644 --- a/loginsecurity.py +++ b/loginsecurity.py @@ -8,7 +8,7 @@ import mysqlhack from com.ziclix.python.sql import zxJDBC from java.lang import Runnable -wait_time = 30 #seconds +wait_time = 60 #seconds admin_perm = "utils.loginsecurity.admin" min_pass_length = 8 blocked_events = ["block.BlockBreakEvent", "block.BlockPlaceEvent", "player.PlayerMoveEvent","player.AsyncPlayerChatEvent"] -- 2.45.2 From e65197d3a99bf80b4ba4e44d43229b7e9e6c9da3 Mon Sep 17 00:00:00 2001 From: Evanus Date: Sun, 23 Aug 2015 20:11:30 +0100 Subject: [PATCH 002/217] Added a permission for /forcefeild help cus' viperlordx asked me to --- forcefield.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/forcefield.py b/forcefield.py index 74c728f..e17ad5d 100644 --- a/forcefield.py +++ b/forcefield.py @@ -4,6 +4,7 @@ from helpers import * from org.bukkit.util import Vector from math import sin +ff_help = "utils.forcefeild.help" ff_perm = "utils.forcefield" pass_perm = "utils.forcefield.ignore" ff_prefix = "&8[&bFF&8] " @@ -42,7 +43,7 @@ def on_forcefield_command(sender, command, label, args): else: forcefield_header(sender, "&cInvalid syntax. Use &e/ff ? &cfor info.") - elif args[0] in ["HELP", "?"]: # /forcefield help + elif args[0] in ["HELP", "?"] and sender.hasPermission(ff_help): # /forcefield help forcefield_help(sender) else: forcefield_header(sender, "&cInvalid syntax. Use &e/ff ? &cfor info.") @@ -194,4 +195,4 @@ def on_quit(event): player = event.getPlayer() player_id = uid(player) if player_id in ff_users: - ff_users.remove(player_id) \ No newline at end of file + ff_users.remove(player_id) -- 2.45.2 From cbdfd4af2370ac2070d5746501bb8f1cf243df46 Mon Sep 17 00:00:00 2001 From: NEMESIS13cz Date: Tue, 25 Aug 2015 18:33:43 +0200 Subject: [PATCH 003/217] Added a /sudo blacklist as a final security update --- misc.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/misc.py b/misc.py index c346be9..ff7be9a 100644 --- a/misc.py +++ b/misc.py @@ -114,7 +114,9 @@ def rs_material_broken_by_flow(material): length = len(parts) return length > 1 and (parts[0] == "DIODE" or parts[1] in ("TORCH", "WIRE", "BUTTON", "HOOK") or (length == 3 and parts[1] == "COMPARATOR")) - +sudo_blacklist = ["pyeval", "script_backup_begin", "script_backup_end", "script_backup_error", "script_backup_database_begin", "script_backup_database_dumps", "script_backup_database_end", +"script_backup_database_error", "script_backup_database_abort", "script_trim", "script_trim_result", "script_spigot_update", "script_disk_filled", "script_restart", "script_restart_abort", +"script_stop", "script_stop_abort", "script_shutdown"] @simplecommand("sudo", usage = " [cmd..]", @@ -127,11 +129,14 @@ def on_sudo_command(sender, command, label, args): msg(sender, "&2[SUDO] &rRunning '&e%s&r' as &3%s" % (cmd, target)) is_cmd = cmd[0] == "/" is_console = target.lower() in ["server", "console"] + first_cmd = (args[1])[1:] if is_cmd else None + if first_cmd in sudo_blacklist and (is_player(sender) and uid(sender) not in pythoners): + return "&cYou can't sudo this command" if is_console: server.dispatchCommand(server.getConsoleSender(), cmd[1:] if is_cmd else cmd) return None target_player = server.getPlayer(target) - if target_player and uid(target_player) not in pythoners: + if target_player: target_player.chat(cmd) return None return "&cPlayer %s not found!" % target -- 2.45.2 From 37de65d13099452d71302c6f2c44e1167469d68c Mon Sep 17 00:00:00 2001 From: NEMESIS13cz Date: Thu, 27 Aug 2015 18:09:02 +0200 Subject: [PATCH 004/217] Added /stop to the sudo blacklist --- misc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/misc.py b/misc.py index ff7be9a..51f68d1 100644 --- a/misc.py +++ b/misc.py @@ -116,7 +116,7 @@ def rs_material_broken_by_flow(material): sudo_blacklist = ["pyeval", "script_backup_begin", "script_backup_end", "script_backup_error", "script_backup_database_begin", "script_backup_database_dumps", "script_backup_database_end", "script_backup_database_error", "script_backup_database_abort", "script_trim", "script_trim_result", "script_spigot_update", "script_disk_filled", "script_restart", "script_restart_abort", -"script_stop", "script_stop_abort", "script_shutdown"] +"script_stop", "script_stop_abort", "script_shutdown", "stop"] @simplecommand("sudo", usage = " [cmd..]", -- 2.45.2 From 65f20ae9ca5a6b4ab24bd625a6137b318d1497b9 Mon Sep 17 00:00:00 2001 From: PanFritz Date: Fri, 28 Aug 2015 05:53:36 +0200 Subject: [PATCH 005/217] First working prototype of servercontrol to redstoner --- main.py | 4 +- servercontrol.py | 115 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 118 insertions(+), 1 deletion(-) create mode 100644 servercontrol.py diff --git a/main.py b/main.py index ee14975..d2d8274 100644 --- a/main.py +++ b/main.py @@ -79,7 +79,9 @@ shared["load_modules"] = [ # Replacement for LoginSecurity "loginsecurity", # Centralized Player class - "player" + "player", + # Servercontrol extension for telnet access to logs/AC + "servercontrol" ] shared["modules"] = {} for module in shared["load_modules"]: diff --git a/servercontrol.py b/servercontrol.py new file mode 100644 index 0000000..91055d7 --- /dev/null +++ b/servercontrol.py @@ -0,0 +1,115 @@ +from helpers import * +import socket +import threading +import time +from java.lang import Runnable +from adminchat import adminchat + +""" +Module to allow our servercontrol telnet server forward chat and speak in AC + + +""" +host = "" +port = 1122 + +sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) +sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR,1) + +try: + sock.bind((host,port)) + sock.setblocking(True) + sock.listen(5) +except socket.error as e: + print(str(e)) + +def command_process(text): + text = list(text) + args = [] + arg = "" + + for char in text: + if char != " " and char != "\n" and char != "\r" and char != "\t": + arg += char + elif arg != "": + args.append(arg) + arg = "" + if arg != "": + args.append(arg) + return args + +clients = [] +clients_l = threading.Lock() + +class client(): + def __init__(self,conn,address,name): + self.conn = conn + self.address = address + self.name = name + + with clients_l: + clients.append(self) + + self.conn.setblocking(False) + + self.client_thread = threading.Thread(target=self.client_t) + self.client_thread.daemon = True + self.client_thread.start() + + def getName(self): + return self.name + + + def close_connection(self): + try: + self.conn.close() + with clients_l: + clients.remove(self) + except: + pass + + + def client_t(self): + + while True: + time.sleep(0.1) + try: + data = self.conn.recv(1024) + except: + if self not in clients: + self.close_connection() + continue + + if self not in clients: #If the connection was closed, kill the thread + break + + adminchat(self,data) + + +def handle_conn(): + while True: + try: + conn, address = sock.accept() + except: + time.sleep(0.1) + continue + + #Send name + data = conn.recv(1024) + data = command_process(data) + print "servercontrol connected! %s " %data[0] + client_c = client(conn, address,data[0]) + + +handle_conn_t = threading.Thread(target=handle_conn) +handle_conn_t.daemon = True +handle_conn_t.start() + + +@hook.event("player.AsyncPlayerChatEvent","low") +def on_chat(event): + sender = event.getPlayer().getName() + msg = event.getMessage() + + for entry in clients: + entry.conn.sendall(sender + " " + msg) \ No newline at end of file -- 2.45.2 From b9e71b80adf263385a7f3b53cc5e462b2e9fa8f9 Mon Sep 17 00:00:00 2001 From: NEMESIS13cz Date: Sun, 30 Aug 2015 20:24:49 +0200 Subject: [PATCH 006/217] Added scriptutils and tag into main.py --- main.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index d2d8274..0566e3a 100644 --- a/main.py +++ b/main.py @@ -81,7 +81,11 @@ shared["load_modules"] = [ # Centralized Player class "player", # Servercontrol extension for telnet access to logs/AC - "servercontrol" + "servercontrol", + # Script helper plugin + "scriptutils", + # Per-player notes + "tag" ] shared["modules"] = {} for module in shared["load_modules"]: -- 2.45.2 From 465b235042858543f497ad6352c772d24b580d87 Mon Sep 17 00:00:00 2001 From: NEMESIS13cz Date: Sun, 30 Aug 2015 20:25:10 +0200 Subject: [PATCH 007/217] Added a simple per-player notes module --- tag.py | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 tag.py diff --git a/tag.py b/tag.py new file mode 100644 index 0000000..78a51fd --- /dev/null +++ b/tag.py @@ -0,0 +1,53 @@ +from helpers import * + +add_perm = "utils.tag.add" +check_perm = "utils.tag.check" + +data = open_json_file("tag", {}) + +@hook.command("tag") +def command(sender, command, label, args): + if len(args) > 0: + if str(args[0]) == "add": + if sender.hasPermission(add_perm): + if len(args) > 2: + add(sender, args[1:]) + else: + msg(sender, "&a-&c Usage: /tag add ") + else: + noperm(sender) + elif str(args[0]) == "check": + if sender.hasPermission(check_perm): + if len(args) == 2: + check(sender, args[1:]) + else: + msg(sender, "&a-&c Usage: /tag check ") + else: + noperm(sender) + else: + msg(sender, "&a-&c Unknown subcommand! (add, check)") + else: + msg(sender, "&a&c Usage: /tag add/check") + return True + +def add(sender, args): + player = server.getPlayer(args[0]) + uuid = uid(player) + try: + if data[uuid] == None: + pass + except: + data[uuid] = [] + data[uuid].append(" ".join(args[1:])) + msg(sender, "&a-&e Note added") + save_json_file("tag", data) + +def check(sender, args): + player = server.getPlayer(args[0]) + uuid = uid(player) + try: + for tag in data[uuid]: + msg(sender, "&a-&e %s" % str(tag)) + except: + msg(sender, "&a-&e There are no notes about this player") + -- 2.45.2 From f711f5e46cf246a3bea1c601146c4a0b5188e06e Mon Sep 17 00:00:00 2001 From: PanFritz Date: Mon, 31 Aug 2015 03:25:37 +0200 Subject: [PATCH 008/217] Added async_query since we need to remake all of our db interaction to be in a seperate thread --- helpers.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/helpers.py b/helpers.py index 70479be..1358033 100644 --- a/helpers.py +++ b/helpers.py @@ -13,6 +13,11 @@ from org.bukkit.entity import * from player import get_py_player from player import py_players +#Imports for async query +import mysqlhack +from com.ziclix.python.sql import zxJDBC +import threading + from traceback import format_exc as trace @@ -188,6 +193,30 @@ def known_player(player): """ return player.hasPlayedBefore() +""" +Runs a async query, calls target function with fetchall as an argument, it will be an empty list if there is nothing to fetch. +(So make sure your function takes that argument.) + +If you want your function to run sync in the case you are doing something spigot wouldn't like to be async use the bukkit scheduler. +Example can be found in loginsecurity.py + +""" +def async_query(mysql_database,mysql_user,mysql_pass,query,args,target): + + def async_query_t(mysql_database,mysql_user,mysql_pass,query,args,target): + db_conn = zxJDBC.connect("servercontrol.db") + db_curs = db_conn.cursor() + db_curs.execute(query,args) + db_conn.commit() + fetchall = db_curs.fetchall() + db_curs.close() + db_conn.close() + target(fetchall) + + t = threading.Thread(target=async_query_t,args=(mysql_database,mysql_user,mysql_pass,query,args,target)) + t.daemon = True + t.start() + def open_json_file(filename, default = None): """ -- 2.45.2 From 945cc977a772e5ab8e6cd75e4ec8af5fbd44bd12 Mon Sep 17 00:00:00 2001 From: PanFritz Date: Tue, 1 Sep 2015 00:42:19 +0200 Subject: [PATCH 009/217] Imported db password and user from secrets, added target_args --- helpers.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/helpers.py b/helpers.py index 1358033..58339b7 100644 --- a/helpers.py +++ b/helpers.py @@ -14,6 +14,7 @@ from player import get_py_player from player import py_players #Imports for async query +from secrets import * import mysqlhack from com.ziclix.python.sql import zxJDBC import threading @@ -201,19 +202,19 @@ If you want your function to run sync in the case you are doing something spigot Example can be found in loginsecurity.py """ -def async_query(mysql_database,mysql_user,mysql_pass,query,args,target): +def async_query(mysql_database,query,query_args,target_args,target): - def async_query_t(mysql_database,mysql_user,mysql_pass,query,args,target): - db_conn = zxJDBC.connect("servercontrol.db") + def async_query_t(mysql_database,query,query_args,target_args,target): + db_conn = zxJDBC.connect(mysql_database, mysql_user, mysql_pass, "com.mysql.jdbc.Driver") db_curs = db_conn.cursor() - db_curs.execute(query,args) + db_curs.execute(query,query_args) db_conn.commit() fetchall = db_curs.fetchall() db_curs.close() db_conn.close() - target(fetchall) + target(fetchall,target_args) - t = threading.Thread(target=async_query_t,args=(mysql_database,mysql_user,mysql_pass,query,args,target)) + t = threading.Thread(target=async_query_t,args=(mysql_database,query,query_args,target_args,target)) t.daemon = True t.start() -- 2.45.2 From 29a10032f7a80688817f815bcf9c3632b161adc7 Mon Sep 17 00:00:00 2001 From: Evanus Date: Tue, 1 Sep 2015 21:43:15 +0100 Subject: [PATCH 010/217] Remaking blockplacemods renamed dico's version to "dicode bpm" --- bpm.py | 94 ++++++++++++++++++++++++++++++ blockplacemods.py => dicode bpm.py | 0 main.py | 4 +- 3 files changed, 96 insertions(+), 2 deletions(-) create mode 100644 bpm.py rename blockplacemods.py => dicode bpm.py (100%) diff --git a/bpm.py b/bpm.py new file mode 100644 index 0000000..853e0e4 --- /dev/null +++ b/bpm.py @@ -0,0 +1,94 @@ +from helpers import * +import org.bukkit.block.BlockFace as BlockSide +import org.bukkit.Material as Material + +""" +remake of dicodes blockplacemods +""" + +slab_toggle_list = [] +cauldron_toggle_list = [] +inventory_toggle_list = [] + +sides = { + BlockSide.DOWN : 0, + BlockSide.UP : 1, + BlockSide.NORTH : 2, + BlockSide.SOUTH : 3, + BlockSide.WEST : 4, + BlockSide.EAST : 5 +} + +blocks = {Material.DROPPER, Material.HOPPER, Material.FURNACE, Material.DISPENSER} + +tog_perm = "utils.toggle" + +@hook.event("block.BlockPlaceEvent", "monitor") +def on_block_place(event): + material = block.getType() + user = server.getPlayer().getName() + if (material in (Material.WOOD_STEP, Material.STEP)) and user in slab_toggle_list: + block.setData(block.getData() + 8) + elif (material == Material.CAULDRON) and user in cauldron_toggle_list: + block.setData(block.getData() + 3) + elif (material in blocks) and user in inventory_toggle_list: + inv = user.getInventory().getItemInHand() + state = block.getState() + block_inv = state.getInventory() + block_inv.setItem(int(slot), toStack(inv)) + +""" +Idk if this is needed, but meh. makes it look cleaner +""" + +# block handelling + +def slab(): + user = server.getPlayer().getName() + if user in slab_toggle_list: + msg(sender, "&a Disabled automatically flipping slabs.") + slab_toggle_list.remove(name) + else: + msg(sender, "&a Enabled automatically flipping slabs.") + slab_toggle_list.remove(name) + +def cauldron(): + user = server.getPlayer().getName() + if user in cauldron_toggle_list: + msg(sender, "&a Disabled automatically filling cauldrons.") + cauldron_toggle_list.remove(name) + else: + msg(sender, "&a Enabled automatically filling cauldrons.") + cauldron_toggle_list.remove(name) + +def inventory(): + user = server.getPlayer().getName() + if user in inventory_toggle_list: + msg(sender, "&a disabled automatically putting items in inventories.") + inventory_toggle_list.remove(name) + else: + msg(sender, "&a Enabled automatically putting items in inventories.") + inventory_toggle_list.remove(name) + +# Command handelling + +@hook.command("toggle") +def toggle_command(sender, args): + name = sender.getName() + if sender.hasPermission(togPerm) and sender.getWorld(Creative): + if args[0] == "slab": + slab() + elif args[0] == "cauldron": + cauldron() + elif args[0] == "inv" or "inventory": + inventory() + else: + msg(sender, "&9Unknown argument \n &3please use: &9slab&3, &9inventory &3or &9cauldron&3.") + +@hook.command("set") +def set_command(sender, args): + return toggle_command(sender, args) + +@hook.command("setting") +def set_command(sender, args): + return toggle_command(sender, args) diff --git a/blockplacemods.py b/dicode bpm.py similarity index 100% rename from blockplacemods.py rename to dicode bpm.py diff --git a/main.py b/main.py index ee14975..d50900c 100644 --- a/main.py +++ b/main.py @@ -38,8 +38,8 @@ shared["load_modules"] = [ "adminchat", # Adds /badge, allows to give players achievements "badges", - # Adds a few block placement corrections/mods - "blockplacemods", + # Adds a few block placement corrections/mods + "bpm", # Adds /calc, toggles automatic solving of Math expressions in chat "calc", # Plugin to locate laggy chunks. /lc lists chunks with more than n entities -- 2.45.2 From 75a78dfef090227720d1675cf799ee511ebb1452 Mon Sep 17 00:00:00 2001 From: jomo Date: Tue, 1 Sep 2015 23:59:43 +0200 Subject: [PATCH 011/217] Fix #25 which -s is not available on all platforms --- setup.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/setup.sh b/setup.sh index 3748cca..336376f 100755 --- a/setup.sh +++ b/setup.sh @@ -4,7 +4,7 @@ set -e for cmd in curl java unzip git pip; do - if ! which -s "$cmd"; then + if ! which "$cmd" >/dev/null; then tput setf 4 >&2 echo "Error: please install '$cmd' to proceed" >&2 tput sgr0 >&2 @@ -172,4 +172,4 @@ echo "eula=true" > eula.txt echo -e "\n> $(tput setf 2)All Done! $(tput sgr0)Don't forget to configure plugins for your needs." echo "> Run redstoner/server/start.sh to start the server" -echo "> Our plugins are in redstoner/server/plugins/redstoner-utils.py.dir" \ No newline at end of file +echo "> Our plugins are in redstoner/server/plugins/redstoner-utils.py.dir" -- 2.45.2 From aa3f76e897cf44481e7e1db13fff396ea7799566 Mon Sep 17 00:00:00 2001 From: NEMESIS13cz Date: Fri, 4 Sep 2015 20:51:28 +0200 Subject: [PATCH 012/217] Added note deletion in tag --- tag.py | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/tag.py b/tag.py index 78a51fd..0a312aa 100644 --- a/tag.py +++ b/tag.py @@ -1,6 +1,7 @@ from helpers import * add_perm = "utils.tag.add" +del_perm = "utils.tag.del" check_perm = "utils.tag.check" data = open_json_file("tag", {}) @@ -24,12 +25,34 @@ def command(sender, command, label, args): msg(sender, "&a-&c Usage: /tag check ") else: noperm(sender) + elif str(args[0]) == "del": + if sender.hasPermission(del_perm): + if len(args) == 3: + delete(sender, args[1:]) + else: + msg(sender, "&a-&c Usage: /tag del ") else: - msg(sender, "&a-&c Unknown subcommand! (add, check)") + msg(sender, "&a-&c Unknown subcommand! (add, check, del)") else: msg(sender, "&a&c Usage: /tag add/check") return True +def delete(sender, args): + player = server.getPlayer(args[0]) + uuid = uid(player) + try: + if data[uuid] == None: + pass + except: + msg(sender, "&a-&e There are no notes about this player") + return + if int(args[1]) - 1 >= len(data[uuid]): + msg(sender, "&a-&c Id of note is out of range") + return + del (data[uuid])[int(args[1]) - 1] + save_json_file("tag", data) + msg(sender, "&a-&e Deleted note at %s" % args[1]) + def add(sender, args): player = server.getPlayer(args[0]) uuid = uid(player) @@ -46,8 +69,10 @@ def check(sender, args): player = server.getPlayer(args[0]) uuid = uid(player) try: + num = 0 for tag in data[uuid]: - msg(sender, "&a-&e %s" % str(tag)) + num += 1 + msg(sender, "&a-&e %s: %s" % (str(num), str(tag))) except: msg(sender, "&a-&e There are no notes about this player") -- 2.45.2 From 823dd373415444a50bd784ea2cc1fc9167370c23 Mon Sep 17 00:00:00 2001 From: NEMESIS13cz Date: Sun, 6 Sep 2015 01:39:53 +0200 Subject: [PATCH 013/217] Added a temporary fix for the knows /vanish bug --- vanishfix.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 vanishfix.py diff --git a/vanishfix.py b/vanishfix.py new file mode 100644 index 0000000..b13b059 --- /dev/null +++ b/vanishfix.py @@ -0,0 +1,14 @@ +from helpers import * +from java.lang import Runnable + +class run(Runnable): + + def run(self): + players = server.getOnlinePlayers() + for player in players: + if player.hasPermission("essentials.vanish"): + player.performCommand("vanish") + player.performCommand("vanish") + +def enabled(): + server.getScheduler().runTaskTimer(server.getPluginManager().getPlugin("RedstonerUtils"), run(), 20, 1200) -- 2.45.2 From 579b906b2a427621a73d478d8e187d30c8e80b4f Mon Sep 17 00:00:00 2001 From: NEMESIS13cz Date: Sun, 6 Sep 2015 01:40:13 +0200 Subject: [PATCH 014/217] Added vanishfix.py into modules + call its enabled method --- main.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index 0566e3a..dca8836 100644 --- a/main.py +++ b/main.py @@ -19,6 +19,7 @@ except: @hook.enable def on_enable(): + shared["modules"]["vanishfix"].enabled() info("RedstonerUtils enabled!") @@ -85,7 +86,9 @@ shared["load_modules"] = [ # Script helper plugin "scriptutils", # Per-player notes - "tag" + "tag", + # vanish toggle module - temporary fix + "vanishfix" ] shared["modules"] = {} for module in shared["load_modules"]: -- 2.45.2 From 65b74511d0c6376078a34c4f9ed76857f58824bd Mon Sep 17 00:00:00 2001 From: NEMESIS13cz Date: Sun, 6 Sep 2015 15:20:10 +0200 Subject: [PATCH 015/217] Added punishments.py to module list --- main.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index dca8836..aa5cdd4 100644 --- a/main.py +++ b/main.py @@ -88,7 +88,9 @@ shared["load_modules"] = [ # Per-player notes "tag", # vanish toggle module - temporary fix - "vanishfix" + "vanishfix", + # obisidian mining punishment plugin + "punishments" ] shared["modules"] = {} for module in shared["load_modules"]: -- 2.45.2 From 449c5015444269ff631a819c426a4e48bce18683 Mon Sep 17 00:00:00 2001 From: NEMESIS13cz Date: Sun, 6 Sep 2015 15:20:53 +0200 Subject: [PATCH 016/217] Added evil obsidian mining punishments plugins thing >:D --- punishments.py | 128 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100644 punishments.py diff --git a/punishments.py b/punishments.py new file mode 100644 index 0000000..4c39092 --- /dev/null +++ b/punishments.py @@ -0,0 +1,128 @@ +from helpers import * +from java.util.UUID import fromString as juuid +import org.bukkit.Material as Material + +spawn_world = "Spawn" +punish_world = "Punishments" + +slave_perm = "utils.minerslaves" + +slaves = [] + +def save_slaves(): + buf = [] + for slave in slaves: + buf.append(slave.get_data()) + save_json_file("miner_slaves", buf) + +def load_slaves(): + buf = open_json_file("miner_slaves", []) + for data in buf: + slave = Slave(True, None, None) + slave.load_data(data) + slaves.append(slave) + +def get_slave(player): + for slave in slaves: + if slave.get_uuid() == player: + return slave + return None + +class Slave(object): + + def __init__(self, from_file, player, amount): + if from_file: + self.players = None + self.blocks = None + return + slave = get_slave(uid(player)) + if slave != None: + slave.set_blocks(slave.get_blocks() + amount) + else: + self.player = uid(player) + self.blocks = amount + slaves.append(self) + + def get_uuid(self): + return self.player + + def get_blocks(self): + return self.blocks + + def set_blocks(self, amount): + self.blocks = amount + + def update(self): + self.blocks -= 1 + if self.blocks <= 0: + server.getPlayer(juuid(self.get_uuid())).teleport(server.getWorld(spawn_world).getSpawnLocation()) + slaves.remove(self) + save_slaves() + + def get_data(self): + return { + "player": self.player, + "amount": self.blocks + } + + def load_data(self, data): + self.player = str(data["player"]) + self.blocks = int(data["amount"]) + +load_slaves() + +@hook.event("block.BlockBreakEvent", "low") +def event(event): + if event.getPlayer().getWorld().getName() != punish_world: + return + slave = get_slave(uid(event.getPlayer())) + if slave != None and event.getBlock().getType() == Material.OBSIDIAN: + slave.update() + +@hook.command("miner") +def command(sender, cmd, label, args): + if not sender.hasPermission(slave_perm): + noperm(sender) + return True + if len(args) == 0 or (len(args) != 1 and args[0] == "list") or (len(args) != 2 and args[0] == "rem") or (len(args) != 3 and args[0] == "add"): + msg(sender, "&e-&a /miner add/rem/list ") + return True + if args[0] == "add": + try: + int(args[2]) + except: + msg(sender, "&cArgument is not a number") + return True + if args[0] == "list": + if len(slaves) == 0: + msg(sender, "&e-&a There are no people mining obsidian") + return True + for slave in slaves: + msg(sender, "&e-&a %s: %s blocks" % (slave.get_uuid(), slave.get_blocks())) + return True + elif args[0] == "add": + player = server.getOfflinePlayer(str(args[1])) + if player.isOnline(): + player.teleport(server.getWorld(punish_world).getSpawnLocation()) + Slave(False, player, int(args[2])) + save_slaves() + msg(sender, "&e-&a Player %s has been added into punishments for %s blocks of obsidian" % (player.getName(), args[2])) + else: + msg(sender, "&cYou can only punish online players") + return True + elif args[0] == "rem": + player = server.getOfflinePlayer(str(args[1])) + if player.isOnline(): + slave = get_slave(uid(player)) + if slave != None: + server.getPlayer(juuid(slave.get_uuid())).teleport(server.getWorld(spawn_world).getSpawnLocation()) + slaves.remove(slave) + save_slaves() + else: + msg(sender, "&e-&a Player not in punishments") + else: + msg(sender, "&cYou can only remove online players") + return True + else: + msg(sender, "&e-&a /miner add/rem/list ") + return True -- 2.45.2 From 0fd0f6c57f346affa718b1cc08c701125b43fc65 Mon Sep 17 00:00:00 2001 From: Evanus Date: Tue, 8 Sep 2015 21:28:21 +0100 Subject: [PATCH 017/217] Mentio toggle toggles mentio... yeah --- mentio.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/mentio.py b/mentio.py index dbcd4ce..631e3dd 100644 --- a/mentio.py +++ b/mentio.py @@ -8,6 +8,7 @@ max_amount = 3 arrow = colorify(u"&r&7\u2192&r") colors_reg = reg_compile(u"\u00A7[\\da-fk-or]") # finds color codes +mentio_toggle = [] def saveMentions(): save_json_file("mentio", mentions) @@ -19,6 +20,8 @@ def onChat(event): sender = event.getPlayer() words = event.getMessage().split(" ") recipients = event.getRecipients() # set of , may be a lazy or unmodifiable collection + n = sender.getName() + for recipient in list(recipients): recuid = uid(recipient) @@ -46,7 +49,7 @@ def onChat(event): break # player was mentioned - if rec_words != words: + if rec_words != words and n in mentio_toggle: try: recipients.remove(recipient) # don't send original message except: @@ -116,6 +119,7 @@ def show_help(player): msg(player, "&a/mentio add ") msg(player, "&a/mentio del ") msg(player, "&a/mentio list") + msg(player, "&a/mentio toggle") @hook.command("mentio") @@ -142,6 +146,14 @@ def onListenCommand(sender, command, label, args): msg(sender, "&c- &3%s" % word) if not keywords: msg(sender, "&cYou are currently listening for no words! Try &6/mentio add ") + elif argnum == 1 and cmd == "toggle": + n = sender.getName() + if n in mentio_toggle: + msg(sender,"&aNo longer listening.") + mentio_toggle.remove(n) + else: + msg(sender,"&aNow listening.") + mentio_toggle.append(n) else: show_help(sender) else: -- 2.45.2 From ebb893289cc3d0f9979a2ca5c8ccac858c1a175d Mon Sep 17 00:00:00 2001 From: PanFritz Date: Fri, 11 Sep 2015 11:39:06 +0200 Subject: [PATCH 018/217] Converted to use async_query --- check.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/check.py b/check.py index 8bbfdeb..cd13a6b 100644 --- a/check.py +++ b/check.py @@ -31,14 +31,11 @@ def get_last_seen(player): # receive link and email from website -def get_website_data(player): - conn = zxJDBC.connect(mysql_database, mysql_user, mysql_pass, "com.mysql.jdbc.Driver") - curs = conn.cursor() +def get_webite_data(player): uuid = str(uid(player)).replace("-", "") - curs.execute("SELECT DISTINCT `id`, `email` FROM users WHERE `uuid` = ? LIMIT 1", (uuid,)) - results = curs.fetchall() - curs.close() - conn.close() + async_query(mysql_database,"SELECT DISTINCT `id`, `email` FROM users WHERE `uuid` = ? LIMIT 1",(uuid,),get_website_data_target) + +def get_website_data_target(results): return ("http://redstoner.com/users/%s" % results[0][0], results[0][1]) if results else (None, None) -- 2.45.2 From d751654ff8b6ece57d28b09d4dadb9cabdbf351a Mon Sep 17 00:00:00 2001 From: PanFritz Date: Fri, 11 Sep 2015 11:43:57 +0200 Subject: [PATCH 019/217] Acctualy, its simpler to just do it all in a thread. --- check.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/check.py b/check.py index cd13a6b..f7924b8 100644 --- a/check.py +++ b/check.py @@ -31,11 +31,14 @@ def get_last_seen(player): # receive link and email from website -def get_webite_data(player): +def get_website_data(player): + conn = zxJDBC.connect(mysql_database, mysql_user, mysql_pass, "com.mysql.jdbc.Driver") + curs = conn.cursor() uuid = str(uid(player)).replace("-", "") - async_query(mysql_database,"SELECT DISTINCT `id`, `email` FROM users WHERE `uuid` = ? LIMIT 1",(uuid,),get_website_data_target) - -def get_website_data_target(results): + curs.execute("SELECT DISTINCT `id`, `email` FROM users WHERE `uuid` = ? LIMIT 1", (uuid,)) + results = curs.fetchall() + curs.close() + conn.close() return ("http://redstoner.com/users/%s" % results[0][0], results[0][1]) if results else (None, None) @@ -83,7 +86,10 @@ def on_hook_command(sender, command, label, args): plugin_header(sender, "Check") msg(sender, "&7Please notice that the data may not be fully accurate!") player = server.getOfflinePlayer(args[0]) if len(args) > 0 else None - get_all_data(sender, player) + + t = threading.Thread(target=get_all_data args=(sender, player)) + t.daemon = True + t.start() else: msg(sender, "&4You don't have the required permissions to execute this command!") return True \ No newline at end of file -- 2.45.2 From 1cc8126a9f8c48e06253c7d5bd1160d10dc1e9d9 Mon Sep 17 00:00:00 2001 From: PanFritz Date: Fri, 11 Sep 2015 11:44:46 +0200 Subject: [PATCH 020/217] Added args and kwargs --- helpers.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/helpers.py b/helpers.py index 58339b7..4aba904 100644 --- a/helpers.py +++ b/helpers.py @@ -202,9 +202,9 @@ If you want your function to run sync in the case you are doing something spigot Example can be found in loginsecurity.py """ -def async_query(mysql_database,query,query_args,target_args,target): +def async_query(mysql_database,query,query_args,target,*target_args,**target_kwargs): - def async_query_t(mysql_database,query,query_args,target_args,target): + def async_query_t(mysql_database,query,query_args,target,target_args,target_kwargs): db_conn = zxJDBC.connect(mysql_database, mysql_user, mysql_pass, "com.mysql.jdbc.Driver") db_curs = db_conn.cursor() db_curs.execute(query,query_args) @@ -212,9 +212,9 @@ def async_query(mysql_database,query,query_args,target_args,target): fetchall = db_curs.fetchall() db_curs.close() db_conn.close() - target(fetchall,target_args) + target(fetchall,target_args,target_kwargs) - t = threading.Thread(target=async_query_t,args=(mysql_database,query,query_args,target_args,target)) + t = threading.Thread(target=async_query_t,args=(mysql_database,query,query_args,target,target_args,target_kwargs)) t.daemon = True t.start() -- 2.45.2 From 256bcadf8d10db71d3807f81b93cb8e9d8655078 Mon Sep 17 00:00:00 2001 From: PanFritz Date: Fri, 11 Sep 2015 11:48:42 +0200 Subject: [PATCH 021/217] Disabled servercontrol for now --- main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.py b/main.py index aa5cdd4..3445447 100644 --- a/main.py +++ b/main.py @@ -82,7 +82,7 @@ shared["load_modules"] = [ # Centralized Player class "player", # Servercontrol extension for telnet access to logs/AC - "servercontrol", + #"servercontrol", # Script helper plugin "scriptutils", # Per-player notes -- 2.45.2 From a7ed59cfbf8e1111dd739b7aecf6d6517c713011 Mon Sep 17 00:00:00 2001 From: NEMESIS13cz Date: Sat, 12 Sep 2015 21:06:49 +0200 Subject: [PATCH 022/217] Added a lag warning broadcast command --- misc.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/misc.py b/misc.py index 51f68d1..ea7bf9a 100644 --- a/misc.py +++ b/misc.py @@ -256,6 +256,13 @@ def on_modules_command(sender, command, label, args): plugin_header(sender, "Modules") msg(sender, ", ".join([(("&a" if mod in shared["modules"] else "&c") + mod) for mod in shared["load_modules"]])) +@hook.command("warn") +def on_warn_command(sender, command, label, args): + broadcast(None, " &b= &2&lLag incoming! &r-%s" % sender.getDisplayName()) + +@hook.command("warnp") +def on_warnp_command(sender, command, label, args): + broadcast(None, " &b= &2&lPosible lag incoming! &r-%s" % sender.getDisplayName()) """ Something I'm planning for schematics @hook.event("player.PlayerCommandPreprocessEvent", "low") -- 2.45.2 From fff55eb0169e9c3f884c4922a0bfc89dcab3ce1f Mon Sep 17 00:00:00 2001 From: NEMESIS13cz Date: Sat, 12 Sep 2015 21:10:17 +0200 Subject: [PATCH 023/217] Fixed spelling error (thanks keyboard) --- misc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/misc.py b/misc.py index ea7bf9a..ea9ba6a 100644 --- a/misc.py +++ b/misc.py @@ -262,7 +262,7 @@ def on_warn_command(sender, command, label, args): @hook.command("warnp") def on_warnp_command(sender, command, label, args): - broadcast(None, " &b= &2&lPosible lag incoming! &r-%s" % sender.getDisplayName()) + broadcast(None, " &b= &2&lPossible lag incoming! &r-%s" % sender.getDisplayName()) """ Something I'm planning for schematics @hook.event("player.PlayerCommandPreprocessEvent", "low") -- 2.45.2 From a1973b666636cbd554cc4c261f6159c9b4c181eb Mon Sep 17 00:00:00 2001 From: PanFritz Date: Sun, 13 Sep 2015 00:56:52 +0200 Subject: [PATCH 024/217] Fixed syntax error --- check.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/check.py b/check.py index f7924b8..33ffb57 100644 --- a/check.py +++ b/check.py @@ -87,7 +87,7 @@ def on_hook_command(sender, command, label, args): msg(sender, "&7Please notice that the data may not be fully accurate!") player = server.getOfflinePlayer(args[0]) if len(args) > 0 else None - t = threading.Thread(target=get_all_data args=(sender, player)) + t = threading.Thread(target=get_all_data, args=(sender, player)) t.daemon = True t.start() else: -- 2.45.2 From d4bb481b248abea843a352e4c2fc644c1a6814ca Mon Sep 17 00:00:00 2001 From: PanFritz Date: Sun, 13 Sep 2015 01:32:13 +0200 Subject: [PATCH 025/217] Now cancles all commands besides /login whilst not logged in --- loginsecurity.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/loginsecurity.py b/loginsecurity.py index bf56a40..9295379 100644 --- a/loginsecurity.py +++ b/loginsecurity.py @@ -264,3 +264,11 @@ for blocked_event in blocked_events: user = get_py_player(event.getPlayer()) if user.logging_in: event.setCancelled(True) + +@hook.event("player.PlayerCommandPreprocessEvent","normal") +def pre_command_proccess(event): + player = get_py_player(event.getPlayer()) + if player.logging_in: + args = event.getMessage().split(" ") + if not args[0].lower() == "/login": + event.setCancelled(True) \ No newline at end of file -- 2.45.2 From b3ff447d05485d94de9c9bd33a9535c7e3092567 Mon Sep 17 00:00:00 2001 From: NEMESIS13cz Date: Sun, 13 Sep 2015 01:34:02 +0200 Subject: [PATCH 026/217] Added sudo aliases to the sudo blacklist --- misc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/misc.py b/misc.py index ea9ba6a..6145f86 100644 --- a/misc.py +++ b/misc.py @@ -116,7 +116,7 @@ def rs_material_broken_by_flow(material): sudo_blacklist = ["pyeval", "script_backup_begin", "script_backup_end", "script_backup_error", "script_backup_database_begin", "script_backup_database_dumps", "script_backup_database_end", "script_backup_database_error", "script_backup_database_abort", "script_trim", "script_trim_result", "script_spigot_update", "script_disk_filled", "script_restart", "script_restart_abort", -"script_stop", "script_stop_abort", "script_shutdown", "stop"] +"script_stop", "script_stop_abort", "script_shutdown", "stop", "esudo", "essentials:sudo"] @simplecommand("sudo", usage = " [cmd..]", -- 2.45.2 From de2b097484faaffbe191c413ceff06bed0883829 Mon Sep 17 00:00:00 2001 From: PanFritz Date: Sun, 13 Sep 2015 01:43:41 +0200 Subject: [PATCH 027/217] Changed login event to highest, added a message to the command interrupt --- loginsecurity.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/loginsecurity.py b/loginsecurity.py index 9295379..e6922a6 100644 --- a/loginsecurity.py +++ b/loginsecurity.py @@ -203,7 +203,7 @@ def delete_pass(uuid): curs.close() conn.close() -@hook.event("player.PlayerJoinEvent", "low") +@hook.event("player.PlayerJoinEvent", "highest") def on_join(event): user = event.getPlayer() py_player = get_py_player(event.getPlayer()) @@ -271,4 +271,5 @@ def pre_command_proccess(event): if player.logging_in: args = event.getMessage().split(" ") if not args[0].lower() == "/login": + msg(player.player, "&6You need to login before you do that!") event.setCancelled(True) \ No newline at end of file -- 2.45.2 From 33fab330e6c51a85f3522c1d53d227db52cc0cb3 Mon Sep 17 00:00:00 2001 From: PanFritz Date: Sun, 13 Sep 2015 02:13:10 +0200 Subject: [PATCH 028/217] Changed color for messages --- loginsecurity.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/loginsecurity.py b/loginsecurity.py index e6922a6..edf51e9 100644 --- a/loginsecurity.py +++ b/loginsecurity.py @@ -208,7 +208,7 @@ def on_join(event): user = event.getPlayer() py_player = get_py_player(event.getPlayer()) if is_registered(uid(user)): - msg(event.getPlayer(), "&6You will be disconnected after 60 seconds if you don't &alogin") + msg(event.getPlayer(), "&4You will be disconnected after 60 seconds if you don't &alogin") msg(user, "&cUse /login ") py_player.logging_in = True py_player.login_time = time.time() @@ -271,5 +271,5 @@ def pre_command_proccess(event): if player.logging_in: args = event.getMessage().split(" ") if not args[0].lower() == "/login": - msg(player.player, "&6You need to login before you do that!") + msg(player.player, "&4You need to login before you do that!") event.setCancelled(True) \ No newline at end of file -- 2.45.2 From 6e4f34e9d8f24fe21228dd54dbf8ea2302d7969e Mon Sep 17 00:00:00 2001 From: NEMESIS13cz Date: Sun, 13 Sep 2015 02:51:50 +0200 Subject: [PATCH 029/217] Fixed error tracing --- calc.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/calc.py b/calc.py index 8ac48f0..ed6ae12 100644 --- a/calc.py +++ b/calc.py @@ -10,6 +10,12 @@ calc_perm = "utils.calc" calc_perm_power = "utils.calc.power" def calc(sender, text): + try: + do_calc(sender, text) + except: + return + +def do_calc(sender, text): """ extracts a mathematical expression from `text` returns (expression, result) or None -- 2.45.2 From 4947c7edd24d5b538f37a4f295c761ea28125a46 Mon Sep 17 00:00:00 2001 From: NEMESIS13cz Date: Sun, 13 Sep 2015 03:37:40 +0200 Subject: [PATCH 030/217] Fixed missing return --- calc.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/calc.py b/calc.py index ed6ae12..1da634b 100644 --- a/calc.py +++ b/calc.py @@ -11,9 +11,9 @@ calc_perm_power = "utils.calc.power" def calc(sender, text): try: - do_calc(sender, text) + return do_calc(sender, text) except: - return + return None def do_calc(sender, text): """ -- 2.45.2 From ebfb4b4140525ffc9ad8e7ad5eba8377ee6299ec Mon Sep 17 00:00:00 2001 From: NEMESIS13cz Date: Sun, 13 Sep 2015 23:27:11 +0200 Subject: [PATCH 031/217] Added a permission to /warn and /warnp --- misc.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/misc.py b/misc.py index 6145f86..a29454b 100644 --- a/misc.py +++ b/misc.py @@ -258,11 +258,17 @@ def on_modules_command(sender, command, label, args): @hook.command("warn") def on_warn_command(sender, command, label, args): - broadcast(None, " &b= &2&lLag incoming! &r-%s" % sender.getDisplayName()) + sender.hasPermission("utils.warn"): + broadcast(None, " &b= &2&lLag incoming! &r-%s" % sender.getDisplayName()) + else: + noperm(sender) @hook.command("warnp") def on_warnp_command(sender, command, label, args): - broadcast(None, " &b= &2&lPossible lag incoming! &r-%s" % sender.getDisplayName()) + sender.hasPermission("utils.warnp"): + broadcast(None, " &b= &2&lPossible lag incoming! &r-%s" % sender.getDisplayName()) + else: + noperm(sender) """ Something I'm planning for schematics @hook.event("player.PlayerCommandPreprocessEvent", "low") -- 2.45.2 From 28f8340ef034d0c840d297dd24081a0faed1b4c8 Mon Sep 17 00:00:00 2001 From: Evanus Date: Tue, 15 Sep 2015 00:31:03 +0100 Subject: [PATCH 032/217] Remake of blockplacemods --- bpm.py | 142 ++++++++++++++++++++++++++++----------------------------- 1 file changed, 69 insertions(+), 73 deletions(-) diff --git a/bpm.py b/bpm.py index 853e0e4..06fe6ef 100644 --- a/bpm.py +++ b/bpm.py @@ -6,89 +6,85 @@ import org.bukkit.Material as Material remake of dicodes blockplacemods """ -slab_toggle_list = [] -cauldron_toggle_list = [] -inventory_toggle_list = [] - -sides = { - BlockSide.DOWN : 0, - BlockSide.UP : 1, - BlockSide.NORTH : 2, - BlockSide.SOUTH : 3, - BlockSide.WEST : 4, - BlockSide.EAST : 5 -} +slabToggle = [] +cauldronToggle = [] +inventoryToggle = [] blocks = {Material.DROPPER, Material.HOPPER, Material.FURNACE, Material.DISPENSER} +info = "please use: &9Slab&3, &9Inventory&3, &9Cauldron &3or &9Help&3." -tog_perm = "utils.toggle" +togPerm = "utils.toggle" @hook.event("block.BlockPlaceEvent", "monitor") -def on_block_place(event): +def blockPlace(event): + block = event.getBlockPlaced() material = block.getType() - user = server.getPlayer().getName() - if (material in (Material.WOOD_STEP, Material.STEP)) and user in slab_toggle_list: + n = event.getPlayer().getName() + + if (material in (Material.WOOD_STEP, Material.STEP)) and n in slabToggle: block.setData(block.getData() + 8) - elif (material == Material.CAULDRON) and user in cauldron_toggle_list: + + elif (material == Material.CAULDRON) and n in cauldronToggle: block.setData(block.getData() + 3) - elif (material in blocks) and user in inventory_toggle_list: + + elif (material in blocks) and n in inventoryToggle: inv = user.getInventory().getItemInHand() state = block.getState() - block_inv = state.getInventory() - block_inv.setItem(int(slot), toStack(inv)) - -""" -Idk if this is needed, but meh. makes it look cleaner -""" - -# block handelling - -def slab(): - user = server.getPlayer().getName() - if user in slab_toggle_list: - msg(sender, "&a Disabled automatically flipping slabs.") - slab_toggle_list.remove(name) - else: - msg(sender, "&a Enabled automatically flipping slabs.") - slab_toggle_list.remove(name) - -def cauldron(): - user = server.getPlayer().getName() - if user in cauldron_toggle_list: - msg(sender, "&a Disabled automatically filling cauldrons.") - cauldron_toggle_list.remove(name) - else: - msg(sender, "&a Enabled automatically filling cauldrons.") - cauldron_toggle_list.remove(name) - -def inventory(): - user = server.getPlayer().getName() - if user in inventory_toggle_list: - msg(sender, "&a disabled automatically putting items in inventories.") - inventory_toggle_list.remove(name) - else: - msg(sender, "&a Enabled automatically putting items in inventories.") - inventory_toggle_list.remove(name) - -# Command handelling - + blockInv = state.getInventory() + blockInv.setItem(int(slot), toStack(inv)) +def help(): + msg(sender, "&a-=[&6BPM&a]=-") + msg(sender, "&6Aliases for /toggle: \n &e/set, /setting and /config\n") + msg(sender, "&6Available settings: \n &eSlab, Cauldron and Inventory\n") + msg(sender, "&6Slab: \n&eThe slab setting flips slabs to the top half \nof the block on placing them.\n") + msg(sender, "&6Cauldron: \n&eThe cauldron setting fills cauldrons on placing them.\n") + msg(sender, "&6Inventory: \n&eThe inventory setting puts a block in an item with an inventory.\n") @hook.command("toggle") -def toggle_command(sender, args): +def toggleCommand(sender, cmd, label, args): name = sender.getName() - if sender.hasPermission(togPerm) and sender.getWorld(Creative): - if args[0] == "slab": - slab() - elif args[0] == "cauldron": - cauldron() - elif args[0] == "inv" or "inventory": - inventory() + try: + if sender.hasPermission(togPerm) and sender.getWorld().getName() == "creative": + if len(args) > 0: + if str(args[0]) == "slab": + if name in slabToggle: + msg(sender, "&a Disabled automatically flipping slabs.") + slabToggle.remove(name) + else: + msg(sender, "&a Enabled automatically flipping slabs.") + slabToggle.append(name) + + elif str(args[0]) == "cauldron": + if name in cauldronToggle: + msg(sender, "&a Disabled automatically filling cauldrons.") + cauldronToggle.remove(name) + else: + msg(sender, "&a Enabled automatically filling cauldrons.") + cauldronToggle.append(name) + + elif str(args[0]) == "inv" or "inventory": + if name in cauldronToggle: + msg(sender, "&a Disabled automatically putting items in inventories.") + cauldronToggle.remove(name) + else: + msg(sender, "&a Enabled automatically putting items in inventories.") + cauldronToggle.append(name) + + elif str(args[0]) == "help" or "?" or "wut": + help() + + elif len(args) > 1: + msg(sender,"&aToo many arguments, \n&3&s") % info + + else: + msg(sender, "&9Unknown argument \n &3%s") % info + else: + help() + + + elif sender.getWorld() != "creative": + msg(sender, "&aBPM doesn't work in this world.") + print sender.getWorld().getName() else: - msg(sender, "&9Unknown argument \n &3please use: &9slab&3, &9inventory &3or &9cauldron&3.") - -@hook.command("set") -def set_command(sender, args): - return toggle_command(sender, args) - -@hook.command("setting") -def set_command(sender, args): - return toggle_command(sender, args) + msg(sender, "&aNo permission.") + except: + print trace() \ No newline at end of file -- 2.45.2 From db1d54c599962011b481d4e050f2f9dd08c33393 Mon Sep 17 00:00:00 2001 From: Evanus Date: Tue, 15 Sep 2015 00:35:04 +0100 Subject: [PATCH 033/217] Right file this time --- bpm.py | 83 +++++++++++++++++++++++----------------------------------- 1 file changed, 33 insertions(+), 50 deletions(-) diff --git a/bpm.py b/bpm.py index 06fe6ef..cb540c0 100644 --- a/bpm.py +++ b/bpm.py @@ -1,84 +1,67 @@ from helpers import * -import org.bukkit.block.BlockFace as BlockSide import org.bukkit.Material as Material """ remake of dicodes blockplacemods """ -slabToggle = [] -cauldronToggle = [] -inventoryToggle = [] - blocks = {Material.DROPPER, Material.HOPPER, Material.FURNACE, Material.DISPENSER} info = "please use: &9Slab&3, &9Inventory&3, &9Cauldron &3or &9Help&3." togPerm = "utils.toggle" -@hook.event("block.BlockPlaceEvent", "monitor") -def blockPlace(event): - block = event.getBlockPlaced() - material = block.getType() - n = event.getPlayer().getName() +@hook.event("block.BlockPlaceEvent", "low") +def block_place(event): + try: + block = event.getBlockPlaced() + material = block.getType() + sender = event.getPlayer() + py_player = get_py_player(sender) + if (material in (Material.WOOD_STEP, Material.STEP)) and py_player.slab_toggle and block.getData() < 8: + block.setData(block.getData() + 8) - if (material in (Material.WOOD_STEP, Material.STEP)) and n in slabToggle: - block.setData(block.getData() + 8) + elif (material == Material.CAULDRON) and py_player.cauldron_toggle: + block.setData(block.getData() + 3) + except: + print trace() - elif (material == Material.CAULDRON) and n in cauldronToggle: - block.setData(block.getData() + 3) +def help(sender): + try: + msg(sender, "&a-=[&6BPM&a]=-") + msg(sender, "&6Aliases for /toggle: \n &e/set, /setting and /config\n") + msg(sender, "&6Available settings: \n &eSlab and Cauldron\n") + msg(sender, "&6Slab: \n&eThe slab setting flips slabs to the top half \nof the block on placing them.\n") + msg(sender, "&6Cauldron: \n&eThe cauldron setting fills cauldrons on placing them.\n") + except: + print trace() - elif (material in blocks) and n in inventoryToggle: - inv = user.getInventory().getItemInHand() - state = block.getState() - blockInv = state.getInventory() - blockInv.setItem(int(slot), toStack(inv)) -def help(): - msg(sender, "&a-=[&6BPM&a]=-") - msg(sender, "&6Aliases for /toggle: \n &e/set, /setting and /config\n") - msg(sender, "&6Available settings: \n &eSlab, Cauldron and Inventory\n") - msg(sender, "&6Slab: \n&eThe slab setting flips slabs to the top half \nof the block on placing them.\n") - msg(sender, "&6Cauldron: \n&eThe cauldron setting fills cauldrons on placing them.\n") - msg(sender, "&6Inventory: \n&eThe inventory setting puts a block in an item with an inventory.\n") @hook.command("toggle") -def toggleCommand(sender, cmd, label, args): - name = sender.getName() +def toggle_command(sender, cmd, label, args): + py_player = get_py_player(sender) + print py_player.player.getName() try: if sender.hasPermission(togPerm) and sender.getWorld().getName() == "creative": if len(args) > 0: if str(args[0]) == "slab": - if name in slabToggle: + if py_player.slab_toggle == True: msg(sender, "&a Disabled automatically flipping slabs.") - slabToggle.remove(name) + py_player.slab_toggle = False else: msg(sender, "&a Enabled automatically flipping slabs.") - slabToggle.append(name) + py_player.slab_toggle = True elif str(args[0]) == "cauldron": - if name in cauldronToggle: + if py_player.cauldron_toggle == True: msg(sender, "&a Disabled automatically filling cauldrons.") - cauldronToggle.remove(name) + py_player.cauldron_toggle = False else: msg(sender, "&a Enabled automatically filling cauldrons.") - cauldronToggle.append(name) - - elif str(args[0]) == "inv" or "inventory": - if name in cauldronToggle: - msg(sender, "&a Disabled automatically putting items in inventories.") - cauldronToggle.remove(name) - else: - msg(sender, "&a Enabled automatically putting items in inventories.") - cauldronToggle.append(name) - - elif str(args[0]) == "help" or "?" or "wut": - help() - - elif len(args) > 1: - msg(sender,"&aToo many arguments, \n&3&s") % info + py_player.cauldron_toggle = True else: - msg(sender, "&9Unknown argument \n &3%s") % info + help(sender) else: - help() + help(sender) elif sender.getWorld() != "creative": -- 2.45.2 From ed4f60d5a3a3c9f55a25388802496feb54dd1c21 Mon Sep 17 00:00:00 2001 From: Evanus Date: Tue, 15 Sep 2015 00:41:05 +0100 Subject: [PATCH 034/217] cleanup --- bpm.py | 87 +++++++++++++++++++++++----------------------------------- 1 file changed, 34 insertions(+), 53 deletions(-) diff --git a/bpm.py b/bpm.py index cb540c0..4cdd7d1 100644 --- a/bpm.py +++ b/bpm.py @@ -5,69 +5,50 @@ import org.bukkit.Material as Material remake of dicodes blockplacemods """ -blocks = {Material.DROPPER, Material.HOPPER, Material.FURNACE, Material.DISPENSER} -info = "please use: &9Slab&3, &9Inventory&3, &9Cauldron &3or &9Help&3." - togPerm = "utils.toggle" @hook.event("block.BlockPlaceEvent", "low") def block_place(event): - try: - block = event.getBlockPlaced() - material = block.getType() - sender = event.getPlayer() - py_player = get_py_player(sender) - if (material in (Material.WOOD_STEP, Material.STEP)) and py_player.slab_toggle and block.getData() < 8: - block.setData(block.getData() + 8) - - elif (material == Material.CAULDRON) and py_player.cauldron_toggle: - block.setData(block.getData() + 3) - except: - print trace() + block = event.getBlockPlaced() + material = block.getType() + sender = event.getPlayer() + py_player = get_py_player(sender) + if (material in (Material.WOOD_STEP, Material.STEP)) and py_player.slab_toggle and block.getData() < 8: + block.setData(block.getData() + 8) + elif (material == Material.CAULDRON) and py_player.cauldron_toggle: + block.setData(block.getData() + 3) def help(sender): - try: - msg(sender, "&a-=[&6BPM&a]=-") - msg(sender, "&6Aliases for /toggle: \n &e/set, /setting and /config\n") - msg(sender, "&6Available settings: \n &eSlab and Cauldron\n") - msg(sender, "&6Slab: \n&eThe slab setting flips slabs to the top half \nof the block on placing them.\n") - msg(sender, "&6Cauldron: \n&eThe cauldron setting fills cauldrons on placing them.\n") - except: - print trace() + msg(sender, "&a-=[&6BPM&a]=-") + msg(sender, "&6Aliases for /toggle: \n &e/set, /setting and /config\n") + msg(sender, "&6Available settings: \n &eSlab and Cauldron\n") + msg(sender, "&6Slab: \n&eThe slab setting flips slabs to the top half \nof the block on placing them.\n") + msg(sender, "&6Cauldron: \n&eThe cauldron setting fills cauldrons on placing them.\n") @hook.command("toggle") def toggle_command(sender, cmd, label, args): py_player = get_py_player(sender) - print py_player.player.getName() - try: - if sender.hasPermission(togPerm) and sender.getWorld().getName() == "creative": - if len(args) > 0: - if str(args[0]) == "slab": - if py_player.slab_toggle == True: - msg(sender, "&a Disabled automatically flipping slabs.") - py_player.slab_toggle = False - else: - msg(sender, "&a Enabled automatically flipping slabs.") - py_player.slab_toggle = True - - elif str(args[0]) == "cauldron": - if py_player.cauldron_toggle == True: - msg(sender, "&a Disabled automatically filling cauldrons.") - py_player.cauldron_toggle = False - else: - msg(sender, "&a Enabled automatically filling cauldrons.") - py_player.cauldron_toggle = True - + if sender.hasPermission(togPerm) and sender.getWorld().getName() == "creative": + if len(args) > 0: + if str(args[0]) == "slab": + if py_player.slab_toggle == True: + msg(sender, "&a Disabled automatically flipping slabs.") + py_player.slab_toggle = False else: - help(sender) + msg(sender, "&a Enabled automatically flipping slabs.") + py_player.slab_toggle = True + elif str(args[0]) == "cauldron": + if py_player.cauldron_toggle == True: + msg(sender, "&a Disabled automatically filling cauldrons.") + py_player.cauldron_toggle = False + else: + msg(sender, "&a Enabled automatically filling cauldrons.") + py_player.cauldron_toggle = True else: - help(sender) - - - elif sender.getWorld() != "creative": - msg(sender, "&aBPM doesn't work in this world.") - print sender.getWorld().getName() + help(sender) else: - msg(sender, "&aNo permission.") - except: - print trace() \ No newline at end of file + help(sender) + elif sender.getWorld() != "creative": + msg(sender, "&aBPM doesn't work in this world.") + else: + msg(sender, "&aNo permission.") \ No newline at end of file -- 2.45.2 From 9bf7d626da0b5026522b2663bd68357e2366dd7d Mon Sep 17 00:00:00 2001 From: Dico200 Date: Tue, 15 Sep 2015 16:45:22 +0200 Subject: [PATCH 035/217] Serversigns Replacement, accessible for everyone. Untested. :accept: --- serversigns.py | 221 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 221 insertions(+) create mode 100644 serversigns.py diff --git a/serversigns.py b/serversigns.py new file mode 100644 index 0000000..c7bc23c --- /dev/null +++ b/serversigns.py @@ -0,0 +1,221 @@ +from helpers import * +from basecommands import simplecommand, Validate +import org.bukkit.Material as Material +import java.util.UUID as UUID +import org.bukkit.Material as Material +import java.util.HashSet as JSet + + +cmd_use_perm = "utils.svs.cmd" +msg_use_perm = "utils.svs.msg" + +signs = open_json_file("serversigns", {}) # {("world", x, y, z): ["owner_id", "msg1", "msg2"]} + +lines = {} #Accumulated messages so players can have longer messages: {"Dico200": "Message...........", ""} + +transparent_blocks_set = JSet([Material.AIR, Material.GLASS, Material.STAINED_GLASS]) #used in sender.getTargetBlock() + +@simplecommand(cmd = "serversigns", aliases = ["svs", "signmsg"], + description = "Makes something happen when you right click certain signs", + usage = "[claim|unclaim|add |remove |clear|info|help]", + helpNoargs = True, + senderLimit = 0) +def svs_command(sender, command, label, args): + try: + arg1 = args[0].lower() + if arg1 not in ("add", "remove", "clear", "claim", "unclaim", "help"): + return "&4That argument could not be recognized, use &o/svs &4help for more information" + + sender = server.getPlayer(sender.getName()) + block = sender.getTargetBlock(transparent_blocks_set, 8) + info("Block type: " + str(block.getType())) + if block.getType() not in (Material.SIGN_POST, Material.WALL_SIGN): + return "&4You have to be looking at a sign to use that!" + + loc = fromLoc(block.getLocation()) + sign = getSign(loc) + arglen = len(args) + arg2 = args[1].lower() if arglen > 1 else None + + + if arg1 == "claim": + Validate.isAuthorized(sender, "utils.serversigns.claim") + target = sender + if arg2: + Validate.isAuthorized(sender, "utils.serversigns.admin") + target = server.getOfflinePlayer(arg2) + Validate.notNone(target, signsMsg("That player could not be found", '4')) + + Validate.isPlayer(target) + uuid = uid(sender) + if sign != None: + if sign[0] == uuid: + return signsMsg(identifySign(loc, True) + " was already owned by that player", '4') + else: + sign[0] = uuid + else: + signs[loc] = [uuid] + + return signsMsg("Claimed " + identifySign(loc)) + + + elif arg1 == "unclaim": + Validate.isAuthorized(sender, "utils.serversigns.unclaim") + Validate.isTrue(canEdit(sign, sender), signsMsg("You cannot unclaim the %s!" % identifySign(loc)), '4') + + if not (("-c" in args) and sender.hasPermission("utils.serversigns.admin")): + del signs[locAt] + return signsMsg("The %s was reset successfully" % identifySign(loc)) + sign[0] = "" + return signsMsg("The %s had its owner removed successfully" % identifySign(loc)) + + + elif arg1 == "help": + admin = sender.hasPermission("utils.serversigns.admin") + + return + + + elif arg1 == "add": + Validate.isTrue(canEdit(sign, sender), signsMsg("You cannot edit the %s!" % identifySign(loc)), '4') + line = " ".join(args[1:]) + Validate.isTrue(line != "" and line != None, signsMsg("You have to enter a message to add or accumulate!", '4')) + key = sender.getName() + + Validate.isTrue(key in lines or line[:1] != "/" or sender.hasPermission("utils.serversigns.command"), signsMsg("You cannot add commands to a sign!", '4')) + + if line[-2:] == "++": + if key not in lines: + lines[key] = "" + lines[key] += " " + line[:-2] + elif key in lines: + line = lines[key] + " " + line + sign.append(colorify(line) if line[0] != "/" else line) + return signsMsg("Added line \"%s&a\" to the %s" % (line, identifySign(loc))) + + + elif arg1 == "info": + Validate.notNone(sign, signsMsg("The %s has not been claimed" % identifySign(loc), '4')) + lines = "" + for id, line in enumerate(sign[1:]): + lines += ("\n &a%s: \"%s&a\"" % (id + 1, line)) + msg = signsMsg("Some information about the %s:\n Owner: %s\n Lines: %s" % identifySign(loc), getOwner(sign), lines) + + + elif arg1 == "remove": + Validate.notNone(arg2, signsMsg("You have to enter the ID of the message to remove!", '4')) + try: + id = int(arg2) + except: + return signsMsg("The ID of the message has to be a number and can be found by using &o/svs info", '4') + Validate.isTrue(id != 0 and id < len(sign), signsMsg("The %s has no message with an ID of %s, use &o/svs info &4for all messages." % (identifySign(loc), id), '4')) + sign.remove(id) + return signsMsg("Removed message with id %s from the %s" % (id, identifySign(loc))) + except: + error(trace()) + + + +@hook.event("player.PlayerInteractEvent") +def onClick(event): + if str(event.getAction()) != "RIGHT_CLICK_BLOCK": + return + block = event.getClickedBlock() + if block.getType() not in (Material.WALL_SIGN, Material.SIGN_POST): + return + sign = getSign(fromLoc(block.getLocation())) + if sign != None: + player = event.getPlayer() + for message in sign[1:]: + if message[:1] == "/": + server.dispatchCommand(player, message[1:]) + else: + msg(player, message, usecolor = False) + +def fromLoc(bLoc): #Bukkit Location to ("world", x, y, z) + return (bLoc.getWorld().getName(), bLoc.getBlockX(), bLoc.getBlockY(), bLoc.getBlockZ()) + +def equals(loc1, loc2): + for i in range(4): + if loc1[i] != loc2[i]: + return False + return True + +def getOwner(sign): + return retrieve_player(sign[0]).getName() + +def isOwner(sign, player): + return sign and sign[0] == uid(player) + +def canEdit(sign, player): + return player.hasPermission("utils.serversigns.admin") or isOwner(sign, player) + +def getSign(locAt): + for loc, sign in signs.iteritems(): + if equals(locAt, loc): + return sign + return None + +def identifySign(loc, capital = False): + return "%sign at (%s) in %s" % ("S" if capital else "s", ",".join(loc[1:]), loc[0]) + +def signsMsg(msg, colour = 'a'): + return "&c[Signs] &" + colour + msg + + + + + + +""" +def eventhook(event, priority = "normal"): + + if "." not in event: + word = "" + for s in event: + if word != "" and s in "ABCDEFGHIJKLMNOPQRSTUVWXYZ": + break; + word += s.lower() + event = "%s.%s" % (word, event) + + def decorator(function): + + @hook.event(event, priority) + def hook(event): + try: + function(event) + except EventException, e: + pass + + return hook + + return decorator + +class EventException(Exception): + def __init__(self, msg): + self.msg = msg + +"" +@eventhook("PlayerInteractEvent") +def x(event): + + p = event.getPlayer() + if p == None: + raise EventException(Stuff) +"" +""" + + + + + + + + + + + + + + + -- 2.45.2 From 9b3a63503d741cab2a4bcd1460d382330c6336c8 Mon Sep 17 00:00:00 2001 From: Evanus Date: Tue, 15 Sep 2015 17:06:00 +0100 Subject: [PATCH 036/217] Enabled mentio by default --- mentio.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/mentio.py b/mentio.py index 631e3dd..528d7ad 100644 --- a/mentio.py +++ b/mentio.py @@ -49,7 +49,7 @@ def onChat(event): break # player was mentioned - if rec_words != words and n in mentio_toggle: + if rec_words != words and n not in mentio_toggle: try: recipients.remove(recipient) # don't send original message except: @@ -146,13 +146,15 @@ def onListenCommand(sender, command, label, args): msg(sender, "&c- &3%s" % word) if not keywords: msg(sender, "&cYou are currently listening for no words! Try &6/mentio add ") + + # /mentio toggle elif argnum == 1 and cmd == "toggle": n = sender.getName() if n in mentio_toggle: - msg(sender,"&aNo longer listening.") + msg(sender,"&aNow listening.") mentio_toggle.remove(n) else: - msg(sender,"&aNow listening.") + msg(sender,"&aNo longer listening.") mentio_toggle.append(n) else: show_help(sender) -- 2.45.2 From 9422fa22eb94921be6a76eba82d4cad997d907ef Mon Sep 17 00:00:00 2001 From: Evanus Date: Tue, 15 Sep 2015 17:06:35 +0100 Subject: [PATCH 037/217] added emptying water from cauldrons --- bpm.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/bpm.py b/bpm.py index 4cdd7d1..6e6e99e 100644 --- a/bpm.py +++ b/bpm.py @@ -18,6 +18,18 @@ def block_place(event): elif (material == Material.CAULDRON) and py_player.cauldron_toggle: block.setData(block.getData() + 3) +@hook.event("player.PlayerInteractEvent", "high") +def on_interact(event): + block = event.getClickedBlock() + sender = event.getPlayer() + py_player = get_py_player(sender) + if str(event.getAction()) != "RIGHT_CLICK_BLOCK": + return + if block.getType() == Material.CAULDRON and py_player.cauldron_toggle: + block.setData(block.getData() - 1 if block.getData() > 0 else 3) + else: + return + def help(sender): msg(sender, "&a-=[&6BPM&a]=-") msg(sender, "&6Aliases for /toggle: \n &e/set, /setting and /config\n") @@ -51,4 +63,6 @@ def toggle_command(sender, cmd, label, args): elif sender.getWorld() != "creative": msg(sender, "&aBPM doesn't work in this world.") else: - msg(sender, "&aNo permission.") \ No newline at end of file + msg(sender, "&aNo permission.") + + -- 2.45.2 From 0ecdb5f5abbf09af3755e4a7a7cb2097d90a97d2 Mon Sep 17 00:00:00 2001 From: Evanus Date: Fri, 18 Sep 2015 00:30:56 +0100 Subject: [PATCH 038/217] adding slab_toggle and cauldron_toggle to py_player --- bpm.py | 12 ++++-------- player.py | 10 ++++++---- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/bpm.py b/bpm.py index 6e6e99e..405ada4 100644 --- a/bpm.py +++ b/bpm.py @@ -1,11 +1,7 @@ from helpers import * import org.bukkit.Material as Material -""" -remake of dicodes blockplacemods -""" - -togPerm = "utils.toggle" +tog_perm = "utils.toggle" @hook.event("block.BlockPlaceEvent", "low") def block_place(event): @@ -20,8 +16,8 @@ def block_place(event): @hook.event("player.PlayerInteractEvent", "high") def on_interact(event): - block = event.getClickedBlock() - sender = event.getPlayer() + block = event.getClickedBlock() + sender = event.getPlayer() py_player = get_py_player(sender) if str(event.getAction()) != "RIGHT_CLICK_BLOCK": return @@ -40,7 +36,7 @@ def help(sender): @hook.command("toggle") def toggle_command(sender, cmd, label, args): py_player = get_py_player(sender) - if sender.hasPermission(togPerm) and sender.getWorld().getName() == "creative": + if sender.hasPermission(tog_perm) and sender.getWorld().getName() == "creative": if len(args) > 0: if str(args[0]) == "slab": if py_player.slab_toggle == True: diff --git a/player.py b/player.py index 0897493..ccd8e56 100644 --- a/player.py +++ b/player.py @@ -4,10 +4,12 @@ py_players = [] class py_player: def __init__(self,player): - self.player = player - self.logging_in = False - self.login_time = 0 - + self.player = player + self.logging_in = False + self.login_time = 0 + self.slab_toggle = False + self.cauldron_toggle = False + def get_py_player(player): #py_player = py_players[py_players.index(player)] -- 2.45.2 From f57d7f5b9b131fe164b4b3dd390ca135e11311b5 Mon Sep 17 00:00:00 2001 From: Evanus Date: Fri, 18 Sep 2015 01:03:01 +0100 Subject: [PATCH 039/217] fixed naming --- bpm.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/bpm.py b/bpm.py index 6e6e99e..df6b3c8 100644 --- a/bpm.py +++ b/bpm.py @@ -1,11 +1,7 @@ from helpers import * import org.bukkit.Material as Material -""" -remake of dicodes blockplacemods -""" - -togPerm = "utils.toggle" +tog_perm = "utils.toggle" @hook.event("block.BlockPlaceEvent", "low") def block_place(event): @@ -40,7 +36,7 @@ def help(sender): @hook.command("toggle") def toggle_command(sender, cmd, label, args): py_player = get_py_player(sender) - if sender.hasPermission(togPerm) and sender.getWorld().getName() == "creative": + if sender.hasPermission(tog_perm) and sender.getWorld().getName() == "creative": if len(args) > 0: if str(args[0]) == "slab": if py_player.slab_toggle == True: -- 2.45.2 From d2fafec640443fbb3099ff1cd259626eff5d1c5b Mon Sep 17 00:00:00 2001 From: Evanus Date: Fri, 18 Sep 2015 01:05:10 +0100 Subject: [PATCH 040/217] Update player.py --- player.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/player.py b/player.py index 0897493..289b247 100644 --- a/player.py +++ b/player.py @@ -4,10 +4,12 @@ py_players = [] class py_player: def __init__(self,player): - self.player = player - self.logging_in = False - self.login_time = 0 - + self.player = player + self.logging_in = False + self.login_time = 0 + self.slab_toggle = False + self.cauldron_toggle = False + def get_py_player(player): #py_player = py_players[py_players.index(player)] @@ -25,4 +27,4 @@ def on_join(event): @hook.event("player.PlayerQuitEvent","highest") def on_leave(event): - py_players.remove(get_py_player(event.getPlayer())) \ No newline at end of file + py_players.remove(get_py_player(event.getPlayer())) -- 2.45.2 From 4d6cd9df328c021264ea7c3596320260c673320e Mon Sep 17 00:00:00 2001 From: Evanus Date: Fri, 18 Sep 2015 02:18:38 +0100 Subject: [PATCH 041/217] Renamed bpm --- bpm.py => blockplacemods.py | 0 main.py | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename bpm.py => blockplacemods.py (100%) diff --git a/bpm.py b/blockplacemods.py similarity index 100% rename from bpm.py rename to blockplacemods.py diff --git a/main.py b/main.py index d50900c..2038e43 100644 --- a/main.py +++ b/main.py @@ -39,7 +39,7 @@ shared["load_modules"] = [ # Adds /badge, allows to give players achievements "badges", # Adds a few block placement corrections/mods - "bpm", + "blockplacemods", # Adds /calc, toggles automatic solving of Math expressions in chat "calc", # Plugin to locate laggy chunks. /lc lists chunks with more than n entities -- 2.45.2 From d5c9e2fae13f3d87804d48bcdaf60426772a8a7a Mon Sep 17 00:00:00 2001 From: Dico200 Date: Sat, 19 Sep 2015 01:00:51 +0200 Subject: [PATCH 042/217] Added vanish module, a simple replacement for the essentials version I tried to use underscores where ever I could ^^ --- main.py | 8 ++-- vanish.py | 120 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 125 insertions(+), 3 deletions(-) create mode 100644 vanish.py diff --git a/main.py b/main.py index 3445447..eb9ca94 100644 --- a/main.py +++ b/main.py @@ -39,8 +39,8 @@ shared["load_modules"] = [ "adminchat", # Adds /badge, allows to give players achievements "badges", - # Adds a few block placement corrections/mods - "blockplacemods", + # Adds a few block placement corrections/mods + "blockplacemods", # Adds /calc, toggles automatic solving of Math expressions in chat "calc", # Plugin to locate laggy chunks. /lc lists chunks with more than n entities @@ -90,7 +90,9 @@ shared["load_modules"] = [ # vanish toggle module - temporary fix "vanishfix", # obisidian mining punishment plugin - "punishments" + "punishments", + # a simple replacement for the buggy essentials /vanish + "vanish" ] shared["modules"] = {} for module in shared["load_modules"]: diff --git a/vanish.py b/vanish.py new file mode 100644 index 0000000..5aa8c90 --- /dev/null +++ b/vanish.py @@ -0,0 +1,120 @@ +from helpers import * +from basecommands import simplecommand +from basecommands import Validate + +vanished = [] + + +def is_authorized(player): + return player.hasPermission("utils.vanish") + + +def is_vanished(player): + return uid(player) in vanished + + +#this can be used to silently set the vanished state of a player +def set_state(player, state): + if state == is_vanished(player): + return + + if state: + enable_vanish(player) + else: + disable_vanish(player) + + +def enable_vanish(target): + vanished.append(uid(target)) + for player in list(server.getOnlinePlayers()): + player.hidePlayer(target) + + +def disable_vanish(target): + vanished.remove(uid(target)) + for player in list(server.getOnlinePlayers()): + player.showPlayer(target) + + +@simplecommand("vanish", + aliases = ["v"], + usage = "[on/off]", + description = "Toggles vanish mode, hiding you and your online status \nfrom other players.", + senderLimit = 0, + amin = 0, + amax = 1, + helpNoargs = False, + helpSubcmd = True +) +def vanish_command(sender, command, label, args): + try: + current_state = is_vanished(sender) + new_state = not current_state + + if len(args) == 1: + arg = args[0].lower() + if arg == "on": + new_state = True + elif arg == "off": + new_state = False + + if current_state == new_state: + return "&cYou were %s vanished!" % ("already" if current_state else "not yet") + + set_state(sender, new_state) + return "&a%s vanish mode!" % ("Enabled" if new_state else "Disabled") + except: + error(trace()) + + +@hook.event("player.PlayerJoinEvent") +def on_player_join(event): + player = event.getPlayer() + + if not is_authorized(player): + for uuid in vanished: + player.hidePlayer(retrieve_player(uuid)) + + elif is_vanished(player): + msg(player, "&cKeep in mind that you are still vanished! Use /vanish to disable.") + + +@hook.event("player.PlayerQuitEvent") +def on_player_quit(event): + player = event.getPlayer() + + if not is_authorized(player): + for uuid in vanished: + player.showPlayer(retrieve_player(uuid)) + + +@simplecommand("vanishother", + usage = "{player} [on/off]", + description = "Toggles vanish mode for someone, hiding them and their online status from other players.", + amin = 1, + amax = 2, + helpNoargs = True, + helpSubcmd = True) +def vanishother_command(sender, command, label, args): + target = server.getPlayer(args[0]) + Validate.notNone(target, "&cThe specified player is not online") + + current_state = is_vanished(target) + new_state = not current_state + + if len(args) == 2: + arg = args[1].lower() + if arg == "on": + new_state = True + elif arg == "off": + new_state = False + + if current_state == new_state: + return "&cThat player was already vanished!" if current_state else "&cThat player was not yet vanished!" + + set_state(target, new_state) + + enabled_str = "enabled" if new_state else "disabled" + if target != sender: + msg(target, "&aVanish mode %s by %s" % (enabled_str, sender.getDisplayName() if is_player(sender) else "&9CONSOLE")) + return "&aVanish mode %s%s" % (enabled_str, " for " + target.getDisplayName() if target != sender else "") -- 2.45.2 From 393d7f791da4869b9672a928bf60a9e7ab0887cb Mon Sep 17 00:00:00 2001 From: Dico200 Date: Sat, 19 Sep 2015 01:26:26 +0200 Subject: [PATCH 043/217] Small fix to make sure staff can always see other staff in vanish mode --- vanish.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/vanish.py b/vanish.py index 5aa8c90..a572ebc 100644 --- a/vanish.py +++ b/vanish.py @@ -27,7 +27,8 @@ def set_state(player, state): def enable_vanish(target): vanished.append(uid(target)) for player in list(server.getOnlinePlayers()): - player.hidePlayer(target) + if not is_authorized(player): + player.hidePlayer(target) def disable_vanish(target): -- 2.45.2 From 4404674c2948cad339d6434e7b50a3aef969ea75 Mon Sep 17 00:00:00 2001 From: Dico200 Date: Sat, 19 Sep 2015 02:22:21 +0200 Subject: [PATCH 044/217] Disabled vanishfix, preparing merge I replaced /warn and /warnp commands with @simplecommand hook. they happened to be missing the 'if' from the permission checks and this takes care of some other things as well. I added a module called vanish which will replace essentials vanish which happens to be really buggy as you know. I added a serversigns module but it is not added to main.py and thus it will not cause problems! --- main.py | 2 +- misc.py | 30 ++++++++++++++++++------------ 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/main.py b/main.py index eb9ca94..1367148 100644 --- a/main.py +++ b/main.py @@ -88,7 +88,7 @@ shared["load_modules"] = [ # Per-player notes "tag", # vanish toggle module - temporary fix - "vanishfix", + #"vanishfix", # obisidian mining punishment plugin "punishments", # a simple replacement for the buggy essentials /vanish diff --git a/misc.py b/misc.py index a29454b..9aadae9 100644 --- a/misc.py +++ b/misc.py @@ -256,19 +256,25 @@ def on_modules_command(sender, command, label, args): plugin_header(sender, "Modules") msg(sender, ", ".join([(("&a" if mod in shared["modules"] else "&c") + mod) for mod in shared["load_modules"]])) -@hook.command("warn") -def on_warn_command(sender, command, label, args): - sender.hasPermission("utils.warn"): - broadcast(None, " &b= &2&lLag incoming! &r-%s" % sender.getDisplayName()) - else: - noperm(sender) -@hook.command("warnp") -def on_warnp_command(sender, command, label, args): - sender.hasPermission("utils.warnp"): - broadcast(None, " &b= &2&lPossible lag incoming! &r-%s" % sender.getDisplayName()) - else: - noperm(sender) +@simplecommand("warn", + usage = "", + description = "Warns everybody on the server that you will cause lag shortly", + amax = 0, + helpSubcmd = True): +def warn_command(sender, command, label, args): + broadcast(None, " &b= &2&lLag incoming! &r-%s" % sender.getDisplayName()) + + +@simplecommand("warnp", + usage = "", + description = "Warns everybody on the server that you might cause lag shortly", + amax = 0, + helpSubcmd = True): +def warn_command(sender, command, label, args): + broadcast(None, " &b= &2&lPossible lag incoming! &r-%s" % sender.getDisplayName()) + + """ Something I'm planning for schematics @hook.event("player.PlayerCommandPreprocessEvent", "low") -- 2.45.2 From 12ea31cd02f8da24015f9d3fd524e0574574fe23 Mon Sep 17 00:00:00 2001 From: Dico200 Date: Sat, 19 Sep 2015 02:24:39 +0200 Subject: [PATCH 045/217] fix in misc.py - ofc I forget to save --- misc.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/misc.py b/misc.py index 9aadae9..7c280ca 100644 --- a/misc.py +++ b/misc.py @@ -261,7 +261,7 @@ def on_modules_command(sender, command, label, args): usage = "", description = "Warns everybody on the server that you will cause lag shortly", amax = 0, - helpSubcmd = True): + helpSubcmd = True) def warn_command(sender, command, label, args): broadcast(None, " &b= &2&lLag incoming! &r-%s" % sender.getDisplayName()) @@ -270,7 +270,7 @@ def warn_command(sender, command, label, args): usage = "", description = "Warns everybody on the server that you might cause lag shortly", amax = 0, - helpSubcmd = True): + helpSubcmd = True) def warn_command(sender, command, label, args): broadcast(None, " &b= &2&lPossible lag incoming! &r-%s" % sender.getDisplayName()) -- 2.45.2 From 920738bd658fbea9c4065791ad2d1510198c5f21 Mon Sep 17 00:00:00 2001 From: Dico200 Date: Sat, 19 Sep 2015 02:25:58 +0200 Subject: [PATCH 046/217] Another fix -.- these single characters... It's been too long since I committed properly --- misc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/misc.py b/misc.py index 7c280ca..dc3475e 100644 --- a/misc.py +++ b/misc.py @@ -271,7 +271,7 @@ def warn_command(sender, command, label, args): description = "Warns everybody on the server that you might cause lag shortly", amax = 0, helpSubcmd = True) -def warn_command(sender, command, label, args): +def warnp_command(sender, command, label, args): broadcast(None, " &b= &2&lPossible lag incoming! &r-%s" % sender.getDisplayName()) -- 2.45.2 From b4c485776149ee5b1a854b63b78f0fde889ba52f Mon Sep 17 00:00:00 2001 From: PanFritz Date: Sun, 20 Sep 2015 01:47:36 +0200 Subject: [PATCH 047/217] Attempt to make a sync decorator --- sync.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 sync.py diff --git a/sync.py b/sync.py new file mode 100644 index 0000000..0a2cd0b --- /dev/null +++ b/sync.py @@ -0,0 +1,21 @@ +from helpers import * +from java.lang import Runnable + +class Sync_class(Runnable): + + def __init__(self,function,*args,**kwargs): + self.function = function + self.args = args + self.kwargs = kwargs + + def run(self): + self.function(self.args,self.kwargs) + + + +def sync(function): + def wrapper(*args,**kwargs): + sync_function = Sync_class(function) + server.getScheduler().runTask(server.getPluginManager().getPlugin("RedstonerUtils"),sync_function) + return None + return wrapper \ No newline at end of file -- 2.45.2 From 069cc8aec150386e77edbd571df1d0e84a1a84e1 Mon Sep 17 00:00:00 2001 From: NEMESIS13cz Date: Tue, 29 Sep 2015 21:53:45 +0200 Subject: [PATCH 048/217] Removed a vanishfix.py call as we are no longer using it --- main.py | 1 - 1 file changed, 1 deletion(-) diff --git a/main.py b/main.py index 1367148..65948b8 100644 --- a/main.py +++ b/main.py @@ -19,7 +19,6 @@ except: @hook.enable def on_enable(): - shared["modules"]["vanishfix"].enabled() info("RedstonerUtils enabled!") -- 2.45.2 From 9c2934a374693242fc9574c87e91fdfbd66f0056 Mon Sep 17 00:00:00 2001 From: NEMESIS13cz Date: Sun, 11 Oct 2015 15:33:31 +0200 Subject: [PATCH 049/217] Fixed spelling mistake --- scriptutils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scriptutils.py b/scriptutils.py index 2e0dd2d..312f6c4 100644 --- a/scriptutils.py +++ b/scriptutils.py @@ -149,7 +149,7 @@ arg 0 size of backup @hook.command("script_backup_database_end") def print_backup_db_end(sender, command, label, args): if not is_player(sender): - broadcast(None, "&6 =&2 Databse backup completed.") + broadcast(None, "&6 =&2 Database backup completed.") server.dispatchCommand(server.getConsoleSender(), "ac &abackup size: &2%sMB&a." % args[0]) else: noperm(sender) -- 2.45.2 From 05a74b416b40d3f4e8ebf040e392d293a4ce7170 Mon Sep 17 00:00:00 2001 From: Dico200 Date: Sun, 11 Oct 2015 23:25:12 +0200 Subject: [PATCH 050/217] /signalstrength progress --- misc.py | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/misc.py b/misc.py index dc3475e..5ac4e54 100644 --- a/misc.py +++ b/misc.py @@ -142,6 +142,82 @@ def on_sudo_command(sender, command, label, args): return "&cPlayer %s not found!" % target +container_levels = dict( + FURNACE = [], + HOPPER = [], + CHEST = [], +) + + +""" +Suggestion by Armadillo28, see thread: http://redstoner.com/forums/threads/2213-putting-the-correct-amount-of-items-in-a-container?page=1#reply-14507 +""" +""" +@simplecommand("signalstrength", + usage = " [item] [data]", + aliases = ["ss", "level"], + description = "Fills the targeted container with the correct amount of items to achieve the desired signal strength.", + amin = 1, + amax = 3, + helpNoargs = True, + helpSubcmd = True, + senderLimit = 0) +def on_signalstrength_command(sender, command, label, args): + values = [] + try: + for i in range(len(args)): + values[i] = int(args[i]) + except ValueError: + return "&cYou have to enter a number for the signal strength" + + + target_block = sender.getTargetBlock(None, 5) + Validate.notNone(target_block) + target_type = str(target_block.getType()) + Validate.isTrue(target_type in container_levels) + + levels = container_levels[target_type] + + item_value = 1 + item_type = Material.REDSTONE + item_data = 0 + if len(values) > 1: + item_type = Material.getMaterial(values[1]) + if item_type == None: + return "&cThat is not an item ID" + if len(values) == 3: + item_data = values[2] + if not (0 <= item_data <= 15): + return "&cThe data must be a number from 0 to a maximum of 15" + if values[1] in (items that stack up to 16): + item_value = 4 + elif values[1] in (items that stack up to 1): + item_value = 64 + + target_strength = values[0] + + item_count = levels[target_strength] / item_value + + if int(item_count) * item_value < levels[target_strength] and (int(item_count) + 1) * item_value >= levels[target_strength + 1]: #if target_strength = 15, first check will always be false, so no IndexError + return "&cThe desired signal strength could not be achieved with the requested item type" + + item_count = int(item_count) + if item_count % 1 != 0: + item_count += 1 + + def stack(count): + return ItemStack(values[1]) + + full_stacks = int(item_count / item_value) + for i in range(0, full_stacks) #amount of full stacks + target_block.setItem(i, ItemStack()) +""" + + + + + + @simplecommand("me", usage = "[message..]", -- 2.45.2 From e85f716dc548e337f88001b55092cd1b2851405d Mon Sep 17 00:00:00 2001 From: Dico200 Date: Sun, 11 Oct 2015 23:27:20 +0200 Subject: [PATCH 051/217] /signalstrength progress --- player.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/player.py b/player.py index 0897493..0f4a47f 100644 --- a/player.py +++ b/player.py @@ -25,4 +25,5 @@ def on_join(event): @hook.event("player.PlayerQuitEvent","highest") def on_leave(event): - py_players.remove(get_py_player(event.getPlayer())) \ No newline at end of file + py_players.remove(get_py_player(event.getPlayer())) + -- 2.45.2 From f5df50e353e1755eb19f404b37aa0dd9587db3e8 Mon Sep 17 00:00:00 2001 From: NEMESIS13cz Date: Wed, 14 Oct 2015 21:14:40 +0200 Subject: [PATCH 052/217] Added Dico to pythoners --- misc.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/misc.py b/misc.py index 5ac4e54..da7e2cc 100644 --- a/misc.py +++ b/misc.py @@ -279,7 +279,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", -- 2.45.2 From ed27cdf561f2ac4fa35909e689d024a6de04c1fe Mon Sep 17 00:00:00 2001 From: PixelSergey Date: Fri, 16 Oct 2015 17:20:17 +0300 Subject: [PATCH 053/217] Added the chat aliasing plugin --- chatalias.py | 100 +++++++++++++++++++++++++++++++++++++++++++++++++++ main.py | 2 ++ 2 files changed, 102 insertions(+) create mode 100755 chatalias.py diff --git a/chatalias.py b/chatalias.py new file mode 100755 index 0000000..09eaf7e --- /dev/null +++ b/chatalias.py @@ -0,0 +1,100 @@ +# 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 values. + +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 = "/ [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 False + + 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 : removes from aliased words. Use * to remove all aliased words.") + msg(sender, "/alias : Will change to in chat") + msg(sender, "\nYour Aliases:") + data = safe_open_json() + try: + for alias, value in data[sender.getName()].items(): + msg(sender, "%s ==> %s" % (alias, value)) + except KeyError: + pass + return True + + elif len(args) == 1: + data = safe_open_json() + if args[0] == "*": + data[sender.getName()].clear() + save_json_file("aliases", data) + plugin_header(recipient = sender, name = "Chat Alias") + msg(sender, "ALL alias data successfuly removed!") + return True + + if data[sender.getName()].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 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[sender.getName()]) >= int(data["gnl"]["max_entries"]) and 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[sender.getName()] = {} + + data[sender.getName()][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(e): + if e.isCancelled(): + return + + data = safe_open_json() + for alias, value in data[e.getPlayer().getName()].items(): + e.setMessage(e.getMessage().replace(alias, value)) diff --git a/main.py b/main.py index 65948b8..2138216 100644 --- a/main.py +++ b/main.py @@ -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 lists chunks with more than n entities "lagchunks", # Adds /report and /rp, Stores reports with time and location -- 2.45.2 From b9293d7be2d595e1da0489024055924b01f531f2 Mon Sep 17 00:00:00 2001 From: PixelSergey Date: Fri, 16 Oct 2015 17:37:52 +0300 Subject: [PATCH 054/217] Updated event variable --- chatalias.py | 200 +++++++++++++++++++++++++-------------------------- 1 file changed, 100 insertions(+), 100 deletions(-) diff --git a/chatalias.py b/chatalias.py index 09eaf7e..3d9cf31 100755 --- a/chatalias.py +++ b/chatalias.py @@ -1,100 +1,100 @@ -# 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 values. - -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 = "/ [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 False - - 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 : removes from aliased words. Use * to remove all aliased words.") - msg(sender, "/alias : Will change to in chat") - msg(sender, "\nYour Aliases:") - data = safe_open_json() - try: - for alias, value in data[sender.getName()].items(): - msg(sender, "%s ==> %s" % (alias, value)) - except KeyError: - pass - return True - - elif len(args) == 1: - data = safe_open_json() - if args[0] == "*": - data[sender.getName()].clear() - save_json_file("aliases", data) - plugin_header(recipient = sender, name = "Chat Alias") - msg(sender, "ALL alias data successfuly removed!") - return True - - if data[sender.getName()].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 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[sender.getName()]) >= int(data["gnl"]["max_entries"]) and 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[sender.getName()] = {} - - data[sender.getName()][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(e): - if e.isCancelled(): - return - - data = safe_open_json() - for alias, value in data[e.getPlayer().getName()].items(): - e.setMessage(e.getMessage().replace(alias, value)) +# 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 values. + +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 = "/ [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 False + + 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 : removes from aliased words. Use * to remove all aliased words.") + msg(sender, "/alias : Will change to in chat") + msg(sender, "\nYour Aliases:") + data = safe_open_json() + try: + for alias, value in data[sender.getName()].items(): + msg(sender, "%s ==> %s" % (alias, value)) + except KeyError: + pass + return True + + elif len(args) == 1: + data = safe_open_json() + if args[0] == "*": + data[sender.getName()].clear() + save_json_file("aliases", data) + plugin_header(recipient = sender, name = "Chat Alias") + msg(sender, "ALL alias data successfuly removed!") + return True + + if data[sender.getName()].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 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[sender.getName()]) >= int(data["gnl"]["max_entries"]) and 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[sender.getName()] = {} + + data[sender.getName()][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[event.getPlayer().getName()].items(): + event.setMessage(event.getMessage().replace(alias, value)) -- 2.45.2 From 28da124088ac754354d4353054003702734d4ff7 Mon Sep 17 00:00:00 2001 From: PixelSergey Date: Fri, 16 Oct 2015 22:54:44 +0300 Subject: [PATCH 055/217] Changed names to UUID, fixed empty dicts --- chatalias.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/chatalias.py b/chatalias.py index 3d9cf31..ddc45e9 100755 --- a/chatalias.py +++ b/chatalias.py @@ -38,7 +38,7 @@ def on_alias_command(sender, cmd, label, args): msg(sender, "\nYour Aliases:") data = safe_open_json() try: - for alias, value in data[sender.getName()].items(): + for alias, value in data[str(sender.getUniqueId())].items(): msg(sender, "%s ==> %s" % (alias, value)) except KeyError: pass @@ -47,13 +47,13 @@ def on_alias_command(sender, cmd, label, args): elif len(args) == 1: data = safe_open_json() if args[0] == "*": - data[sender.getName()].clear() + 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[sender.getName()].pop(args[0], None) is None: + 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 @@ -72,14 +72,14 @@ def on_alias_command(sender, cmd, label, args): msg(sender, "Please do not alias long words/sentences.") return True - if len(data[sender.getName()]) >= int(data["gnl"]["max_entries"]) and data["gnl"]["max_entries"] > 0: + if len(data[str(sender.getUniqueId())]) >= int(data["gnl"]["max_entries"]) and 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[sender.getName()] = {} + data[str(sender.getUniqueId())] = {} - data[sender.getName()][args[0]] = alias + 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)) @@ -96,5 +96,5 @@ def on_player_chat(event): return data = safe_open_json() - for alias, value in data[event.getPlayer().getName()].items(): + for alias, value in data[str(event.getPlayer().getUniqueId())].items(): event.setMessage(event.getMessage().replace(alias, value)) -- 2.45.2 From b8ab9a2fc7a828fafb3f4009ae31355dbdaaa8d0 Mon Sep 17 00:00:00 2001 From: PixelSergey Date: Fri, 16 Oct 2015 23:32:19 +0300 Subject: [PATCH 056/217] Added permission check, fixed negative setting --- chatalias.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/chatalias.py b/chatalias.py index ddc45e9..9eb8037 100755 --- a/chatalias.py +++ b/chatalias.py @@ -10,7 +10,7 @@ # file named "aliases". The # file is generated if not # present. Set values to -1 -# for unlimited values. +# for "unlimited" setting. from helpers import * @@ -25,9 +25,14 @@ def safe_open_json(): @hook.command("alias", usage = "/ [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 False + return True + + if not sender.hasPermission("utils.alias.allowed"): + plugin_header(recipient = sender, name = "Chat Alias") + noperm(sender) if len(args) == 0: plugin_header(recipient = sender, name = "Chat Alias") @@ -67,12 +72,12 @@ def on_alias_command(sender, cmd, label, args): data = safe_open_json() alias = " ".join(args[1:]) try: - if len(alias) > int(data["gnl"]["max_len"]) and data["gnl"]["max_len"] > 0: + 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 data["gnl"]["max_entries"] > 0: + 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 -- 2.45.2 From 2811f74888e2cc5f759e455a605549ea9e43a551 Mon Sep 17 00:00:00 2001 From: Sergey Date: Sun, 18 Oct 2015 01:33:03 +0300 Subject: [PATCH 057/217] Fixed missing return statement --- chatalias.py | 1 + 1 file changed, 1 insertion(+) diff --git a/chatalias.py b/chatalias.py index 9eb8037..69ac343 100755 --- a/chatalias.py +++ b/chatalias.py @@ -33,6 +33,7 @@ def on_alias_command(sender, cmd, label, args): 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") -- 2.45.2 From 9a93cd3203d1f515b1ce518ccc7e0c841088f09b Mon Sep 17 00:00:00 2001 From: Pepich Date: Sun, 18 Oct 2015 15:36:08 +0200 Subject: [PATCH 058/217] Added two functions for the iptracker --- helpers.py | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/helpers.py b/helpers.py index 4aba904..0cb7cbc 100644 --- a/helpers.py +++ b/helpers.py @@ -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 -- 2.45.2 From d2204d9706f929d71becdd428ac6604c11bfd568 Mon Sep 17 00:00:00 2001 From: Pepich Date: Sun, 18 Oct 2015 15:36:50 +0200 Subject: [PATCH 059/217] Initial iptracker commit allowing username - IP lookups and vice versa --- iptracker.py | 95 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 iptracker.py diff --git a/iptracker.py b/iptracker.py new file mode 100644 index 0000000..824f829 --- /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): + try: + 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() + except: + error(trace()) + curs.close() + conn.close() + + +@hook.command("getinfo") +def on_getinfo_command(sender, args): + try: + 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])) + 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: + 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 " + sender.getName() + " was seen with " + str(len(ips)) + " different IPs:") + for i in range(0, len(ips)): + 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: + noperm(sender) + return True + except: + error(trace()) -- 2.45.2 From 70662bdd0b006642466adec9c92a0f08b1744f10 Mon Sep 17 00:00:00 2001 From: Pepich Date: Sun, 18 Oct 2015 15:37:17 +0200 Subject: [PATCH 060/217] Added support for an infinite amount of mentio keywords --- mentio.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mentio.py b/mentio.py index dbcd4ce..936b424 100644 --- a/mentio.py +++ b/mentio.py @@ -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 " % 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 -- 2.45.2 From fbbbad1853ac7bd377fa68b374bf40caa72e7432 Mon Sep 17 00:00:00 2001 From: Pepich Date: Sun, 18 Oct 2015 16:06:09 +0200 Subject: [PATCH 061/217] added console support and fixed a small cosmetic bug --- iptracker.py | 146 +++++++++++++++++++++++++-------------------------- 1 file changed, 73 insertions(+), 73 deletions(-) diff --git a/iptracker.py b/iptracker.py index 824f829..a25dcce 100644 --- a/iptracker.py +++ b/iptracker.py @@ -11,85 +11,85 @@ iptrack_permission = "utils.iptrack" @hook.event("player.PlayerJoinEvent", "low") def on_player_join(event): - try: - 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 = [] + 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: - ips = json.loads(results[0][0]) - curs.execute("SELECT uuids FROM iptrack_iptouuids WHERE ip = ?", (ip, )) - results = curs.fetchall() - if len(results) == 0: - uuids = [] + 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: - 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() - except: - error(trace()) + 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): - try: - 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])) - 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: - 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 " + sender.getName() + " was seen with " + str(len(ips)) + " different IPs:") - for i in range(0, len(ips)): - 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"}]}}}]') + if(sender.hasPermission(iptrack_permission)): + if not checkargs(sender, args, 1, 1): + return false else: - noperm(sender) - return True - except: - error(trace()) + 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 -- 2.45.2 From 0676c535ad34373740c7ca7e88874965ff9b4883 Mon Sep 17 00:00:00 2001 From: Dico200 Date: Tue, 20 Oct 2015 01:01:53 +0200 Subject: [PATCH 062/217] Finished signal strength command --- misc.py | 119 ++++++++++++++++++++++++++++++++------------------------ 1 file changed, 69 insertions(+), 50 deletions(-) diff --git a/misc.py b/misc.py index 5ac4e54..a9c29cf 100644 --- a/misc.py +++ b/misc.py @@ -4,9 +4,13 @@ from time import time as now from time import sleep from sys import exc_info import thread + import org.bukkit.inventory.ItemStack as ItemStack +import org.bukkit.Material as Material +from math import ceil + import org.bukkit.Bukkit as Bukkit -from basecommands import simplecommand +from basecommands import simplecommand, Validate @@ -70,7 +74,6 @@ def cmd_event2(event): - """ Disabled while builder can't access Trusted @hook.event("player.PlayerGameModeChangeEvent", "low") def on_gamemode(event): @@ -142,17 +145,24 @@ def on_sudo_command(sender, command, label, args): return "&cPlayer %s not found!" % target -container_levels = dict( - FURNACE = [], - HOPPER = [], - CHEST = [], -) - - """ Suggestion by Armadillo28, see thread: http://redstoner.com/forums/threads/2213-putting-the-correct-amount-of-items-in-a-container?page=1#reply-14507 + +Clarification on these formulas on http://minecraft.gamepedia.com/Redstone_Comparator#Containers """ -""" + +def required_item_count(strength, slots, stack): + if strength == 0: + count = 0 + elif strength == 1: + count = 1 + else: + count = int(ceil(slots * stack / 14.0 * (strength - 1))) + + resulting_strength = int(1 + 14.0 * count / stack / slots) + + return count if resulting_strength == strength else None + @simplecommand("signalstrength", usage = " [item] [data]", aliases = ["ss", "level"], @@ -163,58 +173,67 @@ Suggestion by Armadillo28, see thread: http://redstoner.com/forums/threads/2213- helpSubcmd = True, senderLimit = 0) def on_signalstrength_command(sender, command, label, args): - values = [] - try: - for i in range(len(args)): - values[i] = int(args[i]) - except ValueError: - return "&cYou have to enter a number for the signal strength" - target_block = sender.getTargetBlock(None, 5) - Validate.notNone(target_block) - target_type = str(target_block.getType()) - Validate.isTrue(target_type in container_levels) + Validate.notNone(target_block, "&cThat command can only be used when a container is targeted") - levels = container_levels[target_type] + try: + inv = target_block.getState().getInventory() + except AttributeError: + return "&cThat command can only be used when a container is targeted" - item_value = 1 - item_type = Material.REDSTONE - item_data = 0 - if len(values) > 1: - item_type = Material.getMaterial(values[1]) - if item_type == None: - return "&cThat is not an item ID" - if len(values) == 3: - item_data = values[2] - if not (0 <= item_data <= 15): - return "&cThe data must be a number from 0 to a maximum of 15" - if values[1] in (items that stack up to 16): - item_value = 4 - elif values[1] in (items that stack up to 1): - item_value = 64 + #--------Check if all arguments are an int >= 0 and reassign args--------- + for i in range(len(args)): + if not args[i].isdigit(): + return "&cThe %s has to be a number >= 0" % ("signal strength", "item", "data")[i] + args = [int(arg) for arg in args] - target_strength = values[0] + #---------Define the requested strength, item type and item data---------- + strength = args[0] + Validate.isTrue(0 <= strength <= 15, "&cThe signal strength has to be a value from 0 to 15") - item_count = levels[target_strength] / item_value + item_type = Material.REDSTONE if len(args) < 2 else Material.getMaterial(args[1]) + Validate.notNone(item_type, "&cThat item id does not exist") - if int(item_count) * item_value < levels[target_strength] and (int(item_count) + 1) * item_value >= levels[target_strength + 1]: #if target_strength = 15, first check will always be false, so no IndexError - return "&cThe desired signal strength could not be achieved with the requested item type" + item_data = 0 if len(args) < 3 else args[2] + Validate.isTrue(0 <= item_data <= 15, "&cThe data has to be a value from 0 to 15") - item_count = int(item_count) - if item_count % 1 != 0: - item_count += 1 + #--------Get the stack size and required amount of items to achieve the desired signal strength--------- + stack_size = item_type.getMaxStackSize() + item_count = required_item_count(strength, inv.getSize(), stack_size) + Validate.notNone(item_count, "&cThe desired signal strength could not be achieved with the requested item type") - def stack(count): - return ItemStack(values[1]) - - full_stacks = int(item_count / item_value) - for i in range(0, full_stacks) #amount of full stacks - target_block.setItem(i, ItemStack()) -""" + #------------Add the other side of the chest if target is a double chest-------------- + target_blocks = [target_block] + target_type = target_block.getType() + if target_type in (Material.CHEST, Material.TRAPPED_CHEST): + loc = target_block.getLocation() + x = loc.getBlockX() + y = loc.getBlockY() + z = loc.getBlockZ() + world = loc.getWorld() + target_blocks += [ + block for block in ( + world.getBlockAt(x + 1, y, z), + world.getBlockAt(x - 1, y, z), + world.getBlockAt(x, y, z + 1), + world.getBlockAt(x, y, z - 1), + ) if block.getType() == target_type + ] + + #----------------Insert items------------- + full_stack_count, remaining = divmod(item_count, stack_size) + + inv.clear() + for block in target_blocks: + for i in range(full_stack_count): + inv.setItem(i, ItemStack(item_type, stack_size, item_data)) + if remaining > 0: + inv.setItem(full_stack_count, ItemStack(item_type, remaining, item_data)) + return "&aSuccesfully edited the targeted %s to give out a signal strenth of %s to comparators" % (str(target_type).lower().replace("_", " "), strength) -- 2.45.2 From 2db8142b35a92e93459fb9a9505778db303291a9 Mon Sep 17 00:00:00 2001 From: Dico200 Date: Tue, 20 Oct 2015 02:58:42 +0200 Subject: [PATCH 063/217] Small update to /signalstrength --- misc.py | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/misc.py b/misc.py index 4db1ae0..ed10bf8 100644 --- a/misc.py +++ b/misc.py @@ -146,7 +146,7 @@ def on_sudo_command(sender, command, label, args): """ -Suggestion by Armadillo28, see thread: http://redstoner.com/forums/threads/2213-putting-the-correct-amount-of-items-in-a-container?page=1#reply-14507 +Suggestion by Armadillo28, see thread: http://redstoner.com/forums/threads/2213?page=1#reply-14507 Clarification on these formulas on http://minecraft.gamepedia.com/Redstone_Comparator#Containers """ @@ -182,20 +182,14 @@ def on_signalstrength_command(sender, command, label, args): except AttributeError: return "&cThat command can only be used when a container is targeted" - #--------Check if all arguments are an int >= 0 and reassign args--------- - for i in range(len(args)): - if not args[i].isdigit(): - return "&cThe %s has to be a number >= 0" % ("signal strength", "item", "data")[i] - args = [int(arg) for arg in args] - #---------Define the requested strength, item type and item data---------- - strength = args[0] - Validate.isTrue(0 <= strength <= 15, "&cThe signal strength has to be a value from 0 to 15") + Validate.isTrue(args[0].isdigit() and 0 <= int(args[0]) <= 15, "&cThe signal strength has to be a value from 0 to 15") + strength = int(args[0]) - item_type = Material.REDSTONE if len(args) < 2 else Material.getMaterial(args[1]) + item_type = Material.REDSTONE if len(args) < 2 else Material.getMaterial(int(args[1]) if args[1].isdigit() else args[1]) Validate.notNone(item_type, "&cThat item id does not exist") - item_data = 0 if len(args) < 3 else args[2] + item_data = 0 if len(args) < 3 else int(args[2]) if args[2].isdigit() else -1 Validate.isTrue(0 <= item_data <= 15, "&cThe data has to be a value from 0 to 15") #--------Get the stack size and required amount of items to achieve the desired signal strength--------- @@ -233,7 +227,8 @@ def on_signalstrength_command(sender, command, label, args): inv.setItem(full_stack_count, ItemStack(item_type, remaining, item_data)) - return "&aSuccesfully edited the targeted %s to give out a signal strenth of %s to comparators" % (str(target_type).lower().replace("_", " "), strength) + return "&aSuccesfully edited the targeted %s to give out a signal strenth of %s to comparators" % ( + str(target_type).lower().replace("_", " "), strength) -- 2.45.2 From 9119c3d1500a02b49d078a8a0d01a271e630092b Mon Sep 17 00:00:00 2001 From: Dico200 Date: Tue, 20 Oct 2015 18:03:05 +0200 Subject: [PATCH 064/217] Moved /signalstrength to its own file, added default configurability, added basecommands documentation, added can_build() to helpers --- basecommands.py | 59 ++++++++++++++++++++++++++++++-- helpers.py | 10 ++++++ main.py | 2 ++ misc.py | 91 ------------------------------------------------- 4 files changed, 68 insertions(+), 94 deletions(-) diff --git a/basecommands.py b/basecommands.py index 89e08aa..dee79f8 100644 --- a/basecommands.py +++ b/basecommands.py @@ -1,13 +1,66 @@ from helpers import * -to_see_permission = "utils.showpermission" # See cmd permission in help +""" +@simplecommand is a decorator which is meant to replace @hook.command in redstoner-utils, where useful. +It takes care of checks such as whether the sender is a player, whether they have permission, +whether there are enough argumens, and also takes care of a help message. +On top of that, it makes the code shorter and easier to write with features like Validate, and returning a message instead of a boolean value. +@simplecommand has an inbuilt tracing feature, so you won't have to put all your code in a try/except statement anymore. +Make sure to `from basecommands import simplecommand` before using this decorator. +The arguments are as follows: +* cmd: the command, self explanatory (required); + +* aliases: A list containing any aliases for the command, like shortcuts; + +* usage: a String defining the expected arguments for the command. Example: + Let's say I have a command /tp . The usage is: " ". + I suggest we use the same format throughout redstoner-utils: + - Separate arguments by spaces; + - Use <> if the argument is required, and [] if the argument is optional; + - Add .. to the argument's identifier (name) if it is for example a message (containing spaces). + for example in /msg, the usage would be " " + +* description: a description of what the command does. Defaults to "Handles cmd". + This is used for the help message, where the description is (meant to be) indented. To keep this indentation + with longer descriptions, call the help message (with the command, ingame) and add '\n' + when it jumps to a new line in the chat. The decorator will take care of the indentation after that. + +* senderLimit: an integer resembling the accepted sender type. Defaults to -1. Use: + -1 for console as well as players; + 0 for players only; + 1 for console only. + +* amin: an integer resembling the minimum amount of arguments. Defaults to 0 + +* amax: an integer resembling the maximum amount of arguments. Defaults to -1, which means that there is no maximum. + +* helpNoargs: a boolean value resembling whether the help message should be displayed when no arguments are given. + Defaults to False. + +* helpSubcmd: a boolean value resembling whether the help message should be displayed when the first argument.lower() equals "help". + Defaults to False. + +Comments on the function added to the decorator: +It should return a message to send to the player. Color codes are translated automatically. It can return None or an empty string to send nothing. + +Inside the function, calls to static methods in the class Validate can be used to make the code shorter and easier to write (maybe not easier to read). +For example, to make sure that a condition is met, use Validate.isTrue(condition, message to send to the player if the condition is not met) +Don't forget to `from basecommands import Validate` if you wish to make use of this. +For all other Validate checks, see the code below. Feel free to add your own. + +Instead of returning a message mid-code to describe an error, you can also use raise CommandException(msg), but it is almost always possible +to replace this return statement with a call to one of the functions in the Validate class. Once again, if you use raise CommandException(msg), +don't forget to `from basecommands import CommandException`. +""" + +to_see_permission = "utils.showpermission" # See cmd permission in help def isSenderValid(senderLimit, isPlayer): return True if senderLimit == -1 else senderLimit != isPlayer def invalidSenderMsg(isPlayer): - return "&cThat command can only be run from the console" if isPlayer else "&cThat command can only be run by players" + return "&cThat command can only be used by " + ("the console" if isPlayer else "players") def helpMsg(sender, cmd, description, usage, aliases, permission): help_msg = "&aInformation about command /%s:\n &9%s" % (cmd, description.replace("\n", "\n ")) @@ -65,7 +118,7 @@ def simplecommand(cmd, except CommandException, e: return e.message except Exception, e: - error(e.message, trace()) + error(trace()) return "&cAn internal error occurred while attempting to perform this command" return call diff --git a/helpers.py b/helpers.py index 0cb7cbc..dcf5cc3 100644 --- a/helpers.py +++ b/helpers.py @@ -6,6 +6,7 @@ import org.bukkit as bukkit import org.bukkit.Location as Location import org.bukkit.entity.Player as Player import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause as TeleportCause +import org.bukkit.event.block.BlockBreakEvent as BlockBreakEvent import org.bukkit.block as bblock import org.bukkit.event.entity as entity import org.bukkit.command.ConsoleCommandSender @@ -143,6 +144,15 @@ def is_player(obj): return (isinstance(obj, Player)) +def can_build(player, block): + """ + return True if the player can change/build at the location of given block + """ + event = BlockBreakEvent(block, player) + server.getPluginManager().callEvent(event) + return not event.isCancelled() + + def checkargs(sender, args, amin, amax): """ check if a command has a valid amount of args, otherwise notify the sender diff --git a/main.py b/main.py index 2138216..b66b3ac 100644 --- a/main.py +++ b/main.py @@ -54,6 +54,8 @@ shared["load_modules"] = [ "webtoken", # Adds /lol, broadcasts random funyy messages. A bit like the splash text in the menu "saylol", + # Adds /signalstrength, lets you request a signal strength and an amount of items will be inserted into target container to meet that strength. + "signalstrength", # Shows the owner of a skull when right-clicked "skullclick", # Adds /listen, highlights chat and plays a sound when your name was mentioned diff --git a/misc.py b/misc.py index ed10bf8..e5727bc 100644 --- a/misc.py +++ b/misc.py @@ -4,11 +4,7 @@ from time import time as now from time import sleep from sys import exc_info import thread - import org.bukkit.inventory.ItemStack as ItemStack -import org.bukkit.Material as Material -from math import ceil - import org.bukkit.Bukkit as Bukkit from basecommands import simplecommand, Validate @@ -145,93 +141,6 @@ def on_sudo_command(sender, command, label, args): return "&cPlayer %s not found!" % target -""" -Suggestion by Armadillo28, see thread: http://redstoner.com/forums/threads/2213?page=1#reply-14507 - -Clarification on these formulas on http://minecraft.gamepedia.com/Redstone_Comparator#Containers -""" - -def required_item_count(strength, slots, stack): - if strength == 0: - count = 0 - elif strength == 1: - count = 1 - else: - count = int(ceil(slots * stack / 14.0 * (strength - 1))) - - resulting_strength = int(1 + 14.0 * count / stack / slots) - - return count if resulting_strength == strength else None - -@simplecommand("signalstrength", - usage = " [item] [data]", - aliases = ["ss", "level"], - description = "Fills the targeted container with the correct amount of items to achieve the desired signal strength.", - amin = 1, - amax = 3, - helpNoargs = True, - helpSubcmd = True, - senderLimit = 0) -def on_signalstrength_command(sender, command, label, args): - - target_block = sender.getTargetBlock(None, 5) - Validate.notNone(target_block, "&cThat command can only be used when a container is targeted") - - try: - inv = target_block.getState().getInventory() - except AttributeError: - return "&cThat command can only be used when a container is targeted" - - #---------Define the requested strength, item type and item data---------- - Validate.isTrue(args[0].isdigit() and 0 <= int(args[0]) <= 15, "&cThe signal strength has to be a value from 0 to 15") - strength = int(args[0]) - - item_type = Material.REDSTONE if len(args) < 2 else Material.getMaterial(int(args[1]) if args[1].isdigit() else args[1]) - Validate.notNone(item_type, "&cThat item id does not exist") - - item_data = 0 if len(args) < 3 else int(args[2]) if args[2].isdigit() else -1 - Validate.isTrue(0 <= item_data <= 15, "&cThe data has to be a value from 0 to 15") - - #--------Get the stack size and required amount of items to achieve the desired signal strength--------- - stack_size = item_type.getMaxStackSize() - item_count = required_item_count(strength, inv.getSize(), stack_size) - Validate.notNone(item_count, "&cThe desired signal strength could not be achieved with the requested item type") - - #------------Add the other side of the chest if target is a double chest-------------- - target_blocks = [target_block] - target_type = target_block.getType() - if target_type in (Material.CHEST, Material.TRAPPED_CHEST): - loc = target_block.getLocation() - x = loc.getBlockX() - y = loc.getBlockY() - z = loc.getBlockZ() - world = loc.getWorld() - - target_blocks += [ - block for block in ( - world.getBlockAt(x + 1, y, z), - world.getBlockAt(x - 1, y, z), - world.getBlockAt(x, y, z + 1), - world.getBlockAt(x, y, z - 1), - ) if block.getType() == target_type - ] - - #----------------Insert items------------- - full_stack_count, remaining = divmod(item_count, stack_size) - - inv.clear() - for block in target_blocks: - for i in range(full_stack_count): - inv.setItem(i, ItemStack(item_type, stack_size, item_data)) - if remaining > 0: - inv.setItem(full_stack_count, ItemStack(item_type, remaining, item_data)) - - - return "&aSuccesfully edited the targeted %s to give out a signal strenth of %s to comparators" % ( - str(target_type).lower().replace("_", " "), strength) - - - @simplecommand("me", usage = "[message..]", -- 2.45.2 From ce4fa316d9dbc61868650fc927e0eb23827c5938 Mon Sep 17 00:00:00 2001 From: Dico200 Date: Tue, 20 Oct 2015 18:05:40 +0200 Subject: [PATCH 065/217] Added the signalstrength.py file. --- signalstrength.py | 159 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 159 insertions(+) create mode 100644 signalstrength.py diff --git a/signalstrength.py b/signalstrength.py new file mode 100644 index 0000000..b264143 --- /dev/null +++ b/signalstrength.py @@ -0,0 +1,159 @@ +from helpers import * +import org.bukkit.inventory.ItemStack as ItemStack +import org.bukkit.Material as Material +from math import ceil +from basecommands import simplecommand, Validate, CommandException + +""" Suggestion by Armadillo28, see thread: http://redstoner.com/forums/threads/2213?page=1#reply-14507 """ + +disallowed_item_types = ( + Material.getMaterial(0), + Material.getMaterial(175), + Material.getMaterial(383), +) + +default_args = open_json_file("signalstrengthdefaults", {}) + +def save_defaults(): + save_json_file("signalstrengthdefaults", default_args) + + +def item_name(item_type, remove_underscores = True): + typ = str(item_type).lower() + return typ.replace("_", "") if remove_underscores else typ + + +def item_type_allowed(item_type): + return not item_type in disallowed_item_types + + +def required_item_count(strength, stack_size, slot_count): + if strength == 0: + item_count = 0 + elif strength == 1: + item_count = 1 + else: + item_count = int(ceil(slot_count * stack_size / 14.0 * (strength - 1))) + + resulting_strength = 0 if item_count == 0 else int(1 + 14.0 * item_count / stack_size / slot_count) + #Clarification on these formulas at http://minecraft.gamepedia.com/Redstone_Comparator#Containers + + return item_count if resulting_strength == strength else None + + +def get_data(player, args): + uuid = uid(player) + if uuid in default_args: + strength, item_type, item_data = default_args[uuid] + item_type = Material.getMaterial(item_type) + else: + strength = 1 + item_type = Material.REDSTONE + item_data = 0 + + if len(args) > 0: + Validate.isTrue(args[0].isdigit() and 0 <= int(args[0]) <= 15, "&cThe signal strength has to be a value from 0 to 15") + strength = int(args[0]) + + if len(args) > 1: + if args[1].isdigit(): + item_type = Material.getMaterial(int(args[1])) + else: + item_type = Material.matchMaterial(args[1]) + Validate.notNone(item_type, "&cThat item type could not be found") + Validate.isTrue(item_type not in disallowed_item_types, "&cThat item type may not be used") + + if len(args) > 2: + Validate.isTrue(args[2].isdigit() and 0 <= int(args[2]) <= 15, "&cThe data has to be a value from 0 to 15") + item_data = int(args[2]) + + return (strength, item_type, item_data) + + +def get_inventory(block): + try: + return block.getState().getInventory() + except AttributeError: + return None + + +def get_entire_container(container): + container_blocks = [container] + container_type = container.getType() + if container_type in (Material.CHEST, Material.TRAPPED_CHEST): + loc = container.getLocation() + x = loc.getBlockX() + y = loc.getBlockY() + z = loc.getBlockZ() + world = loc.getWorld() + + container_blocks += [ + block for block in ( + world.getBlockAt(x + 1, y, z), + world.getBlockAt(x - 1, y, z), + world.getBlockAt(x, y, z + 1), + world.getBlockAt(x, y, z - 1), + ) if block.getType() == target_type + ] + + return container_blocks + + + +@simplecommand("signalstrength", + usage = "( [item] [data]) or (default [data])", + aliases = ["ss", "level"], + description = "Fills the targeted container with the correct amount of items to achieve the desired signal strength.", + amin = 0, + amax = 4, + helpSubcmd = True, + senderLimit = 0) +def on_signalstrength_command(sender, command, label, args): + + if len(args) > 0 and args[0].lower() in ("default", "defaults", "setdefaults"): + strength, item_type, item_data = get_data(sender, args[1:]) + + uuid = uid(sender) + if strength == 1 and item_type == Material.REDSTONE and item_data == 0: + if uuid in default_args: + del default_args[uuid] + save_defaults() + else: + default_args[uuid] = (strength, str(item_type), item_data) + save_defaults() + + return "&aSet your signal strength defaults to (%s, %s, %s)" % (strength, item_name(item_type, False), item_data) + + Validate.isTrue(len(args) <= 3, "&cExpected at most 3 arguments") + + target_block = sender.getTargetBlock(None, 5) + Validate.notNone(target_block, "&cThat command can only be used when a container is targeted") + + inventory = get_inventory(target_block) + Validate.notNone(inventory, "&cThat command can only be used if a container is targeted") + + strength, item_type, item_data = get_data(sender, args) + + #--------Get the stack size and required amount of items to achieve the desired signal strength--------- + stack_size = item_type.getMaxStackSize() + slot_count = inventory.getSize() + + item_count = required_item_count(strength, stack_size, slot_count) + Validate.notNone(item_count, "&cThe desired signal strength could not be achieved with the requested item type") + + #--------Add the other side of the chest if target is a double chest and check if player can build--------- + container_blocks = get_entire_container(target_block) + for block in container_blocks: + Validate.isTrue(can_build(sender, block), "&cYou do not have permission to do that here") + + #----------------Insert items------------- + full_stack_count, remaining = divmod(item_count, stack_size) + for block in container_blocks: + inv = block.getState().getInventory() + inv.clear() + for i in range(full_stack_count): + inv.setItem(i, ItemStack(item_type, stack_size, item_data)) + if remaining > 0: + inv.setItem(full_stack_count, ItemStack(item_type, remaining, item_data)) + + return "&aComparators attached to that %s will now put out a signal strength of %s" % (item_name(target_block.getType()), strength) -- 2.45.2 From b4f5a68e4e3ba4993e8326d2f11f9582933b694e Mon Sep 17 00:00:00 2001 From: Dico200 Date: Tue, 20 Oct 2015 18:10:56 +0200 Subject: [PATCH 066/217] small addition to basecommands documentation --- basecommands.py | 1 + 1 file changed, 1 insertion(+) diff --git a/basecommands.py b/basecommands.py index dee79f8..7bfb8c2 100644 --- a/basecommands.py +++ b/basecommands.py @@ -43,6 +43,7 @@ The arguments are as follows: Comments on the function added to the decorator: It should return a message to send to the player. Color codes are translated automatically. It can return None or an empty string to send nothing. +Returning "HELP" makes it show the help message. Inside the function, calls to static methods in the class Validate can be used to make the code shorter and easier to write (maybe not easier to read). For example, to make sure that a condition is met, use Validate.isTrue(condition, message to send to the player if the condition is not met) -- 2.45.2 From fb7871bb3b65d0300cc08a97cb0a2413a866feed Mon Sep 17 00:00:00 2001 From: PixelSergey Date: Tue, 20 Oct 2015 19:42:14 +0300 Subject: [PATCH 067/217] Added I'M BUSY! plugin --- imbusy.py | 107 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 imbusy.py diff --git a/imbusy.py b/imbusy.py new file mode 100644 index 0000000..64fa30b --- /dev/null +++ b/imbusy.py @@ -0,0 +1,107 @@ +# I'M BUSY! Plugin by Curs3d # +############################## +# Concept by CookieManors :D # +# http://bit.ly/1GnNPW8 # +############################## +# This plugin permits users to +# send a command that renders +# them "busy", not letting them +# to get tpa requests or direct +# messages, except from console. +# On restart, all busy data will +# be cleared. + +from helpers import * +from basecommands import simplecommand +from traceback import format_exc as trace +busy_players = [] + + +def unclear(): + msg(sender, "Umm, what? Sorry, directions unlclear, got head stuck in washing machine") + + +@hook.command("busy", + aliases = ["focus"], + usage = "/ ", + description = "Sets busy mode on, you cannot recieve tpas and MSGs" + ) +def on_busy_command(sender, cmd, label, args): + + if not is_player(sender): + msg(sender, "Sorry, Console cannot be busy") + return True + + if not sender.hasPermission("utils.busy.allowed"): + plugin_header(recipient = sender, name = "I'M BUSY!") + noperm(sender) + return True + + if len(args) == 0: + plugin_header(recipient = sender, name = "I'M BUSY!") + msg(sender, "This plugin allows being busy, and when turned on you will not recieve any direct messages or tpa requests.") + msg(sender, "\nCommands:") + msg(sender, "/busy on: turns on busy mode") + msg(sender, "/busy off: turns off busy mode") + msg(sender, "/busy status [player]: shows your or [player]'s current busy status.") + return True + + elif len(args) == 1: + if args[0] == "on": + if sender.getName() in busy_players: + plugin_header(recipient = sender, name = "I'M BUSY!") + msg(sender, "You cannot be even more focused than this without being a jedi!") + return True + busy_players.append(sender.getName()) + plugin_header(recipient = sender, name = "I'M BUSY!") + broadcast(None, "%s is now SUPER busy! Don't even TRY bothering them, it will not work!" % sender.getName()) + return True + + elif args[0] == "off": + plugin_header(recipient = sender, name = "I'M BUSY!") + try: + busy_players.remove(sender.getName()) + msg(sender, "Master has sent /busy command, %s is freeee!" % sender.getName()) + return True + except ValueError: + msg(sender, "You are not busy! You cannot be even less busy! Are you perhaps bored?") + return True + + elif args[0] == "status": + plugin_header(recipient = sender, name = "I'M BUSY!") + if sender.getName() in busy_players: + msg(sender, "You are super-duper busy and concentrated right now. Think, think, think!") + return True + else: + msg(sender, "You are completely unable to focus right now.") + return True + + else: + plugin_header(recipient = sender, name = "I'M BUSY!") + unclear() + return False + + elif len(args) == 2 and args[0] == "status": + plugin_header(recipient = sender, name = "I'M BUSY!") + if args[1] in busy_players: + msg(sender, "Yes, %s is busy. Shhh..." % args[1]) + return True + else: + msg(sender, "No, you're good. Feel free to chat with %s!" % args[1]) + return True + + else: + plugin_header(recipient = sender, name = "I'M BUSY!") + unclear() + return False + + +@hook.event("player.PlayerCommandPreprocessEvent", "monitor") +def on_cmd_preprocess_event(event): + message = event.getMessage().split(" ") + if message[0] == "/msg" or message[0] == "/w" or message[0] == "/m" or \ + message[0] == "/tell" or message[0] == "/tpa" or message[0] == "/tpahere": + if message[1] in busy_players: + plugin_header(recipient = event.getPlayer(), name = "I'M BUSY!") + msg(event.getPlayer(), "We are sorry, but %s is currently busy. Please try again later." % message[1]) + event.setCancelled(True) -- 2.45.2 From e036716a62e7e011c2d9df6a4aa37d9f17770c73 Mon Sep 17 00:00:00 2001 From: PixelSergey Date: Tue, 20 Oct 2015 19:45:53 +0300 Subject: [PATCH 068/217] Remembered to edit main.py :) --- main.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/main.py b/main.py index b66b3ac..0f436a8 100644 --- a/main.py +++ b/main.py @@ -54,8 +54,11 @@ shared["load_modules"] = [ "webtoken", # Adds /lol, broadcasts random funyy messages. A bit like the splash text in the menu "saylol", +<<<<<<< HEAD +======= # Adds /signalstrength, lets you request a signal strength and an amount of items will be inserted into target container to meet that strength. "signalstrength", +>>>>>>> b4f5a68e4e3ba4993e8326d2f11f9582933b694e # Shows the owner of a skull when right-clicked "skullclick", # Adds /listen, highlights chat and plays a sound when your name was mentioned @@ -74,6 +77,8 @@ shared["load_modules"] = [ "check", # Adds /an, a command you can use to share thoughts/plans/news "adminnotes", + # Adds busy status to players + "imbusy", # Adds /imout, displays fake leave/join messages "imout", #adds snowbrawl minigame -- 2.45.2 From 3d34f15c41c6b8960c12a19d07877315c66189ac Mon Sep 17 00:00:00 2001 From: NEMESIS13cz Date: Tue, 27 Oct 2015 17:05:55 +0100 Subject: [PATCH 069/217] Changed to ignore lower/upper case --- calc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/calc.py b/calc.py index 1da634b..47326b3 100644 --- a/calc.py +++ b/calc.py @@ -11,7 +11,7 @@ calc_perm_power = "utils.calc.power" def calc(sender, text): try: - return do_calc(sender, text) + return do_calc(sender, text.lower()) except: return None -- 2.45.2 From b369ea75575c5cb387378e8d3a87f49372c0594a Mon Sep 17 00:00:00 2001 From: Sergey Date: Wed, 28 Oct 2015 18:49:52 +0200 Subject: [PATCH 070/217] Removed random crap How did it get there?! --- main.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/main.py b/main.py index 0f436a8..d9aa66b 100644 --- a/main.py +++ b/main.py @@ -54,11 +54,8 @@ shared["load_modules"] = [ "webtoken", # Adds /lol, broadcasts random funyy messages. A bit like the splash text in the menu "saylol", -<<<<<<< HEAD -======= # Adds /signalstrength, lets you request a signal strength and an amount of items will be inserted into target container to meet that strength. "signalstrength", ->>>>>>> b4f5a68e4e3ba4993e8326d2f11f9582933b694e # Shows the owner of a skull when right-clicked "skullclick", # Adds /listen, highlights chat and plays a sound when your name was mentioned -- 2.45.2 From 45a9b260d91ba9a324e27c4317171f9761de921e Mon Sep 17 00:00:00 2001 From: NEMESIS13cz Date: Fri, 30 Oct 2015 16:31:23 +0100 Subject: [PATCH 071/217] Now works with offline players --- tag.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tag.py b/tag.py index 0a312aa..b2aa98d 100644 --- a/tag.py +++ b/tag.py @@ -34,11 +34,11 @@ def command(sender, command, label, args): else: msg(sender, "&a-&c Unknown subcommand! (add, check, del)") else: - msg(sender, "&a&c Usage: /tag add/check") + msg(sender, "&a&c Usage: /tag add/check/del") return True def delete(sender, args): - player = server.getPlayer(args[0]) + player = server.getOfflinePlayer(args[0]) uuid = uid(player) try: if data[uuid] == None: @@ -54,7 +54,7 @@ def delete(sender, args): msg(sender, "&a-&e Deleted note at %s" % args[1]) def add(sender, args): - player = server.getPlayer(args[0]) + player = server.getOfflinePlayer(args[0]) uuid = uid(player) try: if data[uuid] == None: @@ -66,7 +66,7 @@ def add(sender, args): save_json_file("tag", data) def check(sender, args): - player = server.getPlayer(args[0]) + player = server.getOfflinePlayer(args[0]) uuid = uid(player) try: num = 0 -- 2.45.2 From 086eade43f18df65bee40ec7f1bd8c1f4bde2989 Mon Sep 17 00:00:00 2001 From: Pepich Date: Fri, 30 Oct 2015 16:36:47 +0100 Subject: [PATCH 072/217] fixed colorify method --- helpers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helpers.py b/helpers.py index dcf5cc3..898dea7 100644 --- a/helpers.py +++ b/helpers.py @@ -87,7 +87,7 @@ def colorify(text): """ replace &-codes with real color codes """ - return sub("&(?=[?\\da-fk-or])", u"\u00A7", "%s" % text) + return sub("&" + u"\u00A7", "&", "%s" % sub("&(?=[?\\da-fk-or])", u"\u00A7", "%s" % text)) def stripcolors(text): -- 2.45.2 From 4ed319f15db990f3623b28f3ac876e7d39393041 Mon Sep 17 00:00:00 2001 From: NEMESIS13cz Date: Fri, 30 Oct 2015 16:37:47 +0100 Subject: [PATCH 073/217] Fixed offline players and no notification for the punished player --- punishments.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/punishments.py b/punishments.py index 4c39092..4b57be1 100644 --- a/punishments.py +++ b/punishments.py @@ -98,7 +98,7 @@ def command(sender, cmd, label, args): msg(sender, "&e-&a There are no people mining obsidian") return True for slave in slaves: - msg(sender, "&e-&a %s: %s blocks" % (slave.get_uuid(), slave.get_blocks())) + msg(sender, "&e-&a %s: %s blocks" % (server.getOfflinePlayer(juuid(slave.get_uuid())).getName(), slave.get_blocks())) return True elif args[0] == "add": player = server.getOfflinePlayer(str(args[1])) @@ -106,6 +106,7 @@ def command(sender, cmd, label, args): player.teleport(server.getWorld(punish_world).getSpawnLocation()) Slave(False, player, int(args[2])) save_slaves() + msg(player, "&e-&a You have been punished, mine %s blocks of obsidian to get out!" % args[2]) msg(sender, "&e-&a Player %s has been added into punishments for %s blocks of obsidian" % (player.getName(), args[2])) else: msg(sender, "&cYou can only punish online players") -- 2.45.2 From c66fb40df54ef30b5513f7986f72960e1da71ba5 Mon Sep 17 00:00:00 2001 From: NEMESIS13cz Date: Fri, 30 Oct 2015 16:44:07 +0100 Subject: [PATCH 074/217] changed limit to 1000 --- mentio.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mentio.py b/mentio.py index 936b424..f6496a3 100644 --- a/mentio.py +++ b/mentio.py @@ -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 = -1 +max_amount = 1000 arrow = colorify(u"&r&7\u2192&r") colors_reg = reg_compile(u"\u00A7[\\da-fk-or]") # finds color codes -- 2.45.2 From 743d42f71958b1a81dafebc9a6c3187b09a376cc Mon Sep 17 00:00:00 2001 From: NEMESIS13cz Date: Fri, 30 Oct 2015 16:47:51 +0100 Subject: [PATCH 075/217] added iptracker to main.py --- main.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index d9aa66b..4769bc5 100644 --- a/main.py +++ b/main.py @@ -97,7 +97,9 @@ shared["load_modules"] = [ # obisidian mining punishment plugin "punishments", # a simple replacement for the buggy essentials /vanish - "vanish" + "vanish", + # ip-tracking utility + "iptracker" ] shared["modules"] = {} for module in shared["load_modules"]: -- 2.45.2 From 629a938b3ec3c086e810a74bc06b67299eaa6dc5 Mon Sep 17 00:00:00 2001 From: NEMESIS13cz Date: Fri, 30 Oct 2015 17:06:59 +0100 Subject: [PATCH 076/217] Changed database stuff --- iptracker.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/iptracker.py b/iptracker.py index a25dcce..517bb87 100644 --- a/iptracker.py +++ b/iptracker.py @@ -5,6 +5,7 @@ from java.util import UUID as UUID from helpers import * from org.bukkit import * from traceback import format_exc as trace +from iptracker_secrets import * iptrack_permission = "utils.iptrack" @@ -16,13 +17,13 @@ def on_player_join(event): 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, )) + curs.execute("SELECT ips FROM uuid2ips 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, )) + curs.execute("SELECT uuids FROM ip2uuids WHERE ip = ?", (ip, )) results = curs.fetchall() if len(results) == 0: uuids = [] @@ -33,15 +34,15 @@ def on_player_join(event): if ip not in ips: ips.append(ip) if new_ip_entry: - curs.execute("INSERT INTO iptrack_uuidtoips VALUES (?,?)", (uuid, json.dumps(ips), )) + curs.execute("INSERT INTO uuid2ips VALUES (?,?)", (uuid, json.dumps(ips), )) else: - curs.execute("UPDATE iptrack_uuidtoips SET ips = ? WHERE uuid = ?", (uuid, json.dumps(ips), )) + curs.execute("UPDATE uuid2ips 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), )) + curs.execute("INSERT INTO ip2uuids VALUES (?,?)", (ip, json.dumps(uuids), )) else: - curs.execute("UPDATE iptrack_iptouuids SET uuids = ? WHERE uuid = ?", (ip, json.dumps(uuids), )) + curs.execute("UPDATE ip2uuids SET uuids = ? WHERE uuid = ?", (ip, json.dumps(uuids), )) conn.commit() curs.close() conn.close() @@ -56,7 +57,7 @@ def on_getinfo_command(sender, args): 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], )) + curs.execute("SELECT uuids FROM ip2uuids WHERE ip = ?", (args[0], )) results = curs.fetchall() curs.close() conn.close() @@ -76,7 +77,7 @@ def on_getinfo_command(sender, args): 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(), )) + curs.execute("SELECT ips FROM uuid2ips WHERE uuid = ?", (uuid.toString(), )) results = curs.fetchall() curs.close() conn.close() -- 2.45.2 From 278f0b411cf963ba5606a45a4d8666c29aeccefa Mon Sep 17 00:00:00 2001 From: NEMESIS13cz Date: Fri, 30 Oct 2015 17:16:31 +0100 Subject: [PATCH 077/217] Made iptracker async --- iptracker.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/iptracker.py b/iptracker.py index 517bb87..70cab1a 100644 --- a/iptracker.py +++ b/iptracker.py @@ -7,11 +7,17 @@ from org.bukkit import * from traceback import format_exc as trace from iptracker_secrets import * + iptrack_permission = "utils.iptrack" @hook.event("player.PlayerJoinEvent", "low") def on_player_join(event): + t = threading.Thread(target=on_player_join_thread, args=(event)) + t.daemon = True + t.start() + +def on_player_join_thread(event): player = event.getPlayer() ip = player.getAddress().getHostString() uuid = uid(player) @@ -50,9 +56,14 @@ def on_player_join(event): @hook.command("getinfo") def on_getinfo_command(sender, args): + t = threading.Thread(target=on_player_join_thread, args=(sender, args)) + t.daemon = True + t.start() + +def on_getinfo_command_thread(sender, args): if(sender.hasPermission(iptrack_permission)): if not checkargs(sender, args, 1, 1): - return false + return False else: if isIP(args[0]): conn = zxJDBC.connect(mysql_database, mysql_user, mysql_pass, "com.mysql.jdbc.Driver") -- 2.45.2 From 9c3d9696959d6f4d95cb8171163c2a101f53f295 Mon Sep 17 00:00:00 2001 From: Dico200 Date: Sat, 31 Oct 2015 15:52:03 +0100 Subject: [PATCH 078/217] Fixed signalstrength error and minor change --- signalstrength.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/signalstrength.py b/signalstrength.py index b264143..d51f35a 100644 --- a/signalstrength.py +++ b/signalstrength.py @@ -93,7 +93,7 @@ def get_entire_container(container): world.getBlockAt(x - 1, y, z), world.getBlockAt(x, y, z + 1), world.getBlockAt(x, y, z - 1), - ) if block.getType() == target_type + ) if block.getType() == container_type ] return container_blocks @@ -101,7 +101,7 @@ def get_entire_container(container): @simplecommand("signalstrength", - usage = "( [item] [data]) or (default [data])", + usage = "(default) [signalstrength] [item] [data]", aliases = ["ss", "level"], description = "Fills the targeted container with the correct amount of items to achieve the desired signal strength.", amin = 0, -- 2.45.2 From 9b47599d063c7c621115cdb0fc72146012537e09 Mon Sep 17 00:00:00 2001 From: PixelSergey Date: Sat, 31 Oct 2015 19:10:22 +0200 Subject: [PATCH 079/217] Fixed ugly stacktraces. And the associated bugs. --- chatalias.py | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/chatalias.py b/chatalias.py index 69ac343..e4f72d7 100755 --- a/chatalias.py +++ b/chatalias.py @@ -13,6 +13,7 @@ # for "unlimited" setting. from helpers import * +from traceback import format_exc as trace def safe_open_json(): @@ -25,7 +26,7 @@ def safe_open_json(): @hook.command("alias", usage = "/ [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 @@ -53,15 +54,25 @@ def on_alias_command(sender, cmd, label, args): elif len(args) == 1: data = safe_open_json() if args[0] == "*": - del data[str(sender.getUniqueId())] + try: + del data[str(sender.getUniqueId())] + except KeyError: + plugin_header(recipient = sender, name = "Chat Alias") + msg(sender, "No alias data to remove!") + return True 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: + try: + 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 + except KeyError: plugin_header(recipient = sender, name = "Chat Alias") - msg(sender, "Could not remove: alias not present!") + msg(sender, "Could not remove: you do not have any aliases!") return True save_json_file("aliases", data) @@ -95,12 +106,18 @@ def on_alias_command(sender, cmd, label, args): return False - @hook.event("player.AsyncPlayerChatEvent", "High") def on_player_chat(event): + playerid = str(event.getPlayer().getUniqueId()) + data = safe_open_json() + if event.isCancelled(): return - data = safe_open_json() - for alias, value in data[str(event.getPlayer().getUniqueId())].items(): + try: + crashtest = data[playerid].items() + except KeyError: + return + + for alias, value in data[playerid].items(): event.setMessage(event.getMessage().replace(alias, value)) -- 2.45.2 From fe8461872f4f8bc778a05c46d5e4a2cf9dc2c536 Mon Sep 17 00:00:00 2001 From: PixelSergey Date: Sat, 31 Oct 2015 19:16:44 +0200 Subject: [PATCH 080/217] Fixed ugly stacktraces. And the associated bugs. --- chatalias.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 chatalias.py diff --git a/chatalias.py b/chatalias.py old mode 100755 new mode 100644 -- 2.45.2 From 398533860bd5242d4089db154173d745d5dbd879 Mon Sep 17 00:00:00 2001 From: PixelSergey Date: Sat, 31 Oct 2015 19:59:55 +0200 Subject: [PATCH 081/217] Fixed ugly stacktraces. And the associated bugs. --- chatalias.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/chatalias.py b/chatalias.py index e4f72d7..8c5c653 100644 --- a/chatalias.py +++ b/chatalias.py @@ -15,8 +15,12 @@ from helpers import * from traceback import format_exc as trace +global data = None def safe_open_json(): + global data + if data is not None: + return data data = open_json_file("aliases") if data is None: data = {"gnl":{"max_len":"35","max_entries":"10"}} -- 2.45.2 From 97e2b80392a8235b1c0d518e4f1b7e86599cde98 Mon Sep 17 00:00:00 2001 From: Curs3d Date: Sat, 31 Oct 2015 20:08:29 +0200 Subject: [PATCH 082/217] Ate pugs. Fixed bugs. --- chatalias.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chatalias.py b/chatalias.py index 8c5c653..2c6ac8f 100644 --- a/chatalias.py +++ b/chatalias.py @@ -15,7 +15,7 @@ from helpers import * from traceback import format_exc as trace -global data = None +data = None def safe_open_json(): global data -- 2.45.2 From 3f677467fced35b2084c01fa1173af88dadc7263 Mon Sep 17 00:00:00 2001 From: NEMESIS13cz Date: Sat, 31 Oct 2015 19:24:33 +0100 Subject: [PATCH 083/217] Fixed conflicts with chatalias --- mentio.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mentio.py b/mentio.py index f6496a3..199eb8c 100644 --- a/mentio.py +++ b/mentio.py @@ -13,7 +13,7 @@ def saveMentions(): save_json_file("mentio", mentions) -@hook.event("player.AsyncPlayerChatEvent", "high") +@hook.event("player.AsyncPlayerChatEvent", "normal") def onChat(event): if not event.isCancelled(): sender = event.getPlayer() -- 2.45.2 From dfa48d7da551db2abb1df965952dae5a5b8c424f Mon Sep 17 00:00:00 2001 From: NEMESIS13cz Date: Sat, 31 Oct 2015 19:31:32 +0100 Subject: [PATCH 084/217] This seems to fix everything --- mentio.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mentio.py b/mentio.py index 199eb8c..fa46d71 100644 --- a/mentio.py +++ b/mentio.py @@ -13,7 +13,7 @@ def saveMentions(): save_json_file("mentio", mentions) -@hook.event("player.AsyncPlayerChatEvent", "normal") +@hook.event("player.AsyncPlayerChatEvent", "monitor") def onChat(event): if not event.isCancelled(): sender = event.getPlayer() -- 2.45.2 From 626ec7f187e95e87d1c53ee2f3e3f930f3c414ea Mon Sep 17 00:00:00 2001 From: NEMESIS13cz Date: Sat, 31 Oct 2015 19:31:46 +0100 Subject: [PATCH 085/217] lowercase please --- chatalias.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chatalias.py b/chatalias.py index 2c6ac8f..dc7db72 100644 --- a/chatalias.py +++ b/chatalias.py @@ -110,7 +110,7 @@ def on_alias_command(sender, cmd, label, args): return False -@hook.event("player.AsyncPlayerChatEvent", "High") +@hook.event("player.AsyncPlayerChatEvent", "high") def on_player_chat(event): playerid = str(event.getPlayer().getUniqueId()) data = safe_open_json() -- 2.45.2 From 438a2f702778d2455c3f1308f5b828a54b0067b3 Mon Sep 17 00:00:00 2001 From: NEMESIS13cz Date: Sun, 1 Nov 2015 14:08:48 +0100 Subject: [PATCH 086/217] Added permissions for warn and warnp --- misc.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/misc.py b/misc.py index e5727bc..c6da200 100644 --- a/misc.py +++ b/misc.py @@ -263,7 +263,10 @@ def on_modules_command(sender, command, label, args): amax = 0, helpSubcmd = True) def warn_command(sender, command, label, args): - broadcast(None, " &b= &2&lLag incoming! &r-%s" % sender.getDisplayName()) + if sender.hasPermission("utils.warn"): + broadcast(None, " &b= &2&lLag incoming! &r-%s" % sender.getDisplayName()) + else: + noperm(sender) @simplecommand("warnp", @@ -272,7 +275,10 @@ def warn_command(sender, command, label, args): amax = 0, helpSubcmd = True) def warnp_command(sender, command, label, args): - broadcast(None, " &b= &2&lPossible lag incoming! &r-%s" % sender.getDisplayName()) + if sender.hasPermission("utils.warnp"): + broadcast(None, " &b= &2&lPossible lag incoming! &r-%s" % sender.getDisplayName()) + else: + noperm(sender) -- 2.45.2 From cb8efcc767429125cf9aac6ebae0d08e26b8d2c7 Mon Sep 17 00:00:00 2001 From: NEMESIS13cz Date: Sun, 1 Nov 2015 14:09:01 +0100 Subject: [PATCH 087/217] fixed errors on login event --- iptracker.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iptracker.py b/iptracker.py index 70cab1a..8bbd053 100644 --- a/iptracker.py +++ b/iptracker.py @@ -13,7 +13,7 @@ iptrack_permission = "utils.iptrack" @hook.event("player.PlayerJoinEvent", "low") def on_player_join(event): - t = threading.Thread(target=on_player_join_thread, args=(event)) + t = threading.Thread(target=on_player_join_thread, args=(event, )) t.daemon = True t.start() -- 2.45.2 From 670203522b16937d768046d3ae2b1a2c97d2685f Mon Sep 17 00:00:00 2001 From: NEMESIS13cz Date: Sun, 1 Nov 2015 14:09:13 +0100 Subject: [PATCH 088/217] Added permission for signalstrength --- signalstrength.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/signalstrength.py b/signalstrength.py index d51f35a..10a4933 100644 --- a/signalstrength.py +++ b/signalstrength.py @@ -109,7 +109,9 @@ def get_entire_container(container): helpSubcmd = True, senderLimit = 0) def on_signalstrength_command(sender, command, label, args): - + if not sender.hasPermission("utils.ss"): + noperm(sender) + return None if len(args) > 0 and args[0].lower() in ("default", "defaults", "setdefaults"): strength, item_type, item_data = get_data(sender, args[1:]) -- 2.45.2 From 5f77eddf5c95b3ff38b8aaa56e1c019daeb1edc0 Mon Sep 17 00:00:00 2001 From: Dico200 Date: Sun, 1 Nov 2015 21:59:05 +0100 Subject: [PATCH 089/217] This module should work now. Can someone test it? --- synchronizeranks.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/synchronizeranks.py b/synchronizeranks.py index 97439e0..56cc20b 100644 --- a/synchronizeranks.py +++ b/synchronizeranks.py @@ -27,19 +27,19 @@ def on_player_join(event): if role != ranks[rank]: set_role(uuid, ranks[rank]) return - if not user.hasPlayedBefore(): - return - if role == None: + if user.hasPlayedBefore() and role == None: msg(user, "&cYou haven't registed yet! Make sure to do so on redstoner.com") - def get_role(uuid): - return execute_query("SELECT `role_id` FROM users WHERE `uuid` = ? LIMIT 1", uuid)[0][17] + results = execute_query("SELECT `role_id` FROM users WHERE `uuid` = ? LIMIT 1", uuid) + return results[0][0] + # Returns a table with 1 row (LIMIT 1) and 1 column (SELECT `role_id`), so we're looking for the first row of the first column. def set_role(uuid, role_id): - execute_update("UPDATE users SET `role_id` = %d WHERE `uuid` = ?" % role_id, uuid) + execute_update(("UPDATE users SET `role_id` = %d WHERE `uuid` = ?" % role_id), uuid) + # %d is like %s for integers (unlogically, you'd expect something like %i), though %s also works here. def execute_query(query, uuid): -- 2.45.2 From eb201196e16659730c36f5742bab19e34261282a Mon Sep 17 00:00:00 2001 From: Dico200 Date: Sun, 1 Nov 2015 22:03:21 +0100 Subject: [PATCH 090/217] Small change <3 --- synchronizeranks.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/synchronizeranks.py b/synchronizeranks.py index 56cc20b..8d0db60 100644 --- a/synchronizeranks.py +++ b/synchronizeranks.py @@ -21,13 +21,12 @@ def on_player_join(event): role = get_role(uuid) if role in [1, 2, 6]: #Disabled/Banned/Superadmin return - if role: + if role != None: for rank in ranks: if user.hasPermission("group." + rank): if role != ranks[rank]: set_role(uuid, ranks[rank]) - return - if user.hasPlayedBefore() and role == None: + elif user.hasPlayedBefore(): msg(user, "&cYou haven't registed yet! Make sure to do so on redstoner.com") -- 2.45.2 From c84dce9d34d35fa6f71f18565ec55d0e54604a2c Mon Sep 17 00:00:00 2001 From: Pepich Date: Mon, 2 Nov 2015 00:02:44 +0100 Subject: [PATCH 091/217] Added colorsupport, fixed perms and limits into file, added length limitations, made file PEP8 conform --- chatalias.py | 97 +++++++++++++++++++++++++++++----------------------- 1 file changed, 54 insertions(+), 43 deletions(-) diff --git a/chatalias.py b/chatalias.py index dc7db72..0a34ebe 100644 --- a/chatalias.py +++ b/chatalias.py @@ -17,95 +17,102 @@ from traceback import format_exc as trace data = None +max_entries = 10 +max_alias_length = 35 +# minecraft message limit is 100 so I decided to give a little tolerance +max_overall_length = 115 + +alias_perm = "utils.alias.allowed" +exceed_length = "utils.alias.exceedlimit" +exceed_entries = "utils.alias.exceedlimit" +exceed_overall_length = "utils.alias.exceedlimit" + + def safe_open_json(): global data if data is not None: return data data = open_json_file("aliases") if data is None: - data = {"gnl":{"max_len":"35","max_entries":"10"}} + data = {} save_json_file("aliases", data) return data -@hook.command("alias", usage = "/ [to_alias] [alias...]", desc = "Aliases words in chat") +@hook.command("alias", + usage="/ [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") + msg(sender, "Sorry, Console cannot alias words") + return True + if not sender.hasPermission(alias_perm): + 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 : removes from aliased words. Use * to remove all aliased words.") - msg(sender, "/alias : Will change to in chat") - msg(sender, "\nYour Aliases:") + plugin_header(recipient=sender, name="Chat Alias") + msg(sender, "&7This is a plugin that allows you to get words" + + "replaced by other ones automatically!") + msg(sender, "&7\nCommands:") + msg(sender, "&e/alias &7removes from your aliases. " + + "Use &e/alias * &7to remove all aliases.") + msg(sender, "&e/alias &7will change &e " + + "&7to &e &7in chat") + msg(sender, "&7\nYour Aliases:") data = safe_open_json() try: for alias, value in data[str(sender.getUniqueId())].items(): - msg(sender, "%s ==> %s" % (alias, value)) + msg(sender, "&7%s &7==> %s" % (alias, value)) except KeyError: pass return True - elif len(args) == 1: data = safe_open_json() if args[0] == "*": try: del data[str(sender.getUniqueId())] except KeyError: - plugin_header(recipient = sender, name = "Chat Alias") - msg(sender, "No alias data to remove!") + plugin_header(recipient=sender, name="Chat Alias") + msg(sender, "&7No alias data to remove!") return True save_json_file("aliases", data) - plugin_header(recipient = sender, name = "Chat Alias") - msg(sender, "ALL alias data successfuly removed!") + plugin_header(recipient=sender, name="Chat Alias") + msg(sender, "&cALL &7alias data successfuly removed!") return True - try: 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!") + plugin_header(recipient=sender, name="Chat Alias") + msg(sender, "&7Could not remove: alias not present!") return True except KeyError: - plugin_header(recipient = sender, name = "Chat Alias") - msg(sender, "Could not remove: you do not have any aliases!") + plugin_header(recipient=sender, name="Chat Alias") + msg(sender, "&7Could not remove: you do not have any aliases!") return True - save_json_file("aliases", data) - plugin_header(recipient = sender, name = "Chat Alias") - msg(sender, "Alias for %s successfuly removed" % args[0]) + plugin_header(recipient=sender, name="Chat Alias") + msg(sender, "&7Alias for %s &7successfuly 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.") + if (len(alias) > max_alias_length) and (max_alias_length >= 0) and (not sender.hasPermission(exceed_length)): + plugin_header(recipient=sender, name="Chat Alias") + msg(sender, "&7Please 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!") + if (len(data[str(sender.getUniqueId())]) >= max_entries) and (max_entries >= 0) and (not sender.hasPermission(exceed_entries)): + plugin_header(recipient=sender, name="Chat Alias") + msg(sender, "&7You have reached your alias limit!") 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)) + plugin_header(recipient=sender, name="Chat Alias") + msg(sender, "&7Chat Alias %s &7==> %s &7successfully created!" % (args[0], alias)) return True - else: return False @@ -114,14 +121,18 @@ def on_alias_command(sender, cmd, label, args): def on_player_chat(event): playerid = str(event.getPlayer().getUniqueId()) data = safe_open_json() - if event.isCancelled(): return - try: crashtest = data[playerid].items() except KeyError: return - for alias, value in data[playerid].items(): event.setMessage(event.getMessage().replace(alias, value)) + if (event.getPlayer().hasPermission('essentials.chat.color')): + event.setMessage(colorify(event.getMessage())) + if (len(event.getMessage()) > max_overall_length) and (not sender.hasPermission(exceed_overall_length)): + event.setCancelled(True) + msg(sender, "&7The message generated was too long and was not sent " + + "but it would've looked like that:") + msg(sender, event.getMessage()) -- 2.45.2 From 93ca9e045628ccc1d76a6ae8b3648126451f6a24 Mon Sep 17 00:00:00 2001 From: Nemes Date: Tue, 3 Nov 2015 16:57:19 +0100 Subject: [PATCH 092/217] Removed secondary permission, sorry my derp --- signalstrength.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/signalstrength.py b/signalstrength.py index 10a4933..ebe2bd1 100644 --- a/signalstrength.py +++ b/signalstrength.py @@ -109,9 +109,6 @@ def get_entire_container(container): helpSubcmd = True, senderLimit = 0) def on_signalstrength_command(sender, command, label, args): - if not sender.hasPermission("utils.ss"): - noperm(sender) - return None if len(args) > 0 and args[0].lower() in ("default", "defaults", "setdefaults"): strength, item_type, item_data = get_data(sender, args[1:]) -- 2.45.2 From aa86881f5eabe0a7471aadf73ee8a7b789e679dc Mon Sep 17 00:00:00 2001 From: Dico200 Date: Tue, 3 Nov 2015 19:05:15 +0100 Subject: [PATCH 093/217] Fix survival use of /signalstrength, other interesting changes --- helpers.py | 10 ++++++ misc.py | 4 ++- signalstrength.py | 5 +++ synchronizeranks.py | 79 +++++++++++++++++++++++++++++++++++++-------- 4 files changed, 84 insertions(+), 14 deletions(-) diff --git a/helpers.py b/helpers.py index 898dea7..79af3a0 100644 --- a/helpers.py +++ b/helpers.py @@ -181,6 +181,16 @@ def is_creative(player): return str(player.getGameMode()) == "CREATIVE" +def is_rank(player, rank): + """ + rank: a string equal to the PEX group name found in /pex groups + returns True if one of the following conditions are met: + - the player is of the given rank, + - their rank inherits the given rank. + """ + return player.hasPermission("groups." + rank) + + def uid(player): """ returns the player's UUID diff --git a/misc.py b/misc.py index c6da200..09abcb8 100644 --- a/misc.py +++ b/misc.py @@ -7,6 +7,7 @@ import thread import org.bukkit.inventory.ItemStack as ItemStack import org.bukkit.Bukkit as Bukkit from basecommands import simplecommand, Validate +import java.util.Arrays as Arrays @@ -161,7 +162,8 @@ def on_pluginversions_command(sender, command, label, args): """ try: plugin_header(sender, "Plugin versions") - plugins = [pl.getDescription() for pl in list(ArrayList(java_array_to_list(server.getPluginManager().getPlugins())))] + raw_plugins = server.getPluginManager().getPlugins() # Plugin[] + plugins = [raw_plugins[i].getDescription() for i in range(len(raw_plugins))] info(type(plugins[0]).__name__) plugins.sort(key = lambda pl: pl.getDescription().getName()) msg(sender, "&3Listing all " + str(len(plugins)) + " plugins and their version:") diff --git a/signalstrength.py b/signalstrength.py index ebe2bd1..c668b46 100644 --- a/signalstrength.py +++ b/signalstrength.py @@ -109,6 +109,11 @@ def get_entire_container(container): helpSubcmd = True, senderLimit = 0) def on_signalstrength_command(sender, command, label, args): + + #Sender has to be in creative and if in Trusted world, they have to be Trusted+. Any ranks above trusted inherit groups.trusted. + if (not is_creative(sender)) or (sender.getWorld().getName() == "Trusted" and not is_rank(sender, "trusted")): + return "&cYou do not have permission to use that command in this world" + if len(args) > 0 and args[0].lower() in ("default", "defaults", "setdefaults"): strength, item_type, item_data = get_data(sender, args[1:]) diff --git a/synchronizeranks.py b/synchronizeranks.py index 8d0db60..4509185 100644 --- a/synchronizeranks.py +++ b/synchronizeranks.py @@ -3,6 +3,14 @@ from secrets import * import mysqlhack from com.ziclix.python.sql import zxJDBC +""" +WORK IN PROGRESS +""" + +#-----------------------Config-------------------------- + +config_file = "website-roles" + ranks = { "member" : 3, "builder" : 7, @@ -13,31 +21,41 @@ ranks = { "admin" : 5 } +ranks = open_json_file(config_file, ranks) + +def save_ranks(): + save_json_file(config_file, ranks) + +#-----------------------Event--------------------------- @hook.event("player.PlayerJoinEvent", "normal") def on_player_join(event): user = event.getPlayer() uuid = uid(player).replace("-", "") - role = get_role(uuid) - if role in [1, 2, 6]: #Disabled/Banned/Superadmin - return - if role != None: - for rank in ranks: - if user.hasPermission("group." + rank): - if role != ranks[rank]: - set_role(uuid, ranks[rank]) - elif user.hasPlayedBefore(): - msg(user, "&cYou haven't registed yet! Make sure to do so on redstoner.com") + + sql_instruction + + def callback_thing(role, args): + + if role in [1, 2, 6]: #Disabled/Banned/Superadmin + return + if role != None: + for rank in ranks: + if user.hasPermission("group." + rank): + if role != ranks[rank]: + set_role(uuid, ranks[rank]) + elif user.hasPlayedBefore(): + msg(user, "&cYou haven't registed yet! Make sure to do so on redstoner.com") def get_role(uuid): - results = execute_query("SELECT `role_id` FROM users WHERE `uuid` = ? LIMIT 1", uuid) + results = execute_query("SELECT `role_id` FROM users WHERE `uuid` = ? LIMIT 1;", uuid) return results[0][0] # Returns a table with 1 row (LIMIT 1) and 1 column (SELECT `role_id`), so we're looking for the first row of the first column. def set_role(uuid, role_id): - execute_update(("UPDATE users SET `role_id` = %d WHERE `uuid` = ?" % role_id), uuid) + execute_update("UPDATE users SET `role_id` = ? WHERE `uuid` = ?;", (role_id, uuid,)) # %d is like %s for integers (unlogically, you'd expect something like %i), though %s also works here. @@ -55,5 +73,40 @@ def execute_update(update, uuid): conn = zxJDBC.connect(mysql_database, mysql_user, mysql_pass, "com.mysql.jdbc.Driver") curs = conn.cursor() curs.execute(update, (uuid,)) + conn.commit() curs.close() - conn.close() \ No newline at end of file + conn.close() + +def get_role(uuid): + sql_instruction() + +#--------------------------------Queries / Updates---------------------------- + +def sql_instruction(instruction, args, fetch = True, callback_func = ignored_func, callback_args = tuple()): + thread = threading.Thread(target = curs_instruction, args = (instruction_executor, instruction, fetch, callback_func, callback_args)) + thread.start() + + +def curs_instruction(func, instruction, fetch, callback_func, callback_args): + conn = zxJDBC.connect(mysql_database, mysql_user, mysql_pass, "com.mysql.jdbc.Driver") + curs = conn.getCursor() + + if fetch: + returned = func(curs, instruction, fetch) + curs.close() + conn.close() + callback_func(returned, callback_args) + + else: + func(curs, instruction, fetch) + conn.commit() + curs.close() + conn.close() + + +def instruction_executor(curs, instruction, fetch): + curs.execute(instruction) + return curs.fetchall() if fetch else None + +def ignored_func(*args): + pass \ No newline at end of file -- 2.45.2 From 7282bf63f647fa217e6aa7d9a4f24050dacf850e Mon Sep 17 00:00:00 2001 From: Dico Date: Tue, 3 Nov 2015 19:16:35 +0100 Subject: [PATCH 094/217] Removed unneeded permission check from signalstrength.py... again xD --- signalstrength.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/signalstrength.py b/signalstrength.py index c668b46..d51f35a 100644 --- a/signalstrength.py +++ b/signalstrength.py @@ -109,10 +109,6 @@ def get_entire_container(container): helpSubcmd = True, senderLimit = 0) def on_signalstrength_command(sender, command, label, args): - - #Sender has to be in creative and if in Trusted world, they have to be Trusted+. Any ranks above trusted inherit groups.trusted. - if (not is_creative(sender)) or (sender.getWorld().getName() == "Trusted" and not is_rank(sender, "trusted")): - return "&cYou do not have permission to use that command in this world" if len(args) > 0 and args[0].lower() in ("default", "defaults", "setdefaults"): strength, item_type, item_data = get_data(sender, args[1:]) -- 2.45.2 From eb491bcd9ef5919acc858c0d48834d6f7fe02c4e Mon Sep 17 00:00:00 2001 From: Dico Date: Wed, 4 Nov 2015 11:52:27 +0100 Subject: [PATCH 095/217] Update chatgroups, add /cg tpahere, add some cool code I added a function do_for_chatgroup which takes a groupname, a function, and additional arguments after a receiver. --- chatgroups.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/chatgroups.py b/chatgroups.py index 326b8d3..ab27e1f 100644 --- a/chatgroups.py +++ b/chatgroups.py @@ -43,6 +43,12 @@ def on_chatgroup_command(sender, command, label, args): msg(sender, "&aUse chat like '&e%s' to send messages to this group." % get_key(sender_id)) elif len(args) == 1 and args[0] == "key": msg(sender, "&aYour chatgroup key is currently: '&c%s&a'" % get_key(sender_id)) + elif len(args) == 1 and args[0] == "tpahere": + if sender_id in groups.keys(): + do_for_chatgroup(groups[sender_id], send_tpa_request, sender) + msg(sender, "&aSent a tpahere request to all users in your chatgroup") + else: + msg(sender, "&cYou have to be in a chatgroup to do that") else: msg(sender, "&e/chatgroup join ") msg(sender, "&e/chatgroup leave") @@ -73,10 +79,16 @@ def groupchat(sender, message, ann = False): else: mesg = "&8[&bCG&8] &f%s&f: &6%s" % (name, message) info("[ChatGroups] %s (%s): %s" % (sender.getDisplayName(), group, message)) + do_for_chatgroup(group, msg, mesg) + +def do_for_chatgroup(group, func, args): for receiver in server.getOnlinePlayers(): - groups.get(uid(receiver)) == group and msg(receiver, mesg) - + if groups.get(uid(receiver)) == group: + func(receiver, args) +def send_tpa_request(receiver, sender): + if not receiver == sender: + runas(sender, "/tpahere " + receiver.getName()) def save_groups(): save_json_file("chatgroups", groups) @@ -115,5 +127,6 @@ def chatgroupkey_command(sender, command, label, args): save_keys() return "&aYour chatgroup key was set to: '&c%s&a'" % key + def save_keys(): save_json_file("chatgroup_keys", cg_keys) -- 2.45.2 From 4a4cdc839be140dc9486b2cffd8c065365a70404 Mon Sep 17 00:00:00 2001 From: Dico Date: Wed, 4 Nov 2015 11:53:09 +0100 Subject: [PATCH 096/217] Add /chatgroup tpahere to chatgroups help message --- chatgroups.py | 1 + 1 file changed, 1 insertion(+) diff --git a/chatgroups.py b/chatgroups.py index ab27e1f..2cd496a 100644 --- a/chatgroups.py +++ b/chatgroups.py @@ -54,6 +54,7 @@ def on_chatgroup_command(sender, command, label, args): msg(sender, "&e/chatgroup leave") msg(sender, "&e/chatgroup info") msg(sender, "&e/chatgroup key") + msg(sender, "&e/chatgroup tpahere") @hook.command("cgt") -- 2.45.2 From 93c9bab421cadc26d2af32a882d38763ddf43bc5 Mon Sep 17 00:00:00 2001 From: Dico Date: Wed, 4 Nov 2015 12:01:38 +0100 Subject: [PATCH 097/217] Chatgroups optimization The message is now colorified just once, not for every recipient. I'll test all this at home <3 --- chatgroups.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/chatgroups.py b/chatgroups.py index 2cd496a..9965b96 100644 --- a/chatgroups.py +++ b/chatgroups.py @@ -79,13 +79,15 @@ def groupchat(sender, message, ann = False): mesg = "&8[&bCG&8] &e&o%s&e&o %s" % (name, message) else: mesg = "&8[&bCG&8] &f%s&f: &6%s" % (name, message) + mesg = colorify(mesg) + info("[ChatGroups] %s (%s): %s" % (sender.getDisplayName(), group, message)) - do_for_chatgroup(group, msg, mesg) + do_for_chatgroup(group, msg, mesg, usecolor = False) -def do_for_chatgroup(group, func, args): +def do_for_chatgroup(group, func, *args, **kwargs): for receiver in server.getOnlinePlayers(): if groups.get(uid(receiver)) == group: - func(receiver, args) + func(receiver, args, kwargs) def send_tpa_request(receiver, sender): if not receiver == sender: -- 2.45.2 From 1b59c79fd715e9b5fc6dc2c197c4547b84c4e312 Mon Sep 17 00:00:00 2001 From: PixelSergey Date: Sat, 21 Nov 2015 12:08:45 +0200 Subject: [PATCH 098/217] Fixed chatalias, no bugs and now SAFE! \o/ --- chatalias.py | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/chatalias.py b/chatalias.py index 0a34ebe..d55269c 100644 --- a/chatalias.py +++ b/chatalias.py @@ -4,23 +4,21 @@ # 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 +# word. The JSON file for this +# plugin is generated if not # present. Set values to -1 # for "unlimited" setting. from helpers import * +import re from traceback import format_exc as trace data = None max_entries = 10 max_alias_length = 35 -# minecraft message limit is 100 so I decided to give a little tolerance -max_overall_length = 115 +# Minecraft message limit is 100 so I decided to give a little tolerance (and I added a bit more) +max_overall_length = 100 + max_alias_length alias_perm = "utils.alias.allowed" exceed_length = "utils.alias.exceedlimit" @@ -38,6 +36,10 @@ def safe_open_json(): save_json_file("aliases", data) return data +def multiple_replace(aliases, text): + regex = re.compile("|".join(map(re.escape, aliases.keys()))) + return regex.sub(lambda mo: aliases[mo.group(0)], text) + @hook.command("alias", usage="/ [to_alias] [alias...]", @@ -45,7 +47,7 @@ def safe_open_json(): def on_alias_command(sender, cmd, label, args): if not is_player(sender): - msg(sender, "Sorry, Console cannot alias words") + msg(sender, "Sorry, non-players cannot alias words") return True if not sender.hasPermission(alias_perm): plugin_header(recipient=sender, name="Chat Alias") @@ -123,16 +125,14 @@ def on_player_chat(event): data = safe_open_json() if event.isCancelled(): return - try: - crashtest = data[playerid].items() - except KeyError: + if not data[playerid]: return - for alias, value in data[playerid].items(): - event.setMessage(event.getMessage().replace(alias, value)) - if (event.getPlayer().hasPermission('essentials.chat.color')): + event.setMessage(multiple_replace(data[playerid], event.getMessage())) + + if (event.getPlayer().hasPermission("essentials.chat.color")): event.setMessage(colorify(event.getMessage())) - if (len(event.getMessage()) > max_overall_length) and (not sender.hasPermission(exceed_overall_length)): + if (max_overall_length >= 0) and (len(event.getMessage()) > max_overall_length) and (not event.getPlayer().hasPermission(exceed_overall_length)): event.setCancelled(True) - msg(sender, "&7The message generated was too long and was not sent " + - "but it would've looked like that:") - msg(sender, event.getMessage()) + plugin_header(recipient=event.getPlayer(), name="Chat Alias") + msg(event.getPlayer(), "&7The message generated was too long and was not sent. :/") + -- 2.45.2 From 23b3bffcf6faa699c3a850ab183675ee6d673c10 Mon Sep 17 00:00:00 2001 From: Dico200 Date: Sun, 22 Nov 2015 14:51:47 +0100 Subject: [PATCH 099/217] Major serversigns overhaul, it mostly works now. A little bit of testing and command help is left --- blockplacemods.py | 4 +- main.py | 4 +- serversigns.py | 362 ++++++++++++++++++++++++++-------------------- 3 files changed, 208 insertions(+), 162 deletions(-) diff --git a/blockplacemods.py b/blockplacemods.py index 246f9eb..85e71c5 100644 --- a/blockplacemods.py +++ b/blockplacemods.py @@ -24,7 +24,7 @@ settingInformation = dict( #[setting type, identifying description, detailed des ], furnace = [1, "automatically filling furnaces upon placement", - "Sets your preferred default furnace contents to your currently held itemstack. Use an empty hand to empty a slot, or /toggle dropper clear to clear all slots.", + "Sets your preferred default furnace contents to your currently held itemstack. Use an empty hand to empty a slot, or /toggle furnace clear to clear all slots.", ["cooker", "fillf"], 2 ], #torch = [0, @@ -44,7 +44,7 @@ settingInformation = dict( #[setting type, identifying description, detailed des ], hopper = [1, "automatically filling hoppers upon placement", - "Sets your preferred default hopper contents to your currently held itemstack. Use an empty hand to empty a slot, or /toggle dropper clear to clear all slots.", + "Sets your preferred default hopper contents to your currently held itemstack. Use an empty hand to empty a slot, or /toggle hopper clear to clear all slots.", ["itemtransporter", "fillh"], 4 ] ) diff --git a/main.py b/main.py index 4769bc5..ede4269 100644 --- a/main.py +++ b/main.py @@ -99,7 +99,9 @@ shared["load_modules"] = [ # a simple replacement for the buggy essentials /vanish "vanish", # ip-tracking utility - "iptracker" + "iptracker", + #server signs for everyone + "serversigns" ] shared["modules"] = {} for module in shared["load_modules"]: diff --git a/serversigns.py b/serversigns.py index c7bc23c..af175ba 100644 --- a/serversigns.py +++ b/serversigns.py @@ -3,17 +3,87 @@ from basecommands import simplecommand, Validate import org.bukkit.Material as Material import java.util.UUID as UUID import org.bukkit.Material as Material -import java.util.HashSet as JSet +import org.bukkit.block.BlockFace as BlockFace +blocked_cmds = ("pex", "kick", "ban", "tempban", "pyeval", "sudo") -cmd_use_perm = "utils.svs.cmd" -msg_use_perm = "utils.svs.msg" +def load_signs(): + signs_obj = open_json_file("serversigns", []) + loaded = {} + for entry in signs_obj: + loaded[tuple(entry[:4])] = list(entry[4:]) + return loaded -signs = open_json_file("serversigns", {}) # {("world", x, y, z): ["owner_id", "msg1", "msg2"]} +def save_signs(): + signs_obj = [] + for key, value in signs.iteritems(): + signs_obj.append(key + tuple(value)) + save_json_file("serversigns", signs_obj) -lines = {} #Accumulated messages so players can have longer messages: {"Dico200": "Message...........", ""} +signs = load_signs() # {("world", x, y, z): ["owner_id", "msg1", "msg2"]} + +lines = {} # Accumulated messages so players can have longer messages: {"Dico200": "Message...........", ""} + +def fromLoc(bLoc): + """ + # Returns a tuple containing the (bukkit)location's world's name and its x, y and z coordinates + # The format for the tuple is ("world_name", x, y, z) + """ + return (bLoc.getWorld().getName(), bLoc.getBlockX(), bLoc.getBlockY(), bLoc.getBlockZ()) + +def equals(loc1, loc2): + """ + # Returns whether loc1 and loc2 represent the same block + """ + for i in range(4): + if loc1[i] != loc2[i]: + return False + return True + +def getOwner(sign): + """ + # Returns the name of the sign its owner + """ + return retrieve_player(sign[0]).getName() + +def isOwner(sign, player): + """ + # Returns whether the given player owns the sign + """ + return sign and sign[0] == uid(player) + +def canEdit(sign, player): + """ + # Returns whether the given player can edit the sign. + # Returns False if the sign wasn't claimed. + """ + return (sign and player.hasPermission("utils.serversigns.admin")) or isOwner(sign, player) + +def getSign(locAt): + """ + # If data was found for a sign at the given location, returns the data. + # This data follows the format of ["owner_id", "msg1", "msg2"...]. + """ + for loc, sign in signs.iteritems(): + if equals(locAt, loc): + return sign + return None + +def identifySign(loc): + """ + # Returns a string from which the user can tell what sign you're talking about. + # The string follows the format of "sign at (x,y,z) in world_name". + """ + return "sign at (%s) in %s" % (",".join((str(i) for i in loc[1:])), loc[0]) + +def signsMsg(msg, colour = '4'): + """ + # Returns the given msg, prefixed with '[Signs] '. + # The given colour is after applied to the msg. + # The colour defaults to 4 (dark red). + """ + return "&c[Signs] &" + colour + msg -transparent_blocks_set = JSet([Material.AIR, Material.GLASS, Material.STAINED_GLASS]) #used in sender.getTargetBlock() @simplecommand(cmd = "serversigns", aliases = ["svs", "signmsg"], description = "Makes something happen when you right click certain signs", @@ -21,103 +91,117 @@ transparent_blocks_set = JSet([Material.AIR, Material.GLASS, Material.STAINED_GL helpNoargs = True, senderLimit = 0) def svs_command(sender, command, label, args): - try: - arg1 = args[0].lower() - if arg1 not in ("add", "remove", "clear", "claim", "unclaim", "help"): - return "&4That argument could not be recognized, use &o/svs &4help for more information" + arg1 = args[0].lower() + Validate.isTrue(arg1 in ("claim", "reset", "add", "remove", "info", "clear", "help", "switch"), signsMsg("That argument could not be recognized, use &o/svs help &4for expected arguments")) + Validate.isAuthorized(sender, "utils.serversigns." + arg1) - sender = server.getPlayer(sender.getName()) - block = sender.getTargetBlock(transparent_blocks_set, 8) - info("Block type: " + str(block.getType())) - if block.getType() not in (Material.SIGN_POST, Material.WALL_SIGN): - return "&4You have to be looking at a sign to use that!" + #-------------------- Sub commands that don't require any conditions ----------------------- + if arg1 == "help": + admin = sender.hasPermission("utils.serversigns.admin") - loc = fromLoc(block.getLocation()) - sign = getSign(loc) - arglen = len(args) - arg2 = args[1].lower() if arglen > 1 else None + return "&2COMMAND HELP HERE" + #------------------------------------------------------------------------------------------- + block = sender.getTargetBlock(None, 5) + Validate.isTrue(block.getType() in (Material.SIGN_POST, Material.WALL_SIGN), signsMsg("You have to be looking at a sign to use that!")) - if arg1 == "claim": - Validate.isAuthorized(sender, "utils.serversigns.claim") - target = sender - if arg2: - Validate.isAuthorized(sender, "utils.serversigns.admin") - target = server.getOfflinePlayer(arg2) - Validate.notNone(target, signsMsg("That player could not be found", '4')) + loc = fromLoc(block.getLocation()) + sign = getSign(loc) + signName = identifySign(loc) + arg2 = args[1].lower() if len(args) > 1 else None + is_admin = sender.hasPermission("utils.serversigns.admin") - Validate.isPlayer(target) - uuid = uid(sender) - if sign != None: - if sign[0] == uuid: - return signsMsg(identifySign(loc, True) + " was already owned by that player", '4') - else: - sign[0] = uuid + #------------------------ Sub commands that require the block to be a sign ------------------------------- + if arg1 == "claim": + target = sender + if arg2: + Validate.isTrue(is_admin, signsMsg("You are not authorized to claim signs for other players")) + target = server.getOfflinePlayer(arg2) + Validate.notNone(target, signsMsg("That player could not be found")) + Validate.isTrue(target.isOnline(), signsMsg("The target has to be online")) + uuid = uid(target) + if sign != None: + if sign[0] == uuid: + return signsMsg("The" + signName + " was already owned by that player") else: - signs[loc] = [uuid] + sign[0] = uuid + else: + signs[loc] = [uuid] + save_signs() + return signsMsg("Claimed the " + signName + ((" for %s" % target.getName()) if (target != sender) else ""), 'a') + #---------------------------------------------------------------------------------------------------------- - return signsMsg("Claimed " + identifySign(loc)) + Validate.notNone(sign, signsMsg("The %s has not been claimed" % signName)) + + #----------------------Sub commands that require the sign to be claimed as well------------------------------------ + if arg1 == "info": + sign_lines = "" + for id, line in enumerate(sign[1:]): + sign_lines += ("\n &a%s: \"&f%s&a\"" % (id + 1, line)) + return signsMsg("Properties of the %s:\n Owner: %s\n Lines: %s" % (signName, getOwner(sign), sign_lines), 'a') + #--------------------------------------------------------------------------------------------------------------- + + Validate.isTrue(canEdit(sign, sender), signsMsg("You do not own the %s!" % signName)) + + #---------------------- Sub commands that require you to own targeted sign as well ------------------------- + if arg1 == "add": + line = " ".join(args[1:]) + Validate.isTrue(line != "" and line != None, signsMsg("You have to enter a message to add or accumulate")) + key = sender.getName() + global lines + Validate.isTrue(key in lines or line[:1] != "/" or sender.hasPermission("utils.serversigns.command"), signsMsg("You cannot add commands to a sign!")) + if line[-2:] == "++": + if key not in lines: + lines[key] = "" + lines[key] += " " + line[:-2] + return signsMsg("Added given message to the message you're accumulating. \nYour accumulated message is now as follows: \n&f%s" % lines[key], 'a') + if key in lines: + line = (lines[key] + " " + line)[1:] + Validate.isTrue(line[0] != "/" or line.split(" ")[0][1:] not in blocked_cmds, signsMsg("Usage of that command with server signs is prohibited")) + sign.append(colorify(line) if line[0] != "/" else line) + save_signs() + return signsMsg("Added line \"&f%s&a\" to the %s" % (line, signName), 'a') - elif arg1 == "unclaim": - Validate.isAuthorized(sender, "utils.serversigns.unclaim") - Validate.isTrue(canEdit(sign, sender), signsMsg("You cannot unclaim the %s!" % identifySign(loc)), '4') - - if not (("-c" in args) and sender.hasPermission("utils.serversigns.admin")): - del signs[locAt] - return signsMsg("The %s was reset successfully" % identifySign(loc)) - sign[0] = "" - return signsMsg("The %s had its owner removed successfully" % identifySign(loc)) + if arg1 == "remove": + Validate.notNone(arg2, signsMsg("You have to enter the ID of the message to remove!")) + try: + id = int(arg2) + except: + return signsMsg("The ID of the message has to be a number and can be found by using &o/svs info") + Validate.isTrue(id != 0 and id < len(sign), signsMsg("The %s has no message with an ID of %s, use &o/svs info &4for all messages." % (signName, id))) + sign.remove(id) + return signsMsg("Removed message with id %s from the %s" % (id, signName), 'a') - elif arg1 == "help": - admin = sender.hasPermission("utils.serversigns.admin") - - return + if arg1 == "switch": + Validate.isTrue(len(args) == 3, signsMsg("You have to enter the 2 IDs of the lines to switch")) + try: + id1 = int(args[1]) + id2 = int(args[2]) + except: + return signsMsg("The ID of the message has to be a number and can be found by using &o/svs info") + for id in (id1, id2): + Validate.isTrue(id != 0 and id < len(sign), signsMsg("The %s has no message with an ID of %s, use &o/svs info &4for all messages." % (signName, id))) + sign[id1], sign[id2] = sign[id2], sign[id1] + return signsMsg("Switched the lines with IDs %s and %s of the %s" % (id1, id2, signName), 'a') - elif arg1 == "add": - Validate.isTrue(canEdit(sign, sender), signsMsg("You cannot edit the %s!" % identifySign(loc)), '4') - line = " ".join(args[1:]) - Validate.isTrue(line != "" and line != None, signsMsg("You have to enter a message to add or accumulate!", '4')) - key = sender.getName() - - Validate.isTrue(key in lines or line[:1] != "/" or sender.hasPermission("utils.serversigns.command"), signsMsg("You cannot add commands to a sign!", '4')) - - if line[-2:] == "++": - if key not in lines: - lines[key] = "" - lines[key] += " " + line[:-2] - elif key in lines: - line = lines[key] + " " + line - sign.append(colorify(line) if line[0] != "/" else line) - return signsMsg("Added line \"%s&a\" to the %s" % (line, identifySign(loc))) + if arg1 == "clear": + signs[loc] = [sign[0]] + return signsMsg("Removed all messages from the %s" % signName, 'a') - elif arg1 == "info": - Validate.notNone(sign, signsMsg("The %s has not been claimed" % identifySign(loc), '4')) - lines = "" - for id, line in enumerate(sign[1:]): - lines += ("\n &a%s: \"%s&a\"" % (id + 1, line)) - msg = signsMsg("Some information about the %s:\n Owner: %s\n Lines: %s" % identifySign(loc), getOwner(sign), lines) + if arg1 == "reset": + del signs[loc] + return signsMsg("Removed all messages and the owner from the %s, it can now be claimed" % signName, 'a') + #------------------------------------------------------------------------------------------------------- - elif arg1 == "remove": - Validate.notNone(arg2, signsMsg("You have to enter the ID of the message to remove!", '4')) - try: - id = int(arg2) - except: - return signsMsg("The ID of the message has to be a number and can be found by using &o/svs info", '4') - Validate.isTrue(id != 0 and id < len(sign), signsMsg("The %s has no message with an ID of %s, use &o/svs info &4for all messages." % (identifySign(loc), id), '4')) - sign.remove(id) - return signsMsg("Removed message with id %s from the %s" % (id, identifySign(loc))) - except: - error(trace()) - @hook.event("player.PlayerInteractEvent") -def onClick(event): +def on_click(event): if str(event.getAction()) != "RIGHT_CLICK_BLOCK": return block = event.getClickedBlock() @@ -132,90 +216,50 @@ def onClick(event): else: msg(player, message, usecolor = False) -def fromLoc(bLoc): #Bukkit Location to ("world", x, y, z) - return (bLoc.getWorld().getName(), bLoc.getBlockX(), bLoc.getBlockY(), bLoc.getBlockZ()) - -def equals(loc1, loc2): - for i in range(4): - if loc1[i] != loc2[i]: - return False - return True - -def getOwner(sign): - return retrieve_player(sign[0]).getName() - -def isOwner(sign, player): - return sign and sign[0] == uid(player) - -def canEdit(sign, player): - return player.hasPermission("utils.serversigns.admin") or isOwner(sign, player) - -def getSign(locAt): - for loc, sign in signs.iteritems(): - if equals(locAt, loc): - return sign - return None - -def identifySign(loc, capital = False): - return "%sign at (%s) in %s" % ("S" if capital else "s", ",".join(loc[1:]), loc[0]) - -def signsMsg(msg, colour = 'a'): - return "&c[Signs] &" + colour + msg - - - - - - -""" -def eventhook(event, priority = "normal"): - - if "." not in event: - word = "" - for s in event: - if word != "" and s in "ABCDEFGHIJKLMNOPQRSTUVWXYZ": - break; - word += s.lower() - event = "%s.%s" % (word, event) - - def decorator(function): - - @hook.event(event, priority) - def hook(event): - try: - function(event) - except EventException, e: - pass - - return hook - - return decorator - -class EventException(Exception): - def __init__(self, msg): - self.msg = msg - -"" -@eventhook("PlayerInteractEvent") -def x(event): - - p = event.getPlayer() - if p == None: - raise EventException(Stuff) -"" -""" - - - - +# ---------------------------Sign breaking-------------------------------- +checking_block = False +faces = { + BlockFace.NORTH : (0,1,2), + BlockFace.SOUTH : 3, + BlockFace.WEST : 4, + BlockFace.EAST : 5 +} +@hook.event("block.BlockBreakEvent", "highest") +def on_break(event): + global checking_block + if checking_block or event.isCancelled(): + return + block = event.getBlock() + if block.getMaterial() in (Material.SIGN_POST, Material.WALL_SIGN): + check_sign(event, block, attached = False) + for block_face, data_values in faces.iteritems(): + block2 = block.getRelative(block_face) + if block2.getData() in data_values: + check_sign(event, block2) + block3 = block.getRelative(BlockFace.UP) + if block3.getMaterial == Material.SIGN_POST: + check_sign(event, block3) +def check_sign(event, block, attached = True): + player = event.getPlayer() + sign = getSign(fromLoc(block.getLocation())) + if not canEdit(sign, player) and not can_build(player, block.getLocation()): + event.setCancelled(True) + msg(event.getPlayer(), signsMsg("You cannot break %s" % ("the sign attached to that block" if attached else "that sign"))) +def can_build(player, block): + global checking_block + event = BlockBreakEvent(block, player) + checking_block = True + server.getPluginManager().callEvent(event) + checking_block = False + return not event.isCancelled() -- 2.45.2 From 8613c9221e741499356a82faaff79725c4b3d1c6 Mon Sep 17 00:00:00 2001 From: Dico200 Date: Sun, 22 Nov 2015 15:52:41 +0100 Subject: [PATCH 100/217] Fix for /svs remove , Added some to blocked_cmds, /svs help still WIP --- serversigns.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/serversigns.py b/serversigns.py index af175ba..ecba2e8 100644 --- a/serversigns.py +++ b/serversigns.py @@ -5,7 +5,7 @@ import java.util.UUID as UUID import org.bukkit.Material as Material import org.bukkit.block.BlockFace as BlockFace -blocked_cmds = ("pex", "kick", "ban", "tempban", "pyeval", "sudo") +blocked_cmds = ("pex", "kick", "ban", "tempban", "pyeval", "sudo", "stop", "reload", "op", "deop", "whitelist") def load_signs(): signs_obj = open_json_file("serversigns", []) @@ -170,7 +170,7 @@ def svs_command(sender, command, label, args): except: return signsMsg("The ID of the message has to be a number and can be found by using &o/svs info") Validate.isTrue(id != 0 and id < len(sign), signsMsg("The %s has no message with an ID of %s, use &o/svs info &4for all messages." % (signName, id))) - sign.remove(id) + del sign[id] return signsMsg("Removed message with id %s from the %s" % (id, signName), 'a') -- 2.45.2 From d3ba9eac73d159684809f9578d983ff223194ce5 Mon Sep 17 00:00:00 2001 From: Dico200 Date: Sun, 22 Nov 2015 17:06:55 +0100 Subject: [PATCH 101/217] More fixes, pretty much finished --- serversigns.py | 46 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 35 insertions(+), 11 deletions(-) diff --git a/serversigns.py b/serversigns.py index ecba2e8..45110f8 100644 --- a/serversigns.py +++ b/serversigns.py @@ -86,20 +86,41 @@ def signsMsg(msg, colour = '4'): @simplecommand(cmd = "serversigns", aliases = ["svs", "signmsg"], - description = "Makes something happen when you right click certain signs", - usage = "[claim|unclaim|add |remove |clear|info|help]", + description = "Makes something happen when you right click signs. \nUse /svs help for more details.", + usage = "[++]|remove |clear|info|help>", helpNoargs = True, senderLimit = 0) def svs_command(sender, command, label, args): arg1 = args[0].lower() - Validate.isTrue(arg1 in ("claim", "reset", "add", "remove", "info", "clear", "help", "switch"), signsMsg("That argument could not be recognized, use &o/svs help &4for expected arguments")) + Validate.isTrue(arg1 in ("claim", "reset", "add", "remove", "info", "clear", "help", "switch", "reverse", "unclaim"), + signsMsg("That argument could not be recognized, use &o/svs help &4for expected arguments")) Validate.isAuthorized(sender, "utils.serversigns." + arg1) #-------------------- Sub commands that don't require any conditions ----------------------- if arg1 == "help": admin = sender.hasPermission("utils.serversigns.admin") - - return "&2COMMAND HELP HERE" + msg = signsMsg("Server signs lets you add messages to a sign.", 'a') + msg += "\nRight clicking the sign will display all the messages. Commands" + msg += "\ncan also be added, by prefixing the message with a '/'." + msg += "\nHow to use &b/serversigns&a:" + msg += "\n&b/svs claim" + ("" if not sender.hasPermission("utils.serversigns.admin") else " [owner]") + msg += "\n&a- Claims the sign so that you can add messages to it" + msg += "\n&b/svs info" + msg += "\n&a- Displays information about the (claimed) sign" + msg += "\n&b/svs add [++]" + msg += "\n&a- Adds the message to the sign. Use ++ at the end" + msg += "\n&a- to add the message to your buffer. You can then use" + msg += "\n&a- the same command again to create a longer message." + msg += "\n&b/svs remove " + msg += "\n&a- Removes the message with the given ID from the sign." + msg += "\n&a- The ID is given before each message by &b/svs info&a." + msg += "\n&b/svs switch|reverse " + msg += "\n&a- Reverses the order in which the given messages are shown." + msg += "\n&b/svs clear" + msg += "\n&a- Removes all messages from the sign." + msg += "\n&b/svs reset|unclaim" + msg += "\n&a- Resets the sign, removing all messages and its owner." + return msg #------------------------------------------------------------------------------------------- block = sender.getTargetBlock(None, 5) @@ -109,13 +130,13 @@ def svs_command(sender, command, label, args): sign = getSign(loc) signName = identifySign(loc) arg2 = args[1].lower() if len(args) > 1 else None - is_admin = sender.hasPermission("utils.serversigns.admin") #------------------------ Sub commands that require the block to be a sign ------------------------------- if arg1 == "claim": + Validate.isTrue(not sign, signsMsg("The %s was already claimed" % signName)) target = sender if arg2: - Validate.isTrue(is_admin, signsMsg("You are not authorized to claim signs for other players")) + Validate.isTrue(player.hasPermission("utils.serversigns.admin"), signsMsg("You are not authorized to claim signs for other players")) target = server.getOfflinePlayer(arg2) Validate.notNone(target, signsMsg("That player could not be found")) Validate.isTrue(target.isOnline(), signsMsg("The target has to be online")) @@ -174,8 +195,8 @@ def svs_command(sender, command, label, args): return signsMsg("Removed message with id %s from the %s" % (id, signName), 'a') - if arg1 == "switch": - Validate.isTrue(len(args) == 3, signsMsg("You have to enter the 2 IDs of the lines to switch")) + if arg1 in ("switch", "reverse"): + Validate.isTrue(len(args) == 3, signsMsg("You have to enter the 2 IDs of the messages to reverse")) try: id1 = int(args[1]) id2 = int(args[2]) @@ -184,16 +205,19 @@ def svs_command(sender, command, label, args): for id in (id1, id2): Validate.isTrue(id != 0 and id < len(sign), signsMsg("The %s has no message with an ID of %s, use &o/svs info &4for all messages." % (signName, id))) sign[id1], sign[id2] = sign[id2], sign[id1] - return signsMsg("Switched the lines with IDs %s and %s of the %s" % (id1, id2, signName), 'a') + save_signs() + return signsMsg("Reversed the messages with IDs %s and %s of the %s" % (id1, id2, signName), 'a') if arg1 == "clear": signs[loc] = [sign[0]] + save_signs() return signsMsg("Removed all messages from the %s" % signName, 'a') - if arg1 == "reset": + if arg1 in ("reset", "unclaim"): del signs[loc] + save_signs() return signsMsg("Removed all messages and the owner from the %s, it can now be claimed" % signName, 'a') #------------------------------------------------------------------------------------------------------- -- 2.45.2 From da9255558c01efdcf0f9cd9ec98eee2ecc165fd6 Mon Sep 17 00:00:00 2001 From: Dico200 Date: Sun, 22 Nov 2015 17:10:16 +0100 Subject: [PATCH 102/217] Testing for sign breaking problems, added trace --- serversigns.py | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/serversigns.py b/serversigns.py index 45110f8..018bbb7 100644 --- a/serversigns.py +++ b/serversigns.py @@ -253,22 +253,25 @@ faces = { @hook.event("block.BlockBreakEvent", "highest") def on_break(event): - global checking_block - if checking_block or event.isCancelled(): - return + try: + global checking_block + if checking_block or event.isCancelled(): + return - block = event.getBlock() - if block.getMaterial() in (Material.SIGN_POST, Material.WALL_SIGN): - check_sign(event, block, attached = False) + block = event.getBlock() + if block.getMaterial() in (Material.SIGN_POST, Material.WALL_SIGN): + check_sign(event, block, attached = False) - for block_face, data_values in faces.iteritems(): - block2 = block.getRelative(block_face) - if block2.getData() in data_values: - check_sign(event, block2) + for block_face, data_values in faces.iteritems(): + block2 = block.getRelative(block_face) + if block2.getData() in data_values: + check_sign(event, block2) - block3 = block.getRelative(BlockFace.UP) - if block3.getMaterial == Material.SIGN_POST: - check_sign(event, block3) + block3 = block.getRelative(BlockFace.UP) + if block3.getMaterial == Material.SIGN_POST: + check_sign(event, block3) + except: + error(trace()) def check_sign(event, block, attached = True): -- 2.45.2 From 5717f5852711a63adf0ffc9f959dc114b091e77a Mon Sep 17 00:00:00 2001 From: Dico200 Date: Sun, 22 Nov 2015 17:12:35 +0100 Subject: [PATCH 103/217] Disabled chatalias so I can see errors --- main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.py b/main.py index ede4269..7411d17 100644 --- a/main.py +++ b/main.py @@ -43,7 +43,7 @@ shared["load_modules"] = [ # Adds /calc, toggles automatic solving of Math expressions in chat "calc", # Adds aliasing of chat words - "chatalias", + #"chatalias", # Plugin to locate laggy chunks. /lc lists chunks with more than n entities "lagchunks", # Adds /report and /rp, Stores reports with time and location -- 2.45.2 From f941f05f1d363c4e072b5ce19e3e97e6f163ac7d Mon Sep 17 00:00:00 2001 From: Dico200 Date: Sun, 22 Nov 2015 17:16:06 +0100 Subject: [PATCH 104/217] Block break fix 1 --- serversigns.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/serversigns.py b/serversigns.py index 018bbb7..00101d0 100644 --- a/serversigns.py +++ b/serversigns.py @@ -259,7 +259,7 @@ def on_break(event): return block = event.getBlock() - if block.getMaterial() in (Material.SIGN_POST, Material.WALL_SIGN): + if block.getType() in (Material.SIGN_POST, Material.WALL_SIGN): check_sign(event, block, attached = False) for block_face, data_values in faces.iteritems(): -- 2.45.2 From d83345d8f286a396431f5cefa692f82f4852bcb5 Mon Sep 17 00:00:00 2001 From: Dico200 Date: Sun, 22 Nov 2015 17:18:03 +0100 Subject: [PATCH 105/217] Block break fix 2 --- serversigns.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/serversigns.py b/serversigns.py index 00101d0..03a50ba 100644 --- a/serversigns.py +++ b/serversigns.py @@ -277,7 +277,7 @@ def on_break(event): def check_sign(event, block, attached = True): player = event.getPlayer() sign = getSign(fromLoc(block.getLocation())) - if not canEdit(sign, player) and not can_build(player, block.getLocation()): + if not canEdit(sign, player) and not can_build(player, block): event.setCancelled(True) msg(event.getPlayer(), signsMsg("You cannot break %s" % ("the sign attached to that block" if attached else "that sign"))) -- 2.45.2 From 019b3c6b579177db11197c85e15b35d842febf76 Mon Sep 17 00:00:00 2001 From: Dico200 Date: Sun, 22 Nov 2015 17:20:54 +0100 Subject: [PATCH 106/217] Block break fix 3 --- serversigns.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/serversigns.py b/serversigns.py index 03a50ba..14e103d 100644 --- a/serversigns.py +++ b/serversigns.py @@ -245,10 +245,10 @@ def on_click(event): checking_block = False faces = { - BlockFace.NORTH : (0,1,2), - BlockFace.SOUTH : 3, - BlockFace.WEST : 4, - BlockFace.EAST : 5 + BlockFace.NORTH : (0,1,2,), + BlockFace.SOUTH : (3,), + BlockFace.WEST : (4,), + BlockFace.EAST : (5,), } @hook.event("block.BlockBreakEvent", "highest") @@ -268,7 +268,7 @@ def on_break(event): check_sign(event, block2) block3 = block.getRelative(BlockFace.UP) - if block3.getMaterial == Material.SIGN_POST: + if block3.getType() == Material.SIGN_POST: check_sign(event, block3) except: error(trace()) -- 2.45.2 From 39b38ff0937ce5b00483e00f61598154a8fe14cf Mon Sep 17 00:00:00 2001 From: Dico200 Date: Sun, 22 Nov 2015 17:25:56 +0100 Subject: [PATCH 107/217] Block break fix 4 --- serversigns.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/serversigns.py b/serversigns.py index 14e103d..cab8258 100644 --- a/serversigns.py +++ b/serversigns.py @@ -260,7 +260,8 @@ def on_break(event): block = event.getBlock() if block.getType() in (Material.SIGN_POST, Material.WALL_SIGN): - check_sign(event, block, attached = False) + if check_sign(event, block, attached = False): + del signs[from] for block_face, data_values in faces.iteritems(): block2 = block.getRelative(block_face) @@ -278,9 +279,13 @@ def check_sign(event, block, attached = True): player = event.getPlayer() sign = getSign(fromLoc(block.getLocation())) if not canEdit(sign, player) and not can_build(player, block): - event.setCancelled(True) - msg(event.getPlayer(), signsMsg("You cannot break %s" % ("the sign attached to that block" if attached else "that sign"))) - + event.setCancelled(True) + msg(event.getPlayer(), signsMsg("You cannot break %s" % ("the sign attached to that block" if attached else "that sign"))) + else: + loc = fromLoc(block.getLocation()) + del signs[loc] + save_signs() + msg(player, signsMsg("Reset the %s which you just broke" % identifySign(loc))) def can_build(player, block): global checking_block -- 2.45.2 From ff365a832d23197965282f26426af81b846ce543 Mon Sep 17 00:00:00 2001 From: Dico200 Date: Sun, 22 Nov 2015 17:28:56 +0100 Subject: [PATCH 108/217] Derp! block break fix 5 --- serversigns.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/serversigns.py b/serversigns.py index cab8258..6550d74 100644 --- a/serversigns.py +++ b/serversigns.py @@ -260,8 +260,7 @@ def on_break(event): block = event.getBlock() if block.getType() in (Material.SIGN_POST, Material.WALL_SIGN): - if check_sign(event, block, attached = False): - del signs[from] + check_sign(event, block, attached = False): for block_face, data_values in faces.iteritems(): block2 = block.getRelative(block_face) -- 2.45.2 From d1d62d71d2225271e94b03448e46c0ca717cb81e Mon Sep 17 00:00:00 2001 From: Dico200 Date: Sun, 22 Nov 2015 17:30:09 +0100 Subject: [PATCH 109/217] Derp 2! block break fix 6 lel --- serversigns.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/serversigns.py b/serversigns.py index 6550d74..995e90c 100644 --- a/serversigns.py +++ b/serversigns.py @@ -260,7 +260,7 @@ def on_break(event): block = event.getBlock() if block.getType() in (Material.SIGN_POST, Material.WALL_SIGN): - check_sign(event, block, attached = False): + check_sign(event, block, attached = False) for block_face, data_values in faces.iteritems(): block2 = block.getRelative(block_face) -- 2.45.2 From 2a68613e779f2f50f9ff66481ae0c3c335e246d7 Mon Sep 17 00:00:00 2001 From: Dico200 Date: Sun, 22 Nov 2015 17:38:21 +0100 Subject: [PATCH 110/217] Block break tweaks --- serversigns.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/serversigns.py b/serversigns.py index 995e90c..5b471c5 100644 --- a/serversigns.py +++ b/serversigns.py @@ -251,7 +251,7 @@ faces = { BlockFace.EAST : (5,), } -@hook.event("block.BlockBreakEvent", "highest") +@hook.event("block.BlockBreakEvent", "lowest") def on_break(event): try: global checking_block @@ -264,7 +264,7 @@ def on_break(event): for block_face, data_values in faces.iteritems(): block2 = block.getRelative(block_face) - if block2.getData() in data_values: + if block2.getType == Material.WALL_SIGN and block2.getData() in data_values: check_sign(event, block2) block3 = block.getRelative(BlockFace.UP) @@ -277,7 +277,7 @@ def on_break(event): def check_sign(event, block, attached = True): player = event.getPlayer() sign = getSign(fromLoc(block.getLocation())) - if not canEdit(sign, player) and not can_build(player, block): + if not can_build(player, block): event.setCancelled(True) msg(event.getPlayer(), signsMsg("You cannot break %s" % ("the sign attached to that block" if attached else "that sign"))) else: -- 2.45.2 From 030b32f86a1c24ceb06cb744fc20dbd26c7b68b6 Mon Sep 17 00:00:00 2001 From: Dico200 Date: Sun, 22 Nov 2015 17:50:26 +0100 Subject: [PATCH 111/217] More tweaks --- serversigns.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/serversigns.py b/serversigns.py index 5b471c5..c26d4f8 100644 --- a/serversigns.py +++ b/serversigns.py @@ -134,6 +134,7 @@ def svs_command(sender, command, label, args): #------------------------ Sub commands that require the block to be a sign ------------------------------- if arg1 == "claim": Validate.isTrue(not sign, signsMsg("The %s was already claimed" % signName)) + Validate.isTrue(can_build2(block, player), signsMsg("You are not permitted to claim signs here")) target = sender if arg2: Validate.isTrue(player.hasPermission("utils.serversigns.admin"), signsMsg("You are not authorized to claim signs for other players")) @@ -251,7 +252,7 @@ faces = { BlockFace.EAST : (5,), } -@hook.event("block.BlockBreakEvent", "lowest") +@hook.event("block.BlockBreakEvent", "monitor") def on_break(event): try: global checking_block @@ -277,7 +278,7 @@ def on_break(event): def check_sign(event, block, attached = True): player = event.getPlayer() sign = getSign(fromLoc(block.getLocation())) - if not can_build(player, block): + if not can_build2(player, block): event.setCancelled(True) msg(event.getPlayer(), signsMsg("You cannot break %s" % ("the sign attached to that block" if attached else "that sign"))) else: @@ -286,7 +287,7 @@ def check_sign(event, block, attached = True): save_signs() msg(player, signsMsg("Reset the %s which you just broke" % identifySign(loc))) -def can_build(player, block): +def can_build2(player, block): global checking_block event = BlockBreakEvent(block, player) checking_block = True -- 2.45.2 From 274ce42fc8face712f381c791c691b6897239f83 Mon Sep 17 00:00:00 2001 From: Dico200 Date: Sun, 22 Nov 2015 17:52:54 +0100 Subject: [PATCH 112/217] Block break fix infinity --- serversigns.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/serversigns.py b/serversigns.py index c26d4f8..3b32def 100644 --- a/serversigns.py +++ b/serversigns.py @@ -134,7 +134,7 @@ def svs_command(sender, command, label, args): #------------------------ Sub commands that require the block to be a sign ------------------------------- if arg1 == "claim": Validate.isTrue(not sign, signsMsg("The %s was already claimed" % signName)) - Validate.isTrue(can_build2(block, player), signsMsg("You are not permitted to claim signs here")) + Validate.isTrue(can_build2(sender, block), signsMsg("You are not permitted to claim signs here")) target = sender if arg2: Validate.isTrue(player.hasPermission("utils.serversigns.admin"), signsMsg("You are not authorized to claim signs for other players")) -- 2.45.2 From ab42a0cb655d5e4123f8eeb8acd90de3531d0367 Mon Sep 17 00:00:00 2001 From: Dico200 Date: Sun, 22 Nov 2015 18:01:27 +0100 Subject: [PATCH 113/217] Sorry for the spam --- serversigns.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/serversigns.py b/serversigns.py index 3b32def..297b727 100644 --- a/serversigns.py +++ b/serversigns.py @@ -265,7 +265,7 @@ def on_break(event): for block_face, data_values in faces.iteritems(): block2 = block.getRelative(block_face) - if block2.getType == Material.WALL_SIGN and block2.getData() in data_values: + if block2.getType() == Material.WALL_SIGN and block2.getData() in data_values: check_sign(event, block2) block3 = block.getRelative(BlockFace.UP) -- 2.45.2 From 2808c5838b33dac74ad3ce34c733b2b7f1199d0a Mon Sep 17 00:00:00 2001 From: PixelSergey Date: Sun, 22 Nov 2015 19:56:11 +0200 Subject: [PATCH 114/217] Fixed a bug in chatalias. Still safe :D --- chatalias.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/chatalias.py b/chatalias.py index d55269c..25e3336 100644 --- a/chatalias.py +++ b/chatalias.py @@ -125,8 +125,9 @@ def on_player_chat(event): data = safe_open_json() if event.isCancelled(): return - if not data[playerid]: + if not playerid in data: return + event.setMessage(multiple_replace(data[playerid], event.getMessage())) if (event.getPlayer().hasPermission("essentials.chat.color")): @@ -135,4 +136,3 @@ def on_player_chat(event): event.setCancelled(True) plugin_header(recipient=event.getPlayer(), name="Chat Alias") msg(event.getPlayer(), "&7The message generated was too long and was not sent. :/") - -- 2.45.2 From 9d0e4c99ba84d4efb7828704ed5b0a8e7bdfc52d Mon Sep 17 00:00:00 2001 From: PanFritz Date: Mon, 23 Nov 2015 01:55:45 +0100 Subject: [PATCH 115/217] Removed "ls" in for loop --- setup.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.sh b/setup.sh index 336376f..74cc599 100755 --- a/setup.sh +++ b/setup.sh @@ -91,7 +91,7 @@ echo -e "\n> All plugins downloaded" cd "redstoner-utils.py.dir" echo -e "\n> Duplicating sample files" -for file in ls ./*.example; do +for file in ./*.example; do cp -v "$file" "$(echo "$file" | rev | cut -d "." -f 2- | rev)" done -- 2.45.2 From 70b4db5318075c6f15eae65f7a75488964ec0390 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Mon, 23 Nov 2015 22:17:40 +0100 Subject: [PATCH 116/217] added wrappers, temp disabled all modules --- helpers.py | 53 +++++++++------------------ main.py | 81 ++++------------------------------------- mysql_utils.py | 33 +++++++++++++++++ mysqlhack.py | 8 ++--- thread_utils.py | 24 +++++++++++++ wrapper.py | 11 ++++++ wrapper_command.py | 11 ++++++ wrapper_event.py | 22 ++++++++++++ wrapper_player.py | 89 ++++++++++++++++++++++++++++++++++++++++++++++ 9 files changed, 217 insertions(+), 115 deletions(-) create mode 100644 mysql_utils.py create mode 100644 thread_utils.py create mode 100644 wrapper.py create mode 100644 wrapper_command.py create mode 100644 wrapper_event.py create mode 100644 wrapper_player.py diff --git a/helpers.py b/helpers.py index 79af3a0..f7e125e 100644 --- a/helpers.py +++ b/helpers.py @@ -1,26 +1,30 @@ #pylint: disable = F0401 -from re import sub -from java.util.UUID import fromString as juuid -from json import dumps as json_dumps, loads as json_loads + import org.bukkit as bukkit -import org.bukkit.Location as Location -import org.bukkit.entity.Player as Player -import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause as TeleportCause -import org.bukkit.event.block.BlockBreakEvent as BlockBreakEvent import org.bukkit.block as bblock +import org.bukkit.Location as Location import org.bukkit.event.entity as entity +import org.bukkit.entity.Player as Player import org.bukkit.command.ConsoleCommandSender +import org.bukkit.event.block.BlockBreakEvent as BlockBreakEvent +import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause as TeleportCause + +from re import sub +from thread_utils import * +from player import py_players from org.bukkit.entity import * from player import get_py_player -from player import py_players +from traceback import format_exc as trace +from java.util.UUID import fromString as juuid +from json import dumps as json_dumps, loads as json_loads #Imports for async query -from secrets import * -import mysqlhack -from com.ziclix.python.sql import zxJDBC import threading +import mysqlhack + +from secrets import * +from com.ziclix.python.sql import zxJDBC -from traceback import format_exc as trace shared = {} # this dict can be used to share stuff across modules @@ -214,31 +218,6 @@ def known_player(player): """ return player.hasPlayedBefore() -""" -Runs a async query, calls target function with fetchall as an argument, it will be an empty list if there is nothing to fetch. -(So make sure your function takes that argument.) - -If you want your function to run sync in the case you are doing something spigot wouldn't like to be async use the bukkit scheduler. -Example can be found in loginsecurity.py - -""" -def async_query(mysql_database,query,query_args,target,*target_args,**target_kwargs): - - def async_query_t(mysql_database,query,query_args,target,target_args,target_kwargs): - db_conn = zxJDBC.connect(mysql_database, mysql_user, mysql_pass, "com.mysql.jdbc.Driver") - db_curs = db_conn.cursor() - db_curs.execute(query,query_args) - db_conn.commit() - fetchall = db_curs.fetchall() - db_curs.close() - db_conn.close() - target(fetchall,target_args,target_kwargs) - - t = threading.Thread(target=async_query_t,args=(mysql_database,query,query_args,target,target_args,target_kwargs)) - t.daemon = True - t.start() - - def open_json_file(filename, default = None): """ opens the given json file and returns an object or returns None on error diff --git a/main.py b/main.py index 7411d17..3e1319d 100644 --- a/main.py +++ b/main.py @@ -11,8 +11,9 @@ 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 * except: - print("[RedstonerUtils] ERROR: Failed to import helpers:") + print("[RedstonerUtils] ERROR: Failed to import Wrapper:") print(print_traceback()) @@ -24,85 +25,17 @@ def on_enable(): @hook.disable def on_disable(): - shared["modules"]["reports"].stop_reporting() + #shared["modules"]["reports"].stop_reporting() info("RedstonerUtils disabled!") info("Loading RedstonerUtils...") + + # Import all modules, in this order -shared["load_modules"] = [ - # Collection of tiny utilities - "misc", - # Adds chat for staff using /ac - "adminchat", - # Adds /badge, allows to give players achievements - "badges", - # Adds a few block placement corrections/mods - "blockplacemods", - # Adds /calc, toggles automatic solving of Math expressions in chat - "calc", - # Adds aliasing of chat words - #"chatalias", - # Plugin to locate laggy chunks. /lc lists chunks with more than n entities - "lagchunks", - # Adds /report and /rp, Stores reports with time and location - "reports", - # Adds group-chat with /chatgroup and /cgt to toggle normal chat into group mode - "chatgroups", - # Adds /token, reads and writes from the database to generate pronouncable (and thus memorable) registration-tokens for the website - "webtoken", - # Adds /lol, broadcasts random funyy messages. A bit like the splash text in the menu - "saylol", - # Adds /signalstrength, lets you request a signal strength and an amount of items will be inserted into target container to meet that strength. - "signalstrength", - # Shows the owner of a skull when right-clicked - "skullclick", - # Adds /listen, highlights chat and plays a sound when your name was mentioned - "mentio", - # Adds /cycler, swaps the hotbar with inventory when player changes slot from right->left or left->right - "cycle", - # Adds /getmotd & /setmotd to update the motd on the fly (no reboot) - "motd", - # AnswerBot. Hides stupid questions from chat and tells the sender about /faq or the like - "abot", - # Adds '/forcefield', creates forcefield for players who want it. - "forcefield", - # Adds /damnspam, creates timeout for buttons/levers to mitigate button spam. - "damnspam", - # Adds /check, useful to lookup details about a player - "check", - # Adds /an, a command you can use to share thoughts/plans/news - "adminnotes", - # Adds busy status to players - "imbusy", - # Adds /imout, displays fake leave/join messages - "imout", - #adds snowbrawl minigame - "snowbrawl", - # Adds /tm [player] for a messages to be sent to this player via /msg - "pmtoggle", - # Replacement for LoginSecurity - "loginsecurity", - # Centralized Player class - "player", - # Servercontrol extension for telnet access to logs/AC - #"servercontrol", - # Script helper plugin - "scriptutils", - # Per-player notes - "tag", - # vanish toggle module - temporary fix - #"vanishfix", - # obisidian mining punishment plugin - "punishments", - # a simple replacement for the buggy essentials /vanish - "vanish", - # ip-tracking utility - "iptracker", - #server signs for everyone - "serversigns" -] +shared["load_modules"] = ["test"] + shared["modules"] = {} for module in shared["load_modules"]: try: diff --git a/mysql_utils.py b/mysql_utils.py new file mode 100644 index 0000000..e59c3d9 --- /dev/null +++ b/mysql_utils.py @@ -0,0 +1,33 @@ +import mysqlhack +from secrets import * +from thread_utils import * +from com.ziclix.python.sql import zxJDBC +from traceback import format_exc as trace + +class mysql_connect: + def __init__(self): + self.conn = zxJDBC.connect(mysql_database, mysql_user, mysql_pass, "com.mysql.jdbc.Driver") + self.curs = self.conn.cursor() + + def execute(self, query, args=None): + if args is None: + return self.curs.execute(query) + else: + return self.curs.execute(query, args) + + def fetchall(self): + return self.curs.fetchall() + + def __enter__(self): + return self + + def __exit__(self, exc_type, exc_inst, exc_tb): + if exc_type is None: + try: + self.conn.commit() + self.curs.close() + self.conn.close() + except: + print(trace()) + else: + print(exc_tb) diff --git a/mysqlhack.py b/mysqlhack.py index 7153bdf..5d45c52 100644 --- a/mysqlhack.py +++ b/mysqlhack.py @@ -4,12 +4,12 @@ A library that makes use of the so called ClassPathHack for jython to allow proper loading of mysql-connector.jar at runtime. Import only, no methods. """ -import java.lang.reflect.Method -import java.io.File -import java.net.URL -import java.net.URLClassLoader import jarray +import java.net.URL +import java.io.File from java.lang import Class +import java.net.URLClassLoader +import java.lang.reflect.Method # hacky code to add mysql-connector to java's classpath ('classPathHack') diff --git a/thread_utils.py b/thread_utils.py new file mode 100644 index 0000000..ec13c6f --- /dev/null +++ b/thread_utils.py @@ -0,0 +1,24 @@ +import threading +""" +Quick implementation of a @synchronized and @asynchronized decorators +""" + +#To be replaced by bukkit scheduler. +""" +def sync(lock=None): + def decorator(wrapped): + def wrapper(*args, **kwargs): + with lock: + return wrapped(*args, **kwargs) + return wrapper + return decorator +""" + +def async(daemon = True): + def decorator(function): + def wrapper(*args,**kwargs): + thread = threading.Thread(target=function,args=args,kwargs=kwargs) + thread.daemon = daemon + thread.start() + return wrapper + return decorator \ No newline at end of file diff --git a/wrapper.py b/wrapper.py new file mode 100644 index 0000000..ddca5b5 --- /dev/null +++ b/wrapper.py @@ -0,0 +1,11 @@ +""" +Adapter classes for spigot api for more idiomatic python code. + +Before you run away from this if the class you need to use isn't here, please create it. + + +""" +from helpers import * +from wrapper_event import * +from wrapper_player import * +from wrapper_command import * \ No newline at end of file diff --git a/wrapper_command.py b/wrapper_command.py new file mode 100644 index 0000000..dd51534 --- /dev/null +++ b/wrapper_command.py @@ -0,0 +1,11 @@ +from wrapper_player import * + +def command(command = "help"): + def decorator(wrapped): + @hook.command(command) + def wrapper(sender, command, label, args): + try: + return wrapped(sender = py_players[sender], command = command, label = label, args = args) + except: + print(print_traceback()) + return decorator \ No newline at end of file diff --git a/wrapper_event.py b/wrapper_event.py new file mode 100644 index 0000000..083bf33 --- /dev/null +++ b/wrapper_event.py @@ -0,0 +1,22 @@ +from wrapper import * +from wrapper_player import * +from traceback import format_exc as print_traceback + +class py_event: + def __init__(self,event): + self.event = event + try: + self.player = py_players[event.getPlayer()] + except: + warn("Player doesn't exist") + +def event_handler(event_name = None, priority = "normal"): + def decorator(wrapped): + @hook.event(event_name, priority) + def wrapper(event): + try: + wrapped(py_event(event)) + except: + print(print_traceback()) + return decorator + diff --git a/wrapper_player.py b/wrapper_player.py new file mode 100644 index 0000000..aca0e60 --- /dev/null +++ b/wrapper_player.py @@ -0,0 +1,89 @@ +import time +import mysqlhack +from mysql_utils import * +from thread_utils import * +from players_secret import * +from datetime import datetime +from com.ziclix.python.sql import zxJDBC + +class py_player: + def __init__(self,player): + self.player = player + self.login_time = time.time() + self.logging_in = False + + self.nickname = self.name + self.registered = False + self.password = "None" + self.banned = False + self.banned_reason = "You have been banned!" + self.played_time = time.time() - self.login_time + self.last_login = datetime.now() + self.first_seen = datetime.now() + + def kick(self, kick_message = "You have been kicked from the server!"): + self.player.KickPlayer(kick_message) + + @property + def name(self): + return self.player.getName() + + @property + def uuid(self): + return str(self.player.getUniqueId()) + + +class Py_players: + def __init__(self): + self.players = [] + + def __len__(self): + return len(self.players) + + def __getitem__(self, player): + for py_player in self.players: + if py_player.name == player.getName(): + return py_player + else: + return None + + def remove(self, player): + self.players.remove(player) + + def append(self, player): + self.players.append(player) + +py_players = Py_players() + +@async(daemon=True) +def fetch_player(player): + with mysql_connect() as sql: + sql.execute("SELECT * FROM utils_players WHERE uuid = ?", (player.uuid,)) + result = sql.fetchall() + + if len(result) is 0: + with mysql_connect() as sql: + sql.execute("INSERT INTO utils_players \ + (uuid, name, nickname, registered, password, banned, \ + banned_reason, played_time, last_login, first_seen) \ + VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", + + args=(player.uuid, player.name, player.nickname, player.registered, + player.password, player.banned, + player.banned_reason, player.played_time, + player.last_login, player.first_seen)) + else: + pass + + + +@hook.event("player.PlayerJoinEvent","lowest") +def on_join(event): + player = py_player(event.getPlayer()) + py_players.append(player) + fetch_player(player) + + +@hook.event("player.PlayerQuitEvent","highest") +def on_leave(event): + py_players.remove(py_players[event.getPlayer()]) -- 2.45.2 From 781714bc7423565cd7aeb7b3b29899269cf80454 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Mon, 23 Nov 2015 22:28:11 +0100 Subject: [PATCH 117/217] Test --- wrapper_player.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wrapper_player.py b/wrapper_player.py index aca0e60..a889ede 100644 --- a/wrapper_player.py +++ b/wrapper_player.py @@ -74,7 +74,7 @@ def fetch_player(player): player.last_login, player.first_seen)) else: pass - + #test @hook.event("player.PlayerJoinEvent","lowest") -- 2.45.2 From 522a7a99a115b2c32e8edd00fe47d1b288d6b006 Mon Sep 17 00:00:00 2001 From: Dico200 Date: Wed, 25 Nov 2015 01:15:44 +0100 Subject: [PATCH 118/217] wrapper_command WIP --- serversigns.py | 53 ++++++---- vanish.py | 53 +++++----- wrapper_command.py | 237 +++++++++++++++++++++++++++++++++++++++++++-- wrapper_player.py | 3 + 4 files changed, 290 insertions(+), 56 deletions(-) diff --git a/serversigns.py b/serversigns.py index 297b727..f8f9db5 100644 --- a/serversigns.py +++ b/serversigns.py @@ -5,6 +5,14 @@ import java.util.UUID as UUID import org.bukkit.Material as Material import org.bukkit.block.BlockFace as BlockFace +""" + # About permissions: + # To use the command, the user needs to have utils.serversigns. + # To use ANY subcommand, the user needs to have utils.serversigns. IN ADDITION to the previously mentioned node. + # To be able to add commands as messages to a sign, a user will need the node utils.serversigns.command. + # To be able to claim a sign for another player or to edit signs that the user doesn't own, they will need utils.serversigns.admin. +""" + blocked_cmds = ("pex", "kick", "ban", "tempban", "pyeval", "sudo", "stop", "reload", "op", "deop", "whitelist") def load_signs(): @@ -24,6 +32,18 @@ signs = load_signs() # {("world", x, y, z): ["owner_id", "msg1", "msg2"]} lines = {} # Accumulated messages so players can have longer messages: {"Dico200": "Message...........", ""} +@hook.enable +def check_all_signs(): + # Check if all saved signs actually represent a sign block. There are ways to break the signs without the plugin knowing. + for loc in dict(signs): # Can't change dict size during iteration, using a copy + world = server.getWorld(loc[0]) + if world and world.getBlockAt(loc[1], loc[2], loc[3]).getType() in (Material.SIGN_POST, Material.WALL_SIGN): + continue + del signs[loc] + info("[Server Signs] Couldn't find a %s, removed the data for the sign that was once there." % identifySign(loc)) + save_signs() + + def fromLoc(bLoc): """ # Returns a tuple containing the (bukkit)location's world's name and its x, y and z coordinates @@ -222,9 +242,6 @@ def svs_command(sender, command, label, args): return signsMsg("Removed all messages and the owner from the %s, it can now be claimed" % signName, 'a') #------------------------------------------------------------------------------------------------------- - - - @hook.event("player.PlayerInteractEvent") def on_click(event): if str(event.getAction()) != "RIGHT_CLICK_BLOCK": @@ -254,25 +271,22 @@ faces = { @hook.event("block.BlockBreakEvent", "monitor") def on_break(event): - try: - global checking_block - if checking_block or event.isCancelled(): - return + global checking_block + if checking_block or event.isCancelled(): + return - block = event.getBlock() - if block.getType() in (Material.SIGN_POST, Material.WALL_SIGN): - check_sign(event, block, attached = False) + block = event.getBlock() + if block.getType() in (Material.SIGN_POST, Material.WALL_SIGN): + check_sign(event, block, attached = False) - for block_face, data_values in faces.iteritems(): - block2 = block.getRelative(block_face) - if block2.getType() == Material.WALL_SIGN and block2.getData() in data_values: - check_sign(event, block2) + for block_face, data_values in faces.iteritems(): + block2 = block.getRelative(block_face) + if block2.getType() == Material.WALL_SIGN and block2.getData() in data_values: + check_sign(event, block2) - block3 = block.getRelative(BlockFace.UP) - if block3.getType() == Material.SIGN_POST: - check_sign(event, block3) - except: - error(trace()) + block3 = block.getRelative(BlockFace.UP) + if block3.getType() == Material.SIGN_POST: + check_sign(event, block3) def check_sign(event, block, attached = True): @@ -287,6 +301,7 @@ def check_sign(event, block, attached = True): save_signs() msg(player, signsMsg("Reset the %s which you just broke" % identifySign(loc))) + def can_build2(player, block): global checking_block event = BlockBreakEvent(block, player) diff --git a/vanish.py b/vanish.py index a572ebc..87a667b 100644 --- a/vanish.py +++ b/vanish.py @@ -13,7 +13,7 @@ def is_vanished(player): return uid(player) in vanished -#this can be used to silently set the vanished state of a player +#this can be used to silently set the vanished state of a player I guess. def set_state(player, state): if state == is_vanished(player): return @@ -37,6 +37,10 @@ def disable_vanish(target): player.showPlayer(target) +def get_online_vanished_players(): + return (player.getPlayer() for player in (retrieve_player(uuid) for uuid in vanished) if player.isOnline()) + + @simplecommand("vanish", aliases = ["v"], usage = "[on/off]", @@ -48,45 +52,38 @@ def disable_vanish(target): helpSubcmd = True ) def vanish_command(sender, command, label, args): - try: - current_state = is_vanished(sender) - new_state = not current_state + current_state = is_vanished(sender) + new_state = not current_state - if len(args) == 1: - arg = args[0].lower() - if arg == "on": - new_state = True - elif arg == "off": - new_state = False + if len(args) == 1: + arg = args[0].lower() + if arg == "on": + new_state = True + elif arg == "off": + new_state = False - if current_state == new_state: - return "&cYou were %s vanished!" % ("already" if current_state else "not yet") - - set_state(sender, new_state) - return "&a%s vanish mode!" % ("Enabled" if new_state else "Disabled") - except: - error(trace()) + Validate.isTrue(current_state != new_state, "&cYou were %s vanished!" % ("already" if current_state else "not yet")) + set_state(sender, new_state) + return "&a%s vanish mode!" % ("Enabled" if new_state else "Disabled") @hook.event("player.PlayerJoinEvent") def on_player_join(event): player = event.getPlayer() - if not is_authorized(player): - for uuid in vanished: - player.hidePlayer(retrieve_player(uuid)) - - elif is_vanished(player): - msg(player, "&cKeep in mind that you are still vanished! Use /vanish to disable.") + for vanished in get_online_vanished_players(): + player.hidePlayer(vanished) @hook.event("player.PlayerQuitEvent") def on_player_quit(event): player = event.getPlayer() - if not is_authorized(player): - for uuid in vanished: - player.showPlayer(retrieve_player(uuid)) + for vanished in get_online_vanished_players(): + player.showPlayer(vanished) + + elif is_vanished(player): + disable_vanish(player) @simplecommand("vanishother", @@ -110,9 +107,7 @@ def vanishother_command(sender, command, label, args): elif arg == "off": new_state = False - if current_state == new_state: - return "&cThat player was already vanished!" if current_state else "&cThat player was not yet vanished!" - + Validate.isTrue(current_state != new_state, "&cThat player was %s vanished!" % ("already" if current_state else "not yet")) set_state(target, new_state) enabled_str = "enabled" if new_state else "disabled" diff --git a/wrapper_command.py b/wrapper_command.py index dd51534..90eaf01 100644 --- a/wrapper_command.py +++ b/wrapper_command.py @@ -1,11 +1,232 @@ from wrapper_player import * +from helpers import * -def command(command = "help"): - def decorator(wrapped): - @hook.command(command) - def wrapper(sender, command, label, args): +root_commands = Command_dict() # {"command": command_object} + +def check_arguments(command, arguments): + prev_required = True + type_message_seen = False + prev_arg = arguments[0] if len(arguments) > 0 else None + for arg_info in arguments[1:]: + + if not prev_arg.required and arg_info.required: + raise Argument_exception("Command: %s; There may not be required arguments after non-required arguments" % command) + + if prev_arg.type == Argument.MESSAGE: + raise Argument_exception("Command: %s; An argument of type MESSAGE may not be followed by other arguments" % command) + + prev_arg = arg_info + +#-------------------------------------------------------------------------------------- + +class Command_dict(dict): + #{"cmd1" : cmd_object} + def get_command_object(self, alias): + for cmd_name, cmd_obj in self.iteritems(): + if alias == cmd_name or alias in cmd_obj.aliases: + return cmd_obj + raise KeyError("Subcommand '%s' was not found" % alias) + +#-------------------------------------------------------------------------------------- + +class Command(object): + + def __init__(self, + command, + aliases = (), + arguments = ( + Argument("target", Argument.string, "the player to teleport to"), + Argument("second target", Argument.string, "the player to teleport", False), + ), + parent = None): + + self.command = command.lower() + self.arguments = arguments + + check_arguments(self.command, self.arguments) + + prev_required = True + for arg_info in self.arguments: + if not prev_required and arg_info.required: + raise Argument_exception("Command: %s; There may not be required arguments after non-required arguments" % self.command) + + self.aliases = tuple(alias.lower() for alias in aliases) + self.parent = parent + self.sub_commands = Command_dict() + + if self.parent == None: + root_commands[self.command] = self + else: try: - return wrapped(sender = py_players[sender], command = command, label = label, args = args) - except: - print(print_traceback()) - return decorator \ No newline at end of file + parent_route = self.parent.split(" ") + parent_sub_commands = root_commands + parent_obj = None + for cmd_name in parent_route: + parent_obj = parent_sub_commands.get_command_object(cmd_name) + parent_sub_commands = parent_obj.sub_commands + parent_obj.sub_commands[self.command] = self + + except command_exception, e: + error("Error occurred while setting up command hierarchy. " + e.message + "\n" + trace()) + + def __call__(self, handler): + self.handler = handler + + if parent == None: + @hook.command(self.command, self.aliases) + def run(sender, command, label, args): + try: + message = self.execute(sender, command, label, args) + except Command_exception as e: + message = e.message + except Exception: + error(trace()) + return True + if message: + sender.sendMessage(message) + return True + + return handler + + def execute(self, sender, command, label, args): + try: + return self.sub_commands.get_command_object(args[0].lower()).execute(sender, command, label, args[1:]) + except (KeyError, IndexError): + self.execute_checks(sender, command, label, args) + + def execute_checks(self, sender, command, label, args): + #TODO + + scape = Command_scape(args, self.arguments) + if is_player(sender): + sender = py_players[sender] + + return self.handler(sender, self, scape) + + def syntax(self): + return " ".join(tuple(arg_info.syntax() for arg_info in self.arguments)) + +#-------------------------------------------------------------------------------------- + +class Command_scape(list): + + def __init__(self, args, arg_layout): + super(list, self).__init__() + self.raw = args + self.arg_layout = arg_layout + + has_message = False + for i in range(len(arg_layout)): + arg_info = arg_layout[i] + + given = (len(args) >= i + 1) + if arg_info.required and not given: + raise Argument_exception("You must specify the " + arg_info.name) + + if not given: + self.append(None) + continue + + given_arg = args[i] + arg_type = arg_info.type + + if arg_type == Argument.STRING: + self.append(given_arg) + + elif arg_type == Argument.INTEGER: + try: + value = int(given_arg) + except ValueError: + raise Argument_exception("The %s has to be a round number" % arg_info.name) + self.append(value) + + elif arg_type == Argument.FLOAT: + try: + value = float(given_arg) + except ValueError: + raise Argument_exception("The %s has to be a number" % arg_info.name) + self.append(value) + + elif arg_type == Argument.PLAYER: + 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]) + + elif arg_type == Argument.OFFLINE_PLAYER: + try: + # Code to get the PY PLAYER by name. Possibly, uid(server.getOfflinePlayer(given_arg)) can be used? + pass + except KeyError: + raise Argument_exception("The %s has to be an existing player" % arg_info.name) + self.append(None) + + elif arg_type == Argument.MESSAGE: + self.append(" ".join(args[i:])) + has_message = True + else: + error("Argument type not found: %d" % arg_type) + raise Argument_exception("A weird thing has happened, please contact an administrator") + + if not has_message: + self.remainder = args[len(arg_layout):] + else: + self.remainder = None + + def has_flag(self, flag, check_all = False): + return (("-" + flag) in self.raw) if check_all else (("-" + flag) in self.remainder) + + def get_raw(self): + return self.raw + + def get_arg_layout(self): + return self.arg_layout + +#-------------------------------------------------------------------------------------- + +class Command_exception(Exception): + + def __init__(self, message): + self.message = message + +class Argument_exception(Exception): + + def __init__(self, message): + self.message = message + +#-------------------------------------------------------------------------------------- + +class Argument(): + + STRING = 0 + INTEGER = 1 + FLOAT = 2 + PLAYER = 3 + OFFLINE_PLAYER = 4 + MESSAGE = 5 + + def __init__(self, name, type, definition, required = True): + self.name = name + self.type = type + self.definition = definition + self.required = required + + def syntax(self): + syntax = self.name + if self.type == Argument.MESSAGE: + syntax += "..." + return (("<%s>" if self.required else "[%s]") % syntax) + +#-------------------------------------------------------------------------------------- + +class Validate(): + + @staticmethod + def is_true(expression, fail_message): + if not expression: + raise Command_exception(fail_message) + + @staticmethod + def not_none(obj, fail_message): + if obj == None: + raise Command_exception(fail_message) diff --git a/wrapper_player.py b/wrapper_player.py index a889ede..db7f6cc 100644 --- a/wrapper_player.py +++ b/wrapper_player.py @@ -6,6 +6,9 @@ from players_secret import * from datetime import datetime from com.ziclix.python.sql import zxJDBC +def get_py_player(player): + + class py_player: def __init__(self,player): self.player = player -- 2.45.2 From 0172cf2feb199773d8fcf6c3fb707804f7952ecd Mon Sep 17 00:00:00 2001 From: Dico200 Date: Wed, 25 Nov 2015 15:24:34 +0100 Subject: [PATCH 119/217] Revert "wrapper_command WIP" This reverts commit 522a7a99a115b2c32e8edd00fe47d1b288d6b006. --- serversigns.py | 53 ++++------ vanish.py | 53 +++++----- wrapper_command.py | 237 ++------------------------------------------- wrapper_player.py | 3 - 4 files changed, 56 insertions(+), 290 deletions(-) diff --git a/serversigns.py b/serversigns.py index f8f9db5..297b727 100644 --- a/serversigns.py +++ b/serversigns.py @@ -5,14 +5,6 @@ import java.util.UUID as UUID import org.bukkit.Material as Material import org.bukkit.block.BlockFace as BlockFace -""" - # About permissions: - # To use the command, the user needs to have utils.serversigns. - # To use ANY subcommand, the user needs to have utils.serversigns. IN ADDITION to the previously mentioned node. - # To be able to add commands as messages to a sign, a user will need the node utils.serversigns.command. - # To be able to claim a sign for another player or to edit signs that the user doesn't own, they will need utils.serversigns.admin. -""" - blocked_cmds = ("pex", "kick", "ban", "tempban", "pyeval", "sudo", "stop", "reload", "op", "deop", "whitelist") def load_signs(): @@ -32,18 +24,6 @@ signs = load_signs() # {("world", x, y, z): ["owner_id", "msg1", "msg2"]} lines = {} # Accumulated messages so players can have longer messages: {"Dico200": "Message...........", ""} -@hook.enable -def check_all_signs(): - # Check if all saved signs actually represent a sign block. There are ways to break the signs without the plugin knowing. - for loc in dict(signs): # Can't change dict size during iteration, using a copy - world = server.getWorld(loc[0]) - if world and world.getBlockAt(loc[1], loc[2], loc[3]).getType() in (Material.SIGN_POST, Material.WALL_SIGN): - continue - del signs[loc] - info("[Server Signs] Couldn't find a %s, removed the data for the sign that was once there." % identifySign(loc)) - save_signs() - - def fromLoc(bLoc): """ # Returns a tuple containing the (bukkit)location's world's name and its x, y and z coordinates @@ -242,6 +222,9 @@ def svs_command(sender, command, label, args): return signsMsg("Removed all messages and the owner from the %s, it can now be claimed" % signName, 'a') #------------------------------------------------------------------------------------------------------- + + + @hook.event("player.PlayerInteractEvent") def on_click(event): if str(event.getAction()) != "RIGHT_CLICK_BLOCK": @@ -271,22 +254,25 @@ faces = { @hook.event("block.BlockBreakEvent", "monitor") def on_break(event): - global checking_block - if checking_block or event.isCancelled(): - return + try: + global checking_block + if checking_block or event.isCancelled(): + return - block = event.getBlock() - if block.getType() in (Material.SIGN_POST, Material.WALL_SIGN): - check_sign(event, block, attached = False) + block = event.getBlock() + if block.getType() in (Material.SIGN_POST, Material.WALL_SIGN): + check_sign(event, block, attached = False) - for block_face, data_values in faces.iteritems(): - block2 = block.getRelative(block_face) - if block2.getType() == Material.WALL_SIGN and block2.getData() in data_values: - check_sign(event, block2) + for block_face, data_values in faces.iteritems(): + block2 = block.getRelative(block_face) + if block2.getType() == Material.WALL_SIGN and block2.getData() in data_values: + check_sign(event, block2) - block3 = block.getRelative(BlockFace.UP) - if block3.getType() == Material.SIGN_POST: - check_sign(event, block3) + block3 = block.getRelative(BlockFace.UP) + if block3.getType() == Material.SIGN_POST: + check_sign(event, block3) + except: + error(trace()) def check_sign(event, block, attached = True): @@ -301,7 +287,6 @@ def check_sign(event, block, attached = True): save_signs() msg(player, signsMsg("Reset the %s which you just broke" % identifySign(loc))) - def can_build2(player, block): global checking_block event = BlockBreakEvent(block, player) diff --git a/vanish.py b/vanish.py index 87a667b..a572ebc 100644 --- a/vanish.py +++ b/vanish.py @@ -13,7 +13,7 @@ def is_vanished(player): return uid(player) in vanished -#this can be used to silently set the vanished state of a player I guess. +#this can be used to silently set the vanished state of a player def set_state(player, state): if state == is_vanished(player): return @@ -37,10 +37,6 @@ def disable_vanish(target): player.showPlayer(target) -def get_online_vanished_players(): - return (player.getPlayer() for player in (retrieve_player(uuid) for uuid in vanished) if player.isOnline()) - - @simplecommand("vanish", aliases = ["v"], usage = "[on/off]", @@ -52,38 +48,45 @@ def get_online_vanished_players(): helpSubcmd = True ) def vanish_command(sender, command, label, args): - current_state = is_vanished(sender) - new_state = not current_state + try: + current_state = is_vanished(sender) + new_state = not current_state - if len(args) == 1: - arg = args[0].lower() - if arg == "on": - new_state = True - elif arg == "off": - new_state = False + if len(args) == 1: + arg = args[0].lower() + if arg == "on": + new_state = True + elif arg == "off": + new_state = False - Validate.isTrue(current_state != new_state, "&cYou were %s vanished!" % ("already" if current_state else "not yet")) - set_state(sender, new_state) - return "&a%s vanish mode!" % ("Enabled" if new_state else "Disabled") + if current_state == new_state: + return "&cYou were %s vanished!" % ("already" if current_state else "not yet") + + set_state(sender, new_state) + return "&a%s vanish mode!" % ("Enabled" if new_state else "Disabled") + except: + error(trace()) @hook.event("player.PlayerJoinEvent") def on_player_join(event): player = event.getPlayer() + if not is_authorized(player): - for vanished in get_online_vanished_players(): - player.hidePlayer(vanished) + for uuid in vanished: + player.hidePlayer(retrieve_player(uuid)) + + elif is_vanished(player): + msg(player, "&cKeep in mind that you are still vanished! Use /vanish to disable.") @hook.event("player.PlayerQuitEvent") def on_player_quit(event): player = event.getPlayer() - if not is_authorized(player): - for vanished in get_online_vanished_players(): - player.showPlayer(vanished) - elif is_vanished(player): - disable_vanish(player) + if not is_authorized(player): + for uuid in vanished: + player.showPlayer(retrieve_player(uuid)) @simplecommand("vanishother", @@ -107,7 +110,9 @@ def vanishother_command(sender, command, label, args): elif arg == "off": new_state = False - Validate.isTrue(current_state != new_state, "&cThat player was %s vanished!" % ("already" if current_state else "not yet")) + if current_state == new_state: + return "&cThat player was already vanished!" if current_state else "&cThat player was not yet vanished!" + set_state(target, new_state) enabled_str = "enabled" if new_state else "disabled" diff --git a/wrapper_command.py b/wrapper_command.py index 90eaf01..dd51534 100644 --- a/wrapper_command.py +++ b/wrapper_command.py @@ -1,232 +1,11 @@ from wrapper_player import * -from helpers import * -root_commands = Command_dict() # {"command": command_object} - -def check_arguments(command, arguments): - prev_required = True - type_message_seen = False - prev_arg = arguments[0] if len(arguments) > 0 else None - for arg_info in arguments[1:]: - - if not prev_arg.required and arg_info.required: - raise Argument_exception("Command: %s; There may not be required arguments after non-required arguments" % command) - - if prev_arg.type == Argument.MESSAGE: - raise Argument_exception("Command: %s; An argument of type MESSAGE may not be followed by other arguments" % command) - - prev_arg = arg_info - -#-------------------------------------------------------------------------------------- - -class Command_dict(dict): - #{"cmd1" : cmd_object} - def get_command_object(self, alias): - for cmd_name, cmd_obj in self.iteritems(): - if alias == cmd_name or alias in cmd_obj.aliases: - return cmd_obj - raise KeyError("Subcommand '%s' was not found" % alias) - -#-------------------------------------------------------------------------------------- - -class Command(object): - - def __init__(self, - command, - aliases = (), - arguments = ( - Argument("target", Argument.string, "the player to teleport to"), - Argument("second target", Argument.string, "the player to teleport", False), - ), - parent = None): - - self.command = command.lower() - self.arguments = arguments - - check_arguments(self.command, self.arguments) - - prev_required = True - for arg_info in self.arguments: - if not prev_required and arg_info.required: - raise Argument_exception("Command: %s; There may not be required arguments after non-required arguments" % self.command) - - self.aliases = tuple(alias.lower() for alias in aliases) - self.parent = parent - self.sub_commands = Command_dict() - - if self.parent == None: - root_commands[self.command] = self - else: +def command(command = "help"): + def decorator(wrapped): + @hook.command(command) + def wrapper(sender, command, label, args): try: - parent_route = self.parent.split(" ") - parent_sub_commands = root_commands - parent_obj = None - for cmd_name in parent_route: - parent_obj = parent_sub_commands.get_command_object(cmd_name) - parent_sub_commands = parent_obj.sub_commands - parent_obj.sub_commands[self.command] = self - - except command_exception, e: - error("Error occurred while setting up command hierarchy. " + e.message + "\n" + trace()) - - def __call__(self, handler): - self.handler = handler - - if parent == None: - @hook.command(self.command, self.aliases) - def run(sender, command, label, args): - try: - message = self.execute(sender, command, label, args) - except Command_exception as e: - message = e.message - except Exception: - error(trace()) - return True - if message: - sender.sendMessage(message) - return True - - return handler - - def execute(self, sender, command, label, args): - try: - return self.sub_commands.get_command_object(args[0].lower()).execute(sender, command, label, args[1:]) - except (KeyError, IndexError): - self.execute_checks(sender, command, label, args) - - def execute_checks(self, sender, command, label, args): - #TODO - - scape = Command_scape(args, self.arguments) - if is_player(sender): - sender = py_players[sender] - - return self.handler(sender, self, scape) - - def syntax(self): - return " ".join(tuple(arg_info.syntax() for arg_info in self.arguments)) - -#-------------------------------------------------------------------------------------- - -class Command_scape(list): - - def __init__(self, args, arg_layout): - super(list, self).__init__() - self.raw = args - self.arg_layout = arg_layout - - has_message = False - for i in range(len(arg_layout)): - arg_info = arg_layout[i] - - given = (len(args) >= i + 1) - if arg_info.required and not given: - raise Argument_exception("You must specify the " + arg_info.name) - - if not given: - self.append(None) - continue - - given_arg = args[i] - arg_type = arg_info.type - - if arg_type == Argument.STRING: - self.append(given_arg) - - elif arg_type == Argument.INTEGER: - try: - value = int(given_arg) - except ValueError: - raise Argument_exception("The %s has to be a round number" % arg_info.name) - self.append(value) - - elif arg_type == Argument.FLOAT: - try: - value = float(given_arg) - except ValueError: - raise Argument_exception("The %s has to be a number" % arg_info.name) - self.append(value) - - elif arg_type == Argument.PLAYER: - 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]) - - elif arg_type == Argument.OFFLINE_PLAYER: - try: - # Code to get the PY PLAYER by name. Possibly, uid(server.getOfflinePlayer(given_arg)) can be used? - pass - except KeyError: - raise Argument_exception("The %s has to be an existing player" % arg_info.name) - self.append(None) - - elif arg_type == Argument.MESSAGE: - self.append(" ".join(args[i:])) - has_message = True - else: - error("Argument type not found: %d" % arg_type) - raise Argument_exception("A weird thing has happened, please contact an administrator") - - if not has_message: - self.remainder = args[len(arg_layout):] - else: - self.remainder = None - - def has_flag(self, flag, check_all = False): - return (("-" + flag) in self.raw) if check_all else (("-" + flag) in self.remainder) - - def get_raw(self): - return self.raw - - def get_arg_layout(self): - return self.arg_layout - -#-------------------------------------------------------------------------------------- - -class Command_exception(Exception): - - def __init__(self, message): - self.message = message - -class Argument_exception(Exception): - - def __init__(self, message): - self.message = message - -#-------------------------------------------------------------------------------------- - -class Argument(): - - STRING = 0 - INTEGER = 1 - FLOAT = 2 - PLAYER = 3 - OFFLINE_PLAYER = 4 - MESSAGE = 5 - - def __init__(self, name, type, definition, required = True): - self.name = name - self.type = type - self.definition = definition - self.required = required - - def syntax(self): - syntax = self.name - if self.type == Argument.MESSAGE: - syntax += "..." - return (("<%s>" if self.required else "[%s]") % syntax) - -#-------------------------------------------------------------------------------------- - -class Validate(): - - @staticmethod - def is_true(expression, fail_message): - if not expression: - raise Command_exception(fail_message) - - @staticmethod - def not_none(obj, fail_message): - if obj == None: - raise Command_exception(fail_message) + return wrapped(sender = py_players[sender], command = command, label = label, args = args) + except: + print(print_traceback()) + return decorator \ No newline at end of file diff --git a/wrapper_player.py b/wrapper_player.py index db7f6cc..a889ede 100644 --- a/wrapper_player.py +++ b/wrapper_player.py @@ -6,9 +6,6 @@ from players_secret import * from datetime import datetime from com.ziclix.python.sql import zxJDBC -def get_py_player(player): - - class py_player: def __init__(self,player): self.player = player -- 2.45.2 From 1969584312c4dc2f9b22ce04f571e47a71ac880f Mon Sep 17 00:00:00 2001 From: Dico200 Date: Wed, 25 Nov 2015 15:49:52 +0100 Subject: [PATCH 120/217] Revert "Merge branch 'wrapper' of https://github.com/RedstonerServer/redstoner-utils into wrapper" This reverts commit 4d5861fd3648e969b6a5dc6b210a81eccda2636c, reversing changes made to 9d0e4c99ba84d4efb7828704ed5b0a8e7bdfc52d. --- helpers.py | 57 +++++++++++++++++++---------- loginsecurity.py | 4 +-- main.py | 81 +++++++++++++++++++++++++++++++++++++---- mysql_utils.py | 33 ----------------- mysqlhack.py | 10 +++--- thread_utils.py | 24 ------------- wrapper.py | 11 ------ wrapper_command.py | 11 ------ wrapper_event.py | 22 ------------ wrapper_player.py | 89 ---------------------------------------------- 10 files changed, 120 insertions(+), 222 deletions(-) delete mode 100644 mysql_utils.py delete mode 100644 thread_utils.py delete mode 100644 wrapper.py delete mode 100644 wrapper_command.py delete mode 100644 wrapper_event.py delete mode 100644 wrapper_player.py diff --git a/helpers.py b/helpers.py index f7e125e..79af3a0 100644 --- a/helpers.py +++ b/helpers.py @@ -1,30 +1,26 @@ #pylint: disable = F0401 - -import org.bukkit as bukkit -import org.bukkit.block as bblock -import org.bukkit.Location as Location -import org.bukkit.event.entity as entity -import org.bukkit.entity.Player as Player -import org.bukkit.command.ConsoleCommandSender -import org.bukkit.event.block.BlockBreakEvent as BlockBreakEvent -import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause as TeleportCause - from re import sub -from thread_utils import * -from player import py_players -from org.bukkit.entity import * -from player import get_py_player -from traceback import format_exc as trace from java.util.UUID import fromString as juuid from json import dumps as json_dumps, loads as json_loads +import org.bukkit as bukkit +import org.bukkit.Location as Location +import org.bukkit.entity.Player as Player +import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause as TeleportCause +import org.bukkit.event.block.BlockBreakEvent as BlockBreakEvent +import org.bukkit.block as bblock +import org.bukkit.event.entity as entity +import org.bukkit.command.ConsoleCommandSender +from org.bukkit.entity import * +from player import get_py_player +from player import py_players #Imports for async query -import threading -import mysqlhack - from secrets import * +import mysqlhack from com.ziclix.python.sql import zxJDBC +import threading +from traceback import format_exc as trace shared = {} # this dict can be used to share stuff across modules @@ -218,6 +214,31 @@ def known_player(player): """ return player.hasPlayedBefore() +""" +Runs a async query, calls target function with fetchall as an argument, it will be an empty list if there is nothing to fetch. +(So make sure your function takes that argument.) + +If you want your function to run sync in the case you are doing something spigot wouldn't like to be async use the bukkit scheduler. +Example can be found in loginsecurity.py + +""" +def async_query(mysql_database,query,query_args,target,*target_args,**target_kwargs): + + def async_query_t(mysql_database,query,query_args,target,target_args,target_kwargs): + db_conn = zxJDBC.connect(mysql_database, mysql_user, mysql_pass, "com.mysql.jdbc.Driver") + db_curs = db_conn.cursor() + db_curs.execute(query,query_args) + db_conn.commit() + fetchall = db_curs.fetchall() + db_curs.close() + db_conn.close() + target(fetchall,target_args,target_kwargs) + + t = threading.Thread(target=async_query_t,args=(mysql_database,query,query_args,target,target_args,target_kwargs)) + t.daemon = True + t.start() + + def open_json_file(filename, default = None): """ opens the given json file and returns an object or returns None on error diff --git a/loginsecurity.py b/loginsecurity.py index 89f9e47..edf51e9 100644 --- a/loginsecurity.py +++ b/loginsecurity.py @@ -8,7 +8,7 @@ import mysqlhack from com.ziclix.python.sql import zxJDBC from java.lang import Runnable -wait_time = 60 #seconds +wait_time = 30 #seconds admin_perm = "utils.loginsecurity.admin" min_pass_length = 8 blocked_events = ["block.BlockBreakEvent", "block.BlockPlaceEvent", "player.PlayerMoveEvent","player.AsyncPlayerChatEvent"] @@ -272,4 +272,4 @@ def pre_command_proccess(event): args = event.getMessage().split(" ") if not args[0].lower() == "/login": msg(player.player, "&4You need to login before you do that!") - event.setCancelled(True) + event.setCancelled(True) \ No newline at end of file diff --git a/main.py b/main.py index 3e1319d..7411d17 100644 --- a/main.py +++ b/main.py @@ -11,9 +11,8 @@ 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 * except: - print("[RedstonerUtils] ERROR: Failed to import Wrapper:") + print("[RedstonerUtils] ERROR: Failed to import helpers:") print(print_traceback()) @@ -25,17 +24,85 @@ def on_enable(): @hook.disable def on_disable(): - #shared["modules"]["reports"].stop_reporting() + shared["modules"]["reports"].stop_reporting() info("RedstonerUtils disabled!") info("Loading RedstonerUtils...") - - # Import all modules, in this order -shared["load_modules"] = ["test"] - +shared["load_modules"] = [ + # Collection of tiny utilities + "misc", + # Adds chat for staff using /ac + "adminchat", + # Adds /badge, allows to give players achievements + "badges", + # Adds a few block placement corrections/mods + "blockplacemods", + # Adds /calc, toggles automatic solving of Math expressions in chat + "calc", + # Adds aliasing of chat words + #"chatalias", + # Plugin to locate laggy chunks. /lc lists chunks with more than n entities + "lagchunks", + # Adds /report and /rp, Stores reports with time and location + "reports", + # Adds group-chat with /chatgroup and /cgt to toggle normal chat into group mode + "chatgroups", + # Adds /token, reads and writes from the database to generate pronouncable (and thus memorable) registration-tokens for the website + "webtoken", + # Adds /lol, broadcasts random funyy messages. A bit like the splash text in the menu + "saylol", + # Adds /signalstrength, lets you request a signal strength and an amount of items will be inserted into target container to meet that strength. + "signalstrength", + # Shows the owner of a skull when right-clicked + "skullclick", + # Adds /listen, highlights chat and plays a sound when your name was mentioned + "mentio", + # Adds /cycler, swaps the hotbar with inventory when player changes slot from right->left or left->right + "cycle", + # Adds /getmotd & /setmotd to update the motd on the fly (no reboot) + "motd", + # AnswerBot. Hides stupid questions from chat and tells the sender about /faq or the like + "abot", + # Adds '/forcefield', creates forcefield for players who want it. + "forcefield", + # Adds /damnspam, creates timeout for buttons/levers to mitigate button spam. + "damnspam", + # Adds /check, useful to lookup details about a player + "check", + # Adds /an, a command you can use to share thoughts/plans/news + "adminnotes", + # Adds busy status to players + "imbusy", + # Adds /imout, displays fake leave/join messages + "imout", + #adds snowbrawl minigame + "snowbrawl", + # Adds /tm [player] for a messages to be sent to this player via /msg + "pmtoggle", + # Replacement for LoginSecurity + "loginsecurity", + # Centralized Player class + "player", + # Servercontrol extension for telnet access to logs/AC + #"servercontrol", + # Script helper plugin + "scriptutils", + # Per-player notes + "tag", + # vanish toggle module - temporary fix + #"vanishfix", + # obisidian mining punishment plugin + "punishments", + # a simple replacement for the buggy essentials /vanish + "vanish", + # ip-tracking utility + "iptracker", + #server signs for everyone + "serversigns" +] shared["modules"] = {} for module in shared["load_modules"]: try: diff --git a/mysql_utils.py b/mysql_utils.py deleted file mode 100644 index e59c3d9..0000000 --- a/mysql_utils.py +++ /dev/null @@ -1,33 +0,0 @@ -import mysqlhack -from secrets import * -from thread_utils import * -from com.ziclix.python.sql import zxJDBC -from traceback import format_exc as trace - -class mysql_connect: - def __init__(self): - self.conn = zxJDBC.connect(mysql_database, mysql_user, mysql_pass, "com.mysql.jdbc.Driver") - self.curs = self.conn.cursor() - - def execute(self, query, args=None): - if args is None: - return self.curs.execute(query) - else: - return self.curs.execute(query, args) - - def fetchall(self): - return self.curs.fetchall() - - def __enter__(self): - return self - - def __exit__(self, exc_type, exc_inst, exc_tb): - if exc_type is None: - try: - self.conn.commit() - self.curs.close() - self.conn.close() - except: - print(trace()) - else: - print(exc_tb) diff --git a/mysqlhack.py b/mysqlhack.py index 5d45c52..7153bdf 100644 --- a/mysqlhack.py +++ b/mysqlhack.py @@ -4,12 +4,12 @@ A library that makes use of the so called ClassPathHack for jython to allow proper loading of mysql-connector.jar at runtime. Import only, no methods. """ -import jarray -import java.net.URL -import java.io.File -from java.lang import Class -import java.net.URLClassLoader import java.lang.reflect.Method +import java.io.File +import java.net.URL +import java.net.URLClassLoader +import jarray +from java.lang import Class # hacky code to add mysql-connector to java's classpath ('classPathHack') diff --git a/thread_utils.py b/thread_utils.py deleted file mode 100644 index ec13c6f..0000000 --- a/thread_utils.py +++ /dev/null @@ -1,24 +0,0 @@ -import threading -""" -Quick implementation of a @synchronized and @asynchronized decorators -""" - -#To be replaced by bukkit scheduler. -""" -def sync(lock=None): - def decorator(wrapped): - def wrapper(*args, **kwargs): - with lock: - return wrapped(*args, **kwargs) - return wrapper - return decorator -""" - -def async(daemon = True): - def decorator(function): - def wrapper(*args,**kwargs): - thread = threading.Thread(target=function,args=args,kwargs=kwargs) - thread.daemon = daemon - thread.start() - return wrapper - return decorator \ No newline at end of file diff --git a/wrapper.py b/wrapper.py deleted file mode 100644 index ddca5b5..0000000 --- a/wrapper.py +++ /dev/null @@ -1,11 +0,0 @@ -""" -Adapter classes for spigot api for more idiomatic python code. - -Before you run away from this if the class you need to use isn't here, please create it. - - -""" -from helpers import * -from wrapper_event import * -from wrapper_player import * -from wrapper_command import * \ No newline at end of file diff --git a/wrapper_command.py b/wrapper_command.py deleted file mode 100644 index dd51534..0000000 --- a/wrapper_command.py +++ /dev/null @@ -1,11 +0,0 @@ -from wrapper_player import * - -def command(command = "help"): - def decorator(wrapped): - @hook.command(command) - def wrapper(sender, command, label, args): - try: - return wrapped(sender = py_players[sender], command = command, label = label, args = args) - except: - print(print_traceback()) - return decorator \ No newline at end of file diff --git a/wrapper_event.py b/wrapper_event.py deleted file mode 100644 index 083bf33..0000000 --- a/wrapper_event.py +++ /dev/null @@ -1,22 +0,0 @@ -from wrapper import * -from wrapper_player import * -from traceback import format_exc as print_traceback - -class py_event: - def __init__(self,event): - self.event = event - try: - self.player = py_players[event.getPlayer()] - except: - warn("Player doesn't exist") - -def event_handler(event_name = None, priority = "normal"): - def decorator(wrapped): - @hook.event(event_name, priority) - def wrapper(event): - try: - wrapped(py_event(event)) - except: - print(print_traceback()) - return decorator - diff --git a/wrapper_player.py b/wrapper_player.py deleted file mode 100644 index a889ede..0000000 --- a/wrapper_player.py +++ /dev/null @@ -1,89 +0,0 @@ -import time -import mysqlhack -from mysql_utils import * -from thread_utils import * -from players_secret import * -from datetime import datetime -from com.ziclix.python.sql import zxJDBC - -class py_player: - def __init__(self,player): - self.player = player - self.login_time = time.time() - self.logging_in = False - - self.nickname = self.name - self.registered = False - self.password = "None" - self.banned = False - self.banned_reason = "You have been banned!" - self.played_time = time.time() - self.login_time - self.last_login = datetime.now() - self.first_seen = datetime.now() - - def kick(self, kick_message = "You have been kicked from the server!"): - self.player.KickPlayer(kick_message) - - @property - def name(self): - return self.player.getName() - - @property - def uuid(self): - return str(self.player.getUniqueId()) - - -class Py_players: - def __init__(self): - self.players = [] - - def __len__(self): - return len(self.players) - - def __getitem__(self, player): - for py_player in self.players: - if py_player.name == player.getName(): - return py_player - else: - return None - - def remove(self, player): - self.players.remove(player) - - def append(self, player): - self.players.append(player) - -py_players = Py_players() - -@async(daemon=True) -def fetch_player(player): - with mysql_connect() as sql: - sql.execute("SELECT * FROM utils_players WHERE uuid = ?", (player.uuid,)) - result = sql.fetchall() - - if len(result) is 0: - with mysql_connect() as sql: - sql.execute("INSERT INTO utils_players \ - (uuid, name, nickname, registered, password, banned, \ - banned_reason, played_time, last_login, first_seen) \ - VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", - - args=(player.uuid, player.name, player.nickname, player.registered, - player.password, player.banned, - player.banned_reason, player.played_time, - player.last_login, player.first_seen)) - else: - pass - #test - - -@hook.event("player.PlayerJoinEvent","lowest") -def on_join(event): - player = py_player(event.getPlayer()) - py_players.append(player) - fetch_player(player) - - -@hook.event("player.PlayerQuitEvent","highest") -def on_leave(event): - py_players.remove(py_players[event.getPlayer()]) -- 2.45.2 From 2690da56663950a6391be53ee02cfc00a7bead99 Mon Sep 17 00:00:00 2001 From: Dico200 Date: Mon, 30 Nov 2015 02:19:07 +0100 Subject: [PATCH 121/217] This should keep players from interacting with comparators where they cannot build --- misc.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/misc.py b/misc.py index 09abcb8..236f6dd 100644 --- a/misc.py +++ b/misc.py @@ -114,6 +114,17 @@ def rs_material_broken_by_flow(material): length = len(parts) return length > 1 and (parts[0] == "DIODE" or parts[1] in ("TORCH", "WIRE", "BUTTON", "HOOK") or (length == 3 and parts[1] == "COMPARATOR")) + +@hook.event("player.PlayerInteractEvent") +def on_interact(event): + if (not event.isCancelled() + and str(event.getAction()) == "RIGHT_CLICK_BLOCK" + and str(event.getMaterial()) in ("REDSTONE_COMPARATOR_OFF", "REDSTONE_COMPARATOR_ON") + and not can_build(player, event.getClickedBlock()) + ): + event.setCancelled(True) + + sudo_blacklist = ["pyeval", "script_backup_begin", "script_backup_end", "script_backup_error", "script_backup_database_begin", "script_backup_database_dumps", "script_backup_database_end", "script_backup_database_error", "script_backup_database_abort", "script_trim", "script_trim_result", "script_spigot_update", "script_disk_filled", "script_restart", "script_restart_abort", "script_stop", "script_stop_abort", "script_shutdown", "stop", "esudo", "essentials:sudo"] -- 2.45.2 From 2c8bfff01f5c35976fb89ecdfed7085f7fa11744 Mon Sep 17 00:00:00 2001 From: Dico200 Date: Mon, 30 Nov 2015 02:31:28 +0100 Subject: [PATCH 122/217] Add sudo_blacklist to blocked_cmds in serversigns --- misc.py | 2 +- serversigns.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/misc.py b/misc.py index 236f6dd..0fd4a6a 100644 --- a/misc.py +++ b/misc.py @@ -127,7 +127,7 @@ def on_interact(event): sudo_blacklist = ["pyeval", "script_backup_begin", "script_backup_end", "script_backup_error", "script_backup_database_begin", "script_backup_database_dumps", "script_backup_database_end", "script_backup_database_error", "script_backup_database_abort", "script_trim", "script_trim_result", "script_spigot_update", "script_disk_filled", "script_restart", "script_restart_abort", -"script_stop", "script_stop_abort", "script_shutdown", "stop", "esudo", "essentials:sudo"] +"script_stop", "script_stop_abort", "script_shutdown", "stop", "esudo", "essentials:sudo", "sudo"] @simplecommand("sudo", usage = " [cmd..]", diff --git a/serversigns.py b/serversigns.py index 297b727..d9f2a44 100644 --- a/serversigns.py +++ b/serversigns.py @@ -5,7 +5,7 @@ import java.util.UUID as UUID import org.bukkit.Material as Material import org.bukkit.block.BlockFace as BlockFace -blocked_cmds = ("pex", "kick", "ban", "tempban", "pyeval", "sudo", "stop", "reload", "op", "deop", "whitelist") +blocked_cmds = tuple(shared["modules"]["misc"].sudo_blacklist) + ("pex", "kick", "ban", "tempban", "reload", "op", "deop", "whitelist") def load_signs(): signs_obj = open_json_file("serversigns", []) -- 2.45.2 From 528269afd6a8b772f374c1980e9a54f052c7c791 Mon Sep 17 00:00:00 2001 From: Dico200 Date: Wed, 9 Dec 2015 22:33:48 +0100 Subject: [PATCH 123/217] Added comment with permission nodes to blockplacemods --- blockplacemods.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/blockplacemods.py b/blockplacemods.py index 85e71c5..fd7071e 100644 --- a/blockplacemods.py +++ b/blockplacemods.py @@ -11,6 +11,17 @@ import org.bukkit.event.block.Action as Action import org.bukkit.block.BlockFace as BlockFace import org.bukkit.scheduler.BukkitRunnable as Runnable +""" + # Permissions: + # - utils.toggle: for use of the command + # - utils.toggle.cauldron + # - utils.toggle.slab + # - utils.toggle.furnace + # - utils.toggle.piston + # - utils.toggle.dropper + # - utils.toggle.hopper +""" + settingInformation = dict( #[setting type, identifying description, detailed description, aliases, (optional) max slot id], setting types: 0 = toggle, default on. 1 = Set your setting to held itemstack, 2 = toggle, default off cauldron = [0, "easy cauldron water level control", -- 2.45.2 From fa81ace66eea366d66971c23c612b271a0e1c3a9 Mon Sep 17 00:00:00 2001 From: psrcek Date: Sat, 26 Dec 2015 23:57:34 +0100 Subject: [PATCH 124/217] Fixed capitalization --- setup.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.sh b/setup.sh index 74cc599..e542e09 100755 --- a/setup.sh +++ b/setup.sh @@ -25,7 +25,7 @@ mkdir -v "build" cd "build" echo -e "\n> Downloading Spigot build tools" -curl --progress-bar -Lo "buildtools.jar" "https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar" +curl --progress-bar -Lo "BuildTools.jar" "https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar" echo -e "\n> Building Spigot, this will take a while ..." java -jar BuildTools.jar > /dev/null -- 2.45.2 From 883b02acd55da8b2c5c5f3d4528be36c8ecc3fd0 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Sat, 9 Jan 2016 16:40:57 +0100 Subject: [PATCH 125/217] Initial commit of chatalias.py v2 --- chatalias.py | 421 ++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 302 insertions(+), 119 deletions(-) diff --git a/chatalias.py b/chatalias.py index 25e3336..a73decb 100644 --- a/chatalias.py +++ b/chatalias.py @@ -1,138 +1,321 @@ -# 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. The JSON file for this -# plugin is generated if not -# present. Set values to -1 -# for "unlimited" setting. +############################################ +# Alias v2.0 by Pepich # +# Changes to previous version from curs3d: # +# Dynamic alias limit from permissions # +# AC/CG/MSG support # +# Color support # +# Bugfixes # +# # +# TODO: # +# Add command support... # +############################################ +import os +import org.bukkit as bukkit +from org.bukkit import * from helpers import * -import re from traceback import format_exc as trace +from secrets import * -data = None +# Version number and requirements -max_entries = 10 -max_alias_length = 35 -# Minecraft message limit is 100 so I decided to give a little tolerance (and I added a bit more) -max_overall_length = 100 + max_alias_length +alias_version = "2.0.0" +helpers_versions = ["1.1.0", "2.0.0"] +enabled = False +error = colorify("&cUnspecified error") +commands_per_page = 5 +global_aliases = {"./":"/"} +data = {} +use_mysql = False -alias_perm = "utils.alias.allowed" -exceed_length = "utils.alias.exceedlimit" -exceed_entries = "utils.alias.exceedlimit" -exceed_overall_length = "utils.alias.exceedlimit" +# Permissions: + +# Grants full access immediately +permission_ALL = "utils.alias.*" +# Access to the command to display the help screen +permission_BASE = "utils.alias" +# Make replacements only when the user has this permission +permission_USE = "utils.alias.use" +# Modify aliases +permission_MODIFY = "utils.alias.modify" +permission_MODIFY_OTHERS = "utils.alias.modify.others" +# List aliases +permission_LIST = "utils.alias.list" +permission_LIST_OTHERS = "utils.alias.list.others" +# Set alias amounts/length limits, e.g. utils.alias.amount.420 +permission_AMOUNT = "utils.alias.amount." +permission_LENGTH = "utils.alias.length." +# See when the plugin was disabled due to version errors +permission_INFO = "utils.alias.info" +permission_FINFO = "utils.alias.finfo" + +######## +# CODE # +######## + +enabled = helpers_version in helpers_versions +if not enabled: + error = colorify("&6Incompatible versions detected (&chelpers.py&6)") -def safe_open_json(): - global data - if data is not None: - return data - data = open_json_file("aliases") - if data is None: - data = {} - save_json_file("aliases", data) - return data - -def multiple_replace(aliases, text): - regex = re.compile("|".join(map(re.escape, aliases.keys()))) - return regex.sub(lambda mo: aliases[mo.group(0)], text) +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") + value = open_json_file("aliases/" + uuid) + if value is None: + value = global_aliases + save_json_file("aliases/" + uuid, value) + return value @hook.command("alias", - usage="/ [to_alias] [alias...]", - desc="Aliases words in chat") + usage="/ [...]", + desc="Allows aliasing of words") def on_alias_command(sender, cmd, label, args): + try: + args = array_to_list(args) + if not enabled: + disabled_fallback(sender) + return True + if not hasPerm(sender, permission_BASE): + plugin_header(recipient=sender, name="Alias") + noperm(sender) + return True + return subcommands[args[0].lower()](sender, args[1:]) + except: + print(trace()) + return subcommands["help"](sender, "1") - if not is_player(sender): - msg(sender, "Sorry, non-players cannot alias words") - return True - if not sender.hasPermission(alias_perm): - plugin_header(recipient=sender, name="Chat Alias") - noperm(sender) - return True - if len(args) == 0: - plugin_header(recipient=sender, name="Chat Alias") - msg(sender, "&7This is a plugin that allows you to get words" + - "replaced by other ones automatically!") - msg(sender, "&7\nCommands:") - msg(sender, "&e/alias &7removes from your aliases. " + - "Use &e/alias * &7to remove all aliases.") - msg(sender, "&e/alias &7will change &e " + - "&7to &e &7in chat") - msg(sender, "&7\nYour Aliases:") - data = safe_open_json() - try: - for alias, value in data[str(sender.getUniqueId())].items(): - msg(sender, "&7%s &7==> %s" % (alias, value)) - except KeyError: - pass - return True - elif len(args) == 1: - data = safe_open_json() - if args[0] == "*": - try: - del data[str(sender.getUniqueId())] - except KeyError: - plugin_header(recipient=sender, name="Chat Alias") - msg(sender, "&7No alias data to remove!") - return True - save_json_file("aliases", data) - plugin_header(recipient=sender, name="Chat Alias") - msg(sender, "&cALL &7alias data successfuly removed!") - return True - try: - if data[str(sender.getUniqueId())].pop(args[0], None) is None: - plugin_header(recipient=sender, name="Chat Alias") - msg(sender, "&7Could not remove: alias not present!") - return True - except KeyError: - plugin_header(recipient=sender, name="Chat Alias") - msg(sender, "&7Could not remove: you do not have any aliases!") - return True - save_json_file("aliases", data) - plugin_header(recipient=sender, name="Chat Alias") - msg(sender, "&7Alias for %s &7successfuly removed" % args[0]) - return True - elif len(args) >= 2: - data = safe_open_json() - alias = " ".join(args[1:]) - try: - if (len(alias) > max_alias_length) and (max_alias_length >= 0) and (not sender.hasPermission(exceed_length)): - plugin_header(recipient=sender, name="Chat Alias") - msg(sender, "&7Please do not alias long words/sentences.") - return True - if (len(data[str(sender.getUniqueId())]) >= max_entries) and (max_entries >= 0) and (not sender.hasPermission(exceed_entries)): - plugin_header(recipient=sender, name="Chat Alias") - msg(sender, "&7You have reached your alias limit!") - 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, "&7Chat Alias %s &7==> %s &7successfully created!" % (args[0], alias)) - return True - else: - return False + +def help(sender, args): + commands = [colorify("&e/alias help [page]")] + if hasPerm(sender, permission_LIST): + commands += [colorify("&e/alias list &7- Lists all your aliases")] + if hasPerm(sender, permission_MODIFY): + commands += [colorify("&e/alias add &7- Add an alias")] + commands += [colorify("&e/alias remove &7- Remove an alias")] + if can_remote(sender): + while len(commands) < commands_per_page: + commands += [""] + commands += [colorify("&7Following commands will be executed on yet all output will be redirected to you, except when you set silent to false, then will see it too.")] + if hasPerm(sender, permission_LIST_OTHERS): + commands += [colorify("&e/alias player list [silent]")] + if hasPerm(sender, permission_MODIFY_OTHERS): + commands += [colorify("&e/alias player add [silent]")] + commands += [colorify("&e/alias player remove [silent]")] + pages = (len(commands)-1)/commands_per_page + 1 + page = 1 + if len(args) != 0: + page = int(args[0]) + if (page > pages): + page = pages + if page < 1: + page = 1 + msg(sender, colorify("&e---- &6Help &e-- &6Page &c" + str(page) + "&6/&c" + str(pages) + " &e----")) + page -= 1 + to_display = commands[5*page:5*page+5] + 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))) + return True + + +@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: + print(trace()) @hook.event("player.AsyncPlayerChatEvent", "high") def on_player_chat(event): - playerid = str(event.getPlayer().getUniqueId()) - data = safe_open_json() - if event.isCancelled(): - return - if not playerid in data: - return + try: + if enabled: + if event.isCancelled(): + return + if not hasPerm(event.getPlayer(), permission_USE): + return + for alias, value in data[str(uid(event.getPlayer()))].items(): + if not event.getPlayer().hasPermission(permission_ALL) and len(event.getMessage()) > int(get_permission_content(event.getPlayer(), permission_LENGTH)): + event.setCanceled(True) + plugin_header(event.getPlayer, "Alias") + msg(event.getPlayer(), "The message you wanted to generate would exceed your limit. Please make it shorter!") + return + if event.getPlayer().hasPermission("essentials.chat.color"): + event.setMessage(event.getMessage().replace(colorify(alias), colorify(value))) + else: + event.setMessage(event.getMessage().replace(alias, value)) + except: + print(trace()) - event.setMessage(multiple_replace(data[playerid], event.getMessage())) +def hasPerm(player, permission): + return (player.hasPermission(permission)) or (player.hasPermission(permission_ALL)) - if (event.getPlayer().hasPermission("essentials.chat.color")): - event.setMessage(colorify(event.getMessage())) - if (max_overall_length >= 0) and (len(event.getMessage()) > max_overall_length) and (not event.getPlayer().hasPermission(exceed_overall_length)): - event.setCancelled(True) - plugin_header(recipient=event.getPlayer(), name="Chat Alias") - msg(event.getPlayer(), "&7The message generated was too long and was not sent. :/") + +def disabled_fallback(receiver): + if not hasPerm(receiver, permission_INFO): + msg(receiver, colorify("&cUnknown command. Use &e/help&c, &e/plugins &cor ask a mod.")) + else: + msg(receiver, colorify("&cPlugin alias v" + alias_version + " has experienced an &eEMERGENCY SHUTDOWN:")) + msg(receiver, error) + msg(receiver, colorify("&cPlease contact a dev/admin (especially pep :P) about this to take a look at it.")) + + +def can_remote(player): + return hasPerm(player, permission_LIST_OTHERS) or hasPerm(player, permission_MODIFY_OTHERS) + + +def add(sender, args): + plugin_header(sender, "Alias") + if not sender.hasPermission(permission_ALL) and len(data[uid(sender)]) >= int(get_permission_content(sender, permission_AMOUNT)): + 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)) + msg(sender, colorify("&7Alias: ") + args[0] + colorify("&7 -> " + args[1] + colorify("&7 was succesfully created!")), usecolor=sender.hasPermission("essentials.chat.color")) + return True + + +def radd(sender, args): + args = [args[0:1]] + [" ".join([args[2:len(args)-2]])] + [args[len(args)-1]] + plugin_header(sender, "Alias") + if args[3].lower() == "false": + plugin_header(target, "Alias") + msg(target, "&cPlayer " + sender_name + " &cis creating an alias for you!") + 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": + 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]) + save_data(uid(target)) + 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 remove(sender, args): + plugin_header(sender, "Alias") + try: + msg(sender, colorify("&7Successfully removed alias ") + args[0] + colorify(" &7-> ") + data[uid(sender)].pop(args[0]) + colorify("&7!"), usecolor=sender.hasPermission("essentials.chat.color")) + save_data(uid(sender)) + except: + msg(sender, colorify("&cCould not remove alias ") + args[0] + colorify(", it does not exist."), usecolor=sender.hasPermission("essentials.chat.color")) + return True + + +def rremove(sender, args): + plugin_header(sender, "Alias") + target = get_player(args[0]) + if is_player(sender): + 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: + alias = data[uid(target)].pop(args[1]) + msg(sender, colorify("&7Successfully removed alias ") + args[1] + colorify(" &7-> ") + alias + colorify("&7!"), usecolor=sender.hasPermission("essentials.chat.color")) + if args[2].lower() == "false": + msg(target, colorify("&7Successfully removed alias ") + args[1] + colorify(" &7-> ") + alias + colorify("&7!"), usecolor=sender.hasPermission("essentials.chat.color")) + save_data(uid(target)) + except: + msg(sender, colorify("&cCould not remove alias ") + args[1] + colorify(", it does not exist."), usecolor=sender.hasPermission("essentials.chat.color")) + if args[2].lower() == "false": + msg(target, colorify("&cCould not remove alias ") + args[1] + colorify(", it does not exist."), usecolor=sender.hasPermission("essentials.chat.color")) + return True + + +def list_alias(sender, args): + plugin_header(sender, "Alias") + msg(sender, "&7You have a total of " + str(len(data[uid(sender)])) + " aliases:") + for word, alias in data[str(uid(sender))].items(): + msg(sender, colorify("&7") + word + colorify("&7 -> ") + alias, usecolor=sender.hasPermission("essentials.chat.color")) + return True + + +def rlist_alias(sender, args): + plugin_header(sender, "Alias") + target = get_player(args[0]) + if is_player(sender): + sender_name = colorify(sender.getDisplayName) + else: + sender_name = colorify("&6Console") + if len(args) == 1: + args += ["true"] + 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):") + 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 + + +def remote(sender, args): + try: + return remotes[args[1].lower()](sender, [args[0]] + [args[2:]]) + except: + print(trace()) + return subcommands["help"](sender, ["2"]) + + +def load_data(uuid): + if use_mysql: + conn = zxJDBC.connect(mysql_database, mysql_user, mysql_pass, "com.mysql.jdbc.Driver") + curs = conn.cursor() + curs.execute("SELECT alias FROM alias WHERE uuid = ?", (uuid, )) + results = curs.fetchall() + if len(results) == 0: + results = global_aliases + curs.execute("INSERT INTO alias VALUES (?,?)", (uuid, results, )) + data[uuid] = results + else: + data[uuid] = safe_open_json(uuid) + + +def save_data(uuid): + if use_mysql: + conn = zxJDBC.connect(mysql_database, mysql_user, mysql_pass, "com.mysql.jdbc.Driver") + curs = conn.cursor() + curs.execute("UPDATE alias SET alias = ? WHERE uuid = ?", (data[uuid], uuid, )) + else: + save_json_file("aliases/" + uuid, data[uuid]) + +# Subcommands: + +subcommands = { + "help": help, + "add": add, + "remove": remove, + "player": remote, + "list": list_alias +} + +remotes = { + "add": radd, + "remove": rremove, + "list": rlist_alias, +} -- 2.45.2 From cbc77de8262204b64bb3695a78acafb76c8ca47f Mon Sep 17 00:00:00 2001 From: BuildTools Date: Sat, 9 Jan 2016 16:42:26 +0100 Subject: [PATCH 126/217] Helpers v2.0.0, added versioning, added array_to_list and get_permission_content, renamed isIP to is_ip --- helpers.py | 41 ++++++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 13 deletions(-) mode change 100644 => 100755 helpers.py diff --git a/helpers.py b/helpers.py old mode 100644 new mode 100755 index 79af3a0..8485b2a --- a/helpers.py +++ b/helpers.py @@ -22,7 +22,7 @@ import threading from traceback import format_exc as trace - +helpers_version = "2.0.0" shared = {} # this dict can be used to share stuff across modules server = bukkit.Bukkit.getServer() @@ -87,7 +87,7 @@ def colorify(text): """ replace &-codes with real color codes """ - return sub("&" + u"\u00A7", "&", "%s" % sub("&(?=[?\\da-fk-or])", u"\u00A7", "%s" % text)) + return sub("&(?=[?\\da-fk-or])", u"\u00A7", "%s" % text) def stripcolors(text): @@ -181,16 +181,6 @@ def is_creative(player): return str(player.getGameMode()) == "CREATIVE" -def is_rank(player, rank): - """ - rank: a string equal to the PEX group name found in /pex groups - returns True if one of the following conditions are met: - - the player is of the given rank, - - their rank inherits the given rank. - """ - return player.hasPermission("groups." + rank) - - def uid(player): """ returns the player's UUID @@ -281,7 +271,8 @@ def send_JSON_message(playername, message): bukkit.Bukkit.getServer().dispatchCommand(bukkit.Bukkit.getServer().getConsoleSender(), "tellraw " + playername + " " + message) -def isIP(tocheck): +# Allows to check if a String is a valid IPv4 or not. Accepts any string, returns true if the String is a valid IPv4 +def is_ip(tocheck): subsets = ["","","",""] i = 0 for j in range(0,len(tocheck)): @@ -299,3 +290,27 @@ def isIP(tocheck): if not ((int(subsets[j]) >= 0) & (int(subsets[j]) <= 255)): return False return True + + +# Allows the use of e.g. numeric permission nodes like "permission.amount.5" and similar. +# To get the data fetch the player and the start of the permission node, looking like "permission.amount." +def get_permission_content(player, permnode): + perms = player.getEffectivePermissions() + for perm in perms: + if str(perm.getPermission()).startswith(permnode): + return str(perm.getPermission()).replace(permnode, "") + + +# Gets an online player from their name +def get_player(name): + for p in bukkit.Bukkit.getServer().getOnlinePlayers(): + if p.getName().lower() == name.lower(): + return p + return None + + +def array_to_list(array): + return_list = [] + for a in array: + return_list += [a] + return return_list -- 2.45.2 From 3a2d1193ca90697bcff0fd977f76cb03adcc3182 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Sat, 9 Jan 2016 16:43:19 +0100 Subject: [PATCH 127/217] iptracker v1.1.0 updating to helpers v2.0.0 functions; fixing bugs in data management and command execution --- iptracker.py | 215 ++++++++++++++++++++++++++------------------------- 1 file changed, 108 insertions(+), 107 deletions(-) mode change 100644 => 100755 iptracker.py diff --git a/iptracker.py b/iptracker.py old mode 100644 new mode 100755 index 8bbd053..969a822 --- a/iptracker.py +++ b/iptracker.py @@ -1,107 +1,108 @@ -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 -from iptracker_secrets import * - - -iptrack_permission = "utils.iptrack" - - -@hook.event("player.PlayerJoinEvent", "low") -def on_player_join(event): - t = threading.Thread(target=on_player_join_thread, args=(event, )) - t.daemon = True - t.start() - -def on_player_join_thread(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 uuid2ips WHERE uuid = ?", (uuid, )) - results = curs.fetchall() - if len(results) == 0: - ips = [] - else: - ips = json.loads(results[0][0]) - curs.execute("SELECT uuids FROM ip2uuids 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 uuid2ips VALUES (?,?)", (uuid, json.dumps(ips), )) - else: - curs.execute("UPDATE uuid2ips SET ips = ? WHERE uuid = ?", (uuid, json.dumps(ips), )) - if uuid not in uuids: - uuids.append(uuid) - if new_uuid_entry: - curs.execute("INSERT INTO ip2uuids VALUES (?,?)", (ip, json.dumps(uuids), )) - else: - curs.execute("UPDATE ip2uuids SET uuids = ? WHERE uuid = ?", (ip, json.dumps(uuids), )) - conn.commit() - curs.close() - conn.close() - - -@hook.command("getinfo") -def on_getinfo_command(sender, args): - t = threading.Thread(target=on_player_join_thread, args=(sender, args)) - t.daemon = True - t.start() - -def on_getinfo_command_thread(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 ip2uuids 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 uuid2ips 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 +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 +from iptracker_secrets import * + + +iptrack_permission = "utils.iptrack" +iptrack_version = "1.1.0" + + +@hook.event("player.PlayerJoinEvent", "low") +def on_player_join(event): + t = threading.Thread(target=on_player_join_thread, args=(event, )) + t.daemon = True + t.start() + +def on_player_join_thread(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 uuid2ips WHERE uuid = ?", (uuid, )) + results = curs.fetchall() + if len(results) == 0: + ips = [] + else: + ips = json.loads(results[0][0]) + curs.execute("SELECT uuids FROM ip2uuids 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 uuid2ips VALUES (?,?)", (uuid, json.dumps(ips), )) + else: + curs.execute("UPDATE uuid2ips SET ips = ? WHERE uuid = ?", (json.dumps(ips), uuid, )) + if uuid not in uuids: + uuids.append(uuid) + if new_uuid_entry: + curs.execute("INSERT INTO ip2uuids VALUES (?,?)", (ip, json.dumps(uuids), )) + else: + curs.execute("UPDATE ip2uuids SET uuids = ? WHERE ip = ?", (json.dumps(uuids), ip, )) + conn.commit() + curs.close() + conn.close() + + +@hook.command("getinfo") +def on_getinfo_command(sender, args): + t = threading.Thread(target=on_getinfo_command_thread, args=(sender, args)) + t.daemon = True + t.start() + +def on_getinfo_command_thread(sender, args): + if(sender.hasPermission(iptrack_permission)): + if not checkargs(sender, args, 1, 1): + return False + else: + if is_ip(args[0]): + conn = zxJDBC.connect(mysql_database, mysql_user, mysql_pass, "com.mysql.jdbc.Driver") + curs = conn.cursor() + curs.execute("SELECT uuids FROM ip2uuids 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 uuid2ips 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 -- 2.45.2 From 799584df46a0c53484a3b8cab11efdd4d67d319a Mon Sep 17 00:00:00 2001 From: PixelSergey Date: Sun, 7 Feb 2016 13:15:51 +0200 Subject: [PATCH 128/217] Unbusies on logout --- imbusy.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/imbusy.py b/imbusy.py index 64fa30b..37a964e 100644 --- a/imbusy.py +++ b/imbusy.py @@ -105,3 +105,10 @@ def on_cmd_preprocess_event(event): plugin_header(recipient = event.getPlayer(), name = "I'M BUSY!") msg(event.getPlayer(), "We are sorry, but %s is currently busy. Please try again later." % message[1]) event.setCancelled(True) + +@hook.event("player.PlayerQuitEvent", "lowest") +def on_player_leave(event): + try: + busy_players.remove(event.getPlayer().getName()) + except: + pass -- 2.45.2 From f03f34777b1d0ddc95c2ddb17e6eddfd832a8332 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Sun, 14 Feb 2016 22:24:11 +0100 Subject: [PATCH 129/217] Added tabnames module, disabled iptracker due to instability --- main.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/main.py b/main.py index 7411d17..2d6f253 100644 --- a/main.py +++ b/main.py @@ -98,10 +98,12 @@ shared["load_modules"] = [ "punishments", # a simple replacement for the buggy essentials /vanish "vanish", - # ip-tracking utility - "iptracker", + # ip-tracking utility - disabled as of instability + #"iptracker", #server signs for everyone - "serversigns" + "serversigns", + # tabnames module to make players names colored on their chars and sort tab after ranks + "tabnames" ] shared["modules"] = {} for module in shared["load_modules"]: -- 2.45.2 From 70f2001e7b24bf35202d5d255c3a3f7398c708af Mon Sep 17 00:00:00 2001 From: BuildTools Date: Sun, 14 Feb 2016 22:25:02 +0100 Subject: [PATCH 130/217] initial commit, adding the tabnames module --- tabnames.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100755 tabnames.py diff --git a/tabnames.py b/tabnames.py new file mode 100755 index 0000000..049098c --- /dev/null +++ b/tabnames.py @@ -0,0 +1,35 @@ +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 +from iptracker_secrets import * + +tabnames_version = "v1.0.0" + +############################################################## +# # +# This module automatically puts people in the corresponding # +# scoreboard team so that their name is colored properly and # +# tab will be nicely sorted. # +# # +############################################################## + +ranks = ["visitor", "member", "builder", "trusted", "modintraining", "mod", "admin", "breaker"] +prefixes = {"admin":"a", "mod":"b", "modintraining":"c", "trusted":"d", "builder":"e", "member":"f","visitor":"g"} + +@hook.event("player.PlayerJoinEvent", "low") +def on_player_join(event): + scoreboard_team = prefix(get_Rank(event.getPlayer())) + bukkit.Bukkit.getServer().dispatchCommand(bukkit.Bukkit.getServer().getConsoleSender(), "scoreboard teams join " + scoreboard_team + " " + event.getPlayer().getName()) + +def get_Rank(player): + for i in range(0, len(ranks) - 1): + if not player.hasPermission("group." + ranks[i]): + break + return ranks[i-1] + +def prefix(rank): + return prefixes.get(rank) + "_" + rank -- 2.45.2 From 91afa684cd09cd4638ee74733a5cb60b2e4a247f Mon Sep 17 00:00:00 2001 From: BuildTools Date: Sun, 14 Feb 2016 22:33:44 +0100 Subject: [PATCH 131/217] removed unnessecary imports, code cleanup --- tabnames.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/tabnames.py b/tabnames.py index 049098c..c0848c0 100755 --- a/tabnames.py +++ b/tabnames.py @@ -1,11 +1,6 @@ -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 -from iptracker_secrets import * tabnames_version = "v1.0.0" @@ -23,7 +18,8 @@ prefixes = {"admin":"a", "mod":"b", "modintraining":"c", "trusted":"d", "builder @hook.event("player.PlayerJoinEvent", "low") def on_player_join(event): scoreboard_team = prefix(get_Rank(event.getPlayer())) - bukkit.Bukkit.getServer().dispatchCommand(bukkit.Bukkit.getServer().getConsoleSender(), "scoreboard teams join " + scoreboard_team + " " + event.getPlayer().getName()) + bukkit.Bukkit.getServer().dispatchCommand(bukkit.Bukkit.getServer().getConsoleSender(), + "scoreboard teams join " + scoreboard_team + " " + event.getPlayer().getName()) def get_Rank(player): for i in range(0, len(ranks) - 1): -- 2.45.2 From 5a0477fdbfaa222350c62ce948d8371c34bd538f Mon Sep 17 00:00:00 2001 From: jomo Date: Sun, 14 Feb 2016 23:52:50 +0100 Subject: [PATCH 132/217] clean up tabnames doesn't throw exceptions when group can't be found, will print warning instead --- tabnames.py | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/tabnames.py b/tabnames.py index c0848c0..65e1a2c 100755 --- a/tabnames.py +++ b/tabnames.py @@ -1,6 +1,4 @@ -import org.bukkit as bukkit from helpers import * -from org.bukkit import * tabnames_version = "v1.0.0" @@ -12,20 +10,29 @@ tabnames_version = "v1.0.0" # # ############################################################## -ranks = ["visitor", "member", "builder", "trusted", "modintraining", "mod", "admin", "breaker"] +ranks = ["visitor", "member", "builder", "trusted", "modintraining", "mod", "admin"] prefixes = {"admin":"a", "mod":"b", "modintraining":"c", "trusted":"d", "builder":"e", "member":"f","visitor":"g"} @hook.event("player.PlayerJoinEvent", "low") def on_player_join(event): - scoreboard_team = prefix(get_Rank(event.getPlayer())) - bukkit.Bukkit.getServer().dispatchCommand(bukkit.Bukkit.getServer().getConsoleSender(), - "scoreboard teams join " + scoreboard_team + " " + event.getPlayer().getName()) + player = event.getPlayer() + team = get_team(player) + if team: + cmd = "scoreboard teams join %s %s" % (team, player.getName()) + server.dispatchCommand(server.getConsoleSender(), cmd) -def get_Rank(player): - for i in range(0, len(ranks) - 1): - if not player.hasPermission("group." + ranks[i]): +def get_rank(player): + player_rank = None + for rank in ranks: + if not player.hasPermission("group.%s" % rank): break - return ranks[i-1] + player_rank = rank + if not player_rank: + warn("Couldn't find rank for player %s" % player.getName()) + return player_rank -def prefix(rank): - return prefixes.get(rank) + "_" + rank +def get_team(player): + rank = get_rank(player) + if rank: + prefix = prefixes.get(rank) + return "_".join([prefix, rank]) \ No newline at end of file -- 2.45.2 From 6a4d1447ece65d7cfcfba6b9596f60003e436490 Mon Sep 17 00:00:00 2001 From: jomo Date: Mon, 15 Feb 2016 01:27:13 +0100 Subject: [PATCH 133/217] rename tabnames to nametags I think it's a more descriptive name --- main.py | 6 +++--- tabnames.py => nametags.py | 3 +-- 2 files changed, 4 insertions(+), 5 deletions(-) rename tabnames.py => nametags.py (94%) diff --git a/main.py b/main.py index 2d6f253..be3a65b 100644 --- a/main.py +++ b/main.py @@ -89,7 +89,7 @@ shared["load_modules"] = [ # Servercontrol extension for telnet access to logs/AC #"servercontrol", # Script helper plugin - "scriptutils", + "scriptutils", # Per-player notes "tag", # vanish toggle module - temporary fix @@ -102,8 +102,8 @@ shared["load_modules"] = [ #"iptracker", #server signs for everyone "serversigns", - # tabnames module to make players names colored on their chars and sort tab after ranks - "tabnames" + # Makes player's names colored, sorts tab list by rank + "nametags" ] shared["modules"] = {} for module in shared["load_modules"]: diff --git a/tabnames.py b/nametags.py similarity index 94% rename from tabnames.py rename to nametags.py index 65e1a2c..88c0696 100755 --- a/tabnames.py +++ b/nametags.py @@ -1,7 +1,5 @@ from helpers import * -tabnames_version = "v1.0.0" - ############################################################## # # # This module automatically puts people in the corresponding # @@ -11,6 +9,7 @@ tabnames_version = "v1.0.0" ############################################################## ranks = ["visitor", "member", "builder", "trusted", "modintraining", "mod", "admin"] +# prefixes are used for sorting in the tab list prefixes = {"admin":"a", "mod":"b", "modintraining":"c", "trusted":"d", "builder":"e", "member":"f","visitor":"g"} @hook.event("player.PlayerJoinEvent", "low") -- 2.45.2 From 34ed3a1023a757f4cdecb13d9e72bcbc188a269f Mon Sep 17 00:00:00 2001 From: BuildTools Date: Mon, 15 Feb 2016 16:50:21 +0100 Subject: [PATCH 134/217] Fixed naming error in rank trainingmod --- nametags.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nametags.py b/nametags.py index 88c0696..4d86bbe 100755 --- a/nametags.py +++ b/nametags.py @@ -8,9 +8,9 @@ from helpers import * # # ############################################################## -ranks = ["visitor", "member", "builder", "trusted", "modintraining", "mod", "admin"] +ranks = ["visitor", "member", "builder", "trusted", "trainingmod", "mod", "admin"] # prefixes are used for sorting in the tab list -prefixes = {"admin":"a", "mod":"b", "modintraining":"c", "trusted":"d", "builder":"e", "member":"f","visitor":"g"} +prefixes = {"admin":"a", "mod":"b", "trainingmod":"c", "trusted":"d", "builder":"e", "member":"f","visitor":"g"} @hook.event("player.PlayerJoinEvent", "low") def on_player_join(event): -- 2.45.2 From 9160c85d09248b031b5378d48d188148d8cb8c56 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Mon, 15 Feb 2016 17:32:50 +0100 Subject: [PATCH 135/217] Added automatic disabling of cgt when leaving a chatgroup --- chatgroups.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/chatgroups.py b/chatgroups.py index 9965b96..aed22cd 100644 --- a/chatgroups.py +++ b/chatgroups.py @@ -21,6 +21,8 @@ def on_chatgroup_command(sender, command, label, args): if len(args) == 1 and args[0] == "leave": if sender_id in groups.keys(): groupchat(sender, "left the group", True) + if sender in cg_toggle_list: + cg_toggle_list.remove(p) group = groups[sender_id] del(groups[sender_id]) save_groups() -- 2.45.2 From 412ed59225a864e9c59d36fa11ad670410a44fe2 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Mon, 15 Feb 2016 17:33:14 +0100 Subject: [PATCH 136/217] Added aliases and proper command description --- pmtoggle.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pmtoggle.py b/pmtoggle.py index e1bac06..1cdf17b 100644 --- a/pmtoggle.py +++ b/pmtoggle.py @@ -5,7 +5,11 @@ from java.util.UUID import fromString as juuid toggle_dict = {} permission = "utils.pmtoggle" -@hook.command("tm") +@hook.command("tm", + aliases = ["tmsg", "mt", "msgt"], + usage = "/ [player]", + description = "Toggle automatic sending of messages" + ) def on_toggle_message_command(sender, command, label, args): if not sender.hasPermission(permission) or not is_player(sender): noperm(sender) -- 2.45.2 From 0aad531f9ec75f3e133f7d6060a1d1b64e17b7dc Mon Sep 17 00:00:00 2001 From: BuildTools Date: Mon, 15 Feb 2016 17:38:19 +0100 Subject: [PATCH 137/217] Added more aliases --- pmtoggle.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pmtoggle.py b/pmtoggle.py index 1cdf17b..19caf9e 100644 --- a/pmtoggle.py +++ b/pmtoggle.py @@ -5,8 +5,8 @@ from java.util.UUID import fromString as juuid toggle_dict = {} permission = "utils.pmtoggle" -@hook.command("tm", - aliases = ["tmsg", "mt", "msgt"], +@hook.command("pmtoggle", + aliases = ["tm", "mt", "tmsg", "msgt", "pmt", "tpm"], usage = "/ [player]", description = "Toggle automatic sending of messages" ) -- 2.45.2 From 621f4ca23b1a1befacfb71c85255a19db0d260e1 Mon Sep 17 00:00:00 2001 From: PixelSergey Date: Tue, 8 Mar 2016 20:32:56 +0200 Subject: [PATCH 138/217] Added a debug decorator, use @debug to nicely print function errors --- helpers.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/helpers.py b/helpers.py index 8485b2a..4c32e24 100755 --- a/helpers.py +++ b/helpers.py @@ -314,3 +314,13 @@ def array_to_list(array): for a in array: return_list += [a] return return_list + + +#debug wrapper +def debug(func): + def wrap(*args, **kwargs): + try: + func(*args, **kwargs) + except: + print(trace()) + return wrap -- 2.45.2 From fad1ae0f90022aee9d336618dd2c0cc3b8ba95a2 Mon Sep 17 00:00:00 2001 From: Dico200 Date: Sat, 12 Mar 2016 01:00:07 +0100 Subject: [PATCH 139/217] Fixed a return message in blockplacemods.py --- blockplacemods.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/blockplacemods.py b/blockplacemods.py index fd7071e..b87c5ee 100644 --- a/blockplacemods.py +++ b/blockplacemods.py @@ -150,7 +150,8 @@ def toggle_command(sender, command, label, args): if arg2 == "clear": if enabled: del values[uuid] - return " &aDisabled " + details[1] + return " &aDisabled " + details[1] + return " &cAlready disabled: " + details[1] if arg2 == "details": return " &aSetting %s:\n &9%s \n&6Accepted arguments: [|clear|details]" % (setting, details[2]) -- 2.45.2 From 286f8751b5d3edcaa2e1f8c22b47f292887c979f Mon Sep 17 00:00:00 2001 From: Dico200 Date: Sat, 12 Mar 2016 01:02:48 +0100 Subject: [PATCH 140/217] Fix tab -.- lol why did it load locally? --- blockplacemods.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/blockplacemods.py b/blockplacemods.py index b87c5ee..8d18699 100644 --- a/blockplacemods.py +++ b/blockplacemods.py @@ -150,7 +150,7 @@ def toggle_command(sender, command, label, args): if arg2 == "clear": if enabled: del values[uuid] - return " &aDisabled " + details[1] + return " &aDisabled " + details[1] return " &cAlready disabled: " + details[1] if arg2 == "details": -- 2.45.2 From c870561f7db96d0ab010e99fdd22699a24e0630b Mon Sep 17 00:00:00 2001 From: psrcek Date: Sat, 26 Mar 2016 21:56:10 +0100 Subject: [PATCH 141/217] removed some unnecesary code The below if statement is always true and the value of timeout_on isn't used before a return statement. timeout_on = False if timeout_on == False: --- damnspam.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/damnspam.py b/damnspam.py index 6a4c2b3..af800af 100644 --- a/damnspam.py +++ b/damnspam.py @@ -47,8 +47,6 @@ def on_dammnspam_command(sender, command, label, args): timeout_on = round(float(timeout_on), 2) timeout_off = timeout_on if 60 >= timeout_on <= -2 or timeout_on == 0: - timeout_on = False - if timeout_on == False: msg(sender, "&cThe timeout must be within 0-60 or -1.") return True except ValueError: -- 2.45.2 From 46f1564af03a35c006448df77b1207f516592489 Mon Sep 17 00:00:00 2001 From: Pepich Date: Mon, 11 Apr 2016 15:18:59 +0200 Subject: [PATCH 142/217] Fixed indentation error ll 39-41 --- damnspam.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/damnspam.py b/damnspam.py index 6a4c2b3..83dfb5f 100644 --- a/damnspam.py +++ b/damnspam.py @@ -36,9 +36,9 @@ def on_dammnspam_command(sender, command, label, args): msg(sender, "&c/damnspam &e(Levers only)") return True #Gittestlol - if not is_creative(sender): - msg(sender, "&cYou can only do this in Creative mode.") - return True + if not is_creative(sender): + msg(sender, "&cYou can only do this in Creative mode.") + return True # /damnspam if len(args) == 1: -- 2.45.2 From fa1d5e900d13c546ddf069849e14eadafdc79377 Mon Sep 17 00:00:00 2001 From: Pepich Date: Mon, 11 Apr 2016 16:59:42 +0200 Subject: [PATCH 143/217] 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 144/217] 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 145/217] 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 From a5556760761974590b0666c3e89043aa5fc98a1d Mon Sep 17 00:00:00 2001 From: Dico200 Date: Wed, 25 May 2016 02:39:05 +0200 Subject: [PATCH 146/217] Prevent complete multi-replacement in chatalias. Doesn't prevent 1 -> 2 and 23 -> 5 to make for 13 -> 5, but does prevent a -> 20 and 2 -> 3. Tested. --- chatalias.py | 25 +++++++++++++++++++++---- main.py | 2 +- plugin.yml | 3 +-- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/chatalias.py b/chatalias.py index da1a657..be97228 100644 --- a/chatalias.py +++ b/chatalias.py @@ -86,6 +86,7 @@ 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") @@ -179,8 +180,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 an alias for this sequence because a priorly added alias contains it") + 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 @@ -203,14 +205,29 @@ 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 an alias for this sequence because a priorly added alias contains it" + 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] + if aliased not in prior: + for alias in prior.values(): + if aliased in alias: + return False + prior[aliased] = new_alias + save_data(puuid) + return True + + def remove(sender, args): plugin_header(sender, "Alias") try: diff --git a/main.py b/main.py index be3a65b..651a547 100644 --- a/main.py +++ b/main.py @@ -43,7 +43,7 @@ shared["load_modules"] = [ # Adds /calc, toggles automatic solving of Math expressions in chat "calc", # Adds aliasing of chat words - #"chatalias", + "chatalias", # Plugin to locate laggy chunks. /lc lists chunks with more than n entities "lagchunks", # Adds /report and /rp, Stores reports with time and location diff --git a/plugin.yml b/plugin.yml index 4991e40..97e69a1 100644 --- a/plugin.yml +++ b/plugin.yml @@ -1,5 +1,4 @@ name: RedstonerUtils main: main.py version: 3.1.0 -author: redstone_sheep - +author: redstone_sheep \ No newline at end of file -- 2.45.2 From 4e6bd44c387b4956da5bf39a3a80b25b0b495aba Mon Sep 17 00:00:00 2001 From: Dico200 Date: Wed, 25 May 2016 02:40:50 +0200 Subject: [PATCH 147/217] Undoing these small changes from last commit... --- chatalias.py | 1 - plugin.yml | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/chatalias.py b/chatalias.py index be97228..24a445e 100644 --- a/chatalias.py +++ b/chatalias.py @@ -86,7 +86,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") diff --git a/plugin.yml b/plugin.yml index 97e69a1..bdd5acb 100644 --- a/plugin.yml +++ b/plugin.yml @@ -1,4 +1,4 @@ name: RedstonerUtils main: main.py version: 3.1.0 -author: redstone_sheep \ No newline at end of file +author: redstone_sheep -- 2.45.2 From 7fdaee155aabc69e658d5eaf4d6aa502ab90239c Mon Sep 17 00:00:00 2001 From: Dico200 Date: Wed, 25 May 2016 02:46:53 +0200 Subject: [PATCH 148/217] Fix yo shitty chatgroups code --- chatgroups.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chatgroups.py b/chatgroups.py index aed22cd..be29e53 100644 --- a/chatgroups.py +++ b/chatgroups.py @@ -89,7 +89,7 @@ def groupchat(sender, message, ann = False): def do_for_chatgroup(group, func, *args, **kwargs): for receiver in server.getOnlinePlayers(): if groups.get(uid(receiver)) == group: - func(receiver, args, kwargs) + func(receiver, *args, **kwargs) def send_tpa_request(receiver, sender): if not receiver == sender: -- 2.45.2 From fca3cf250c10c47d849c2faef7a1a1f2d601d57b Mon Sep 17 00:00:00 2001 From: Dico200 Date: Wed, 25 May 2016 02:52:24 +0200 Subject: [PATCH 149/217] Imbusy: Fixed typos and some *flaws* which I will disregard here @curs3d --- imbusy.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/imbusy.py b/imbusy.py index 37a964e..153c00f 100644 --- a/imbusy.py +++ b/imbusy.py @@ -17,8 +17,8 @@ from traceback import format_exc as trace busy_players = [] -def unclear(): - msg(sender, "Umm, what? Sorry, directions unlclear, got head stuck in washing machine") +def unclear(sender): + msg(sender, "Umm, what? Sorry, directions unclear, got head stuck in washing machine") @hook.command("busy", @@ -39,7 +39,7 @@ def on_busy_command(sender, cmd, label, args): if len(args) == 0: plugin_header(recipient = sender, name = "I'M BUSY!") - msg(sender, "This plugin allows being busy, and when turned on you will not recieve any direct messages or tpa requests.") + msg(sender, "This plugin allows being busy, and when turned on you will not receive any direct messages or tpa requests.") msg(sender, "\nCommands:") msg(sender, "/busy on: turns on busy mode") msg(sender, "/busy off: turns off busy mode") @@ -78,7 +78,7 @@ def on_busy_command(sender, cmd, label, args): else: plugin_header(recipient = sender, name = "I'M BUSY!") - unclear() + unclear(sender) return False elif len(args) == 2 and args[0] == "status": @@ -92,7 +92,7 @@ def on_busy_command(sender, cmd, label, args): else: plugin_header(recipient = sender, name = "I'M BUSY!") - unclear() + unclear(sender) return False -- 2.45.2 From 8165d5977b407d10b97e65a2e15bbcf97855f224 Mon Sep 17 00:00:00 2001 From: Dico200 Date: Wed, 25 May 2016 03:00:35 +0200 Subject: [PATCH 150/217] Small change to imbusy messages --- imbusy.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/imbusy.py b/imbusy.py index 153c00f..049d721 100644 --- a/imbusy.py +++ b/imbusy.py @@ -54,14 +54,14 @@ def on_busy_command(sender, cmd, label, args): return True busy_players.append(sender.getName()) plugin_header(recipient = sender, name = "I'M BUSY!") - broadcast(None, "%s is now SUPER busy! Don't even TRY bothering them, it will not work!" % sender.getName()) + broadcast(None, "&c[&2Busy&c] &fNow busy: %s&f, don't even TRY bothering them!" % sender.getDisplayName()) return True elif args[0] == "off": plugin_header(recipient = sender, name = "I'M BUSY!") try: busy_players.remove(sender.getName()) - msg(sender, "Master has sent /busy command, %s is freeee!" % sender.getName()) + msg(sender, "Master has sent /busy command, %s&f is freeee of bothering!" % sender.getDisplayName()) return True except ValueError: msg(sender, "You are not busy! You cannot be even less busy! Are you perhaps bored?") @@ -82,7 +82,7 @@ def on_busy_command(sender, cmd, label, args): return False elif len(args) == 2 and args[0] == "status": - plugin_header(recipient = sender, name = "I'M BUSY!") + plugin_header(recipient = sender, name = "I'M BUSY!") if args[1] in busy_players: msg(sender, "Yes, %s is busy. Shhh..." % args[1]) return True -- 2.45.2 From 29e7ce174b5f353d79773f1e73f047bb0007acbc Mon Sep 17 00:00:00 2001 From: Dico200 Date: Wed, 25 May 2016 03:02:01 +0200 Subject: [PATCH 151/217] Imbusy command: Replace plugin_header calls with a single one at the start --- imbusy.py | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/imbusy.py b/imbusy.py index 049d721..8e84cbd 100644 --- a/imbusy.py +++ b/imbusy.py @@ -32,13 +32,13 @@ def on_busy_command(sender, cmd, label, args): msg(sender, "Sorry, Console cannot be busy") return True + plugin_header(recipient = sender, name = "I'M BUSY!") + if not sender.hasPermission("utils.busy.allowed"): - plugin_header(recipient = sender, name = "I'M BUSY!") noperm(sender) return True if len(args) == 0: - plugin_header(recipient = sender, name = "I'M BUSY!") msg(sender, "This plugin allows being busy, and when turned on you will not receive any direct messages or tpa requests.") msg(sender, "\nCommands:") msg(sender, "/busy on: turns on busy mode") @@ -49,16 +49,13 @@ def on_busy_command(sender, cmd, label, args): elif len(args) == 1: if args[0] == "on": if sender.getName() in busy_players: - plugin_header(recipient = sender, name = "I'M BUSY!") msg(sender, "You cannot be even more focused than this without being a jedi!") return True busy_players.append(sender.getName()) - plugin_header(recipient = sender, name = "I'M BUSY!") broadcast(None, "&c[&2Busy&c] &fNow busy: %s&f, don't even TRY bothering them!" % sender.getDisplayName()) return True elif args[0] == "off": - plugin_header(recipient = sender, name = "I'M BUSY!") try: busy_players.remove(sender.getName()) msg(sender, "Master has sent /busy command, %s&f is freeee of bothering!" % sender.getDisplayName()) @@ -68,7 +65,6 @@ def on_busy_command(sender, cmd, label, args): return True elif args[0] == "status": - plugin_header(recipient = sender, name = "I'M BUSY!") if sender.getName() in busy_players: msg(sender, "You are super-duper busy and concentrated right now. Think, think, think!") return True @@ -77,12 +73,10 @@ def on_busy_command(sender, cmd, label, args): return True else: - plugin_header(recipient = sender, name = "I'M BUSY!") unclear(sender) return False elif len(args) == 2 and args[0] == "status": - plugin_header(recipient = sender, name = "I'M BUSY!") if args[1] in busy_players: msg(sender, "Yes, %s is busy. Shhh..." % args[1]) return True @@ -91,7 +85,6 @@ def on_busy_command(sender, cmd, label, args): return True else: - plugin_header(recipient = sender, name = "I'M BUSY!") unclear(sender) return False -- 2.45.2 From 9a1006e7114e9ed63b67e1197a3ec934a9089814 Mon Sep 17 00:00:00 2001 From: Dico200 Date: Wed, 25 May 2016 03:05:59 +0200 Subject: [PATCH 152/217] Imbusy command: status tweaked, cleaned up return statements --- imbusy.py | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/imbusy.py b/imbusy.py index 8e84cbd..a480e2e 100644 --- a/imbusy.py +++ b/imbusy.py @@ -44,49 +44,45 @@ def on_busy_command(sender, cmd, label, args): msg(sender, "/busy on: turns on busy mode") msg(sender, "/busy off: turns off busy mode") msg(sender, "/busy status [player]: shows your or [player]'s current busy status.") - return True elif len(args) == 1: if args[0] == "on": if sender.getName() in busy_players: msg(sender, "You cannot be even more focused than this without being a jedi!") - return True - busy_players.append(sender.getName()) - broadcast(None, "&c[&2Busy&c] &fNow busy: %s&f, don't even TRY bothering them!" % sender.getDisplayName()) - return True + else: + busy_players.append(sender.getName()) + broadcast(None, "&c[&2Busy&c] &fNow busy: %s&r, don't even TRY bothering them!" % sender.getDisplayName()) elif args[0] == "off": try: busy_players.remove(sender.getName()) - msg(sender, "Master has sent /busy command, %s&f is freeee of bothering!" % sender.getDisplayName()) - return True + msg(sender, "Master has sent /busy command, %s&r is freeee of bothering!" % sender.getDisplayName()) except ValueError: msg(sender, "You are not busy! You cannot be even less busy! Are you perhaps bored?") - return True elif args[0] == "status": if sender.getName() in busy_players: msg(sender, "You are super-duper busy and concentrated right now. Think, think, think!") - return True else: msg(sender, "You are completely unable to focus right now.") - return True else: unclear(sender) return False elif len(args) == 2 and args[0] == "status": - if args[1] in busy_players: - msg(sender, "Yes, %s is busy. Shhh..." % args[1]) - return True + target = server.getPlayer(args[1]) + if target is None: + msg(sender, "That player is not online, I doubt they are busy.") + elif target.getName() in busy_players: + msg(sender, "Yes, %s&r is busy. Shhh..." % target.getDisplayName()) else: - msg(sender, "No, you're good. Feel free to chat with %s!" % args[1]) - return True + msg(sender, "No, you're good. Feel free to chat with %s&r!" % target.getDisplayName()) else: unclear(sender) return False + return True @hook.event("player.PlayerCommandPreprocessEvent", "monitor") -- 2.45.2 From 5592e16200212b22f61f358183740d8a34030bc9 Mon Sep 17 00:00:00 2001 From: Dico Date: Wed, 25 May 2016 15:49:11 +0200 Subject: [PATCH 153/217] Solidify imbusy blocking pms, tpas, etc. I used reflection to get the Map object from the SimpleCommandMap instance stored in the implementation of PluginManager. I replaced all Command instances in there that handle /msg, /tpa, /tpahere and /reply, minus /minecraft:tell, with a wrapper that checks if the target is busy. Tested adequately, but some more would be nice. --- imbusy.py | 141 ++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 131 insertions(+), 10 deletions(-) diff --git a/imbusy.py b/imbusy.py index a480e2e..8d7ae74 100644 --- a/imbusy.py +++ b/imbusy.py @@ -13,7 +13,9 @@ from helpers import * from basecommands import simplecommand +import org.bukkit.command.Command as Command from traceback import format_exc as trace + busy_players = [] @@ -85,19 +87,138 @@ def on_busy_command(sender, cmd, label, args): return True -@hook.event("player.PlayerCommandPreprocessEvent", "monitor") -def on_cmd_preprocess_event(event): - message = event.getMessage().split(" ") - if message[0] == "/msg" or message[0] == "/w" or message[0] == "/m" or \ - message[0] == "/tell" or message[0] == "/tpa" or message[0] == "/tpahere": - if message[1] in busy_players: - plugin_header(recipient = event.getPlayer(), name = "I'M BUSY!") - msg(event.getPlayer(), "We are sorry, but %s is currently busy. Please try again later." % message[1]) - event.setCancelled(True) - @hook.event("player.PlayerQuitEvent", "lowest") def on_player_leave(event): try: busy_players.remove(event.getPlayer().getName()) except: pass + + +#---- Dicode for catching any bothering of busy people ---- + + +reply_targets = {} +override_perm = "utils.imbusy.override" + + +def whisper(sender, target_name): + target = server.getPlayer(target_name) + + if target is not None: + if target is not sender and not sender.hasPermission(override_perm) and target.getName() in busy_players: + msg(sender, "&c[&fBUSY&c] %s&r is busy!" % target.getDisplayName()) + return False + + reply_targets[sender.getName()] = target.getName() + + # allow the target to reply regardless of sender being busy + if target.getName() in reply_targets: + del reply_targets[target.getName()] + return True + + +def reply(sender): + if sender.getName() in reply_targets: + target = server.getPlayer(reply_targets[sender.getName()]) + if target is not None: + if target is not sender and not sender.hasPermission(override_perm) and target.getName() in busy_players: + msg(sender, "&c[&fBUSY&c] %s&r is busy!" % target.getDisplayName()) + return False + + # allow the target to reply regardless of sender being busy + if target.getName() in reply_targets: + del reply_targets[target.getName()] + return True + + +class CommandWrapper(Command): + + def __init__(self, wrapped, checker): + Command.__init__(self, wrapped.getName()) + self.setDescription(wrapped.getDescription()) + self.setPermission(wrapped.getPermission()) + self.setUsage(wrapped.getUsage()) + self.setAliases(wrapped.getAliases()) + self.wrapped = wrapped + self.checker = checker + + def execute(self, sender, label, args): + try: + if self.checker(sender, args): + return self.wrapped.execute(sender, label, args) + except: + error(trace()) + return True + + def tabComplete(self, sender, alias, args): + return self.wrapped.tabComplete(sender, alias, args) + +def msg_command_checker(sender, args): + return len(args) <= 1 or whisper(sender, args[0]) + +def reply_command_checker(sender, args): + return len(args) == 0 or reply(sender) + +def tpa_command_checker(sender, args): + if len(args) == 0: + return True + target = server.getPlayer(args[0]) + if target is not None and target is not sender and not sender.hasPermission(override_perm) and target.getName() in busy_players: + msg(sender, "&c[&fBUSY&c] %s&r is busy!" % target.getDisplayName()) + return False + return True + +def tpahere_command_checker(sender, args): + return tpa_command_checker(sender, args) + + +@hook.event("player.PlayerCommandPreprocessEvent", "monitor") +def on_player_command_preprocess(event): + message = event.getMessage().split(" ") + if len(message) > 1 and message[0].lower() in ("/tell", "/minecraft:tell") and not whisper(event.getPlayer(), message[1]): + event.setCancelled(True) + + +@hook.enable +def replace_ess_commands(): + + try: + mapField = server.getPluginManager().getClass().getDeclaredField("commandMap") + mapField.setAccessible(True) + commandMap = mapField.get(server.getPluginManager()) + + commandsField = commandMap.getClass().getDeclaredField("knownCommands") + commandsField.setAccessible(True) + map = commandsField.get(commandMap) + + essMsgCmd = map.get("essentials:msg") + essReplyCmd = map.get("essentials:reply") + essTpaCmd = map.get("essentials:tpa") + essTpahereCmd = map.get("essentials:tpahere") + + msgCmdWrapper = CommandWrapper(essMsgCmd, msg_command_checker) + replyCmdWrapper = CommandWrapper(essReplyCmd, reply_command_checker) + tpaCmdWrapper = CommandWrapper(essTpaCmd, tpa_command_checker) + tpahereCmdWrapper = CommandWrapper(essTpahereCmd, tpahere_command_checker) + + iterator = map.entrySet().iterator() + while iterator.hasNext(): + entry = iterator.next() + value = entry.getValue() + if value is essMsgCmd: + entry.setValue(msgCmdWrapper) + info("[imbusy] wrapped /" + entry.getKey()) + elif value is essReplyCmd: + entry.setValue(replyCmdWrapper) + info("[imbusy] wrapped /" + entry.getKey()) + elif value is essTpaCmd: + entry.setValue(tpaCmdWrapper) + info("[imbusy] wrapped /" + entry.getKey()) + elif value is essTpahereCmd: + entry.setValue(tpahereCmdWrapper) + info("[imbusy] wrapped /" + entry.getKey()) + + except: + error("[Imbusy] Failed to wrap essentials commands") + error(trace()) -- 2.45.2 From a2a43ed464edbafe9548c156371d8013cc9e054d Mon Sep 17 00:00:00 2001 From: Dico200 Date: Wed, 25 May 2016 16:13:36 +0200 Subject: [PATCH 154/217] Replace camelCase with _ stuff --- imbusy.py | 46 ++++++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/imbusy.py b/imbusy.py index 8d7ae74..2baefa3 100644 --- a/imbusy.py +++ b/imbusy.py @@ -144,6 +144,7 @@ class CommandWrapper(Command): self.checker = checker def execute(self, sender, label, args): + info("/" + self.getLabel() + " executed by " + sender.getName()) try: if self.checker(sender, args): return self.wrapped.execute(sender, label, args) @@ -184,39 +185,40 @@ def on_player_command_preprocess(event): def replace_ess_commands(): try: - mapField = server.getPluginManager().getClass().getDeclaredField("commandMap") - mapField.setAccessible(True) - commandMap = mapField.get(server.getPluginManager()) + info("[imbusy] Wrapping ess commands") + map_field = server.getPluginManager().getClass().getDeclaredField("commandMap") + map_field.setAccessible(True) + command_map = map_field.get(server.getPluginManager()) - commandsField = commandMap.getClass().getDeclaredField("knownCommands") - commandsField.setAccessible(True) - map = commandsField.get(commandMap) + commands_field = command_map.getClass().getDeclaredField("knownCommands") + commands_field.setAccessible(True) + map = commands_field.get(command_map) - essMsgCmd = map.get("essentials:msg") - essReplyCmd = map.get("essentials:reply") - essTpaCmd = map.get("essentials:tpa") - essTpahereCmd = map.get("essentials:tpahere") + ess_msg_cmd = map.get("essentials:msg") + ess_reply_cmd = map.get("essentials:reply") + ess_tpa_cmd = map.get("essentials:tpa") + ess_tpahere_cmd = map.get("essentials:tpahere") - msgCmdWrapper = CommandWrapper(essMsgCmd, msg_command_checker) - replyCmdWrapper = CommandWrapper(essReplyCmd, reply_command_checker) - tpaCmdWrapper = CommandWrapper(essTpaCmd, tpa_command_checker) - tpahereCmdWrapper = CommandWrapper(essTpahereCmd, tpahere_command_checker) + msg_cmd_wrapper = CommandWrapper(ess_msg_cmd, msg_command_checker) + reply_cmd_wrapper = CommandWrapper(ess_reply_cmd, reply_command_checker) + tpa_cmd_wrapper = CommandWrapper(ess_tpa_cmd, tpa_command_checker) + tpahere_cmd_wrapper = CommandWrapper(ess_tpahere_cmd, tpahere_command_checker) iterator = map.entrySet().iterator() while iterator.hasNext(): entry = iterator.next() value = entry.getValue() - if value is essMsgCmd: - entry.setValue(msgCmdWrapper) + if value is ess_msg_cmd: + entry.setValue(msg_cmd_wrapper) info("[imbusy] wrapped /" + entry.getKey()) - elif value is essReplyCmd: - entry.setValue(replyCmdWrapper) + elif value is ess_reply_cmd: + entry.setValue(reply_cmd_wrapper) info("[imbusy] wrapped /" + entry.getKey()) - elif value is essTpaCmd: - entry.setValue(tpaCmdWrapper) + elif value is ess_tpa_cmd: + entry.setValue(tpa_cmd_wrapper) info("[imbusy] wrapped /" + entry.getKey()) - elif value is essTpahereCmd: - entry.setValue(tpahereCmdWrapper) + elif value is ess_tpahere_cmd: + entry.setValue(tpahere_cmd_wrapper) info("[imbusy] wrapped /" + entry.getKey()) except: -- 2.45.2 From 29f846c8f9532ac0950c4187171b042d8e5dee49 Mon Sep 17 00:00:00 2001 From: Dico200 Date: Wed, 25 May 2016 16:31:32 +0200 Subject: [PATCH 155/217] Undo prior changes in favor of pull request --- chatalias.py | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/chatalias.py b/chatalias.py index 24a445e..d1c1b62 100644 --- a/chatalias.py +++ b/chatalias.py @@ -1,3 +1,19 @@ +Skip to content +This repository +Search +Pull requests +Issues +Gist + @Dico200 + Unwatch 13 + Star 5 + Fork 3 RedstonerServer/redstoner-utils + Code Issues 8 Pull requests 3 Wiki Pulse Graphs Settings +Tree: cb1a333a56 Find file Copy pathredstoner-utils/chatalias.py +07039b3 15 hours ago +@Dico200 Dico200 Fix command given for next help page in chatalias.py +5 contributors @PixelSergey @Pepich @NEMESIS13cz @Dico200 @invalid-email-address +RawBlameHistory 337 lines (290 sloc) 12.9 KB ############################################ # Alias v2.0 by Pepich # # Changes to previous version from curs3d: # @@ -179,9 +195,8 @@ def add(sender, args): msg(sender, "&cCould not create alias: Max_limit reached!") return True args = [args[0]] + [" ".join(args[1:])] - if not add_alias_data(uid(sender), str(args[0]), args[1]): - msg(sender, colorify("&c") + "Could not add an alias for this sequence because a priorly added alias contains it") - return True + data[str(uid(sender))][str(args[0])] = args[1] + save_data(uid(sender)) msg(sender, colorify("&7Alias: ") + args[0] + colorify("&7 -> " + args[1] + colorify("&7 was succesfully created!")), usecolor=sender.hasPermission("essentials.chat.color")) return True @@ -204,29 +219,14 @@ def radd(sender, args): return True if len(args) == 3: args += ["true"] - if not add_alias_data(uid(target), str(args[1]), str(args[2])): - message = colorify("&c") + "Could not add an alias for this sequence because a priorly added alias contains it" - msg(sender, message) - if args[3].lower() == "false": - msg(target, message) - return True + data[str(uid(target))][str(args[1])] = str(args[2]) + save_data(uid(target)) 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] - if aliased not in prior: - for alias in prior.values(): - if aliased in alias: - return False - prior[aliased] = new_alias - save_data(puuid) - return True - - def remove(sender, args): plugin_header(sender, "Alias") try: @@ -350,3 +350,5 @@ remotes = { "remove": rremove, "list": rlist_alias, } +Status API Training Shop Blog About +© 2016 GitHub, Inc. Terms Privacy Security Contact Help \ No newline at end of file -- 2.45.2 From d88baa4899d49b3224732e513bb05ea224b6c9f3 Mon Sep 17 00:00:00 2001 From: Dico200 Date: Wed, 25 May 2016 16:37:58 +0200 Subject: [PATCH 156/217] What is this.. sorry --- chatalias.py | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/chatalias.py b/chatalias.py index d1c1b62..5560c5f 100644 --- a/chatalias.py +++ b/chatalias.py @@ -1,19 +1,3 @@ -Skip to content -This repository -Search -Pull requests -Issues -Gist - @Dico200 - Unwatch 13 - Star 5 - Fork 3 RedstonerServer/redstoner-utils - Code Issues 8 Pull requests 3 Wiki Pulse Graphs Settings -Tree: cb1a333a56 Find file Copy pathredstoner-utils/chatalias.py -07039b3 15 hours ago -@Dico200 Dico200 Fix command given for next help page in chatalias.py -5 contributors @PixelSergey @Pepich @NEMESIS13cz @Dico200 @invalid-email-address -RawBlameHistory 337 lines (290 sloc) 12.9 KB ############################################ # Alias v2.0 by Pepich # # Changes to previous version from curs3d: # -- 2.45.2 From 2d6725df73df9d92a36aea2ab76f8573f32faf75 Mon Sep 17 00:00:00 2001 From: Dico Date: Wed, 25 May 2016 16:40:31 +0200 Subject: [PATCH 157/217] Prevent chained aliases in chatalias Prevents 1 -> 23 along with 2 -> 3 and similar stuff --- chatalias.py | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/chatalias.py b/chatalias.py index 5560c5f..7163245 100644 --- a/chatalias.py +++ b/chatalias.py @@ -179,8 +179,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" + 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 @@ -203,14 +204,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: @@ -334,5 +358,3 @@ remotes = { "remove": rremove, "list": rlist_alias, } -Status API Training Shop Blog About -© 2016 GitHub, Inc. Terms Privacy Security Contact Help \ No newline at end of file -- 2.45.2 From 16e78a267766192486b88195bac1ee6c6ea45667 Mon Sep 17 00:00:00 2001 From: Dico200 Date: Wed, 25 May 2016 16:44:09 +0200 Subject: [PATCH 158/217] Add missing ) to chatalias --- chatalias.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chatalias.py b/chatalias.py index 7163245..708179c 100644 --- a/chatalias.py +++ b/chatalias.py @@ -180,7 +180,7 @@ def add(sender, args): return True args = [args[0]] + [" ".join(args[1:])] 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" + 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 -- 2.45.2 From 1fdf97f77a3c5f1a263fa252802a7840416a7bc5 Mon Sep 17 00:00:00 2001 From: Dico200 Date: Wed, 25 May 2016 16:46:49 +0200 Subject: [PATCH 159/217] Add missing _ ... lol --- chatalias.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chatalias.py b/chatalias.py index 708179c..07f132f 100644 --- a/chatalias.py +++ b/chatalias.py @@ -227,7 +227,7 @@ def add_alias_data(puuid, aliased, new_alias): # prevent 1 -> 2 if there is 2 -> 3 for sequence in prior: - if sequence in new alias: + if sequence in new_alias: return False prior[aliased] = new_alias -- 2.45.2 From a532c6b42c2c2629c7772e5538012446047da197 Mon Sep 17 00:00:00 2001 From: Dico200 Date: Wed, 25 May 2016 18:18:27 +0200 Subject: [PATCH 160/217] Changed broadcast message, removed two debugs --- imbusy.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/imbusy.py b/imbusy.py index 2baefa3..4dc6f59 100644 --- a/imbusy.py +++ b/imbusy.py @@ -53,7 +53,7 @@ def on_busy_command(sender, cmd, label, args): msg(sender, "You cannot be even more focused than this without being a jedi!") else: busy_players.append(sender.getName()) - broadcast(None, "&c[&2Busy&c] &fNow busy: %s&r, don't even TRY bothering them!" % sender.getDisplayName()) + broadcast(None, "&c[&2Busy&c] %s&r is now busy, don't even TRY bothering them!" % sender.getDisplayName()) elif args[0] == "off": try: @@ -144,7 +144,6 @@ class CommandWrapper(Command): self.checker = checker def execute(self, sender, label, args): - info("/" + self.getLabel() + " executed by " + sender.getName()) try: if self.checker(sender, args): return self.wrapped.execute(sender, label, args) @@ -185,7 +184,6 @@ def on_player_command_preprocess(event): def replace_ess_commands(): try: - info("[imbusy] Wrapping ess commands") map_field = server.getPluginManager().getClass().getDeclaredField("commandMap") map_field.setAccessible(True) command_map = map_field.get(server.getPluginManager()) -- 2.45.2 From 00e38efd14eaa3261b1dd66f71157a7f048bd92c Mon Sep 17 00:00:00 2001 From: Dico200 Date: Wed, 25 May 2016 18:32:20 +0200 Subject: [PATCH 161/217] Added catcher for /mail send --- imbusy.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/imbusy.py b/imbusy.py index 4dc6f59..225862b 100644 --- a/imbusy.py +++ b/imbusy.py @@ -154,6 +154,7 @@ class CommandWrapper(Command): def tabComplete(self, sender, alias, args): return self.wrapped.tabComplete(sender, alias, args) + def msg_command_checker(sender, args): return len(args) <= 1 or whisper(sender, args[0]) @@ -172,6 +173,15 @@ def tpa_command_checker(sender, args): def tpahere_command_checker(sender, args): return tpa_command_checker(sender, args) +def mail_command_checker(sender, args): + if len(args) < 3 or args[0].lower() != "send": + return True + target = server.getPlayer(args[1]) + if target is not None and target is not sender and not sender.hasPermission(override_perm) and target.getName() in busy_players: + msg(sender, "&c[&fBUSY&c] %s&r is busy!" % target.getDisplayName()) + return False + return True + @hook.event("player.PlayerCommandPreprocessEvent", "monitor") def on_player_command_preprocess(event): @@ -196,11 +206,13 @@ def replace_ess_commands(): ess_reply_cmd = map.get("essentials:reply") ess_tpa_cmd = map.get("essentials:tpa") ess_tpahere_cmd = map.get("essentials:tpahere") + ess_mail_cmd = map.get("essentials:mail") msg_cmd_wrapper = CommandWrapper(ess_msg_cmd, msg_command_checker) reply_cmd_wrapper = CommandWrapper(ess_reply_cmd, reply_command_checker) tpa_cmd_wrapper = CommandWrapper(ess_tpa_cmd, tpa_command_checker) tpahere_cmd_wrapper = CommandWrapper(ess_tpahere_cmd, tpahere_command_checker) + mail_cmd_wrapper = CommandWrapper(ess_mail_cmd, mail_command_checker) iterator = map.entrySet().iterator() while iterator.hasNext(): @@ -218,6 +230,9 @@ def replace_ess_commands(): elif value is ess_tpahere_cmd: entry.setValue(tpahere_cmd_wrapper) info("[imbusy] wrapped /" + entry.getKey()) + elif value is ess_mail_cmd: + entry.setValue(mail_cmd_wrapper) + info("[imbusy] wrapped /" + entry.getKey()) except: error("[Imbusy] Failed to wrap essentials commands") -- 2.45.2 From 8629b39ce10242da9d4686f6bb2dcd7c24b53832 Mon Sep 17 00:00:00 2001 From: Dico200 Date: Wed, 25 May 2016 18:41:42 +0200 Subject: [PATCH 162/217] Make /busy a toggle, move help page to /busy help. Changed a few messages --- imbusy.py | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/imbusy.py b/imbusy.py index 225862b..1fc9e63 100644 --- a/imbusy.py +++ b/imbusy.py @@ -40,34 +40,44 @@ def on_busy_command(sender, cmd, label, args): noperm(sender) return True + sender_name = sender.getName() + if len(args) == 0: - msg(sender, "This plugin allows being busy, and when turned on you will not receive any direct messages or tpa requests.") - msg(sender, "\nCommands:") - msg(sender, "/busy on: turns on busy mode") - msg(sender, "/busy off: turns off busy mode") - msg(sender, "/busy status [player]: shows your or [player]'s current busy status.") + if sender_name in busy_players: + busy_players.remove(sender_name) + msg(sender, "Your busy status was removed, you can be bothered again") + else: + busy_players.append(sender_name) + broadcast(None, "&c[&2Busy&c] %s&r is now busy, don't even TRY bothering them!" % sender.getDisplayName()) elif len(args) == 1: - if args[0] == "on": - if sender.getName() in busy_players: + if args[0].lower() == "on": + if sender_name in busy_players: msg(sender, "You cannot be even more focused than this without being a jedi!") else: - busy_players.append(sender.getName()) + busy_players.append(sender_name) broadcast(None, "&c[&2Busy&c] %s&r is now busy, don't even TRY bothering them!" % sender.getDisplayName()) - elif args[0] == "off": + elif args[0].lower() == "off": try: - busy_players.remove(sender.getName()) - msg(sender, "Master has sent /busy command, %s&r is freeee of bothering!" % sender.getDisplayName()) + busy_players.remove(sender_name) + msg(sender, "Your busy status was removed, you can be bothered again") except ValueError: msg(sender, "You are not busy! You cannot be even less busy! Are you perhaps bored?") - elif args[0] == "status": - if sender.getName() in busy_players: + elif args[0].lower() == "status": + if sender_name in busy_players: msg(sender, "You are super-duper busy and concentrated right now. Think, think, think!") else: msg(sender, "You are completely unable to focus right now.") + elif args[0].lower() in ("?", "help"): + msg(sender, "Let's you put yourself in busy status, preventing pms and tpa requests from other players") + msg(sender, "\nCommands:") + msg(sender, "/busy: toggles busy status") + msg(sender, "/busy on: turns on busy status") + msg(sender, "/busy off: turns off busy status") + msg(sender, "/busy status [player]: shows your or [player]'s current busy status.") else: unclear(sender) return False @@ -75,7 +85,7 @@ def on_busy_command(sender, cmd, label, args): elif len(args) == 2 and args[0] == "status": target = server.getPlayer(args[1]) if target is None: - msg(sender, "That player is not online, I doubt they are busy.") + msg(sender, "That player is not online, they may be busy IRL, we never know") elif target.getName() in busy_players: msg(sender, "Yes, %s&r is busy. Shhh..." % target.getDisplayName()) else: -- 2.45.2 From 28afa1ddcf9d9d43c7cc076e6091b33452bf2b1c Mon Sep 17 00:00:00 2001 From: Dico200 Date: Wed, 25 May 2016 18:54:32 +0200 Subject: [PATCH 163/217] Changed debug output, tweaked [busy] broadcast prefix --- imbusy.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/imbusy.py b/imbusy.py index 1fc9e63..380c920 100644 --- a/imbusy.py +++ b/imbusy.py @@ -48,7 +48,7 @@ def on_busy_command(sender, cmd, label, args): msg(sender, "Your busy status was removed, you can be bothered again") else: busy_players.append(sender_name) - broadcast(None, "&c[&2Busy&c] %s&r is now busy, don't even TRY bothering them!" % sender.getDisplayName()) + broadcast(None, "&c[&fBUSY&c] %s&r is now busy, don't even TRY bothering them!" % sender.getDisplayName()) elif len(args) == 1: if args[0].lower() == "on": @@ -56,7 +56,7 @@ def on_busy_command(sender, cmd, label, args): msg(sender, "You cannot be even more focused than this without being a jedi!") else: busy_players.append(sender_name) - broadcast(None, "&c[&2Busy&c] %s&r is now busy, don't even TRY bothering them!" % sender.getDisplayName()) + broadcast(None, "&c[&fBUSY&c] %s&r is now busy, don't even TRY bothering them!" % sender.getDisplayName()) elif args[0].lower() == "off": try: @@ -184,6 +184,7 @@ def tpahere_command_checker(sender, args): return tpa_command_checker(sender, args) def mail_command_checker(sender, args): + info("Mail command executed") if len(args) < 3 or args[0].lower() != "send": return True target = server.getPlayer(args[1]) @@ -225,24 +226,26 @@ def replace_ess_commands(): mail_cmd_wrapper = CommandWrapper(ess_mail_cmd, mail_command_checker) iterator = map.entrySet().iterator() + wrapped_commands = [] while iterator.hasNext(): entry = iterator.next() value = entry.getValue() + changed = True if value is ess_msg_cmd: entry.setValue(msg_cmd_wrapper) - info("[imbusy] wrapped /" + entry.getKey()) elif value is ess_reply_cmd: entry.setValue(reply_cmd_wrapper) - info("[imbusy] wrapped /" + entry.getKey()) elif value is ess_tpa_cmd: entry.setValue(tpa_cmd_wrapper) - info("[imbusy] wrapped /" + entry.getKey()) elif value is ess_tpahere_cmd: entry.setValue(tpahere_cmd_wrapper) - info("[imbusy] wrapped /" + entry.getKey()) elif value is ess_mail_cmd: entry.setValue(mail_cmd_wrapper) - info("[imbusy] wrapped /" + entry.getKey()) + else: + changed = False + if changed: + wrapped_commands.append(entry.getKey()) + info("[imbusy] wrapped commands: /" + ", /".join(wrapped_commands)) except: error("[Imbusy] Failed to wrap essentials commands") -- 2.45.2 From 89e3982a299d94173704784438ac9393ebd6acaf Mon Sep 17 00:00:00 2001 From: Dico200 Date: Thu, 26 May 2016 04:37:47 +0200 Subject: [PATCH 164/217] Implement some of pizza's changes from imbusy branch --- imbusy.py | 186 +++++++++++++++++++++++++++++++----------------------- 1 file changed, 106 insertions(+), 80 deletions(-) diff --git a/imbusy.py b/imbusy.py index 380c920..2df0a03 100644 --- a/imbusy.py +++ b/imbusy.py @@ -1,99 +1,126 @@ -# I'M BUSY! Plugin by Curs3d # -############################## -# Concept by CookieManors :D # -# http://bit.ly/1GnNPW8 # -############################## -# This plugin permits users to -# send a command that renders -# them "busy", not letting them -# to get tpa requests or direct -# messages, except from console. -# On restart, all busy data will -# be cleared. +################################## +# I'M BUSY! Plugin by Curs3d # +# Concept by CookieManors :D # +################################## +# This plugin permits users to # +# send a command that renders # +# them "busy", not letting them # +# to get tpa requests or direct # +# messages, except from console. # +# On restart, all busy data will # +# be cleared. # +################################## from helpers import * -from basecommands import simplecommand import org.bukkit.command.Command as Command -from traceback import format_exc as trace + +imbusy_version = "v1.1.0" + +base_permission = "utils.busy" # for /busy status +use_permission = "utils.busy.use" # for being busy +override_permission = "utils.busy.override" # for being able to bother busy people + busy_players = [] -def unclear(sender): - msg(sender, "Umm, what? Sorry, directions unclear, got head stuck in washing machine") - - -@hook.command("busy", - aliases = ["focus"], - usage = "/ ", - description = "Sets busy mode on, you cannot recieve tpas and MSGs" +@hook.command("imbusy", + aliases = ["busy"], + usage = "/ [on, off, status/check]", + description = "Offers control over your busy status" ) def on_busy_command(sender, cmd, label, args): - if not is_player(sender): - msg(sender, "Sorry, Console cannot be busy") - return True + msg(sender, "&7Sorry, Console cannot be busy") + return True plugin_header(recipient = sender, name = "I'M BUSY!") - if not sender.hasPermission("utils.busy.allowed"): + #args = array_to_list(args) + if not sender.hasPermission(base_permission): noperm(sender) return True - sender_name = sender.getName() - if len(args) == 0: - if sender_name in busy_players: - busy_players.remove(sender_name) - msg(sender, "Your busy status was removed, you can be bothered again") - else: - busy_players.append(sender_name) - broadcast(None, "&c[&fBUSY&c] %s&r is now busy, don't even TRY bothering them!" % sender.getDisplayName()) + return toggle(sender) - elif len(args) == 1: - if args[0].lower() == "on": - if sender_name in busy_players: - msg(sender, "You cannot be even more focused than this without being a jedi!") - else: - busy_players.append(sender_name) - broadcast(None, "&c[&fBUSY&c] %s&r is now busy, don't even TRY bothering them!" % sender.getDisplayName()) + arg0 = args[0].lower() + if arg0 == "on": + return on(sender) + if arg0 == "off": + return off(sender) + if arg0 in ("status", "check"): + return status(sender, args[1:]) + return help(sender) - elif args[0].lower() == "off": - try: - busy_players.remove(sender_name) - msg(sender, "Your busy status was removed, you can be bothered again") - except ValueError: - msg(sender, "You are not busy! You cannot be even less busy! Are you perhaps bored?") - - elif args[0].lower() == "status": - if sender_name in busy_players: - msg(sender, "You are super-duper busy and concentrated right now. Think, think, think!") - else: - msg(sender, "You are completely unable to focus right now.") - - elif args[0].lower() in ("?", "help"): - msg(sender, "Let's you put yourself in busy status, preventing pms and tpa requests from other players") - msg(sender, "\nCommands:") - msg(sender, "/busy: toggles busy status") - msg(sender, "/busy on: turns on busy status") - msg(sender, "/busy off: turns off busy status") - msg(sender, "/busy status [player]: shows your or [player]'s current busy status.") - else: - unclear(sender) - return False - - elif len(args) == 2 and args[0] == "status": - target = server.getPlayer(args[1]) - if target is None: - msg(sender, "That player is not online, they may be busy IRL, we never know") - elif target.getName() in busy_players: - msg(sender, "Yes, %s&r is busy. Shhh..." % target.getDisplayName()) - else: - msg(sender, "No, you're good. Feel free to chat with %s&r!" % target.getDisplayName()) +def toggle(sender): + if not sender.hasPermission(use_permission): + noperm(sender) + return True + sender_name = sender.getName() + if sender_name in busy_players: + busy_players.remove(sender_name) + broadcast(None, colorify(sender.getDisplayName() + " &7is no longer busy...")) else: - unclear(sender) - return False + busy_players.append(sender_name) + broadcast(None, colorify(sender.getDisplayName() + " &7is now busy...")) + return True + + +def help(sender): + msg(sender, "Let's you put yourself in busy status, preventing pms and tpa requests from other players") + msg(sender, "\n&eCommands:") + msg(sender, "&e/busy &7- Toggles busy status") + msg(sender, "&e/busy on &7- Turns on busy status") + msg(sender, "&e/busy off &7- Turns off busy status") + msg(sender, "&e/busy status [player] &7- shows your or [player]'s current busy status") + return True + + +def on(sender): + if not sender.hasPermission(use_permission): + noperm(sender) + return True + sender_name = sender.getName() + if sender_name in busy_players: + msg(sender, "&7You are already busy!") + return True + busy_players.append(sender_name) + broadcast(None, colorify(sender.getDisplayName() + " &7is now busy...")) + return True + + +def off(sender): + if not sender.hasPermission(use_permission): + noperm(sender) + return True + sender_name = sender.getName() + if sender_name not in busy_players: + msg(sender, "&7You are not busy! You cannot be even less busy! Are you perhaps bored?") + return True + busy_players.remove(sender_name) + broadcast(None, colorify(sender.getDisplayName() + " &7is no longer busy...")) + return True + + +def status(sender, args): + if not sender.hasPermission(base_permission): + noperm(sender) + return True + if len(args) == 0: + if sender.getName() in busy_players: + msg(sender, "&7You are currently busy.") + else: + msg(sender, "&7You are currently not busy.") + else: + target = server.getPlayer(args[0]) + if target is None: + msg(sender, "&7That player is not online") + elif target.getName() in busy_players: + msg(sender, "&7Player &e" + args[0] + " &7is currently busy.") + else: + msg(sender, "&7Player &e" + args[0] + " &7is currently not busy.") return True @@ -109,14 +136,13 @@ def on_player_leave(event): reply_targets = {} -override_perm = "utils.imbusy.override" def whisper(sender, target_name): target = server.getPlayer(target_name) if target is not None: - if target is not sender and not sender.hasPermission(override_perm) and target.getName() in busy_players: + if target is not sender and not sender.hasPermission(override_permission) and target.getName() in busy_players: msg(sender, "&c[&fBUSY&c] %s&r is busy!" % target.getDisplayName()) return False @@ -132,7 +158,7 @@ def reply(sender): if sender.getName() in reply_targets: target = server.getPlayer(reply_targets[sender.getName()]) if target is not None: - if target is not sender and not sender.hasPermission(override_perm) and target.getName() in busy_players: + if target is not sender and not sender.hasPermission(override_permission) and target.getName() in busy_players: msg(sender, "&c[&fBUSY&c] %s&r is busy!" % target.getDisplayName()) return False @@ -175,7 +201,7 @@ def tpa_command_checker(sender, args): if len(args) == 0: return True target = server.getPlayer(args[0]) - if target is not None and target is not sender and not sender.hasPermission(override_perm) and target.getName() in busy_players: + if target is not None and target is not sender and not sender.hasPermission(override_permission) and target.getName() in busy_players: msg(sender, "&c[&fBUSY&c] %s&r is busy!" % target.getDisplayName()) return False return True @@ -188,7 +214,7 @@ def mail_command_checker(sender, args): if len(args) < 3 or args[0].lower() != "send": return True target = server.getPlayer(args[1]) - if target is not None and target is not sender and not sender.hasPermission(override_perm) and target.getName() in busy_players: + if target is not None and target is not sender and not sender.hasPermission(override_permission) and target.getName() in busy_players: msg(sender, "&c[&fBUSY&c] %s&r is busy!" % target.getDisplayName()) return False return True -- 2.45.2 From 3859ad8e4065730458e990eabb9ae8d0fa14799a Mon Sep 17 00:00:00 2001 From: Dico200 Date: Sat, 28 May 2016 21:43:59 +0200 Subject: [PATCH 165/217] Fix error on player quit for player.py --- player.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/player.py b/player.py index 0f4a47f..b1a2ddd 100644 --- a/player.py +++ b/player.py @@ -25,5 +25,6 @@ def on_join(event): @hook.event("player.PlayerQuitEvent","highest") def on_leave(event): - py_players.remove(get_py_player(event.getPlayer())) - + player = get_py_player(event.getPlayer()) + if player in py_players: + py_players.remove(player) -- 2.45.2 From 7a905643eb772fd15c9fbd92942655c66b8dff0d Mon Sep 17 00:00:00 2001 From: Dico200 Date: Sat, 28 May 2016 22:18:27 +0200 Subject: [PATCH 166/217] Enabled friends module, added friends check in imbusy, fixed small mistakes --- friends.py | 4 +++ imbusy.py | 74 ++++++++++++++++++++++++++++++++++++++---------------- main.py | 2 ++ 3 files changed, 58 insertions(+), 22 deletions(-) diff --git a/friends.py b/friends.py index 870560e..130954a 100644 --- a/friends.py +++ b/friends.py @@ -5,6 +5,10 @@ friends = open_json_file("friends", {}) # {Player_UUID:[List_of_friend friend_join_sound = "random.orb" +def is_friend_of(player, other): + lst = friends.get(uid(player)) + return lst is not None and uid(other) in lst + @hook.event("player.PlayerJoinEvent", "high") # creates sound and sends a bold message on friend join def fjm(event): # friend join message diff --git a/imbusy.py b/imbusy.py index 2df0a03..c56ee69 100644 --- a/imbusy.py +++ b/imbusy.py @@ -12,6 +12,7 @@ ################################## from helpers import * +from friends import is_friend_of import org.bukkit.command.Command as Command imbusy_version = "v1.1.0" @@ -21,7 +22,7 @@ use_permission = "utils.busy.use" # for being busy override_permission = "utils.busy.override" # for being able to bother busy people -busy_players = [] +busy_players = {} # name : false/true where false is normal busy and true is super busy @hook.command("imbusy", @@ -51,6 +52,8 @@ def on_busy_command(sender, cmd, label, args): return off(sender) if arg0 in ("status", "check"): return status(sender, args[1:]) + if arg0 == "super": + return super_cmd(sender) return help(sender) @@ -60,11 +63,11 @@ def toggle(sender): return True sender_name = sender.getName() if sender_name in busy_players: - busy_players.remove(sender_name) - broadcast(None, colorify(sender.getDisplayName() + " &7is no longer busy...")) + del busy_players[sender_name] + broadcast(None, sender.getDisplayName() + " &7is no longer busy...") else: busy_players.append(sender_name) - broadcast(None, colorify(sender.getDisplayName() + " &7is now busy...")) + broadcast(None, sender.getDisplayName() + " &7is now busy...") return True @@ -75,6 +78,7 @@ def help(sender): msg(sender, "&e/busy on &7- Turns on busy status") msg(sender, "&e/busy off &7- Turns off busy status") msg(sender, "&e/busy status [player] &7- shows your or [player]'s current busy status") + msg(sender, "&e/busy super &7- sets your status to SUPER busy such that even friends can not bother you") return True @@ -83,11 +87,11 @@ def on(sender): noperm(sender) return True sender_name = sender.getName() - if sender_name in busy_players: + if busy_players.get(sender_name) is False: # can be None, False or True msg(sender, "&7You are already busy!") - return True - busy_players.append(sender_name) - broadcast(None, colorify(sender.getDisplayName() + " &7is now busy...")) + else: + busy_players[sender_name] = False # busy but not super busy + broadcast(None, sender.getDisplayName() + " &7is now busy...") return True @@ -99,8 +103,8 @@ def off(sender): if sender_name not in busy_players: msg(sender, "&7You are not busy! You cannot be even less busy! Are you perhaps bored?") return True - busy_players.remove(sender_name) - broadcast(None, colorify(sender.getDisplayName() + " &7is no longer busy...")) + del busy_players[sender_name] + broadcast(None, sender.getDisplayName() + " &7is no longer busy...") return True @@ -110,7 +114,10 @@ def status(sender, args): return True if len(args) == 0: if sender.getName() in busy_players: - msg(sender, "&7You are currently busy.") + if busy_players[sender_name] is False: + msg(sender, "&7You are currently busy.") + else: + msg(sender, "&7You are currently SUPER busy.") else: msg(sender, "&7You are currently not busy.") else: @@ -118,18 +125,33 @@ def status(sender, args): if target is None: msg(sender, "&7That player is not online") elif target.getName() in busy_players: - msg(sender, "&7Player &e" + args[0] + " &7is currently busy.") + if busy_players[target.getName()] is False: + msg(sender, "&7Player %s &7is currently busy." % target.getDisplayName()) + else: + msg(sender, "&7Player %s &7is currently SUPER busy." % target.getDisplayName()) else: - msg(sender, "&7Player &e" + args[0] + " &7is currently not busy.") + msg(sender, "&7Player %s &7is currently not busy." % target.getDisplayName()) + return True + + +def super_cmd(sender): + if not sender.hasPermission(use_permission): + noperm(sender) + return True + sender_name = sender.getName() + if busy_players.get(sender_name) is True: + msg(sender, "&7You are already SUPER busy!") + else: + busy_players[sender_name] = True # SUPER busy + broadcast(None, sender.getDisplayName() + " &7is now SUPER busy...") return True @hook.event("player.PlayerQuitEvent", "lowest") def on_player_leave(event): - try: - busy_players.remove(event.getPlayer().getName()) - except: - pass + player_name = event.getPlayer().getName() + if player_name in busy_players: + del busy_players[player_name] #---- Dicode for catching any bothering of busy people ---- @@ -138,11 +160,19 @@ def on_player_leave(event): reply_targets = {} +def can_send(sender, target): + if not target.getName() in busy_players: + return True + if target is sender or sender.hasPermission(override_permission): + return True + return busy_players[target.getName()] is False and is_friend_of(target, sender) + + def whisper(sender, target_name): target = server.getPlayer(target_name) if target is not None: - if target is not sender and not sender.hasPermission(override_permission) and target.getName() in busy_players: + if not can_send(sender, target): msg(sender, "&c[&fBUSY&c] %s&r is busy!" % target.getDisplayName()) return False @@ -158,7 +188,7 @@ def reply(sender): if sender.getName() in reply_targets: target = server.getPlayer(reply_targets[sender.getName()]) if target is not None: - if target is not sender and not sender.hasPermission(override_permission) and target.getName() in busy_players: + if not can_send(sender, target): msg(sender, "&c[&fBUSY&c] %s&r is busy!" % target.getDisplayName()) return False @@ -181,7 +211,7 @@ class CommandWrapper(Command): def execute(self, sender, label, args): try: - if self.checker(sender, args): + if not is_player(sender) or self.checker(sender, args): return self.wrapped.execute(sender, label, args) except: error(trace()) @@ -201,7 +231,7 @@ def tpa_command_checker(sender, args): if len(args) == 0: return True target = server.getPlayer(args[0]) - if target is not None and target is not sender and not sender.hasPermission(override_permission) and target.getName() in busy_players: + if target is not None and not can_send(sender, target): msg(sender, "&c[&fBUSY&c] %s&r is busy!" % target.getDisplayName()) return False return True @@ -214,7 +244,7 @@ def mail_command_checker(sender, args): if len(args) < 3 or args[0].lower() != "send": return True target = server.getPlayer(args[1]) - if target is not None and target is not sender and not sender.hasPermission(override_permission) and target.getName() in busy_players: + if target is not None and not can_send(sender, target): msg(sender, "&c[&fBUSY&c] %s&r is busy!" % target.getDisplayName()) return False return True diff --git a/main.py b/main.py index 651a547..64405eb 100644 --- a/main.py +++ b/main.py @@ -44,6 +44,8 @@ shared["load_modules"] = [ "calc", # Adds aliasing of chat words "chatalias", + # For players to point friends + "friends", # Plugin to locate laggy chunks. /lc lists chunks with more than n entities "lagchunks", # Adds /report and /rp, Stores reports with time and location -- 2.45.2 From 28ac05ce0ae43b4598a01cbacbb7ee13f32b350a Mon Sep 17 00:00:00 2001 From: Dico200 Date: Sat, 28 May 2016 22:22:51 +0200 Subject: [PATCH 167/217] Tweak imbusy permission nodes --- imbusy.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/imbusy.py b/imbusy.py index c56ee69..5382f32 100644 --- a/imbusy.py +++ b/imbusy.py @@ -17,9 +17,9 @@ import org.bukkit.command.Command as Command imbusy_version = "v1.1.0" -base_permission = "utils.busy" # for /busy status -use_permission = "utils.busy.use" # for being busy -override_permission = "utils.busy.override" # for being able to bother busy people +base_permission = "utils.imbusy" # for /busy status +use_permission = "utils.imbusy.use" # for being busy +override_permission = "utils.imbusy.override" # for being able to bother busy people busy_players = {} # name : false/true where false is normal busy and true is super busy -- 2.45.2 From a19f0b5bdc5b05496b2d70c78f891fbc7cc7711e Mon Sep 17 00:00:00 2001 From: Pepich Date: Sat, 28 May 2016 22:33:38 +0200 Subject: [PATCH 168/217] Added support for /rl; Made comments more precise --- chatalias.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/chatalias.py b/chatalias.py index 07f132f..7295cca 100644 --- a/chatalias.py +++ b/chatalias.py @@ -55,11 +55,18 @@ permission_FINFO = "utils.alias.finfo" # CODE # ######## -# OnEnable +# 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(event.getPlayer()), )) + t.daemon = True + t.start() + else: + if event.getPlayer().hasPermission(permission_FINFO): + disabled_fallback(event.getPlayer()) def safe_open_json(uuid): if not os.path.exists("plugins/redstoner-utils.py.dir/files/aliases"): -- 2.45.2 From 7da3fd5b717c9bb73576802a8b1e73ac40e8214f Mon Sep 17 00:00:00 2001 From: Pepich Date: Sat, 28 May 2016 22:35:28 +0200 Subject: [PATCH 169/217] That's an "s", not an "S" ._. --- chatalias.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chatalias.py b/chatalias.py index 7295cca..1069ef3 100644 --- a/chatalias.py +++ b/chatalias.py @@ -59,7 +59,7 @@ permission_FINFO = "utils.alias.finfo" enabled = helpers_version in helpers_versions if not enabled: error = colorify("&6Incompatible versions detected (&chelpers.py&6)") -for player in Server.getOnlinePlayers(): +for player in server.getOnlinePlayers(): if enabled: t = threading.Thread(target=load_data, args=(uid(event.getPlayer()), )) t.daemon = True -- 2.45.2 From c534d9316a06ed732ff1f3d0daca19dd693b1761 Mon Sep 17 00:00:00 2001 From: Pepich Date: Sat, 28 May 2016 22:40:08 +0200 Subject: [PATCH 170/217] Moved OnModuleLoad to bottom of file --- chatalias.py | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/chatalias.py b/chatalias.py index 1069ef3..cb7d80c 100644 --- a/chatalias.py +++ b/chatalias.py @@ -55,19 +55,6 @@ permission_FINFO = "utils.alias.finfo" # CODE # ######## -# 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(event.getPlayer()), )) - t.daemon = True - t.start() - else: - if event.getPlayer().hasPermission(permission_FINFO): - disabled_fallback(event.getPlayer()) - 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") @@ -365,3 +352,17 @@ remotes = { "remove": rremove, "list": rlist_alias, } + +# 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(event.getPlayer()), )) + t.daemon = True + t.start() + else: + if event.getPlayer().hasPermission(permission_FINFO): + disabled_fallback(event.getPlayer()) -- 2.45.2 From c3189639f09723500f6597917369e601a44c68cb Mon Sep 17 00:00:00 2001 From: Dico200 Date: Sat, 28 May 2016 23:05:43 +0200 Subject: [PATCH 171/217] Fixes and stuff --- chatalias.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/chatalias.py b/chatalias.py index cb7d80c..449a68f 100644 --- a/chatalias.py +++ b/chatalias.py @@ -191,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": @@ -274,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: @@ -282,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 @@ -341,15 +341,21 @@ 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, } @@ -360,9 +366,9 @@ 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(event.getPlayer()), )) + t = threading.Thread(target=load_data, args=(uid(player), )) t.daemon = True t.start() else: - if event.getPlayer().hasPermission(permission_FINFO): - disabled_fallback(event.getPlayer()) + if player.hasPermission(permission_FINFO): + disabled_fallback(player) -- 2.45.2 From e35fadc353f764a22d1d2c4b29463c81d091b36b Mon Sep 17 00:00:00 2001 From: Dico200 Date: Sun, 29 May 2016 20:55:10 +0200 Subject: [PATCH 172/217] Added/fixed torch breaker setting. Added a few missing saveSettings() calls. Fixed /set on turning it off and vice-versa for boolean settings that are enabled by default. A few more tweaks. --- blockplacemods.py | 165 ++++++++++++++++++++++++++-------------------- 1 file changed, 93 insertions(+), 72 deletions(-) diff --git a/blockplacemods.py b/blockplacemods.py index 8d18699..d012e54 100644 --- a/blockplacemods.py +++ b/blockplacemods.py @@ -9,7 +9,7 @@ import org.bukkit.inventory.ItemStack as ItemStack import org.bukkit.Material as Material import org.bukkit.event.block.Action as Action import org.bukkit.block.BlockFace as BlockFace -import org.bukkit.scheduler.BukkitRunnable as Runnable +import org.bukkit.scheduler.BukkitRunnable as BukkitRunnable """ # Permissions: @@ -38,11 +38,11 @@ settingInformation = dict( #[setting type, identifying description, detailed des "Sets your preferred default furnace contents to your currently held itemstack. Use an empty hand to empty a slot, or /toggle furnace clear to clear all slots.", ["cooker", "fillf"], 2 ], - #torch = [0, - # "removal of torches you place on redstone blocks", - # "Toggles whether redstone torches which you place on redstone blocks will be deleted after a short amount of delay.", - # ["redstonetorch", "tor"] - #], + torch = [0, + "removal of torches you place on redstone blocks", + "Toggles whether redstone torches which you place on redstone blocks will be deleted after a short amount of delay.", + ["redstonetorch", "tor"] + ], piston = [2, "rotating pistons, droppers and hoppers to face the block you place them against", "Toggles whether pistons or sticky pistons which you place will be rotated to face the block which you placed them against.", @@ -66,7 +66,7 @@ defaults = { 2: list } -faces = { +piston_faces = { BlockFace.DOWN : 0, BlockFace.UP : 1, BlockFace.NORTH : 2, @@ -75,6 +75,14 @@ faces = { BlockFace.EAST : 5 } +torch_faces = { + 1: BlockFace.WEST, + 2: BlockFace.EAST, + 3: BlockFace.NORTH, + 4: BlockFace.SOUTH, + 5: BlockFace.DOWN +} + playerSettings = open_json_file("blockplacemods", {}) for setting, details in settingInformation.iteritems(): @@ -128,14 +136,14 @@ def toggle_command(sender, command, label, args): elif arg2 in ("toggle", "switch"): new = not enabled elif arg2 in ("on", "enable"): - new = not default + new = True elif arg2 in ("off", "disable"): - new = default + new = False else: return " &cArgument '%s' was not recognized. \n Use &o/toggle %s info &cfor more information" % (arg2, setting) - if enabled == new: + if enabled is new: return " &cAlready %s: &a%s" % ("enabled" if enabled else "disabled", details[1]) - if new == default: + if new is default: values.remove(uuid) else: values.append(uuid) @@ -150,10 +158,11 @@ def toggle_command(sender, command, label, args): if arg2 == "clear": if enabled: del values[uuid] + saveSettings() return " &aDisabled " + details[1] return " &cAlready disabled: " + details[1] - if arg2 == "details": + if arg2 == "info": return " &aSetting %s:\n &9%s \n&6Accepted arguments: [|clear|details]" % (setting, details[2]) slot = int(arg2) if arg2.isdigit() else 0 @@ -166,10 +175,11 @@ def toggle_command(sender, command, label, args): items = values[uuid] if slot in items: del items[slot] - saveSettings() if len(items) == 0: del items + saveSettings() return " &aDisabled " + details[1] + saveSettings() return " &aCleared slot %s of setting %s" % (slot, setting) return " &cSlot %s of setting %s was already cleared!" % (slot, setting) return " &cAlready disabled: " + details[1] @@ -198,59 +208,63 @@ def isEnabled(toggleSetting, uuid): @hook.event("block.BlockPlaceEvent", "monitor") def on_block_place(event): - if event.isCancelled(): - return - player = event.getPlayer() - if not is_creative(player): - return + try: - uuid = uid(player) - block = event.getBlockPlaced() - material = block.getType() + if event.isCancelled(): + return + player = event.getPlayer() + if not is_creative(player): + return + + uuid = uid(player) + block = event.getBlockPlaced() + material = block.getType() - if (material in (Material.WOOD_STEP, Material.STEP) - and isEnabled("slab", uuid) - and player.hasPermission("utils.toggle.slab") - and block.getData() < 8 - ): - block.setData(block.getData() + 8) # Flip upside down + if (material in (Material.WOOD_STEP, Material.STEP) + and isEnabled("slab", uuid) + and player.hasPermission("utils.toggle.slab") + and block.getData() < 8 + ): + block.setData(block.getData() + 8) # Flip upside down - elif (material == Material.CAULDRON - and isEnabled("cauldron", uuid) - and player.hasPermission("utils.toggle.cauldron") - ): - block.setData(3) #3 layers of water, 3 signal strength + elif (material == Material.CAULDRON + and isEnabled("cauldron", uuid) + and player.hasPermission("utils.toggle.cauldron") + ): + block.setData(3) #3 layers of water, 3 signal strength - elif ((material == Material.FURNACE and player.hasPermission("utils.toggle.furnace")) - or (material == Material.DROPPER and player.hasPermission("utils.toggle.dropper")) - or (material == Material.HOPPER and player.hasPermission("utils.toggle.hopper")) - ): - stacks = get(str(material).lower()).get(uuid) - if stacks != None: # Enabled - state = block.getState() - inv = state.getInventory() - for slot, stack in stacks.iteritems(): - inv.setItem(int(slot), toStack(stack)) - state.update() - - """ - elif (material == Material.REDSTONE_TORCH_ON - and event.getBlockAgainst().getType() == Material.REDSTONE_BLOCK - and isEnabled("torch", uuid) - and player.hasPermission("utils.toggle.torch") - ): - torches_to_break.append(block) - """ + elif ((material == Material.FURNACE and player.hasPermission("utils.toggle.furnace")) + or (material == Material.DROPPER and player.hasPermission("utils.toggle.dropper")) + or (material == Material.HOPPER and player.hasPermission("utils.toggle.hopper")) + ): + stacks = get(str(material).lower()).get(uuid) + if stacks != None: # Enabled + state = block.getState() + inv = state.getInventory() + for slot, stack in stacks.iteritems(): + inv.setItem(int(slot), toStack(stack)) + state.update() - if (material in (Material.PISTON_BASE, Material.PISTON_STICKY_BASE) - and isEnabled("piston", uuid) - and player.hasPermission("utils.toggle.piston") - ): - block.setData(faces[block.getFace(event.getBlockAgainst())]) + elif (material == Material.REDSTONE_TORCH_ON + and isEnabled("torch", uuid) + and player.hasPermission("utils.toggle.torch") + and block.getData() in torch_faces + and block.getRelative(torch_faces[block.getData()]).getType() is Material.REDSTONE_BLOCK + ): + torches_to_break.append(block) + + + elif (material in (Material.PISTON_BASE, Material.PISTON_STICKY_BASE) + and isEnabled("piston", uuid) + and player.hasPermission("utils.toggle.piston") + ): + block.setData(piston_faces[block.getFace(event.getBlockAgainst())]) + except: + error(trace()) @hook.event("player.PlayerInteractEvent", "monitor") @@ -269,29 +283,36 @@ def on_interact(event): if not event2.isCancelled(): block.setData(block.getData() - 1 if block.getData() > 0 else 3) -""" + break_torches = True torches_to_break = deque() def stop_breaking_torches(): break_torches = False - info("Interrupted torch breaking thread") + info("[BlockPlaceMods] Interrupted torch breaking thread") -class torch_breaker(Runnable): +class JBukkitRunnable(BukkitRunnable): - def run(): + def __init__(self, func): + self.run = func - try: - if break_torches: - for i in range(len(torches_to_break)): - block = torches_to_break.popleft() - mat = block.getType() - if mat == Material.REDSTONE_TORCH_OFF: - block.setTypeId(0) - elif mat == Material.REDSTONE_TORCH_ON: + +def torch_breaker(): + + try: + if break_torches: + for i in range(len(torches_to_break)): + block = torches_to_break.popleft() + mat = block.getType() + if mat == Material.REDSTONE_TORCH_OFF: + block.setTypeId(0) + elif mat == Material.REDSTONE_TORCH_ON: + if block.getData() in torch_faces and block.getRelative(torch_faces[block.getData()]).getType() is Material.REDSTONE_BLOCK: torches_to_break.append(block) - except: - error(trace()) -""" + except: + error(trace()) + +def schedule_torch_breaker(): + JBukkitRunnable(torch_breaker).runTaskTimer(server.getPluginManager().getPlugin("RedstonerUtils"), 0, 1) -- 2.45.2 From 5a757b7fb10a959c245d29b3eaddd69325f1ba55 Mon Sep 17 00:00:00 2001 From: Dico200 Date: Sun, 29 May 2016 20:56:29 +0200 Subject: [PATCH 173/217] Removed @hook.enable decs from modules, added them to the on_enable() method of main.py. --- imbusy.py | 1 - main.py | 7 ++++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/imbusy.py b/imbusy.py index 5382f32..05049c5 100644 --- a/imbusy.py +++ b/imbusy.py @@ -257,7 +257,6 @@ def on_player_command_preprocess(event): event.setCancelled(True) -@hook.enable def replace_ess_commands(): try: diff --git a/main.py b/main.py index 64405eb..fba0c5a 100644 --- a/main.py +++ b/main.py @@ -19,12 +19,17 @@ except: @hook.enable def on_enable(): + if "blockplacemods" in shared["modules"]: + shared["modules"]["blockplacemods"].schedule_torch_breaker() + if "imbusy" in shared["modules"]: + shared["modules"]["imbusy"].replace_ess_commands() info("RedstonerUtils enabled!") @hook.disable def on_disable(): - shared["modules"]["reports"].stop_reporting() + if "reports" in shared["modules"]: + shared["modules"]["reports"].stop_reporting() info("RedstonerUtils disabled!") -- 2.45.2 From 8e4f30a017650fc103ccf580aba37986728abd64 Mon Sep 17 00:00:00 2001 From: Dico200 Date: Sun, 29 May 2016 21:08:28 +0200 Subject: [PATCH 174/217] Changed command blacklist to a whitelist. Added /svs commands to show whitelisted commands. Added a few more command aliases. Added maximum line count and maximum line size. --- serversigns.py | 61 ++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 52 insertions(+), 9 deletions(-) diff --git a/serversigns.py b/serversigns.py index d9f2a44..d5a4829 100644 --- a/serversigns.py +++ b/serversigns.py @@ -5,7 +5,23 @@ import java.util.UUID as UUID import org.bukkit.Material as Material import org.bukkit.block.BlockFace as BlockFace -blocked_cmds = tuple(shared["modules"]["misc"].sudo_blacklist) + ("pex", "kick", "ban", "tempban", "reload", "op", "deop", "whitelist") +commands_whitelist = ( + "mail", "email", "memo", + "echo", "ping", + "cg join", + "cg info", + "chatgroup join", + "chatgroup info", + "i", + "item", + "p h", "plot home", "plot h", "p home", "plotme home", "plotme h", + "up", + "tppos", + "seen" +) + +max_line_length = 256 +max_lines = 20 def load_signs(): signs_obj = open_json_file("serversigns", []) @@ -20,9 +36,11 @@ def save_signs(): signs_obj.append(key + tuple(value)) save_json_file("serversigns", signs_obj) -signs = load_signs() # {("world", x, y, z): ["owner_id", "msg1", "msg2"]} +# {("world", x, y, z): ["owner_id", "msg1", "msg2"]} +signs = load_signs() -lines = {} # Accumulated messages so players can have longer messages: {"Dico200": "Message...........", ""} +# Accumulated messages so players can have longer messages: {"Dico200": "Message...........", ""} +lines = {} def fromLoc(bLoc): """ @@ -92,7 +110,8 @@ def signsMsg(msg, colour = '4'): senderLimit = 0) def svs_command(sender, command, label, args): arg1 = args[0].lower() - Validate.isTrue(arg1 in ("claim", "reset", "add", "remove", "info", "clear", "help", "switch", "reverse", "unclaim"), + Validate.isTrue(arg1 in ("claim", "reset", "add", "remove", "rem", "del", "delete", "info", "lines", + "clear", "help", "switch", "reverse", "unclaim", "commands", "whitelist", "wl"), signsMsg("That argument could not be recognized, use &o/svs help &4for expected arguments")) Validate.isAuthorized(sender, "utils.serversigns." + arg1) @@ -105,7 +124,7 @@ def svs_command(sender, command, label, args): msg += "\nHow to use &b/serversigns&a:" msg += "\n&b/svs claim" + ("" if not sender.hasPermission("utils.serversigns.admin") else " [owner]") msg += "\n&a- Claims the sign so that you can add messages to it" - msg += "\n&b/svs info" + msg += "\n&b/svs info|lines" msg += "\n&a- Displays information about the (claimed) sign" msg += "\n&b/svs add [++]" msg += "\n&a- Adds the message to the sign. Use ++ at the end" @@ -120,7 +139,12 @@ def svs_command(sender, command, label, args): msg += "\n&a- Removes all messages from the sign." msg += "\n&b/svs reset|unclaim" msg += "\n&a- Resets the sign, removing all messages and its owner." + msg += "\n&b/svs commands|whitelist|wl" + msg += "\n&a- Shows a list of whitelisted commands" return msg + + if arg1 in ("commands", "whitelist", "wl"): + return signsMsg("Whitelisted commands: &3" + ", ".join(commands_whitelist), 'a') #------------------------------------------------------------------------------------------- block = sender.getTargetBlock(None, 5) @@ -144,7 +168,7 @@ def svs_command(sender, command, label, args): uuid = uid(target) if sign != None: if sign[0] == uuid: - return signsMsg("The" + signName + " was already owned by that player") + return signsMsg("The " + signName + " was already owned by that player") else: sign[0] = uuid else: @@ -156,7 +180,7 @@ def svs_command(sender, command, label, args): Validate.notNone(sign, signsMsg("The %s has not been claimed" % signName)) #----------------------Sub commands that require the sign to be claimed as well------------------------------------ - if arg1 == "info": + if arg1 in ("info", "lines"): sign_lines = "" for id, line in enumerate(sign[1:]): sign_lines += ("\n &a%s: \"&f%s&a\"" % (id + 1, line)) @@ -167,25 +191,43 @@ def svs_command(sender, command, label, args): #---------------------- Sub commands that require you to own targeted sign as well ------------------------- if arg1 == "add": + Validate.isTrue(len(sign) - 1 <= max_lines, signsMsg("This sign already has the maximum amount of lines, you cannot add more")) + line = " ".join(args[1:]) Validate.isTrue(line != "" and line != None, signsMsg("You have to enter a message to add or accumulate")) key = sender.getName() global lines Validate.isTrue(key in lines or line[:1] != "/" or sender.hasPermission("utils.serversigns.command"), signsMsg("You cannot add commands to a sign!")) + if line[-2:] == "++": if key not in lines: lines[key] = "" + Validate.isTrue(len(lines[key]) + len(line[:-2]) + 1 <= max_line_length, signsMsg("This line would be too long, so the given message was not added to the accumulated message")) lines[key] += " " + line[:-2] return signsMsg("Added given message to the message you're accumulating. \nYour accumulated message is now as follows: \n&f%s" % lines[key], 'a') + if key in lines: line = (lines[key] + " " + line)[1:] - Validate.isTrue(line[0] != "/" or line.split(" ")[0][1:] not in blocked_cmds, signsMsg("Usage of that command with server signs is prohibited")) + Validate.isTrue(len(line) <= max_line_length, signsMsg("This line would be too long, so it was not added to the sign. It is however still accumulated.")) + + if line[0] == "/": + cmd = line[1:].lower() + whitelisted = False + for wl_cmd in commands_whitelist: + if cmd[:len(wl_cmd)] == wl_cmd: + whitelisted = True + break + Validate.isTrue(whitelisted, signsMsg("That command is not whitelisted for use with serversigns")) + + if key in lines: + del lines[key] + sign.append(colorify(line) if line[0] != "/" else line) save_signs() return signsMsg("Added line \"&f%s&a\" to the %s" % (line, signName), 'a') - if arg1 == "remove": + if arg1 in ("remove", "rem", "del", "delete"): Validate.notNone(arg2, signsMsg("You have to enter the ID of the message to remove!")) try: id = int(arg2) @@ -220,6 +262,7 @@ def svs_command(sender, command, label, args): del signs[loc] save_signs() return signsMsg("Removed all messages and the owner from the %s, it can now be claimed" % signName, 'a') + #------------------------------------------------------------------------------------------------------- -- 2.45.2 From a0a7d43a3820b8daeede9b0b85a8a2f5a19c122d Mon Sep 17 00:00:00 2001 From: Dico200 Date: Sun, 29 May 2016 21:29:36 +0200 Subject: [PATCH 175/217] Tweak comment above imbusy, removed credits, removed a useless comment with an old line of code --- imbusy.py | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/imbusy.py b/imbusy.py index 05049c5..ec6c57b 100644 --- a/imbusy.py +++ b/imbusy.py @@ -1,15 +1,12 @@ -################################## -# I'M BUSY! Plugin by Curs3d # -# Concept by CookieManors :D # -################################## -# This plugin permits users to # -# send a command that renders # -# them "busy", not letting them # -# to get tpa requests or direct # -# messages, except from console. # -# On restart, all busy data will # -# be cleared. # -################################## +""" +This plugin permits users to +send a command that renders +them "busy", not letting them +to get tpa requests or direct +messages, except from console. +On restart, all busy data will +be cleared. +""" from helpers import * from friends import is_friend_of @@ -37,7 +34,6 @@ def on_busy_command(sender, cmd, label, args): plugin_header(recipient = sender, name = "I'M BUSY!") - #args = array_to_list(args) if not sender.hasPermission(base_permission): noperm(sender) return True -- 2.45.2 From 33d8fd2f08df21052cb2c9a6b30b49baa61305cd Mon Sep 17 00:00:00 2001 From: Dico200 Date: Sun, 29 May 2016 22:18:42 +0200 Subject: [PATCH 176/217] Removed Pan from pythoners, added Pep, added essentials:esudo to sudo_blacklist --- misc.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/misc.py b/misc.py index 0fd4a6a..026650e 100644 --- a/misc.py +++ b/misc.py @@ -127,7 +127,7 @@ def on_interact(event): sudo_blacklist = ["pyeval", "script_backup_begin", "script_backup_end", "script_backup_error", "script_backup_database_begin", "script_backup_database_dumps", "script_backup_database_end", "script_backup_database_error", "script_backup_database_abort", "script_trim", "script_trim_result", "script_spigot_update", "script_disk_filled", "script_restart", "script_restart_abort", -"script_stop", "script_stop_abort", "script_shutdown", "stop", "esudo", "essentials:sudo", "sudo"] +"script_stop", "script_stop_abort", "script_shutdown", "stop", "esudo", "essentials:sudo", "sudo", "essentials:esudo"] @simplecommand("sudo", usage = " [cmd..]", @@ -212,12 +212,12 @@ def eval_thread(sender, code): msg(sender, ">>> %s: %s" % (eclass.__name__, e) + "\n ", False, "c") thread.exit() -pythoners = [ -"e452e012-2c82-456d-853b-3ac8e6b581f5", # Nemes -"ae795aa8-6327-408e-92ab-25c8a59f3ba1", # jomo -"305ccbd7-0589-403e-a45b-d791dcfdee7d", # PanFritz -"51f2ad3c-6cc8-40ea-aa2b-f25970316921" # Dico -] +pythoners = ( + "e452e012-2c82-456d-853b-3ac8e6b581f5", # Nemes + "ae795aa8-6327-408e-92ab-25c8a59f3ba1", # jomo + "d2693e91-93e1-4e3f-929f-f38e1ce8df03", # Pepich1851 + "51f2ad3c-6cc8-40ea-aa2b-f25970316921" # Dico200 +) @simplecommand("pyeval", usage = "[code..]", -- 2.45.2 From 361da9e049ec9b575b2b78eb7b663e6efeff6950 Mon Sep 17 00:00:00 2001 From: Dico200 Date: Sun, 29 May 2016 23:49:45 +0200 Subject: [PATCH 177/217] Chatalias: Fixed all the things (permission AMOUNT, permission LENGTH, and more), incremented version number --- chatalias.py | 164 ++++++++++++++++++++++++++++----------------------- 1 file changed, 89 insertions(+), 75 deletions(-) diff --git a/chatalias.py b/chatalias.py index 449a68f..0e2b297 100644 --- a/chatalias.py +++ b/chatalias.py @@ -1,14 +1,4 @@ -############################################ -# Alias v2.0 by Pepich # -# Changes to previous version from curs3d: # -# Dynamic alias limit from permissions # -# AC/CG/MSG support # -# Color support # -# Bugfixes # -# # -# TODO: # -# Add command support... # -############################################ +# TODO: Add cg/ac/msg support import os import mysqlhack @@ -20,15 +10,14 @@ from secrets import * # Version number and requirements -alias_version = "2.0.0" +alias_version = "2.1.0" helpers_versions = ["1.1.0", "2.0.0"] enabled = False -error = colorify("&cUnspecified error") +error_msg = 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 +use_mysql = True # Permissions: @@ -60,8 +49,8 @@ def safe_open_json(uuid): os.makedirs("plugins/redstoner-utils.py.dir/files/aliases") value = open_json_file("aliases/" + uuid) if value is None: - value = global_aliases - save_json_file("aliases/" + uuid, value) + value = dict(global_aliases) + save_json_file("aliases/" + uuid, value) return value @@ -69,6 +58,9 @@ def safe_open_json(uuid): usage="/ [...]", desc="Allows aliasing of words") def on_alias_command(sender, cmd, label, args): + if not is_player(sender): + msg(sender, "&cThe console cannot use aliases!") + return True try: args = array_to_list(args) if not enabled: @@ -130,24 +122,23 @@ def on_join(event): @hook.event("player.AsyncPlayerChatEvent", "high") def on_player_chat(event): - try: - if enabled: - if event.isCancelled(): + if enabled: + if event.isCancelled(): + return + player = event.getPlayer() + if not hasPerm(player, permission_USE): + return + msg_limit = int(get_permission_content(player, permission_LENGTH)) + for alias, value in data[str(uid(player))].items(): + if player.hasPermission("essentials.chat.color"): + event.setMessage(event.getMessage().replace(colorify(alias), colorify(value))) + else: + event.setMessage(event.getMessage().replace(alias, value)) + if not player.hasPermission(permission_ALL) and len(event.getMessage()) > msg_limit: + event.setCancelled(True) + plugin_header(player, "Alias") + msg(player, "The message you wanted to generate would exceed the length limit limit of %d. Please make it shorter!" % msg_limit) return - if not hasPerm(event.getPlayer(), permission_USE): - return - for alias, value in data[str(uid(event.getPlayer()))].items(): - if not event.getPlayer().hasPermission(permission_ALL) and len(event.getMessage()) > int(get_permission_content(event.getPlayer(), permission_LENGTH)): - event.setCanceled(True) - plugin_header(event.getPlayer, "Alias") - msg(event.getPlayer(), "The message you wanted to generate would exceed your limit. Please make it shorter!") - return - if event.getPlayer().hasPermission("essentials.chat.color"): - event.setMessage(event.getMessage().replace(colorify(alias), colorify(value))) - else: - event.setMessage(event.getMessage().replace(alias, value)) - except: - print(trace()) def hasPerm(player, permission): @@ -159,7 +150,7 @@ def disabled_fallback(receiver): msg(receiver, colorify("&cUnknown command. Use &e/help&c, &e/plugins &cor ask a mod.")) else: msg(receiver, colorify("&cPlugin alias v" + alias_version + " has experienced an &eEMERGENCY SHUTDOWN:")) - msg(receiver, error) + msg(receiver, error_msg) msg(receiver, colorify("&cPlease contact a dev/admin (especially pep :P) about this to take a look at it.")) @@ -169,11 +160,11 @@ def can_remote(player): def add(sender, args): plugin_header(sender, "Alias") - if not sender.hasPermission(permission_ALL) and len(data[uid(sender)]) >= int(get_permission_content(sender, permission_AMOUNT)): - msg(sender, "&cCould not create alias: Max_limit reached!") - return True + uuid = uid(sender) args = [args[0]] + [" ".join(args[1:])] - if not add_alias_data(uid(sender), str(args[0]), args[1]): + if (args[0] not in data[uuid]) and is_alias_limit_reached(sender, sender): + return True + if not add_alias_data(uuid, 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")) @@ -187,20 +178,21 @@ def radd(sender, args): sender_name = colorify(sender.getDisplayName()) else: sender_name = colorify("&6Console") - target = get_player(args[0]) + target = server.getPlayer(args[0]) + if target == None: + msg(sender, "&cThat player is not online") + return True + uuid = uid(target) 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": - msg(target, "&cCould not create alias: Max_limit reached!") + if (args[1] not in data[uuid]) and is_alias_limit_reached(target, sender, args[3].lower() == "false"): return True if len(args) == 3: args += ["true"] - if not add_alias_data(uid(target), str(args[1]), str(args[2])): + if not add_alias_data(uuid, 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": @@ -212,6 +204,19 @@ def radd(sender, args): return True +def is_alias_limit_reached(player, recipient, not_silent = False): + if player.hasPermission(permission_ALL): + return False + alias_limit = int(get_permission_content(player, permission_AMOUNT)) + if len(data[uid(player)]) > alias_limit: + message = ("&cYour limit of %d has been reached" if player is recipient else "&cThe limit of %d has been reached for that player") % alias_limit + msg(recipient, message) + if not_silent: + msg(player, message) + return True + return False + + def add_alias_data(puuid, aliased, new_alias): prior = data[puuid] @@ -298,45 +303,54 @@ def remote(sender, args): 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: - conn = zxJDBC.connect(mysql_database, mysql_user, mysql_pass, "com.mysql.jdbc.Driver") - curs = conn.cursor() - curs.execute("SELECT alias FROM alias WHERE uuid = ?", (uuid, )) - results = curs.fetchall() - if len(results) == 0: - results = global_aliases - curs.execute("INSERT INTO alias VALUES (?,?)", (uuid, results, )) - data[uuid] = results + try: + t = threading.Thread(target=load_data_thread, args=(uuid,)) + t.daemon = True + t.start() + except: + error(trace()) else: data[uuid] = safe_open_json(uuid) +def load_data_thread(uuid): + conn = zxJDBC.connect(mysql_database, mysql_user, mysql_pass, "com.mysql.jdbc.Driver") + curs = conn.cursor() + curs.execute("SELECT `alias` FROM `chatalias` WHERE `uuid` = ?;", (uuid, )) + results = curs.fetchall() + if len(results) == 0: + value = dict(global_aliases) + curs.execute("INSERT INTO `chatalias` VALUES (?,?);", (uuid, json_dumps(results), )) + conn.commit() + else: + value = json_loads(results[0][0]) + curs.close() + conn.close() + data[uuid] = value + def save_data(uuid): - 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: - conn = zxJDBC.connect(mysql_database, mysql_user, mysql_pass, "com.mysql.jdbc.Driver") - curs = conn.cursor() - curs.execute("UPDATE alias SET alias = ? WHERE uuid = ?", (data[uuid], uuid, )) + try: + t = threading.Thread(target=save_data_thread, args=(uuid,)) + t.daemon = True + t.start() + except: + error(trace()) else: save_json_file("aliases/" + uuid, data[uuid]) +def save_data_thread(uuid): + conn = zxJDBC.connect(mysql_database, mysql_user, mysql_pass, "com.mysql.jdbc.Driver") + curs = conn.cursor() + try: + curs.execute("UPDATE `chatalias` SET `alias` = ? WHERE `uuid` = ?;", (json_dumps(data[uuid]), uuid, )) + except: + error(trace()) + conn.commit() + curs.close() + conn.close() + # Subcommands: subcommands = { @@ -363,7 +377,7 @@ remotes = { enabled = helpers_version in helpers_versions if not enabled: - error = colorify("&6Incompatible versions detected (&chelpers.py&6)") + error_msg = colorify("&6Incompatible versions detected (&chelpers.py&6)") for player in server.getOnlinePlayers(): if enabled: t = threading.Thread(target=load_data, args=(uid(player), )) -- 2.45.2 From fe32e7a49cea69678101da332827ca7603a8fe90 Mon Sep 17 00:00:00 2001 From: Dico200 Date: Mon, 30 May 2016 00:05:49 +0200 Subject: [PATCH 178/217] Cleaned up some of helpers.py --- chatalias.py | 4 +--- helpers.py | 27 ++------------------------- loginsecurity.py | 1 + 3 files changed, 4 insertions(+), 28 deletions(-) diff --git a/chatalias.py b/chatalias.py index 0e2b297..bc21e13 100644 --- a/chatalias.py +++ b/chatalias.py @@ -5,8 +5,6 @@ import mysqlhack import org.bukkit as bukkit from org.bukkit import * from helpers import * -from traceback import format_exc as trace -from secrets import * # Version number and requirements @@ -208,7 +206,7 @@ def is_alias_limit_reached(player, recipient, not_silent = False): if player.hasPermission(permission_ALL): return False alias_limit = int(get_permission_content(player, permission_AMOUNT)) - if len(data[uid(player)]) > alias_limit: + if len(data[uid(player)]) >= alias_limit: message = ("&cYour limit of %d has been reached" if player is recipient else "&cThe limit of %d has been reached for that player") % alias_limit msg(recipient, message) if not_silent: diff --git a/helpers.py b/helpers.py index 4c32e24..d6e46bd 100755 --- a/helpers.py +++ b/helpers.py @@ -11,8 +11,6 @@ import org.bukkit.block as bblock import org.bukkit.event.entity as entity import org.bukkit.command.ConsoleCommandSender from org.bukkit.entity import * -from player import get_py_player -from player import py_players #Imports for async query from secrets import * @@ -254,19 +252,6 @@ def save_json_file(filename, obj): error("Failed to write to %s: %s" % (filename, e)) -def toggle(player, ls, name = "Toggle", add = None): - """ - Toggles presence of a player's UUID in a list - If add is given, True explicitely adds it whereas False removes it - """ - pid = uid(player) - if pid in ls or add == False: - ls.remove(pid) - msg(player, "&a%s turned off!" % name) - elif add != False: - ls.append(pid) - msg(player, "&a%s turned on!" % name) - def send_JSON_message(playername, message): bukkit.Bukkit.getServer().dispatchCommand(bukkit.Bukkit.getServer().getConsoleSender(), "tellraw " + playername + " " + message) @@ -298,21 +283,13 @@ def get_permission_content(player, permnode): perms = player.getEffectivePermissions() for perm in perms: if str(perm.getPermission()).startswith(permnode): - return str(perm.getPermission()).replace(permnode, "") - - -# Gets an online player from their name -def get_player(name): - for p in bukkit.Bukkit.getServer().getOnlinePlayers(): - if p.getName().lower() == name.lower(): - return p - return None + return str(perm.getPermission())[len(permnode):] def array_to_list(array): return_list = [] for a in array: - return_list += [a] + return_list.append(a) return return_list diff --git a/loginsecurity.py b/loginsecurity.py index edf51e9..4fbb307 100644 --- a/loginsecurity.py +++ b/loginsecurity.py @@ -7,6 +7,7 @@ from login_secrets import * #Don't forget to make login_secrets aswell import mysqlhack from com.ziclix.python.sql import zxJDBC from java.lang import Runnable +from player import get_py_player, py_players wait_time = 30 #seconds admin_perm = "utils.loginsecurity.admin" -- 2.45.2 From c78d0f651bd1250ad2de34005edd782e11218e7a Mon Sep 17 00:00:00 2001 From: Dico200 Date: Mon, 30 May 2016 01:11:34 +0200 Subject: [PATCH 179/217] Hotfix for chatalias --- chatalias.py | 52 ++++++++++++++++++++++++++-------------------------- helpers.py | 14 +++++++++----- 2 files changed, 35 insertions(+), 31 deletions(-) diff --git a/chatalias.py b/chatalias.py index bc21e13..9db8fdb 100644 --- a/chatalias.py +++ b/chatalias.py @@ -120,23 +120,26 @@ def on_join(event): @hook.event("player.AsyncPlayerChatEvent", "high") def on_player_chat(event): - if enabled: - if event.isCancelled(): - return - player = event.getPlayer() - if not hasPerm(player, permission_USE): - return - msg_limit = int(get_permission_content(player, permission_LENGTH)) - for alias, value in data[str(uid(player))].items(): - if player.hasPermission("essentials.chat.color"): - event.setMessage(event.getMessage().replace(colorify(alias), colorify(value))) - else: - event.setMessage(event.getMessage().replace(alias, value)) - if not player.hasPermission(permission_ALL) and len(event.getMessage()) > msg_limit: - event.setCancelled(True) - plugin_header(player, "Alias") - msg(player, "The message you wanted to generate would exceed the length limit limit of %d. Please make it shorter!" % msg_limit) + try: + if enabled: + if event.isCancelled(): return + player = event.getPlayer() + if not hasPerm(player, permission_USE): + return + msg_limit = int(get_permission_content(player, permission_LENGTH)) + for alias, value in data[uid(player)].iteritems(): + if player.hasPermission("essentials.chat.color"): + event.setMessage(event.getMessage().replace(colorify(alias), colorify(value))) + else: + event.setMessage(event.getMessage().replace(alias, value)) + if not player.hasPermission(permission_ALL) and len(event.getMessage()) > msg_limit: + event.setCancelled(True) + plugin_header(player, "Alias") + msg(player, "The message you wanted to generate would exceed the length limit limit of %d. Please make it shorter!" % msg_limit) + return + except: + error(trace()) def hasPerm(player, permission): @@ -316,14 +319,12 @@ def load_data_thread(uuid): curs = conn.cursor() curs.execute("SELECT `alias` FROM `chatalias` WHERE `uuid` = ?;", (uuid, )) results = curs.fetchall() - if len(results) == 0: - value = dict(global_aliases) - curs.execute("INSERT INTO `chatalias` VALUES (?,?);", (uuid, json_dumps(results), )) - conn.commit() - else: - value = json_loads(results[0][0]) curs.close() conn.close() + if len(results) == 0: + value = dict(global_aliases) + else: + value = json_loads(results[0][0]) data[uuid] = value @@ -341,10 +342,9 @@ def save_data(uuid): def save_data_thread(uuid): conn = zxJDBC.connect(mysql_database, mysql_user, mysql_pass, "com.mysql.jdbc.Driver") curs = conn.cursor() - try: - curs.execute("UPDATE `chatalias` SET `alias` = ? WHERE `uuid` = ?;", (json_dumps(data[uuid]), uuid, )) - except: - error(trace()) + value = json_dumps(data[uuid]) + curs.execute("INSERT INTO `chatalias` VALUES (?, ?) ON DUPLICATE KEY UPDATE `alias` = ?;", + (uuid, value, value)) conn.commit() curs.close() conn.close() diff --git a/helpers.py b/helpers.py index d6e46bd..da0d423 100755 --- a/helpers.py +++ b/helpers.py @@ -279,11 +279,15 @@ def is_ip(tocheck): # Allows the use of e.g. numeric permission nodes like "permission.amount.5" and similar. # To get the data fetch the player and the start of the permission node, looking like "permission.amount." -def get_permission_content(player, permnode): - perms = player.getEffectivePermissions() - for perm in perms: - if str(perm.getPermission()).startswith(permnode): - return str(perm.getPermission())[len(permnode):] +def get_permission_content(player, permnode, default_value = None): + try: + perms = player.getEffectivePermissions() + for perm in perms: + if str(perm.getPermission()).startswith(permnode): + return str(perm.getPermission())[len(permnode):] + return default_value + except: + error(trace()) def array_to_list(array): -- 2.45.2 From 1fb6e08d42449d84fbcd4461e0628a228cd1acdf Mon Sep 17 00:00:00 2001 From: Dico200 Date: Mon, 30 May 2016 03:53:33 +0200 Subject: [PATCH 180/217] Serversigns hotfix --- main.py | 2 ++ serversigns.py | 41 +++++++++++++++++++++-------------------- 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/main.py b/main.py index fba0c5a..ffea209 100644 --- a/main.py +++ b/main.py @@ -23,6 +23,8 @@ def on_enable(): shared["modules"]["blockplacemods"].schedule_torch_breaker() if "imbusy" in shared["modules"]: shared["modules"]["imbusy"].replace_ess_commands() + if "serversigns" in shared["modules"]: + shared["modules"]["serversigns"].check_all_signs() info("RedstonerUtils enabled!") diff --git a/serversigns.py b/serversigns.py index d5a4829..c5238e1 100644 --- a/serversigns.py +++ b/serversigns.py @@ -266,8 +266,6 @@ def svs_command(sender, command, label, args): #------------------------------------------------------------------------------------------------------- - - @hook.event("player.PlayerInteractEvent") def on_click(event): if str(event.getAction()) != "RIGHT_CLICK_BLOCK": @@ -297,39 +295,37 @@ faces = { @hook.event("block.BlockBreakEvent", "monitor") def on_break(event): - try: - global checking_block - if checking_block or event.isCancelled(): - return + if checking_block or event.isCancelled(): + return - block = event.getBlock() - if block.getType() in (Material.SIGN_POST, Material.WALL_SIGN): - check_sign(event, block, attached = False) + block = event.getBlock() + if block.getType() in (Material.SIGN_POST, Material.WALL_SIGN): + check_sign(event, block, attached = False) - for block_face, data_values in faces.iteritems(): - block2 = block.getRelative(block_face) - if block2.getType() == Material.WALL_SIGN and block2.getData() in data_values: - check_sign(event, block2) + for block_face, data_values in faces.iteritems(): + block2 = block.getRelative(block_face) + if block2.getType() == Material.WALL_SIGN and block2.getData() in data_values: + check_sign(event, block2) - block3 = block.getRelative(BlockFace.UP) - if block3.getType() == Material.SIGN_POST: - check_sign(event, block3) - except: - error(trace()) + block3 = block.getRelative(BlockFace.UP) + if block3.getType() == Material.SIGN_POST: + check_sign(event, block3) def check_sign(event, block, attached = True): player = event.getPlayer() - sign = getSign(fromLoc(block.getLocation())) + loc = fromLoc(block.getLocation()) + if block.getType() not in (Material.WALL_SIGN, Material.SIGN_POST) or getSign(loc) is None: + return if not can_build2(player, block): event.setCancelled(True) msg(event.getPlayer(), signsMsg("You cannot break %s" % ("the sign attached to that block" if attached else "that sign"))) else: - loc = fromLoc(block.getLocation()) del signs[loc] save_signs() msg(player, signsMsg("Reset the %s which you just broke" % identifySign(loc))) + def can_build2(player, block): global checking_block event = BlockBreakEvent(block, player) @@ -338,3 +334,8 @@ def can_build2(player, block): checking_block = False return not event.isCancelled() + +def check_all_signs(): + for loc in signs: + if server.getWorld(loc[0]).getBlockAt(loc[1], loc[2], loc[3]).getType() not in (Material.WALL_SIGN, Material.SIGN_POST): + del signs[loc] -- 2.45.2 From d66e8f3294114b82f903effb812691e0b55e14fb Mon Sep 17 00:00:00 2001 From: Dico200 Date: Mon, 30 May 2016 04:07:09 +0200 Subject: [PATCH 181/217] Imbusy hotfix... --- imbusy.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/imbusy.py b/imbusy.py index ec6c57b..d84249d 100644 --- a/imbusy.py +++ b/imbusy.py @@ -62,7 +62,7 @@ def toggle(sender): del busy_players[sender_name] broadcast(None, sender.getDisplayName() + " &7is no longer busy...") else: - busy_players.append(sender_name) + busy_players[sender_name] = False broadcast(None, sender.getDisplayName() + " &7is now busy...") return True -- 2.45.2 From 1da9aa25785e9fd5bd09174155ad9cd1b7306273 Mon Sep 17 00:00:00 2001 From: Dico200 Date: Mon, 30 May 2016 04:15:06 +0200 Subject: [PATCH 182/217] Friends hotfix... Did I really write this code? --- friends.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/friends.py b/friends.py index 130954a..1f41212 100644 --- a/friends.py +++ b/friends.py @@ -98,7 +98,7 @@ def rem(sender, names): notafriend = [] for name in names: - player = server.Player(name) + player = server.getPlayer(name) if player: player_id = uid(player) if player_id in friends.get(sender_id, []): -- 2.45.2 From e08666995cc14436a2566cc03c250ca2e8ff0b3e Mon Sep 17 00:00:00 2001 From: Dico200 Date: Mon, 30 May 2016 04:52:10 +0200 Subject: [PATCH 183/217] Friends fix --- friends.py | 93 ++++++++++++++++++++++++++++++++---------------------- 1 file changed, 55 insertions(+), 38 deletions(-) diff --git a/friends.py b/friends.py index 1f41212..51243ac 100644 --- a/friends.py +++ b/friends.py @@ -29,6 +29,13 @@ def friendmessage(player, message): # sends a message with a prefix msg(player, "&7[&aFriends&7] " + message) +def get_player(name): + result = server.getOfflinePlayer(name) + if result is not None and (result.hasPlayedBefore() or result.isOnline()): + return result + return None + + def ls(sender): try: sender_friends = friends.get(uid(sender), False) @@ -59,21 +66,25 @@ def add(sender, names): added = [] notfound = [] friendalready = [] + added_self = False if not sender_id in friends: friends[sender_id] = [] for name in names: - player = server.getPlayer(name) + player = get_player(name) if player: player_id = uid(player) - not_yourself = player != sender + not_yourself = sender != player if not player_id in friends[sender_id]: if not_yourself: friends[sender_id].append(player_id) added.append(player.getName()) - friendmessage(player.getPlayer(), "&a&o%s &aadded you to their friends list" % stripcolors(sender.getDisplayName())) + if player.isOnline(): + friendmessage(player.getPlayer(), "&a&o%s &aadded you to their friends list" % stripcolors(sender.getDisplayName())) + else: + added_self = True else: friendalready.append(player.getName()) @@ -84,10 +95,10 @@ def add(sender, names): if added: friendmessage(sender, "&a&o%s&a added." % ", ".join(added)) if notfound: - friendmessage(sender, "&c&o%s&c not found. (must be online)" % ", ".join(notfound)) + friendmessage(sender, "&c&o%s&c not found." % ", ".join(notfound)) if friendalready: friendmessage(sender, "&c&o%s&c is/are already your friend." % ", ".join(friendalready)) - if not not_yourself: + if added_self: friendmessage(sender, "&cYou can't add yourself to your friends list.") @@ -98,18 +109,21 @@ def rem(sender, names): notafriend = [] for name in names: - player = server.getPlayer(name) + player = get_player(name) if player: player_id = uid(player) if player_id in friends.get(sender_id, []): friends[sender_id].remove(player_id) removed.append(player.getName()) - friendmessage(player.getPlayer(), "&c&o%s &cremoved you from their friends list" % stripcolors(sender.getDisplayName())) + if player.isOnline(): + friendmessage(player.getPlayer(), "&c&o%s &cremoved you from their friends list" % stripcolors(sender.getDisplayName())) else: notafriend.append(player.getName()) else: notfound.append(name) + if not friends.get(sender_id, False): + del friends[sender_id] save_friends() if removed: friendmessage(sender, "&a&o%s&a removed." % ", ".join(removed)) @@ -130,35 +144,38 @@ def fhelp(sender): @hook.command("friends") def on_friend_command(sender, command, label, args): - if not is_player(sender): - friendmessage(sender, "&c&lYou can't have friends!") + try: + if not is_player(sender): + friendmessage(sender, "&c&lYou can't have friends!") + return True + + cmd = args[0] if args else None + fargs = args[1:] + + # /friends list + if cmd in ["list", "lst", "*"]: + thread.start_new_thread(ls, (sender,)) + + # /friends clear + elif cmd in ["clear", "/"]: + clear(sender) + + # /friends add + elif cmd in ["add", "+"]: + if fargs: + add(sender, fargs) + else: + fhelp(sender) + + # /friends remove + elif cmd in ["remove", "rem", "delete", "del", "-"]: + if fargs: + rem(sender, fargs) + else: + fhelp(sender) + + else: + fhelp(sender) return True - - cmd = args[0] if args else None - fargs = args[1:] - - # /friends list - if cmd in ["list", "lst", "*"]: - thread.start_new_thread(ls, (sender,)) - - # /friends clear - elif cmd in ["clear", "/"]: - clear(sender) - - # /friends add - elif cmd in ["add", "+"]: - if fargs: - add(sender, fargs) - else: - fhelp(sender) - - # /friends remove - elif cmd in ["remove", "rem", "delete", "del", "-"]: - if fargs: - rem(sender, fargs) - else: - fhelp(sender) - - else: - fhelp(sender) - return True \ No newline at end of file + except: + error(trace()) -- 2.45.2 From 4e4acc6b3d26fe7b00231dc220b69f55dae34367 Mon Sep 17 00:00:00 2001 From: Dico200 Date: Mon, 30 May 2016 05:26:07 +0200 Subject: [PATCH 184/217] Remove sync.py file --- imbusy.py | 1 - sync.py | 21 --------------------- 2 files changed, 22 deletions(-) delete mode 100644 sync.py diff --git a/imbusy.py b/imbusy.py index d84249d..48f3e69 100644 --- a/imbusy.py +++ b/imbusy.py @@ -236,7 +236,6 @@ def tpahere_command_checker(sender, args): return tpa_command_checker(sender, args) def mail_command_checker(sender, args): - info("Mail command executed") if len(args) < 3 or args[0].lower() != "send": return True target = server.getPlayer(args[1]) diff --git a/sync.py b/sync.py deleted file mode 100644 index 0a2cd0b..0000000 --- a/sync.py +++ /dev/null @@ -1,21 +0,0 @@ -from helpers import * -from java.lang import Runnable - -class Sync_class(Runnable): - - def __init__(self,function,*args,**kwargs): - self.function = function - self.args = args - self.kwargs = kwargs - - def run(self): - self.function(self.args,self.kwargs) - - - -def sync(function): - def wrapper(*args,**kwargs): - sync_function = Sync_class(function) - server.getScheduler().runTask(server.getPluginManager().getPlugin("RedstonerUtils"),sync_function) - return None - return wrapper \ No newline at end of file -- 2.45.2 From d00301ccc3de42c6b66bf986e79ce84ca2c09d07 Mon Sep 17 00:00:00 2001 From: Dico200 Date: Mon, 30 May 2016 15:45:05 +0200 Subject: [PATCH 185/217] Updated damnspam, made block breaking check attached levers and buttons, denied clicking now mentions timeout left, tweaked command slightly to perceive setting the timeout to 0 as removing it. --- damnspam.py | 165 ++++++++++++++++++++++++++++++++++------------------ 1 file changed, 108 insertions(+), 57 deletions(-) diff --git a/damnspam.py b/damnspam.py index e9f9b84..a72c254 100644 --- a/damnspam.py +++ b/damnspam.py @@ -1,12 +1,15 @@ #pylint: disable = F0401 from helpers import * from time import time as now -import org.bukkit.event.block.BlockBreakEvent as BlockBreakEvent +import org.bukkit.Material as Material +import org.bukkit.block.BlockFace as BlockFace inputs = open_json_file("damnspam", {}) # format "x;y;z;World" accepted_inputs = ["WOOD_BUTTON", "STONE_BUTTON", "LEVER"] changing_input = False removing_input = False +max_timeout = 240 +timeout_error_str = "&cThe timeout must be -1 or within 0 and %d" % max_timeout def save_inputs(): @@ -26,29 +29,35 @@ def add_input(creator, block, timeout_off, timeout_on): } +def is_acceptable_timeout(timeout): + return (0 < timeout <= max_timeout) or timeout == -1 + + @hook.command("damnspam") def on_dammnspam_command(sender, command, label, args): - global changing_input - plugin_header(sender, "DamnSpam") + if not checkargs(sender, args, 1, 2): msg(sender, "&c/damnspam &e(Buttons/Levers)") msg(sender, "&c/damnspam &e(Levers only)") return True #Gittestlol if not is_creative(sender): - msg(sender, "&cYou can only do this in Creative mode.") + msg(sender, "&cYou can only do this in Creative mode") return True # /damnspam + destroying_input = False # if both timeouts are 0, the plugin will attempt to remove the protection if len(args) == 1: timeout_on = args[0] try: timeout_on = round(float(timeout_on), 2) - timeout_off = timeout_on - if 60 >= timeout_on <= -2 or timeout_on == 0: - msg(sender, "&cThe timeout must be within 0-60 or -1.") + if timeout_on == 0: + destroying_input = True + elif not is_acceptable_timeout(timeout_on): + msg(sender, "&cThe timeout must be -1 or within 0 and %d" % max_timeout) return True + timeout_off = timeout_on except ValueError: msg(sender, "&cThe timeout must be a number") return True @@ -60,12 +69,10 @@ def on_dammnspam_command(sender, command, label, args): try: timeout_on = round(float(timeout_on), 2) timeout_off = round(float(timeout_off), 2) - if 60 >= timeout_on <= -2 or timeout_on == 0: - timeout_on = False - if 60 >= timeout_off <= -2 or timeout_off == 0: - timeout_off = False - if timeout_on == False or timeout_off == False: - msg(sender, "&cThe timeout must be within 0-60 or -1.") + if timeout_on == 0 and timeout_off == 0: + destroying_input = True + elif not (is_acceptable_timeout(timeout_on) and is_acceptable_timeout(timeout_off)): + msg(sender, "&cThe timeout must be -1 or within 0 and %d" % max_timeout) return True except ValueError: msg(sender, "&cThe timeout must be a number") @@ -78,72 +85,116 @@ def on_dammnspam_command(sender, command, label, args): msg(sender, "&cPlease look at a button or lever while executing this command!") return True - if location_str(target) in inputs: + global changing_input + target_loc_str = location_str(target) + if target_loc_str in inputs: changing_input = True # this input already has a timeout + + type_str = ttype.lower().replace("_", " ") + # test if player is allowed to build here - test_event = BlockBreakEvent(target, sender) - server.getPluginManager().callEvent(test_event) + build_check = can_build(sender, target) changing_input = False - if test_event.isCancelled(): - msg(sender, "&cYou are not allowed to modify this %s" % str(target.getType()).lower()) + if not build_check: + msg(sender, "&cYou are not allowed to modify this %s" % type_str) return True # add block to inputs - add_input(sender, target, timeout_off, timeout_on) + if destroying_input: + if target_loc_str not in inputs: + msg(sender, "&cThere is no timeout to remove on this %s (by setting the timeout to 0)" % type_str) + return True + del inputs[target_loc_str] + msg(sender, "&aSuccessfully removed the timeout for this %s" % type_str) + else: + add_input(sender, target, timeout_off, timeout_on) + msg(sender, "&aSuccessfully set a timeout for this %s" % type_str) save_inputs() - msg(sender, "&aSuccessfully set a timeout for this %s." % ttype.lower().replace("_", " ")) return True -@hook.event("block.BlockBreakEvent", "normal") -def on_block_break(event): - global removing_input - - if removing_input: +def check_block_break(break_event, block): + if str(block.getType()) not in accepted_inputs: return - sender = event.getPlayer() - block = event.getBlock() - btype = str(block.getType()).lower() - if str(block.getType()) in accepted_inputs and not event.isCancelled(): - pos_str = location_str(block) - if inputs.get(pos_str): - if sender.isSneaking(): - # test if player is allowed to build here - removing_input = True - test_event = BlockBreakEvent(block, sender) - server.getPluginManager().callEvent(test_event) - removing_input = False - if test_event.isCancelled(): - event.setCancelled(True) - msg(sender, "&cYou are not allowed to remove this %s" % btype) - return True - inputs.pop(pos_str) # remove - save_inputs() - msg(sender, "&eSuccessfully removed this %s!" % btype) - return True - elif not changing_input: - event.setCancelled(True) - msg(sender, "&cYou cannot destroy this %s!" % btype) - msg(sender, "&c&nSneak&c and break if you want to remove it.") - return True + pos_str = location_str(block) + if pos_str not in inputs: + return + sender = break_event.getPlayer() + input_str = ("this %s" if block is break_event.getBlock() else "the %s attached to that block") % str(block.getType()).lower().replace("_", " ") + if not sender.isSneaking(): + msg(sender, "&cYou cannot destroy " + input_str) + msg(sender, "&c&nSneak&c and break or set the timeout to 0 if you want to remove it.") + break_event.setCancelled(True) + return + global removing_input + removing_input = True + success = can_build(sender, block) + removing_input = False + if success: + del inputs[pos_str] + save_inputs() + msg(sender, "&aSuccessfully removed %s!" % input_str) + else: + msg(sender, "&cYou are not allowed to remove " + input_str) + break_event.setCancelled(True) + + +# a dict for levers and buttons, with a tuple of tuples as value. The tuples in the tuple represent +# the data values which the block must have if the block were placed towards the linked blockface to be affected. +# The order is DOWN, UP, NORTH, SOUTH, WEST, EAST +attached_blocks = { + + Material.LEVER: ((0, 7, 8, 15), (5, 6, 13, 14), (4, 12), (3, 11), (2, 10), (1, 9)), + Material.STONE_BUTTON: ((0, 8), (5, 6, 7, 13, 14, 15), (4, 12), (3, 11), (2, 10), (1, 9)), + Material.WOOD_BUTTON: ((0, 8), (5, 6, 7, 13, 14, 15), (4, 12), (3, 11), (2, 10), (1, 9)), + +} + +# returns a generator containing the levers or buttons that would be broken if this block were broken +def get_attached_blocks(block): + for i, face in ((0, BlockFace.DOWN), (1, BlockFace.UP), (2, BlockFace.NORTH), (3, BlockFace.SOUTH), (4, BlockFace.WEST), (5, BlockFace.EAST)): + side = block.getRelative(face) + dvalues = attached_blocks.get(side.getType()) + if dvalues is not None and side.getData() in dvalues[i]: + yield side + + +@hook.event("block.BlockBreakEvent", "highest") +def on_block_break(event): + try: + if removing_input or changing_input or event.isCancelled(): + return + block = event.getBlock() + check_block_break(event, event.getBlock()) + for affected_block in get_attached_blocks(block): + check_block_break(event, affected_block) + except: + error(trace()) @hook.event("player.PlayerInteractEvent", "normal") def on_interact(event): if (str(event.getAction()) == "RIGHT_CLICK_BLOCK") and not event.isCancelled(): - sender = event.getPlayer() + sender = event.getPlayer() + if sender.isSneaking(): + return block = event.getClickedBlock() - btype = str(block.getType()).lower() - powered = (block.getData() & 0x8) == 0x8 if btype == "lever" else False # data > 7, but this is how bukkit does it pos_str = location_str(block) data = inputs.get(pos_str) if data: - checktime = data["timeout_on"] if powered else data["timeout_off"] + sender = event.getPlayer() + btype = str(block.getType()).lower().replace("_", " ") + if btype == "lever" and block.getData() < 8: + checktime = data["timeout_off"] + else: + checktime = data["timeout_on"] + time_left = data["last_time"] + checktime - now() + if checktime == -1: event.setCancelled(True) msg(sender, "&cThis %s is locked permanently by /damnspam." % (btype)) - elif data["last_time"] + checktime > now(): + elif time_left > 0: event.setCancelled(True) - msg(sender, "&cThis %s has a damnspam timeout of %ss." % (btype, checktime)) + msg(sender, "&cThis %s has a damnspam timeout of %.2fs, with %.2fs left." % (btype, checktime, time_left)) else: - inputs[pos_str]["last_time"] = round(now(), 2) + data["last_time"] = round(now(), 2) -- 2.45.2 From 6539c34a82b997ddf3cb00715fca838354e2c807 Mon Sep 17 00:00:00 2001 From: Dico200 Date: Mon, 30 May 2016 15:47:24 +0200 Subject: [PATCH 186/217] Removed unneeded try/except clause --- damnspam.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/damnspam.py b/damnspam.py index a72c254..b3cbb0f 100644 --- a/damnspam.py +++ b/damnspam.py @@ -161,15 +161,12 @@ def get_attached_blocks(block): @hook.event("block.BlockBreakEvent", "highest") def on_block_break(event): - try: - if removing_input or changing_input or event.isCancelled(): - return - block = event.getBlock() - check_block_break(event, event.getBlock()) - for affected_block in get_attached_blocks(block): - check_block_break(event, affected_block) - except: - error(trace()) + if removing_input or changing_input or event.isCancelled(): + return + block = event.getBlock() + check_block_break(event, event.getBlock()) + for affected_block in get_attached_blocks(block): + check_block_break(event, affected_block) @hook.event("player.PlayerInteractEvent", "normal") -- 2.45.2 From e46bea31c85aade29aa8a55f1b271ed3a974b6db Mon Sep 17 00:00:00 2001 From: Dico200 Date: Mon, 30 May 2016 21:42:30 +0200 Subject: [PATCH 187/217] Cleaned up chatalias, notable changes: Fixed remotes list and remove, improved prior alias checks for multi-aliasing, fixed color chat permission implementations, grouped the file properly, removed unreasonable complications, changed header from Alias to Chatalias, fixed a mistake where 2 threads are created per player for online players during server reload, moved a lot of repeated code to remote() base function --- chatalias.py | 366 +++++++++++++++++++++++++++------------------------ 1 file changed, 191 insertions(+), 175 deletions(-) diff --git a/chatalias.py b/chatalias.py index 9db8fdb..6febf17 100644 --- a/chatalias.py +++ b/chatalias.py @@ -33,14 +33,13 @@ permission_LIST = "utils.alias.list" permission_LIST_OTHERS = "utils.alias.list.others" # Set alias amounts/length limits, e.g. utils.alias.amount.420 permission_AMOUNT = "utils.alias.amount." +default_alias_limit = 15 permission_LENGTH = "utils.alias.length." +default_length_limit = 120 # See when the plugin was disabled due to version errors permission_INFO = "utils.alias.info" permission_FINFO = "utils.alias.finfo" -######## -# CODE # -######## def safe_open_json(uuid): if not os.path.exists("plugins/redstoner-utils.py.dir/files/aliases"): @@ -52,25 +51,91 @@ def safe_open_json(uuid): return value +def get_player_alias_limit(player): + value = get_permission_content(player, permission_AMOUNT) + if value is not None and value.isdigit(): + return int(value) + return default_alias_limit + + +def get_player_length_limit(player): + value = get_permission_content(player, permission_LENGTH) + if value is not None and value.isdigit(): + return int(value) + return default_length_limit + + +@hook.event("player.PlayerJoinEvent", "high") +def on_join(event): + 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") +def on_player_chat(event): + if enabled: + if event.isCancelled(): + return + player = event.getPlayer() + if not hasPerm(player, permission_USE): + return + msg_limit = get_player_length_limit(player) + for alias, value in data[uid(player)].iteritems(): + if player.hasPermission("essentials.chat.color"): + event.setMessage(event.getMessage().replace(colorify(alias), colorify(value))) + else: + event.setMessage(event.getMessage().replace(alias, value)) + if not player.hasPermission(permission_ALL) and len(event.getMessage()) > msg_limit: + event.setCancelled(True) + plugin_header(player, "Chatalias") + msg(player, "The message you wanted to generate would exceed the length limit limit of %d. Please make it shorter!" % msg_limit) + return + + +def hasPerm(player, permission): + return (player.hasPermission(permission)) or (player.hasPermission(permission_ALL)) + + +def disabled_fallback(receiver): + if not hasPerm(receiver, permission_INFO): + msg(receiver, colorify("&cUnknown command. Use &e/help&c, &e/plugins &cor ask a mod.")) + else: + msg(receiver, colorify("&cPlugin alias v" + alias_version + " has experienced an &eEMERGENCY SHUTDOWN:")) + msg(receiver, error_msg) + msg(receiver, colorify("&cPlease contact a dev/admin (especially pep :P) about this to take a look at it.")) + + +def can_remote(player): + return hasPerm(player, permission_LIST_OTHERS) or hasPerm(player, permission_MODIFY_OTHERS) + + +# Command + @hook.command("alias", usage="/ [...]", desc="Allows aliasing of words") def on_alias_command(sender, cmd, label, args): - if not is_player(sender): - msg(sender, "&cThe console cannot use aliases!") - return True + plugin_header(sender, "Chatalias") try: args = array_to_list(args) if not enabled: disabled_fallback(sender) - return True + return if not hasPerm(sender, permission_BASE): - plugin_header(recipient=sender, name="Alias") noperm(sender) - return True - return subcommands[args[0].lower()](sender, args[1:]) + return + if args[0].lower() != "player" and not is_player(sender): + msg(sender, "&cThe console cannot have aliases") + return + subcommands[args[0].lower()](sender, args[1:]) except: - return subcommands["help"](sender, "1") + subcommands["help"](sender, "1") + return True def help(sender, args): @@ -104,205 +169,179 @@ def help(sender, args): msg(sender, message) if page+1 < pages: msg(sender, colorify("&6To display the next page, type &c/alias help " + str(page+2))) - return True - - -@hook.event("player.PlayerJoinEvent", "high") -def on_join(event): - 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") -def on_player_chat(event): - try: - if enabled: - if event.isCancelled(): - return - player = event.getPlayer() - if not hasPerm(player, permission_USE): - return - msg_limit = int(get_permission_content(player, permission_LENGTH)) - for alias, value in data[uid(player)].iteritems(): - if player.hasPermission("essentials.chat.color"): - event.setMessage(event.getMessage().replace(colorify(alias), colorify(value))) - else: - event.setMessage(event.getMessage().replace(alias, value)) - if not player.hasPermission(permission_ALL) and len(event.getMessage()) > msg_limit: - event.setCancelled(True) - plugin_header(player, "Alias") - msg(player, "The message you wanted to generate would exceed the length limit limit of %d. Please make it shorter!" % msg_limit) - return - except: - error(trace()) - - -def hasPerm(player, permission): - return (player.hasPermission(permission)) or (player.hasPermission(permission_ALL)) - - -def disabled_fallback(receiver): - if not hasPerm(receiver, permission_INFO): - msg(receiver, colorify("&cUnknown command. Use &e/help&c, &e/plugins &cor ask a mod.")) - else: - msg(receiver, colorify("&cPlugin alias v" + alias_version + " has experienced an &eEMERGENCY SHUTDOWN:")) - msg(receiver, error_msg) - msg(receiver, colorify("&cPlease contact a dev/admin (especially pep :P) about this to take a look at it.")) - - -def can_remote(player): - return hasPerm(player, permission_LIST_OTHERS) or hasPerm(player, permission_MODIFY_OTHERS) def add(sender, args): - plugin_header(sender, "Alias") uuid = uid(sender) args = [args[0]] + [" ".join(args[1:])] if (args[0] not in data[uuid]) and is_alias_limit_reached(sender, sender): - return True - if not add_alias_data(uuid, str(args[0]), args[1]): + return + if not add_alias_data(uuid, 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 + return + msg(sender, colorify("&7Alias: ") + args[0] + colorify("&7 -> ") + args[1] + colorify("&7 was succesfully created!"), usecolor=sender.hasPermission("essentials.chat.color")) -def radd(sender, args): - 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 = server.getPlayer(args[0]) - if target == None: - msg(sender, "&cThat player is not online") - return True +def radd(sender, sender_name, target, args, silent): + if len(args) < 2: + msg(sender, "&cYou must pass a sequence and an alias for it") + return + replaced = args[0] + alias = " ".join(args[1:]) uuid = uid(target) - 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 (args[1] not in data[uuid]) and is_alias_limit_reached(target, sender, args[3].lower() == "false"): - return True - if len(args) == 3: - args += ["true"] - if not add_alias_data(uuid, str(args[1]), str(args[2])): + if not silent: + if sender is not target: + plugin_header(target, "Chatalias") + msg(target, "&cPlayer %s &cis creating an alias for you!" % sender_name) + if (replaced not in data[uuid]) and is_alias_limit_reached(target, sender, silent): + return + if not add_alias_data(uuid, replaced, alias): 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 + msg(sender, message, usecolor = False) + if not silent: + msg(target, message, usecolor = False) + return + message = colorify("&7Alias: &7%s&7 -> &7%s&7 was successfully created!") % ((colorify(replaced), colorify(alias)) if target.hasPermission("essentials.chat.color") else (replaced, alias)) + msg(sender, message, usecolor = False) + if not silent: + msg(target, message, usecolor = False) -def is_alias_limit_reached(player, recipient, not_silent = False): +def is_alias_limit_reached(player, recipient, silent = True): if player.hasPermission(permission_ALL): return False - alias_limit = int(get_permission_content(player, permission_AMOUNT)) + alias_limit = get_player_alias_limit(player) if len(data[uid(player)]) >= alias_limit: message = ("&cYour limit of %d has been reached" if player is recipient else "&cThe limit of %d has been reached for that player") % alias_limit msg(recipient, message) - if not_silent: + if not silent: msg(player, message) return True return False def add_alias_data(puuid, aliased, new_alias): - prior = data[puuid] + prior = dict(data[puuid]) + if aliased in prior: + info("Checking prior, removing previous alias for " + aliased) + del prior[aliased] # prevent 2 -> 3 if there is 1 -> 2 - if aliased not in prior: - for alias in prior.values(): - if aliased in alias: - return False + for alias in prior.values(): + if aliased in alias: + info("aliased %s in alias %s" % (aliased, alias)) + return False # prevent 1 -> 2 if there is 2 -> 3 for sequence in prior: if sequence in new_alias: + info("sequence %s in new_alias %s" % (sequence, new_alias)) return False - prior[aliased] = new_alias + data[puuid][aliased] = new_alias save_data(puuid) return True def remove(sender, args): - plugin_header(sender, "Alias") try: msg(sender, colorify("&7Successfully removed alias ") + args[0] + colorify(" &7-> ") + data[uid(sender)].pop(args[0]) + colorify("&7!"), usecolor=sender.hasPermission("essentials.chat.color")) save_data(uid(sender)) except: msg(sender, colorify("&cCould not remove alias ") + args[0] + colorify(", it does not exist."), usecolor=sender.hasPermission("essentials.chat.color")) - return True -def rremove(sender, args): - plugin_header(sender, "Alias") - target = get_player(args[0]) - if is_player(sender): - sender_name = colorify(sender.getDisplayName()) +def rremove(sender, sender_name, target, args, silent): + if len(args) < 1: + msg(sender, "&cYou must specify a sequence whose alias is to be removed") + return + removed = args[0] + uuid = uid(target) + aliases = data[uuid] + if not silent: + msg(target, "&cPlayer %s &cis removing an alias for you!" % sender_name) + if removed in aliases: + alias = aliases.pop(removed) + message = colorify("&7Alias: &7%s&7 -> &7%s&7 successfully removed!") % ((colorify(removed), colorify(alias)) if target.hasPermission("essentials.chat.color") else (removed, alias)) + msg(sender, message, usecolor = False) + if not silent: + msg(target, message, usecolor = False) + save_data(uuid) else: - sender_name = colorify("&6Console") - if args[2].lower() == "false": - plugin_header(target, "Alias") - msg(target, "&cPlayer " + sender_name + " &cis removing an alias for you!") - try: - alias = data[uid(target)].pop(args[1]) - msg(sender, colorify("&7Successfully removed alias ") + args[1] + colorify(" &7-> ") + alias + colorify("&7!"), usecolor=sender.hasPermission("essentials.chat.color")) - if args[2].lower() == "false": - msg(target, colorify("&7Successfully removed alias ") + args[1] + colorify(" &7-> ") + alias + colorify("&7!"), usecolor=sender.hasPermission("essentials.chat.color")) - save_data(uid(target)) - except: - msg(sender, colorify("&cCould not remove alias ") + args[1] + colorify(", it does not exist."), usecolor=sender.hasPermission("essentials.chat.color")) - if args[2].lower() == "false": - msg(target, colorify("&cCould not remove alias ") + args[1] + colorify(", it does not exist."), usecolor=sender.hasPermission("essentials.chat.color")) - return True + message = colorify("&cCould not remove alias &7%s&c, it does not exist") % colorify(removed) if target.hasPermission("essentials.chat.color") else removed + msg(sender, message, usecolor = False) + if not silent: + msg(target, message, usecolor = False) def list_alias(sender, args): - plugin_header(sender, "Alias") msg(sender, "&7You have a total of " + str(len(data[uid(sender)])) + " aliases:") for word, alias in data[str(uid(sender))].items(): msg(sender, colorify("&7") + word + colorify("&7 -> ") + alias, usecolor=sender.hasPermission("essentials.chat.color")) - return True -def rlist_alias(sender, args): - plugin_header(sender, "Alias") - target = get_player(args[0]) - if is_player(sender): - sender_name = colorify(sender.getDisplayName()) +def rlist_alias(sender, sender_name, target, args, silent): + aliases = data[uid(target)] + msg(sender, "&7Player %s has a total of %d aliases:" % (target.getName(), len(aliases))) + if not silent: + if sender is not target: + plugin_header(target, "Chatalias") + msg(target, "&cPlayer %s &cis listing your aliases" % sender_name) + if target.hasPermission("essentials.chat.color"): + for pair in aliases.iteritems(): + msg(sender, colorify("&7%s&7 -> %s" % pair), usecolor = False) else: - sender_name = colorify("&6Console") - if len(args) == 1: - args += ["true"] - 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") - for word, alias in data[str(uid(target))].items(): - msg(sender, colorify("&7") + word + colorify("&7 -> ") + alias, usecolor=target.hasPermission("essentials.chat.color")) - return True + for pair in aliases.iteritems(): + msg(sender, colorify("&7%s&7 -> %s") % pair, usecolor = False) def remote(sender, args): - try: - return remotes[args[1].lower()](sender, [args[0]] + args[2:]) - except: - return subcommands["help"](sender, ["2"]) + if len(args) < 2: + msg(sender, "&cAlias remotes take at least 3 arguments") + return + target_remote = remotes.get(args[1].lower()) + if target_remote is None: + msg(sender, "&cThat remote command does not exist") + return + target = server.getOfflinePlayer(args[0]) + if target is None or not (target.hasPlayedBefore() or target.isOnline()): + msg(sender, "&cThat player could not be found") + return + silent = True + if len(args) > (2 if target_remote is rlist_alias else 3 if target_remote is rremove else 4): + if args[-1].lower() == "false": + silent = sender is target or not target.isOnline() + args = args[:-1] + elif args[-1].lower() == "true": + args = args[:-1] + target_remote(sender, sender.getDisplayName() if is_player(sender) else colorify("&6Console"), target, args[2:], silent) +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, +} + + +# Storage +# MySQL Table: +# CREATE TABLE `chatalias` (`uuid` VARCHAR(36) PRIMARY KEY, `alias` TEXT); + def load_data(uuid): if use_mysql: try: @@ -350,27 +389,6 @@ def save_data_thread(uuid): conn.close() -# 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, -} - # OnModuleLoad enabled = helpers_version in helpers_versions @@ -378,9 +396,7 @@ if not enabled: error_msg = 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() + load_data(uid(player)) else: if player.hasPermission(permission_FINFO): disabled_fallback(player) -- 2.45.2 From c7d872c93b26b66a84a075fe0a6d3ed72dca473c Mon Sep 17 00:00:00 2001 From: Dico200 Date: Mon, 30 May 2016 22:55:06 +0200 Subject: [PATCH 188/217] Fix @debug decorator not returning results --- helpers.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/helpers.py b/helpers.py index da0d423..a72af2e 100755 --- a/helpers.py +++ b/helpers.py @@ -301,7 +301,7 @@ def array_to_list(array): def debug(func): def wrap(*args, **kwargs): try: - func(*args, **kwargs) + return func(*args, **kwargs) except: - print(trace()) + error(trace()) return wrap -- 2.45.2 From 5d3530242ed2088d1fca8a211e9ec05835fe9ee0 Mon Sep 17 00:00:00 2001 From: Dico200 Date: Mon, 30 May 2016 22:58:27 +0200 Subject: [PATCH 189/217] Another tiny tweak to @debug --- helpers.py | 1 + 1 file changed, 1 insertion(+) diff --git a/helpers.py b/helpers.py index a72af2e..40c313b 100755 --- a/helpers.py +++ b/helpers.py @@ -304,4 +304,5 @@ def debug(func): return func(*args, **kwargs) except: error(trace()) + return None return wrap -- 2.45.2 From edf5fa6d32d37a02613c5d99ce53fad166ced46b Mon Sep 17 00:00:00 2001 From: Dico200 Date: Mon, 30 May 2016 22:59:09 +0200 Subject: [PATCH 190/217] Fix /busy status --- imbusy.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/imbusy.py b/imbusy.py index 48f3e69..10d1bca 100644 --- a/imbusy.py +++ b/imbusy.py @@ -109,7 +109,8 @@ def status(sender, args): noperm(sender) return True if len(args) == 0: - if sender.getName() in busy_players: + sender_name = sender.getName() + if sender_name in busy_players: if busy_players[sender_name] is False: msg(sender, "&7You are currently busy.") else: @@ -120,8 +121,9 @@ def status(sender, args): target = server.getPlayer(args[0]) if target is None: msg(sender, "&7That player is not online") - elif target.getName() in busy_players: - if busy_players[target.getName()] is False: + target_name = target.getName() + elif target_name in busy_players: + if busy_players[target_name] is False: msg(sender, "&7Player %s &7is currently busy." % target.getDisplayName()) else: msg(sender, "&7Player %s &7is currently SUPER busy." % target.getDisplayName()) -- 2.45.2 From ae706e8e12fe792c2574f0f0746b2cd8d1603485 Mon Sep 17 00:00:00 2001 From: Dico200 Date: Tue, 31 May 2016 00:13:51 +0200 Subject: [PATCH 191/217] Clean up imbusy. Improve replying to busy people. All working perfectly, tested thoroughly. --- imbusy.py | 136 ++++++++++++++++++++++++++++++------------------------ 1 file changed, 75 insertions(+), 61 deletions(-) diff --git a/imbusy.py b/imbusy.py index 10d1bca..2b81973 100644 --- a/imbusy.py +++ b/imbusy.py @@ -11,6 +11,7 @@ be cleared. from helpers import * from friends import is_friend_of import org.bukkit.command.Command as Command +from time import time as now imbusy_version = "v1.1.0" @@ -18,8 +19,10 @@ base_permission = "utils.imbusy" # for /busy status use_permission = "utils.imbusy.use" # for being busy override_permission = "utils.imbusy.override" # for being able to bother busy people +busy_status_change_timeout = 2 # seconds -busy_players = {} # name : false/true where false is normal busy and true is super busy +busy_players = {} # name : (status, timeout_expire) +# possible statuses: True if SUPER busy, False if normal busy, None if not busy @hook.command("imbusy", @@ -27,6 +30,7 @@ busy_players = {} # name : false/true where false is normal busy and true is sup usage = "/ [on, off, status/check]", description = "Offers control over your busy status" ) +@debug def on_busy_command(sender, cmd, label, args): if not is_player(sender): msg(sender, "&7Sorry, Console cannot be busy") @@ -53,17 +57,47 @@ def on_busy_command(sender, cmd, label, args): return help(sender) +def change_status(target, status): + target_name = target.getName() + old_status = None + if target_name in busy_players: + value = busy_players[target_name] + time_left = value[1] - now() + if time_left > 0: + msg(target, "&cYou must wait %.2fs untill you can change your status" % time_left) + return + old_status = value[0] + + if old_status is status: + if status is True: + msg(target, "&cYou are already SUPER busy") + elif status is False: + msg(target, "&cYou are already busy") + else: + msg(target, "&cYou weren't busy yet") + return + + busy_players[target_name] = (status, now() + busy_status_change_timeout) + if status is True: + broadcast(None, target.getDisplayName() + " &7is now SUPER busy") + elif status is False: + broadcast(None, target.getDisplayName() + " &7is now busy") + else: + broadcast(None, target.getDisplayName() + " &7is not busy anymore") + + +def get_status(target): + return busy_players.get(target.getName(), (None,))[0] + + def toggle(sender): if not sender.hasPermission(use_permission): noperm(sender) return True - sender_name = sender.getName() - if sender_name in busy_players: - del busy_players[sender_name] - broadcast(None, sender.getDisplayName() + " &7is no longer busy...") + if get_status(sender) is None: + change_status(sender, False) else: - busy_players[sender_name] = False - broadcast(None, sender.getDisplayName() + " &7is now busy...") + change_status(sender, None) return True @@ -82,12 +116,7 @@ def on(sender): if not sender.hasPermission(use_permission): noperm(sender) return True - sender_name = sender.getName() - if busy_players.get(sender_name) is False: # can be None, False or True - msg(sender, "&7You are already busy!") - else: - busy_players[sender_name] = False # busy but not super busy - broadcast(None, sender.getDisplayName() + " &7is now busy...") + change_status(sender, False) return True @@ -95,12 +124,7 @@ def off(sender): if not sender.hasPermission(use_permission): noperm(sender) return True - sender_name = sender.getName() - if sender_name not in busy_players: - msg(sender, "&7You are not busy! You cannot be even less busy! Are you perhaps bored?") - return True - del busy_players[sender_name] - broadcast(None, sender.getDisplayName() + " &7is no longer busy...") + change_status(sender, None) return True @@ -109,26 +133,20 @@ def status(sender, args): noperm(sender) return True if len(args) == 0: - sender_name = sender.getName() - if sender_name in busy_players: - if busy_players[sender_name] is False: - msg(sender, "&7You are currently busy.") - else: - msg(sender, "&7You are currently SUPER busy.") - else: - msg(sender, "&7You are currently not busy.") + target = sender else: target = server.getPlayer(args[0]) if target is None: - msg(sender, "&7That player is not online") - target_name = target.getName() - elif target_name in busy_players: - if busy_players[target_name] is False: - msg(sender, "&7Player %s &7is currently busy." % target.getDisplayName()) - else: - msg(sender, "&7Player %s &7is currently SUPER busy." % target.getDisplayName()) - else: - msg(sender, "&7Player %s &7is currently not busy." % target.getDisplayName()) + msg(sender, "&cThat player is not online") + return True + status = get_status(target) + if status is True: + status_str = "SUPER busy" + elif status is False: + status_str = "busy" + else: + status_str = "not busy" + msg(sender, "&7%s currently %s" % ("You are" if target is sender else "Player %s&7 is" % target.getDisplayName()), status_str) return True @@ -136,12 +154,7 @@ def super_cmd(sender): if not sender.hasPermission(use_permission): noperm(sender) return True - sender_name = sender.getName() - if busy_players.get(sender_name) is True: - msg(sender, "&7You are already SUPER busy!") - else: - busy_players[sender_name] = True # SUPER busy - broadcast(None, sender.getDisplayName() + " &7is now SUPER busy...") + change_status(sender, True) return True @@ -152,47 +165,48 @@ def on_player_leave(event): del busy_players[player_name] -#---- Dicode for catching any bothering of busy people ---- +# Block any bothering if should be. If a busy player msgs someone else, they can be replied to and /msg'd as well. +# It's not entirely perfect in that regard as the ability to reply is lost when you are /msg'd by someone else. - -reply_targets = {} +reply_targets = {} # name : (reply_target_name, true if initiated by target) def can_send(sender, target): - if not target.getName() in busy_players: - return True if target is sender or sender.hasPermission(override_permission): return True - return busy_players[target.getName()] is False and is_friend_of(target, sender) + status = get_status(target) + if status is None: + return True + return status is False and is_friend_of(target, sender) def whisper(sender, target_name): target = server.getPlayer(target_name) if target is not None: + sender_name = sender.getName() if not can_send(sender, target): - msg(sender, "&c[&fBUSY&c] %s&r is busy!" % target.getDisplayName()) - return False + value = reply_targets[sender_name] + if value[0] != target_name or value[1] is False: + msg(sender, "&c[&fBUSY&c] %s&r is busy!" % target.getDisplayName()) + return False - reply_targets[sender.getName()] = target.getName() - - # allow the target to reply regardless of sender being busy - if target.getName() in reply_targets: - del reply_targets[target.getName()] + reply_targets[sender_name] = (target_name, False) + reply_targets[target_name] = (sender_name, True) return True def reply(sender): - if sender.getName() in reply_targets: - target = server.getPlayer(reply_targets[sender.getName()]) + sender_name = sender.getName() + if sender_name in reply_targets: + value = reply_targets[sender_name] + target = server.getPlayer(value[0]) if target is not None: - if not can_send(sender, target): + if not value[1] and not can_send(sender, target): msg(sender, "&c[&fBUSY&c] %s&r is busy!" % target.getDisplayName()) return False - # allow the target to reply regardless of sender being busy - if target.getName() in reply_targets: - del reply_targets[target.getName()] + reply_targets[target.getName()] = (sender_name, True) return True -- 2.45.2 From fe2d6eb701179054b0d0fe2e8fd10df16883179a Mon Sep 17 00:00:00 2001 From: Dico200 Date: Tue, 31 May 2016 01:00:15 +0200 Subject: [PATCH 192/217] Forgot to set this timeout back up after testing... Derp --- imbusy.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/imbusy.py b/imbusy.py index 2b81973..a8c5280 100644 --- a/imbusy.py +++ b/imbusy.py @@ -19,7 +19,7 @@ base_permission = "utils.imbusy" # for /busy status use_permission = "utils.imbusy.use" # for being busy override_permission = "utils.imbusy.override" # for being able to bother busy people -busy_status_change_timeout = 2 # seconds +busy_status_change_timeout = 15 # seconds busy_players = {} # name : (status, timeout_expire) # possible statuses: True if SUPER busy, False if normal busy, None if not busy -- 2.45.2 From 6f4357fad785f9e1f0c3d6d09ac9ea5ef3542f1b Mon Sep 17 00:00:00 2001 From: PixelSergey Date: Tue, 31 May 2016 15:39:34 +0300 Subject: [PATCH 193/217] Add lol list pageing. Tested, works perf. --- saylol.py | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/saylol.py b/saylol.py index f1854df..e031b3a 100644 --- a/saylol.py +++ b/saylol.py @@ -5,7 +5,7 @@ from random import randrange lols = open_json_file("lol", []) timeout = 15 last_msg = 0 - +list_limit = 20 def save_lols(): @@ -69,8 +69,23 @@ def on_lol_command(sender, command, label, args): noperm(sender) elif cmd == "list": - for i in range(len(lols)): + arg1 = args[1] if len(args) > 1 else None + if not arg1: + arg1 = "1" + if not arg1.isdigit() or arg1 == "0": + msg(sender, "&cUwot m8 putting invalid data here") + return True + arg1 = int(arg1) - 1 + offset = list_limit * arg1 + if offset > len(lols): + msg(sender, "&cNot enough lol to display. Please pick a smaller page number.") + return True + msg(sender, " &9&nLol list page %s" % str(arg1 + 1)) #"\t" symbol displays weirdly, hence the 4 spaces + for i in range(offset, min(offset + list_limit, len(lols))): msg(sender, "&a%s: &e%s" % (str(i).rjust(3), lols[i])) + msg(sender, "") + msg(sender, "&eFor a specific page, type &a/lol list &e.") + msg(sender, "") #emptyline elif cmd == "search": if sender.hasPermission("utils.lol.search"): @@ -95,9 +110,9 @@ def on_lol_command(sender, command, label, args): msg(sender, "&cInvalid number '&e%s&c'" % args[1]) else: - msg(sender, "&a/lol &eSay random message") - msg(sender, "&a/lol list &eList all messages") - msg(sender, "&a/lol id &eSay specific message") - msg(sender, "&a/lol add &eAdd message") - msg(sender, "&a/lol del &eDelete message") + msg(sender, "&a/lol &eSay random message") + msg(sender, "&a/lol list [page] &eList messages") + msg(sender, "&a/lol id &eSay specific message") + msg(sender, "&a/lol add &eAdd message") + msg(sender, "&a/lol del &eDelete message") return True -- 2.45.2 From 1e34a9b39bcc78bbfd43579ac2a70e19f33b679b Mon Sep 17 00:00:00 2001 From: PixelSergey Date: Tue, 31 May 2016 17:09:42 +0300 Subject: [PATCH 194/217] Fix saylol.py for dico By the way, dico, some of your line notes on the previous commit were completely wrong Once again, this has been tested I didn't clean up the code, I think it's good enough. And it works perfectly. --- saylol.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/saylol.py b/saylol.py index e031b3a..902e801 100644 --- a/saylol.py +++ b/saylol.py @@ -73,12 +73,12 @@ def on_lol_command(sender, command, label, args): if not arg1: arg1 = "1" if not arg1.isdigit() or arg1 == "0": - msg(sender, "&cUwot m8 putting invalid data here") + msg(sender, "&cInvalid argument \"%s\"" % arg1) return True arg1 = int(arg1) - 1 offset = list_limit * arg1 if offset > len(lols): - msg(sender, "&cNot enough lol to display. Please pick a smaller page number.") + msg(sender, "&cNot a valid page (too high).") return True msg(sender, " &9&nLol list page %s" % str(arg1 + 1)) #"\t" symbol displays weirdly, hence the 4 spaces for i in range(offset, min(offset + list_limit, len(lols))): -- 2.45.2 From 5d00af8cedae09b66a0569e03635a04b0b188a1e Mon Sep 17 00:00:00 2001 From: PixelSergey Date: Tue, 31 May 2016 17:34:49 +0300 Subject: [PATCH 195/217] Fix checking for page 0 in saylol.py listing I hope I'm not making this too messy --- saylol.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/saylol.py b/saylol.py index 902e801..3fe2fe5 100644 --- a/saylol.py +++ b/saylol.py @@ -72,9 +72,11 @@ def on_lol_command(sender, command, label, args): arg1 = args[1] if len(args) > 1 else None if not arg1: arg1 = "1" - if not arg1.isdigit() or arg1 == "0": + if not arg1.isdigit(): msg(sender, "&cInvalid argument \"%s\"" % arg1) return True + if int(arg1) == 0: + msg(sender, "&cPage 0 does not exist") arg1 = int(arg1) - 1 offset = list_limit * arg1 if offset > len(lols): -- 2.45.2 From f0ada788bfecd00c2d467f46bbc442af9ed1ecca Mon Sep 17 00:00:00 2001 From: Dico200 Date: Tue, 31 May 2016 16:39:54 +0200 Subject: [PATCH 196/217] Made serversigns force its commands into the command map (to replace the java plugin ServerSigns its commands) --- main.py | 2 +- serversigns.py | 21 ++++++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index ffea209..1b9e3f4 100644 --- a/main.py +++ b/main.py @@ -24,7 +24,7 @@ def on_enable(): if "imbusy" in shared["modules"]: shared["modules"]["imbusy"].replace_ess_commands() if "serversigns" in shared["modules"]: - shared["modules"]["serversigns"].check_all_signs() + shared["modules"]["serversigns"].check_all_signs_and_force_commands() info("RedstonerUtils enabled!") diff --git a/serversigns.py b/serversigns.py index c5238e1..d680acb 100644 --- a/serversigns.py +++ b/serversigns.py @@ -335,7 +335,26 @@ def can_build2(player, block): return not event.isCancelled() -def check_all_signs(): +def check_all_signs_and_force_commands(): for loc in signs: if server.getWorld(loc[0]).getBlockAt(loc[1], loc[2], loc[3]).getType() not in (Material.WALL_SIGN, Material.SIGN_POST): del signs[loc] + + try: + map_field = server.getPluginManager().getClass().getDeclaredField("commandMap") + map_field.setAccessible(True) + command_map = map_field.get(server.getPluginManager()) + + commands_field = command_map.getClass().getDeclaredField("knownCommands") + commands_field.setAccessible(True) + map = commands_field.get(command_map) + + rsutils_cmd = map.get("redstonerutils:serversigns") + info(str(rsutils_cmd)) + map.put("svs", rsutils_cmd) + map.put("serversigns", rsutils_cmd) + map.put("signsmsg", rsutils_cmd) + + except: + error("[Serversigns] failed to force commands") + error(trace()) -- 2.45.2 From 83e75055651eff3a7b1287adc61e92a35b6b03de Mon Sep 17 00:00:00 2001 From: Dico200 Date: Tue, 31 May 2016 16:41:13 +0200 Subject: [PATCH 197/217] Remove debug I forgot to remove in prior commit --- serversigns.py | 1 - 1 file changed, 1 deletion(-) diff --git a/serversigns.py b/serversigns.py index d680acb..722edf8 100644 --- a/serversigns.py +++ b/serversigns.py @@ -350,7 +350,6 @@ def check_all_signs_and_force_commands(): map = commands_field.get(command_map) rsutils_cmd = map.get("redstonerutils:serversigns") - info(str(rsutils_cmd)) map.put("svs", rsutils_cmd) map.put("serversigns", rsutils_cmd) map.put("signsmsg", rsutils_cmd) -- 2.45.2 From f0f32abbfa5cf0c3c710e5816785fd742587b5ab Mon Sep 17 00:00:00 2001 From: PixelSergey Date: Tue, 31 May 2016 17:52:56 +0300 Subject: [PATCH 198/217] Final fix to lol list pageing Can someone tell me whether it's paging or pageing or both? --- saylol.py | 1 + 1 file changed, 1 insertion(+) diff --git a/saylol.py b/saylol.py index 3fe2fe5..b9f0ccb 100644 --- a/saylol.py +++ b/saylol.py @@ -77,6 +77,7 @@ def on_lol_command(sender, command, label, args): return True if int(arg1) == 0: msg(sender, "&cPage 0 does not exist") + return True arg1 = int(arg1) - 1 offset = list_limit * arg1 if offset > len(lols): -- 2.45.2 From 13606638b735acb1112b0aee07c3bb93ffc6f310 Mon Sep 17 00:00:00 2001 From: Dico200 Date: Tue, 31 May 2016 18:03:46 +0200 Subject: [PATCH 199/217] Fix calc --- helpers.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/helpers.py b/helpers.py index 40c313b..285a0f5 100755 --- a/helpers.py +++ b/helpers.py @@ -252,6 +252,21 @@ def save_json_file(filename, obj): error("Failed to write to %s: %s" % (filename, e)) +def toggle(player, ls, name = "Toggle", add = None): + """ + Toggles presence of a player's UUID in a list + If add is given, True explicitely adds it whereas False removes it + """ + pid = uid(player) + if pid in ls or add is False: + ls.remove(pid) + msg(player, "&a%s turned off!" % name) + elif add is not False: + ls.append(pid) + msg(player, "&a%s turned on!" % name) + + + def send_JSON_message(playername, message): bukkit.Bukkit.getServer().dispatchCommand(bukkit.Bukkit.getServer().getConsoleSender(), "tellraw " + playername + " " + message) -- 2.45.2 From 2f943e8b12ac6c8c4d163fe18888e12f7f234df9 Mon Sep 17 00:00:00 2001 From: Dico200 Date: Fri, 3 Jun 2016 20:29:25 +0200 Subject: [PATCH 200/217] Add /clear to serversigns command whitelist --- serversigns.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/serversigns.py b/serversigns.py index 722edf8..cc0b119 100644 --- a/serversigns.py +++ b/serversigns.py @@ -17,7 +17,8 @@ commands_whitelist = ( "p h", "plot home", "plot h", "p home", "plotme home", "plotme h", "up", "tppos", - "seen" + "seen", + "clear", ) max_line_length = 256 -- 2.45.2 From 2c94c40c77dcfd10a5c05e89c7119c17c22c82e2 Mon Sep 17 00:00:00 2001 From: Dico200 Date: Sun, 5 Jun 2016 13:51:12 +0200 Subject: [PATCH 201/217] Remove /clear from commands whitelist for the time being --- serversigns.py | 1 - 1 file changed, 1 deletion(-) diff --git a/serversigns.py b/serversigns.py index cc0b119..1b6742e 100644 --- a/serversigns.py +++ b/serversigns.py @@ -18,7 +18,6 @@ commands_whitelist = ( "up", "tppos", "seen", - "clear", ) max_line_length = 256 -- 2.45.2 From 8e2ff33dbbdcc52e869d697697a5000771f83476 Mon Sep 17 00:00:00 2001 From: Dico200 Date: Sun, 5 Jun 2016 17:46:35 +0200 Subject: [PATCH 202/217] Serversigns permissions fix, adapted help page to user permissions, implemented help pages --- serversigns.py | 133 +++++++++++++++++++++++++++++++++++-------------- 1 file changed, 95 insertions(+), 38 deletions(-) diff --git a/serversigns.py b/serversigns.py index 1b6742e..4fe952e 100644 --- a/serversigns.py +++ b/serversigns.py @@ -4,6 +4,7 @@ import org.bukkit.Material as Material import java.util.UUID as UUID import org.bukkit.Material as Material import org.bukkit.block.BlockFace as BlockFace +from math import ceil commands_whitelist = ( "mail", "email", "memo", @@ -22,6 +23,7 @@ commands_whitelist = ( max_line_length = 256 max_lines = 20 +help_page_size = 12 def load_signs(): signs_obj = open_json_file("serversigns", []) @@ -103,6 +105,46 @@ def signsMsg(msg, colour = '4'): return "&c[Signs] &" + colour + msg +# /svs command + + +subcommand_info = ( + + (("claim",), ( + "Claims the sign so that you can add messages to it", + ), (("[owner]", "claims.other"),)), + (("info", "lines"), ( + "Displays information about the (claimed) sign", + )), + (("add",), ( + "Adds the message to the sign. Use ++ at the end", + "to add the message to your buffer. You can then use", + "the same command again to create a longer message", + ), (("[++]", None),)), + (("remove", "rem", "del", "delete"), ( + "Removes the message with the given ID from the sign.", + "The ID is given before each message by &b/svs info&a.", + ), (("", None),)), + (("switch", "reverse"), ( + "Reverses the order in which the given messages are shown.", + ), ((" ", None),)), + (("clear",), ( + "Removes all messages from the sign.", + )), + (("reset", "unclaim"), ( + "Resets the sign, removing all messages and its owner.", + )), + (("whitelist", "commands", "wl"), ( + "Displays a list of whitelisted commands", + )), + (("help",), ( + "Displays this help page", + ), (("[page]", None),)), + +) + + + @simplecommand(cmd = "serversigns", aliases = ["svs", "signmsg"], description = "Makes something happen when you right click signs. \nUse /svs help for more details.", usage = "[++]|remove |clear|info|help>", @@ -110,40 +152,55 @@ def signsMsg(msg, colour = '4'): senderLimit = 0) def svs_command(sender, command, label, args): arg1 = args[0].lower() - Validate.isTrue(arg1 in ("claim", "reset", "add", "remove", "rem", "del", "delete", "info", "lines", - "clear", "help", "switch", "reverse", "unclaim", "commands", "whitelist", "wl"), - signsMsg("That argument could not be recognized, use &o/svs help &4for expected arguments")) - Validate.isAuthorized(sender, "utils.serversigns." + arg1) + + cmd_info = None + for cmd in subcommand_info: + if arg1 in cmd[0]: + cmd_info = cmd + break + + Validate.notNone(cmd_info, signsMsg("That command could not be recognized, use &o/svs help &4for expected arguments")) + cmd = cmd_info[0][0] + Validate.isAuthorized(sender, "utils.serversigns." + cmd) #-------------------- Sub commands that don't require any conditions ----------------------- - if arg1 == "help": - admin = sender.hasPermission("utils.serversigns.admin") - msg = signsMsg("Server signs lets you add messages to a sign.", 'a') - msg += "\nRight clicking the sign will display all the messages. Commands" - msg += "\ncan also be added, by prefixing the message with a '/'." - msg += "\nHow to use &b/serversigns&a:" - msg += "\n&b/svs claim" + ("" if not sender.hasPermission("utils.serversigns.admin") else " [owner]") - msg += "\n&a- Claims the sign so that you can add messages to it" - msg += "\n&b/svs info|lines" - msg += "\n&a- Displays information about the (claimed) sign" - msg += "\n&b/svs add [++]" - msg += "\n&a- Adds the message to the sign. Use ++ at the end" - msg += "\n&a- to add the message to your buffer. You can then use" - msg += "\n&a- the same command again to create a longer message." - msg += "\n&b/svs remove " - msg += "\n&a- Removes the message with the given ID from the sign." - msg += "\n&a- The ID is given before each message by &b/svs info&a." - msg += "\n&b/svs switch|reverse " - msg += "\n&a- Reverses the order in which the given messages are shown." - msg += "\n&b/svs clear" - msg += "\n&a- Removes all messages from the sign." - msg += "\n&b/svs reset|unclaim" - msg += "\n&a- Resets the sign, removing all messages and its owner." - msg += "\n&b/svs commands|whitelist|wl" - msg += "\n&a- Shows a list of whitelisted commands" - return msg + if cmd == "help": + all_lines = [ + "&aServer signs let's you add messages to a sign.", + "Right clicking the sign will display all the messages. Commands", + "can also be added, by prefixing the message with a '/'.", + "How to use &b/serversigns&a:", + ] - if arg1 in ("commands", "whitelist", "wl"): + for cmd in subcommand_info: + if sender.hasPermission("utils.serversigns." + cmd[0][0]): + params = "" + if len(cmd) == 3: + for param, perm in cmd[2]: + if perm is None or sender.hasPermission("utils.serversigns." + perm): + params += param + " " + all_lines.append("&b/svs %s %s" % ("|".join(cmd[0]), params)) + for info_line in cmd[1]: + all_lines.append("&a- " + info_line) + + last_page = int(ceil(len(all_lines) / help_page_size)) + info("last page: %d" % last_page) + page = 1 + if len(args) > 1 and args[1].isdigit(): + page = int(args[1]) + if page <= 0: + page = 1 + elif page > last_page: + page = last_page + + first_line = signsMsg("Serversigns help page %d" % page, '6') + if page < last_page: + first_line += ", &e/svs help %d&6 for the next" % (page + 1) + page_lines = [first_line] + all_lines[(page - 1) * help_page_size : min(page * help_page_size, len(all_lines))] + return "\n".join(page_lines) + + + if cmd == "whitelist": return signsMsg("Whitelisted commands: &3" + ", ".join(commands_whitelist), 'a') #------------------------------------------------------------------------------------------- @@ -156,7 +213,7 @@ def svs_command(sender, command, label, args): arg2 = args[1].lower() if len(args) > 1 else None #------------------------ Sub commands that require the block to be a sign ------------------------------- - if arg1 == "claim": + if cmd == "claim": Validate.isTrue(not sign, signsMsg("The %s was already claimed" % signName)) Validate.isTrue(can_build2(sender, block), signsMsg("You are not permitted to claim signs here")) target = sender @@ -180,7 +237,7 @@ def svs_command(sender, command, label, args): Validate.notNone(sign, signsMsg("The %s has not been claimed" % signName)) #----------------------Sub commands that require the sign to be claimed as well------------------------------------ - if arg1 in ("info", "lines"): + if cmd == "info": sign_lines = "" for id, line in enumerate(sign[1:]): sign_lines += ("\n &a%s: \"&f%s&a\"" % (id + 1, line)) @@ -190,7 +247,7 @@ def svs_command(sender, command, label, args): Validate.isTrue(canEdit(sign, sender), signsMsg("You do not own the %s!" % signName)) #---------------------- Sub commands that require you to own targeted sign as well ------------------------- - if arg1 == "add": + if cmd == "add": Validate.isTrue(len(sign) - 1 <= max_lines, signsMsg("This sign already has the maximum amount of lines, you cannot add more")) line = " ".join(args[1:]) @@ -227,7 +284,7 @@ def svs_command(sender, command, label, args): return signsMsg("Added line \"&f%s&a\" to the %s" % (line, signName), 'a') - if arg1 in ("remove", "rem", "del", "delete"): + if cmd == "remove": Validate.notNone(arg2, signsMsg("You have to enter the ID of the message to remove!")) try: id = int(arg2) @@ -238,7 +295,7 @@ def svs_command(sender, command, label, args): return signsMsg("Removed message with id %s from the %s" % (id, signName), 'a') - if arg1 in ("switch", "reverse"): + if cmd == "switch": Validate.isTrue(len(args) == 3, signsMsg("You have to enter the 2 IDs of the messages to reverse")) try: id1 = int(args[1]) @@ -252,13 +309,13 @@ def svs_command(sender, command, label, args): return signsMsg("Reversed the messages with IDs %s and %s of the %s" % (id1, id2, signName), 'a') - if arg1 == "clear": + if cmd == "clear": signs[loc] = [sign[0]] save_signs() return signsMsg("Removed all messages from the %s" % signName, 'a') - if arg1 in ("reset", "unclaim"): + if cmd == "reset": del signs[loc] save_signs() return signsMsg("Removed all messages and the owner from the %s, it can now be claimed" % signName, 'a') -- 2.45.2 From f5c51645d28ff9e2ded97924d491900be2860ead Mon Sep 17 00:00:00 2001 From: psrcek Date: Sun, 12 Jun 2016 13:34:33 +0200 Subject: [PATCH 203/217] Fixed typo --- blockplacemods.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/blockplacemods.py b/blockplacemods.py index d012e54..37027f4 100644 --- a/blockplacemods.py +++ b/blockplacemods.py @@ -185,7 +185,7 @@ def toggle_command(sender, command, label, args): return " &cAlready disabled: " + details[1] if arglen == 2 and not arg2.isdigit(): - return " &cArgument '%s' was not recognized. \nUse &o/toggle %s details &cfor more detailsrmation." % (arg2, setting) + return " &cArgument '%s' was not recognized. \nUse &o/toggle %s info &cfor more information." % (arg2, setting) if not enabled: values[uuid] = {} -- 2.45.2 From a6ea05a4599dd54f15fc1b164b7ff61cb17b6005 Mon Sep 17 00:00:00 2001 From: Dico200 Date: Sun, 12 Jun 2016 18:04:17 +0200 Subject: [PATCH 204/217] made /check display email not confirmed warning --- check.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/check.py b/check.py index 33ffb57..3eb4026 100644 --- a/check.py +++ b/check.py @@ -35,11 +35,11 @@ def get_website_data(player): conn = zxJDBC.connect(mysql_database, mysql_user, mysql_pass, "com.mysql.jdbc.Driver") curs = conn.cursor() uuid = str(uid(player)).replace("-", "") - curs.execute("SELECT DISTINCT `id`, `email` FROM users WHERE `uuid` = ? LIMIT 1", (uuid,)) + curs.execute("SELECT DISTINCT `id`, `email`, `confirmed` FROM users WHERE `uuid` = ? LIMIT 1", (uuid,)) results = curs.fetchall() curs.close() conn.close() - return ("http://redstoner.com/users/%s" % results[0][0], results[0][1]) if results else (None, None) + return ("http://redstoner.com/users/%s" % results[0][0], results[0][1], False if results[0][2] == 0 else True) if results else (None, None, True) # receive country based on the user's IP @@ -68,6 +68,8 @@ def get_all_data(sender, player): website = get_website_data(player) msg(sender, "&6> Website account: &e%s" % website[0]) msg(sender, "&6> email: &e%s" % website[1]) + if not website[2]: + msg(sender, "&6> &cEmail NOT Confirmed!") msg(sender, "&7 -- Data provided by ipinfo.io") msg(sender, "&6> Country: &e%s" % get_country(data)) msg(sender, "&7 -- Data provided by Mojang") -- 2.45.2 From 6320d78a37683966c781b66b40997498c1baeee7 Mon Sep 17 00:00:00 2001 From: Dico200 Date: Sun, 12 Jun 2016 18:13:42 +0200 Subject: [PATCH 205/217] Mysql update tweak --- chatalias.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/chatalias.py b/chatalias.py index 6febf17..67de106 100644 --- a/chatalias.py +++ b/chatalias.py @@ -6,6 +6,7 @@ import org.bukkit as bukkit from org.bukkit import * from helpers import * + # Version number and requirements alias_version = "2.1.0" @@ -131,7 +132,7 @@ def on_alias_command(sender, cmd, label, args): return if args[0].lower() != "player" and not is_player(sender): msg(sender, "&cThe console cannot have aliases") - return + return True subcommands[args[0].lower()](sender, args[1:]) except: subcommands["help"](sender, "1") @@ -381,9 +382,8 @@ def save_data(uuid): def save_data_thread(uuid): conn = zxJDBC.connect(mysql_database, mysql_user, mysql_pass, "com.mysql.jdbc.Driver") curs = conn.cursor() - value = json_dumps(data[uuid]) - curs.execute("INSERT INTO `chatalias` VALUES (?, ?) ON DUPLICATE KEY UPDATE `alias` = ?;", - (uuid, value, value)) + curs.execute("INSERT INTO `chatalias` (`uuid`, `alias`) VALUES (?, ?) ON DUPLICATE KEY UPDATE `alias` = VALUES(`alias`);", + (uuid, json_dumps(data[uuid]))) conn.commit() curs.close() conn.close() -- 2.45.2 From cebdb90d601cf4cb0889212cc804893a112f10e7 Mon Sep 17 00:00:00 2001 From: Dico200 Date: Sun, 12 Jun 2016 20:02:06 +0200 Subject: [PATCH 206/217] Fix cycle for 1.10 (will break in 1.8 now..) --- cycle.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cycle.py b/cycle.py index 2caeac2..17889c9 100644 --- a/cycle.py +++ b/cycle.py @@ -56,7 +56,7 @@ def on_slot_change(event): def do_cycle(player, down): inv = player.getInventory() - items = inv.getContents() + items = inv.getStorageContents() shift = -9 if down else 9 shift = shift % len(items) for _ in range(4): @@ -64,7 +64,7 @@ def do_cycle(player, down): uniq_items = sorted(set(list(items)[:9])) # get unique inventory if uniq_items != [None]: # row not empty break - inv.setContents(items) + inv.setStorageContents(items) def save_cyclers(): save_json_file("cycle", no_cyclers) \ No newline at end of file -- 2.45.2 From 1602ad2185907543e19de100d0c8088150254c2a Mon Sep 17 00:00:00 2001 From: psrcek Date: Tue, 21 Jun 2016 21:46:48 +0200 Subject: [PATCH 207/217] Fix for bug, where you can shift click and toggle levers --- damnspam.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/damnspam.py b/damnspam.py index b3cbb0f..a81d3cf 100644 --- a/damnspam.py +++ b/damnspam.py @@ -173,8 +173,6 @@ def on_block_break(event): def on_interact(event): if (str(event.getAction()) == "RIGHT_CLICK_BLOCK") and not event.isCancelled(): sender = event.getPlayer() - if sender.isSneaking(): - return block = event.getClickedBlock() pos_str = location_str(block) data = inputs.get(pos_str) -- 2.45.2 From 00e936532a93940f41603f18adb37a9a14b268a8 Mon Sep 17 00:00:00 2001 From: psrcek Date: Tue, 21 Jun 2016 22:12:13 +0200 Subject: [PATCH 208/217] Added max page number --- saylol.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/saylol.py b/saylol.py index b9f0ccb..c5a0705 100644 --- a/saylol.py +++ b/saylol.py @@ -83,7 +83,7 @@ def on_lol_command(sender, command, label, args): if offset > len(lols): msg(sender, "&cNot a valid page (too high).") return True - msg(sender, " &9&nLol list page %s" % str(arg1 + 1)) #"\t" symbol displays weirdly, hence the 4 spaces + msg(sender, " &9&nLol list page %s/%s" % (str(arg1 + 1), str(int(len(lols) / list_limit)))) #"\t" symbol displays weirdly, hence the 4 spaces for i in range(offset, min(offset + list_limit, len(lols))): msg(sender, "&a%s: &e%s" % (str(i).rjust(3), lols[i])) msg(sender, "") -- 2.45.2 From 5788cd0b3e2ae37340418d8e546ea245b2d78e21 Mon Sep 17 00:00:00 2001 From: psrcek Date: Wed, 22 Jun 2016 15:13:35 +0200 Subject: [PATCH 209/217] Fixed page showing 1 page too little --- saylol.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/saylol.py b/saylol.py index c5a0705..e79edf1 100644 --- a/saylol.py +++ b/saylol.py @@ -83,7 +83,7 @@ def on_lol_command(sender, command, label, args): if offset > len(lols): msg(sender, "&cNot a valid page (too high).") return True - msg(sender, " &9&nLol list page %s/%s" % (str(arg1 + 1), str(int(len(lols) / list_limit)))) #"\t" symbol displays weirdly, hence the 4 spaces + msg(sender, " &9&nLol list page %s/%s" % (str(arg1 + 1), str(int(len(lols) / list_limit) + 1))) #"\t" symbol displays weirdly, hence the 4 spaces for i in range(offset, min(offset + list_limit, len(lols))): msg(sender, "&a%s: &e%s" % (str(i).rjust(3), lols[i])) msg(sender, "") -- 2.45.2 From ae44dade8005bcdcb2cb7328c70c428c2ed723f4 Mon Sep 17 00:00:00 2001 From: psrcek Date: Wed, 22 Jun 2016 15:21:28 +0200 Subject: [PATCH 210/217] fixed derp, should use math.ceil instead of +1 --- saylol.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/saylol.py b/saylol.py index e79edf1..fce356e 100644 --- a/saylol.py +++ b/saylol.py @@ -1,6 +1,7 @@ from time import time from helpers import * from random import randrange +import math lols = open_json_file("lol", []) timeout = 15 @@ -83,7 +84,7 @@ def on_lol_command(sender, command, label, args): if offset > len(lols): msg(sender, "&cNot a valid page (too high).") return True - msg(sender, " &9&nLol list page %s/%s" % (str(arg1 + 1), str(int(len(lols) / list_limit) + 1))) #"\t" symbol displays weirdly, hence the 4 spaces + msg(sender, " &9&nLol list page %s/%s" % (str(arg1 + 1), str(int(math.ceil(len(lols) / list_limit))))) #"\t" symbol displays weirdly, hence the 4 spaces for i in range(offset, min(offset + list_limit, len(lols))): msg(sender, "&a%s: &e%s" % (str(i).rjust(3), lols[i])) msg(sender, "") -- 2.45.2 From 5da7180bfd89e8fe3ac57a84ba3a2d027bdb1715 Mon Sep 17 00:00:00 2001 From: psrcek Date: Wed, 22 Jun 2016 15:35:52 +0200 Subject: [PATCH 211/217] derp... integer division --- saylol.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/saylol.py b/saylol.py index fce356e..0d74506 100644 --- a/saylol.py +++ b/saylol.py @@ -84,7 +84,7 @@ def on_lol_command(sender, command, label, args): if offset > len(lols): msg(sender, "&cNot a valid page (too high).") return True - msg(sender, " &9&nLol list page %s/%s" % (str(arg1 + 1), str(int(math.ceil(len(lols) / list_limit))))) #"\t" symbol displays weirdly, hence the 4 spaces + msg(sender, " &9&nLol list page %s/%s" % (str(arg1 + 1), str(int(math.ceil(len(lols) / float(list_limit)))))) #"\t" symbol displays weirdly, hence the 4 spaces for i in range(offset, min(offset + list_limit, len(lols))): msg(sender, "&a%s: &e%s" % (str(i).rjust(3), lols[i])) msg(sender, "") -- 2.45.2 From a2daa5c0b67c09470050b2a050b2cb4173a36383 Mon Sep 17 00:00:00 2001 From: psrcek Date: Wed, 22 Jun 2016 15:48:20 +0200 Subject: [PATCH 212/217] removed unnecesarry str calls --- saylol.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/saylol.py b/saylol.py index 0d74506..84172af 100644 --- a/saylol.py +++ b/saylol.py @@ -84,7 +84,7 @@ def on_lol_command(sender, command, label, args): if offset > len(lols): msg(sender, "&cNot a valid page (too high).") return True - msg(sender, " &9&nLol list page %s/%s" % (str(arg1 + 1), str(int(math.ceil(len(lols) / float(list_limit)))))) #"\t" symbol displays weirdly, hence the 4 spaces + msg(sender, " &9&nLol list page %s/%s" % (arg1 + 1, int(math.ceil(len(lols) / float(list_limit))))) #"\t" symbol displays weirdly, hence the 4 spaces for i in range(offset, min(offset + list_limit, len(lols))): msg(sender, "&a%s: &e%s" % (str(i).rjust(3), lols[i])) msg(sender, "") -- 2.45.2 From fd368a8aac7e7eb0a0220476c9d68681dc6ae3d3 Mon Sep 17 00:00:00 2001 From: Dico Date: Thu, 23 Jun 2016 05:21:24 +0200 Subject: [PATCH 213/217] Patch buggy movement blocking when logging in Added a separate event handler for PlayerMoveEvent which instead of cancelling the event, sets the new position to the old one. This should fix the buggy, flashy screen you get when you move your cursor while not yet logged in. --- loginsecurity.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/loginsecurity.py b/loginsecurity.py index 4fbb307..d1607ef 100644 --- a/loginsecurity.py +++ b/loginsecurity.py @@ -12,7 +12,7 @@ from player import get_py_player, py_players wait_time = 30 #seconds admin_perm = "utils.loginsecurity.admin" min_pass_length = 8 -blocked_events = ["block.BlockBreakEvent", "block.BlockPlaceEvent", "player.PlayerMoveEvent","player.AsyncPlayerChatEvent"] +blocked_events = ["block.BlockBreakEvent", "block.BlockPlaceEvent", "player.AsyncPlayerChatEvent"] @@ -273,4 +273,10 @@ def pre_command_proccess(event): args = event.getMessage().split(" ") if not args[0].lower() == "/login": msg(player.player, "&4You need to login before you do that!") - event.setCancelled(True) \ No newline at end of file + event.setCancelled(True) + +@hook.event("player.PlayerMoveEvent","normal") +def player_move(event): + user = get_py_player(event.getPlayer()) + if user.logging_in: + event.setTo(event.getFrom()) -- 2.45.2 From 2b803e8de818302e2a13f76cc5b248e24bf0ef24 Mon Sep 17 00:00:00 2001 From: psrcek Date: Wed, 3 Aug 2016 21:57:40 +0200 Subject: [PATCH 214/217] Added psrcek to pythoners --- misc.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/misc.py b/misc.py index 026650e..e495317 100644 --- a/misc.py +++ b/misc.py @@ -216,7 +216,8 @@ pythoners = ( "e452e012-2c82-456d-853b-3ac8e6b581f5", # Nemes "ae795aa8-6327-408e-92ab-25c8a59f3ba1", # jomo "d2693e91-93e1-4e3f-929f-f38e1ce8df03", # Pepich1851 - "51f2ad3c-6cc8-40ea-aa2b-f25970316921" # Dico200 + "51f2ad3c-6cc8-40ea-aa2b-f25970316921", # Dico200 + "15ad0e60-8691-4e29-9de9-2d6b538bf56d" # psrcek ) @simplecommand("pyeval", -- 2.45.2 From 94accc238a61fbef836cb98ddfd704300f126f78 Mon Sep 17 00:00:00 2001 From: psrcek Date: Wed, 3 Aug 2016 23:48:15 +0200 Subject: [PATCH 215/217] Delete plotter.py We have https://github.com/RedstonerServer/Parcels now. --- plotter.py | 30 ------------------------------ 1 file changed, 30 deletions(-) delete mode 100644 plotter.py diff --git a/plotter.py b/plotter.py deleted file mode 100644 index d598554..0000000 --- a/plotter.py +++ /dev/null @@ -1,30 +0,0 @@ -#!/usr/bin/python - -""" -*Very basic* start of a custom plot-plugin like PlotMe -on hold because the PlotMe developer continued to develop PlotMe -""" - -import sys - -x_plot_size = 3 -z_plot_size = 3 -padding = 1 - -def base_coords(x, z): - pid = plot_id(x, z) - return [pid[0] * (x_plot_size + padding), pid[1] * (z_plot_size + padding)] - -def bounds(x, z): - base = base_coords(x, z) - return [base, [base[0] + x_plot_size, base[1] + z_plot_size]] - -def plot_id(x, z): - return [x // (x_plot_size + padding), z // (z_plot_size + padding)] - - -x = int(sys.argv[1]) -z = int(sys.argv[2]) -print "id: %s" % plot_id(x, z) -print "base: %s" % base_coords(x, z) -print "bounds: %s" % bounds(x, z) -- 2.45.2 From 6e497a266270d8ad6ee561abe0cb0e1d7943ce5f Mon Sep 17 00:00:00 2001 From: psrcek Date: Thu, 4 Aug 2016 13:13:56 +0200 Subject: [PATCH 216/217] Fix for bug, where you can use cg without logging in https://redstoner.com/forums/threads/3653-chatgroup-bug --- chatgroups.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/chatgroups.py b/chatgroups.py index be29e53..b3838a0 100644 --- a/chatgroups.py +++ b/chatgroups.py @@ -102,8 +102,9 @@ def save_groups(): @hook.event("player.AsyncPlayerChatEvent", "normal") def on_chat(event): sender = event.getPlayer() + user = get_py_player(sender) msge = event.getMessage() - if not event.isCancelled(): + if (not user.logging_in) and (not event.isCancelled()): sender_id = uid(sender) key = get_key(sender_id) keylen = len(key) -- 2.45.2 From 347f6969bf411b160b2fc734a2c52bd4dea6a5be Mon Sep 17 00:00:00 2001 From: psrcek Date: Sun, 11 Sep 2016 19:25:45 +0200 Subject: [PATCH 217/217] Teleport the player twice to fix #50 --- punishments.py | 1 + 1 file changed, 1 insertion(+) diff --git a/punishments.py b/punishments.py index 4b57be1..886d026 100644 --- a/punishments.py +++ b/punishments.py @@ -55,6 +55,7 @@ class Slave(object): def update(self): self.blocks -= 1 if self.blocks <= 0: + server.getPlayer(juuid(self.get_uuid())).teleport(server.getWorld(spawn_world).getSpawnLocation()) server.getPlayer(juuid(self.get_uuid())).teleport(server.getWorld(spawn_world).getSpawnLocation()) slaves.remove(self) save_slaves() -- 2.45.2