@@ -107,35 +107,36 @@ def __init__(self, **kwargs):
107107 automatically : bool = True
108108
109109
110- class TempConfig ( Serializable ) :
110+ class TempConfig :
111111
112- def __init__ (self , ** kwargs ):
113- super ().__init__ (** kwargs )
112+ def __init__ (self ):
113+ self .hooks = {
114+ 'undefined' : [],
115+
116+ 'on_plugin_loaded' : [],
117+ 'on_plugin_unloaded' : [],
118+
119+ 'on_server_starting' : [],
120+ 'on_server_started' : [],
121+ 'on_server_stopped' : [],
122+ 'on_server_crashed' : [],
123+ 'on_mcdr_started' : [],
124+ 'on_mcdr_stopped' : [],
125+
126+ 'on_player_joined' : [],
127+ 'on_player_left' : [],
128+
129+ 'on_info' : [],
130+ 'on_user_info' : []
131+ }
132+ self .task = {}
114133
115- hooks : dict [str , List [str ]] = {
116- 'undefined' : [],
117-
118- 'on_plugin_loaded' : [],
119- 'on_plugin_unloaded' : [],
120-
121- 'on_server_starting' : [],
122- 'on_server_started' : [],
123- 'on_server_stopped' : [],
124- 'on_server_crashed' : [],
125- 'on_mcdr_started' : [],
126- 'on_mcdr_stopped' : [],
127-
128- 'on_player_joined' : [],
129- 'on_player_left' : [],
130-
131- 'on_info' : [],
132- 'on_user_info' : []
133- }
134+ hooks : dict [str , List [str ]]
134135
135- task : dict [str , Task ] = {}
136+ task : dict [str , Task ]
136137
137138
138- temp_config : TempConfig = TempConfig ()
139+ temp_config : TempConfig
139140
140141config : Configuration
141142
@@ -203,12 +204,12 @@ def mount_task(hook: str, task: str, src: CommandSource, server: PluginServerInt
203204 return
204205
205206 if task in h :
206- src .reply (RTextMCDRTranslation ('hooks.mount.task_already_exist' , task ))
207+ src .reply (RTextMCDRTranslation ('hooks.mount.task_already_exist' , task , hook ))
207208 return
208209
209- src .reply (RTextMCDRTranslation ('hooks.mount.success' , task , hook ))
210210 h .append (task )
211211 server .logger .info (f'Successfully mounted task { task } ' )
212+ src .reply (RTextMCDRTranslation ('hooks.mount.success' , task , hook ))
212213
213214
214215def unmount_task (hook : str , task : str , src : CommandSource , server : PluginServerInterface ):
@@ -222,9 +223,9 @@ def unmount_task(hook: str, task: str, src: CommandSource, server: PluginServerI
222223 src .reply (RTextMCDRTranslation ('hooks.mount.task_not_exist' , task ))
223224 return
224225
225- src .reply (RTextMCDRTranslation ('hooks.mount.unmount' , hook , task ))
226226 h .remove (task )
227227 server .logger .info (f'Successfully unmounted task { task } ' )
228+ src .reply (RTextMCDRTranslation ('hooks.mount.unmount' , hook , task ))
228229
229230
230231def create_task (task_type : str , command : str , name : str , src : CommandSource , server : PluginServerInterface ):
@@ -249,10 +250,10 @@ def delete_task(name: str, src: CommandSource, server: PluginServerInterface):
249250 src .reply (RTextMCDRTranslation ('hooks.mount.task_not_exist' , name ))
250251 return
251252
253+ temp_config .task .pop (name )
254+
252255 server .logger .info (f'Successfully deleted task { name } ' )
253256 src .reply (RTextMCDRTranslation ('hooks.delete.success' , name ))
254-
255- temp_config .task .pop (name )
256257
257258
258259@new_thread ('hooks - list' )
@@ -272,30 +273,20 @@ def list_task(src: CommandSource):
272273
273274@new_thread ('hooks - list' )
274275def list_mount (src : CommandSource ):
275- src .reply (
276- RTextMCDRTranslation ('hooks.list.mount' ,
277- temp_config .hooks .get (Hooks .on_plugin_loaded .value ),
278- temp_config .hooks .get (Hooks .on_plugin_unloaded .value ),
279- temp_config .hooks .get (Hooks .on_server_starting .value ),
280- temp_config .hooks .get (Hooks .on_server_started .value ),
281- temp_config .hooks .get (Hooks .on_server_stopped .value ),
282- temp_config .hooks .get (Hooks .on_server_crashed .value ),
283- temp_config .hooks .get (Hooks .on_mcdr_started .value ),
284- temp_config .hooks .get (Hooks .on_mcdr_stopped .value ),
285- temp_config .hooks .get (Hooks .on_player_joined .value ),
286- temp_config .hooks .get (Hooks .on_player_left .value ),
287- temp_config .hooks .get (Hooks .on_info .value ),
288- temp_config .hooks .get (Hooks .on_user_info .value ),
289- temp_config .hooks .get (Hooks .undefined .value ),
290- )
291- )
276+ list_hooks : list = list ()
277+
278+ for hk in dict (Hooks .__members__ ).keys ():
279+ list_hooks .append (str (temp_config .hooks .get (str (hk ))))
280+
281+ src .reply (RTextMCDRTranslation ('hooks.list.mount' , * list_hooks ))
292282
293283
294284def reload_config (src : CommandSource , server : PluginServerInterface ):
295285 global config , temp_config
296286
297287 temp_config = TempConfig ()
298288 config = server .load_config_simple (target_class = Configuration )
289+
299290 load_scripts (server )
300291 server .logger .info ('Config reloaded.' )
301292 src .reply (RTextMCDRTranslation ('hooks.reload.success' ))
@@ -326,7 +317,7 @@ def register_scripts(script_path: str):
326317 scripts_list [os .path .basename (script_path )] = script_path
327318
328319
329- def parse_and_load_scripts (script : str , server : PluginServerInterface ):
320+ def parse_and_apply_scripts (script : str , server : PluginServerInterface ):
330321 # 读取
331322 with open (scripts_list .get (script ), 'r' ) as f :
332323 content : dict [str , Union [str , Union [list , dict ]]] = yaml .load (f .read (), Loader = yaml .Loader )
@@ -370,7 +361,7 @@ def list_all_files(root_dir) -> list[str]:
370361
371362 # 遍历所有已成功注册的脚本
372363 for script in scripts_list .keys ():
373- parse_and_load_scripts (script , server )
364+ parse_and_apply_scripts (script , server )
374365
375366
376367def process_arg_server (server : PluginServerInterface ) -> PluginServerInterface :
@@ -394,7 +385,6 @@ def on_load(server: PluginServerInterface, old_module):
394385 global config , scripts_folder , temp_config
395386
396387 temp_config = TempConfig ()
397-
398388 config = server .load_config_simple (target_class = Configuration )
399389
400390 scripts_folder = os .path .join (server .get_data_folder (), 'scripts' )
@@ -473,9 +463,11 @@ def on_load(server: PluginServerInterface, old_module):
473463
474464
475465def on_unload (server : PluginServerInterface ):
466+ global temp_config
476467 trigger_hooks (Hooks .on_plugin_unloaded , server , {'server' : process_arg_server (server )})
477468
478469 server .save_config_simple (config )
470+ temp_config = TempConfig ()
479471
480472
481473def on_info (server : PluginServerInterface , info : Info ):
0 commit comments