Added command intercepter tool, used it for //calc #49
105
imbusy.py
105
imbusy.py
@ -209,38 +209,16 @@ def reply(sender):
|
|||||||
reply_targets[target.getName()] = (sender_name, True)
|
reply_targets[target.getName()] = (sender_name, True)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
try:
|
||||||
|
|
||||||
class CommandWrapper(Command):
|
def msg_interception(sender, args):
|
||||||
|
return not is_player(sender) or len(args) <= 1 or whisper(sender, args[0])
|
||||||
|
|
||||||
def __init__(self, wrapped, checker):
|
def reply_interception(sender, args):
|
||||||
Command.__init__(self, wrapped.getName())
|
return not is_player(sender) or len(args) == 0 or reply(sender)
|
||||||
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):
|
def tpa_interception(sender, args):
|
||||||
try:
|
if len(args) == 0 or not is_player(sender):
|
||||||
if not is_player(sender) or 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
|
return True
|
||||||
target = server.getPlayer(args[0])
|
target = server.getPlayer(args[0])
|
||||||
if target is not None and not can_send(sender, target):
|
if target is not None and not can_send(sender, target):
|
||||||
@ -248,11 +226,11 @@ def tpa_command_checker(sender, args):
|
|||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def tpahere_command_checker(sender, args):
|
def tpahere_interception(sender, args):
|
||||||
return tpa_command_checker(sender, args)
|
return tpa_command_checker(sender, args)
|
||||||
|
|
||||||
def mail_command_checker(sender, args):
|
def mail_interception(sender, args):
|
||||||
if len(args) < 3 or args[0].lower() != "send":
|
if len(args) < 3 or args[0].lower() != "send" or not is_player(sender):
|
||||||
return True
|
return True
|
||||||
target = server.getPlayer(args[1])
|
target = server.getPlayer(args[1])
|
||||||
if target is not None and not can_send(sender, target):
|
if target is not None and not can_send(sender, target):
|
||||||
@ -260,59 +238,14 @@ def mail_command_checker(sender, args):
|
|||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
register = shared["modules"]["misc"].CommandInterceptions.register
|
||||||
|
register("essentials", "msg", msg_interception)
|
||||||
|
register("minecraft", "tell", msg_interception)
|
||||||
|
register("essentials", "reply", reply_interception)
|
||||||
|
register("essentials", "tpa", tpa_interception)
|
||||||
|
register("essentials", "tpahere", tpahere_interception)
|
||||||
|
register("essentials", "mail", mail_interception)
|
||||||
|
|
||||||
@hook.event("player.PlayerCommandPreprocessEvent", "monitor")
|
except:
|
||||||
def on_player_command_preprocess(event):
|
error("[Imbusy] Failed to intercept commands:")
|
||||||
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)
|
|
||||||
|
|
||||||
|
|
||||||
def replace_ess_commands():
|
|
||||||
|
|
||||||
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)
|
|
||||||
|
|
||||||
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")
|
|
||||||
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()
|
|
||||||
wrapped_commands = []
|
|
||||||
while iterator.hasNext():
|
|
||||||
entry = iterator.next()
|
|
||||||
value = entry.getValue()
|
|
||||||
changed = True
|
|
||||||
if value is ess_msg_cmd:
|
|
||||||
entry.setValue(msg_cmd_wrapper)
|
|
||||||
elif value is ess_reply_cmd:
|
|
||||||
entry.setValue(reply_cmd_wrapper)
|
|
||||||
elif value is ess_tpa_cmd:
|
|
||||||
entry.setValue(tpa_cmd_wrapper)
|
|
||||||
elif value is ess_tpahere_cmd:
|
|
||||||
entry.setValue(tpahere_cmd_wrapper)
|
|
||||||
elif value is ess_mail_cmd:
|
|
||||||
entry.setValue(mail_cmd_wrapper)
|
|
||||||
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")
|
|
||||||
error(trace())
|
error(trace())
|
||||||
|
2
main.py
2
main.py
@ -21,8 +21,6 @@ except:
|
|||||||
def on_enable():
|
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 "imbusy" in shared["modules"]:
|
|
||||||
shared["modules"]["imbusy"].replace_ess_commands()
|
|
||||||
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_and_force_commands()
|
||||||
info("RedstonerUtils enabled!")
|
info("RedstonerUtils enabled!")
|
||||||
|
Reference in New Issue
Block a user