From cffa3e27c87f60667fe77a717b75ea47e67e5629 Mon Sep 17 00:00:00 2001 From: Dico200 Date: Sat, 25 Jun 2016 11:57:43 +0200 Subject: Replaced serversigns interception implementation with the tool from misc too --- main.py | 2 +- serversigns.py | 36 +++++++++++++++++++++--------------- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/main.py b/main.py index 18bfcab..88b9c57 100644 --- a/main.py +++ b/main.py @@ -22,7 +22,7 @@ def on_enable(): if "blockplacemods" in shared["modules"]: shared["modules"]["blockplacemods"].schedule_torch_breaker() if "serversigns" in shared["modules"]: - shared["modules"]["serversigns"].check_all_signs_and_force_commands() + shared["modules"]["serversigns"].check_all_signs() info("RedstonerUtils enabled!") diff --git a/serversigns.py b/serversigns.py index 4fe952e..9241ee6 100644 --- a/serversigns.py +++ b/serversigns.py @@ -392,25 +392,31 @@ def can_build2(player, block): return not event.isCancelled() -def check_all_signs_and_force_commands(): +def check_all_signs(): + """ + Check if all registered signs have an associated sign block in the world. + WorldEdit commands could remove them without notification. + Pistons might also be able to achieve the same thing. + A sign missing from the world won't affect the world so it only checks on start. + """ + 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()) +try: + CommandInterceptions = shared["modules"]["misc"].CommandInterceptions + rsutils_cmd = CommandInterceptions.cmd_map.get("redstonerutils:serversigns") + label = rsutils_cmd.getLabel() - commands_field = command_map.getClass().getDeclaredField("knownCommands") - commands_field.setAccessible(True) - map = commands_field.get(command_map) + def interception(sender, args): + rsutils_cmd.execute(sender, label, args) + return False - rsutils_cmd = map.get("redstonerutils:serversigns") - map.put("svs", rsutils_cmd) - map.put("serversigns", rsutils_cmd) - map.put("signsmsg", rsutils_cmd) + def tab_completetion(original, sender, alias, args): + return rsutils_cmd.tabComplete(sender, alias, args) - except: - error("[Serversigns] failed to force commands") - error(trace()) + shared["modules"]["misc"].CommandInterceptions.register("serversigns", "serversigns", interception, tab_completion) +except: + error("[Serversigns] failed to force commands") + error(trace()) -- cgit v1.2.3