|
24 | 24 | from cvars import cvar |
25 | 25 | # Engines |
26 | 26 | from engines.server import server_game_dll |
| 27 | +# Entities |
| 28 | +from entities import BaseEntityOutput |
27 | 29 | from entities.datamaps import Variant |
28 | 30 | from entities.helpers import find_output_name |
29 | 31 | # Memory |
|
91 | 93 | 'OnEntityCreated', |
92 | 94 | 'OnEntityDeleted', |
93 | 95 | 'OnEntityOutput', |
| 96 | + 'OnEntityOutputListenerManager', |
94 | 97 | 'OnEntityPreSpawned', |
95 | 98 | 'OnEntitySpawned', |
96 | 99 | 'OnLevelInit', |
|
157 | 160 | on_plugin_loading_manager = ListenerManager() |
158 | 161 | on_plugin_unloading_manager = ListenerManager() |
159 | 162 | on_level_end_listener_manager = ListenerManager() |
160 | | -on_entity_output_listener_manager = ListenerManager() |
161 | 163 |
|
162 | 164 | _check_for_update = ConVar( |
163 | 165 | 'sp_check_for_update', |
@@ -281,6 +283,36 @@ class OnClientSettingsChanged(ListenerManagerDecorator): |
281 | 283 | manager = on_client_settings_changed_listener_manager |
282 | 284 |
|
283 | 285 |
|
| 286 | +class OnEntityOutputListenerManager(ListenerManager): |
| 287 | + """Register/unregister an EntityOutput listener.""" |
| 288 | + |
| 289 | + def initialize(self): |
| 290 | + """Called when the first callback is being registered.""" |
| 291 | + # Get the fire_output method |
| 292 | + fire_output = BaseEntityOutput.fire_output |
| 293 | + |
| 294 | + # If the fire_output method is not implemented, exit the call |
| 295 | + if fire_output is NotImplemented: |
| 296 | + return |
| 297 | + |
| 298 | + # Register the hook on fire_output |
| 299 | + fire_output.add_pre_hook(_pre_fire_output) |
| 300 | + |
| 301 | + def finalize(self): |
| 302 | + """Called when the last callback is being unregistered.""" |
| 303 | + # Get the fire_output method |
| 304 | + fire_output = BaseEntityOutput.fire_output |
| 305 | + |
| 306 | + # If the fire_output method is not implemented, exit the call |
| 307 | + if fire_output is NotImplemented: |
| 308 | + return |
| 309 | + |
| 310 | + # Unregister the hook on fire_output |
| 311 | + fire_output.remove_pre_hook(_pre_fire_output) |
| 312 | + |
| 313 | +on_entity_output_listener_manager = OnEntityOutputListenerManager() |
| 314 | + |
| 315 | + |
284 | 316 | class OnEntityOutput(ListenerManagerDecorator): |
285 | 317 | """Register/unregister an EntityOutput listener.""" |
286 | 318 |
|
|
0 commit comments