Added command intercepter tool, used it for //calc #49

Closed
Dico200 wants to merge 8 commits from command-intercepter into dev
2 changed files with 22 additions and 16 deletions
Showing only changes of commit cffa3e27c8 - Show all commits

View File

@ -22,7 +22,7 @@ def on_enable():
if "blockplacemods" in shared["modules"]: if "blockplacemods" in shared["modules"]:
shared["modules"]["blockplacemods"].schedule_torch_breaker() shared["modules"]["blockplacemods"].schedule_torch_breaker()
if "serversigns" in shared["modules"]: if "serversigns" in shared["modules"]:
shared["modules"]["serversigns"].check_all_signs_and_force_commands() shared["modules"]["serversigns"].check_all_signs()
info("RedstonerUtils enabled!") info("RedstonerUtils enabled!")

View File

@ -392,25 +392,31 @@ def can_build2(player, block):
return not event.isCancelled() 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: 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): if server.getWorld(loc[0]).getBlockAt(loc[1], loc[2], loc[3]).getType() not in (Material.WALL_SIGN, Material.SIGN_POST):
del signs[loc] del signs[loc]
try: try:
map_field = server.getPluginManager().getClass().getDeclaredField("commandMap") CommandInterceptions = shared["modules"]["misc"].CommandInterceptions
map_field.setAccessible(True) rsutils_cmd = CommandInterceptions.cmd_map.get("redstonerutils:serversigns")
command_map = map_field.get(server.getPluginManager()) label = rsutils_cmd.getLabel()
commands_field = command_map.getClass().getDeclaredField("knownCommands") def interception(sender, args):
commands_field.setAccessible(True) rsutils_cmd.execute(sender, label, args)
map = commands_field.get(command_map) return False
rsutils_cmd = map.get("redstonerutils:serversigns") def tab_completetion(original, sender, alias, args):
map.put("svs", rsutils_cmd) return rsutils_cmd.tabComplete(sender, alias, args)
map.put("serversigns", rsutils_cmd)
map.put("signsmsg", rsutils_cmd)
shared["modules"]["misc"].CommandInterceptions.register("serversigns", "serversigns", interception, tab_completion)
except: except:
error("[Serversigns] failed to force commands") error("[Serversigns] failed to force commands")
error(trace()) error(trace())