diff --git a/python/minqlx/_events.py b/python/minqlx/_events.py index 1e25443..e2f0186 100644 --- a/python/minqlx/_events.py +++ b/python/minqlx/_events.py @@ -20,6 +20,16 @@ import re _re_vote = re.compile(r"^(?P[^ ]+)(?: \"?(?P.*?)\"?)?$") +hot_plugged_events = ( + "frame", + "player_connect", + "player_loaded", + "player_disconnect", + "player_spawn", + "kamikaze_use", + "kamikaze_explode", + "damage", +) # ==================================================================== # EVENTS @@ -130,6 +140,9 @@ def add_hook(self, plugin, handler, priority=minqlx.PRI_NORMAL): if self.need_zmq_stats_enabled and not bool(int(minqlx.get_cvar("zmq_stats_enable"))): raise AssertionError("{} hook requires zmq_stats_enabled cvar to have nonzero value".format(self.name)) + if self.name in hot_plugged_events and len(self.plugins) == 0: + minqlx.register_handler(self.name, getattr(minqlx, f"handle_{self.name}")) + if plugin not in self.plugins: # Initialize tuple. self.plugins[plugin] = ([], [], [], [], []) # 5 priority levels. @@ -157,6 +170,9 @@ def remove_hook(self, plugin, handler, priority=minqlx.PRI_NORMAL): for hook in self.plugins[plugin][priority]: if handler == hook: self.plugins[plugin][priority].remove(handler) + if self.name in hot_plugged_events and len(self.plugins) == 0: + minqlx.register_handler(self.name, None) + return raise ValueError("The event has not been hooked with the handler provided") diff --git a/python/minqlx/_handlers.py b/python/minqlx/_handlers.py index d915512..e6d32c1 100644 --- a/python/minqlx/_handlers.py +++ b/python/minqlx/_handlers.py @@ -499,14 +499,6 @@ def register_handlers(): minqlx.register_handler("rcon", handle_rcon) minqlx.register_handler("client_command", handle_client_command) minqlx.register_handler("server_command", handle_server_command) - minqlx.register_handler("frame", handle_frame) minqlx.register_handler("new_game", handle_new_game) minqlx.register_handler("set_configstring", handle_set_configstring) - minqlx.register_handler("player_connect", handle_player_connect) - minqlx.register_handler("player_loaded", handle_player_loaded) - minqlx.register_handler("player_disconnect", handle_player_disconnect) - minqlx.register_handler("player_spawn", handle_player_spawn) minqlx.register_handler("console_print", handle_console_print) - - minqlx.register_handler("kamikaze_use", handle_kamikaze_use) - minqlx.register_handler("kamikaze_explode", handle_kamikaze_explode)