def wrapper(callback: Callable):
     server = ServerInterface.get_instance().as_plugin_server_interface()
     if server is None:
         raise RuntimeError(
             'Cannot get current executing plugin, current thread: {}'.
             format(threading.current_thread()))
     server.register_event_listener(event, callback, priority)
     return callback
Esempio n. 2
0
    def __init__(self, translation_key: str, *args, **kwargs):
        self.translation_key: str = translation_key
        self.args = args
        self.kwargs = kwargs
        self.__translator = lambda *args_, **kwargs_: RText(self.
                                                            translation_key)
        self.__post_process: List[Callable[[RTextBase], RTextBase]] = []

        from mcdreforged.plugin.server_interface import ServerInterface
        server: Optional[ServerInterface] = ServerInterface.get_instance()
        if server is not None:
            self.set_translator(server.tr)
Esempio n. 3
0
 def __get_translated_text(self) -> RTextBase:
     language = getattr(self.__TLS, 'language', None)
     if language is None:
         from mcdreforged.plugin.server_interface import ServerInterface
         server: Optional[ServerInterface] = ServerInterface.get_instance()
         if server is not None:
             language = server.get_mcdr_language()
         else:
             language = core_constant.DEFAULT_LANGUAGE
     processed_text = self.__translator(self.translation_key,
                                        *self.args,
                                        **self.kwargs,
                                        language=language)
     processed_text = RTextBase.from_any(processed_text)
     for process in self.__post_process:
         processed_text = process(processed_text)
     return processed_text
Esempio n. 4
0
 def get_server(self) -> 'ServerInterface':
     return ServerInterface.get_instance()