def exit(self) -> None:
        """
		Exit MCDR when the server is stopped
		:raise: IllegalCallError, if the server is not stopped
		"""
        if self.__mcdr_server.is_server_running():
            raise IllegalCallError(
                'Cannot exit MCDR when the server is running')
        self.__mcdr_server.set_server_state(ServerState.STOPPED)
Exemple #2
0
    def to_rtext(self, *, show_path: bool) -> RTextBase:
        if not self.__has_record:
            raise IllegalCallError('No record yet')

        def add_element(msg: RTextList, element):
            msg.append(element)
            msg.append('; ')

        def add_if_not_empty(msg: RTextList, lst: List['AbstractPlugin'
                                                       or str], key: str):
            if len(lst) > 0:
                text_list = []
                for ele in lst:
                    if isinstance(ele, str):
                        text_list.append(
                            ele if show_path else os.path.basename(ele))
                    else:
                        text_list.append(str(ele))
                add_element(
                    msg,
                    RText(self.__mcdr_server.tr(key, len(lst))).h(
                        '\n'.join(text_list)))

        message = RTextList()
        add_if_not_empty(
            message,
            list(
                filter(
                    lambda plg: plg in self.dependency_check_result.
                    success_list, self.load_result.success_list)),
            'plugin_operation_result.info_loaded_succeeded')
        add_if_not_empty(message, self.unload_result.success_list,
                         'plugin_operation_result.info_unloaded_succeeded')
        add_if_not_empty(message, self.reload_result.success_list,
                         'plugin_operation_result.info_reloaded_succeeded')
        add_if_not_empty(message, self.load_result.failed_list,
                         'plugin_operation_result.info_loaded_failed')
        add_if_not_empty(message, self.unload_result.failed_list,
                         'plugin_operation_result.info_unloaded_failed')
        add_if_not_empty(message, self.reload_result.failed_list,
                         'plugin_operation_result.info_reloaded_failed')
        add_if_not_empty(
            message, self.dependency_check_result.failed_list,
            'plugin_operation_result.info_dependency_check_failed')
        if message.is_empty():
            add_element(
                message,
                self.__mcdr_server.tr('plugin_operation_result.info_none'))
        message.append(
            RText(
                self.__mcdr_server.tr(
                    'plugin_operation_result.info_plugin_amount',
                    len(self.__plugin_manager.plugins))).h('\n'.join(
                        map(str, self.__plugin_manager.plugins.values()))).c(
                            RAction.suggest_command, '!!MCDR plugin list'))
        return message
Exemple #3
0
    def exit(self) -> None:
        """
		Exit MCDR when the server is stopped
		Basically it's the same to invoking set_exit_after_stop_flag(True), but with an extra server not running check
		:raise: IllegalCallError, if the server is not stopped
		"""
        if self._mcdr_server.is_server_running():
            raise IllegalCallError(
                'Cannot exit MCDR when the server is running')
        self._mcdr_server.with_flag(MCDReforgedFlag.EXIT_AFTER_STOP)
Exemple #4
0
    def exit(self):
        """
		Exit MCDR when the server is stopped
		If the server is running return False otherwise return True

		:raise: IllegalCallError, if the server is not stopped
		"""
        if self.__mcdr_server.is_server_running():
            raise IllegalCallError(
                'Cannot exit MCDR when the server is running')
        self.__mcdr_server.set_server_state(ServerState.STOPPED)
Exemple #5
0
	def __kill_server(self):
		"""
		Kill the server process group
		"""
		if self.process and self.process.poll() is None:
			self.logger.info(self.tr('mcdr_server.kill_server.killing'))
			try:
				for child in psutil.Process(self.process.pid).children(recursive=True):
					child.kill()
					self.logger.info(self.tr('mcdr_server.kill_server.process_killed', child.pid))
			except psutil.NoSuchProcess:
				pass
			self.process.kill()
			self.logger.info(self.tr('mcdr_server.kill_server.process_killed', self.process.pid))
		else:
			raise IllegalCallError("Server process has already been terminated")
Exemple #6
0
    def reply(self,
              info: Info,
              text: MessageText,
              *,
              encoding: Optional[str] = None,
              console_text: Optional[MessageText] = None):
        """
		Reply to the source of the Info
		If the Info is from a player then use tell to reply the player
		Otherwise if the Info is from the console use logger.info to output to the console
		In the rest of the situations, the Info is not from a user, a IllegalCallError is raised
		:param info: the Info you want to reply to
		:param text: the message you want to send
		:param console_text: If it's specified, console_text will be used instead of text when replying to console
		:param encoding: The encoding method for the text
		"""
        source = info.get_command_source()
        if source is None:
            raise IllegalCallError('Cannot reply to the given info instance')
        if not source.is_console:
            if console_text is not None:
                text = console_text
        source.reply(text, encoding=encoding)
Exemple #7
0
 def to_command_source(self) -> InfoCommandSource:
     source = self.get_command_source()
     if source is None:
         raise IllegalCallError()
     return source
Exemple #8
0
 def __get_current_plugin(self):
     plugin = self.__mcdr_server.plugin_manager.get_current_running_plugin()
     if plugin.is_regular():
         return plugin
     else:
         raise IllegalCallError('MCDR provided thead is required')
 def get_metadata(self) -> Metadata:
     if self.__metadata is None:
         raise IllegalCallError(
             'Meta data of plugin {} is not loaded. Plugin state = {}'.
             format(repr(self), self.state))
     return self.__metadata