def get_suggestion_text(value: str): text = RText(value, VALUE_COLOR).c( RAction.suggest_command, '{} preference {} set {}'.format(self.control_command_prefix, pref_name, value)) hover_text = RTextList( self.tr('mcdr_command.preference.item.set_suggestion_hint', RText(pref_name, PREF_COLOR), RText(value, VALUE_COLOR))) styles: List[RStyle] = [] extra_descriptions: List[RTextBase] = [] if value == current_value: styles.append(RStyle.underlined) extra_descriptions.append( self.tr('mcdr_command.preference.item.current').set_color( RColor.gray)) if value == default_value: styles.append(RStyle.bold) extra_descriptions.append( self.tr('mcdr_command.preference.item.default').set_color( RColor.gray)) if len(extra_descriptions) > 0: hover_text.append( RTextList( '\n', RText.join(RText(', ', RColor.dark_gray), extra_descriptions))) text.set_styles(styles) return text.h(hover_text)
def show_preference_item(self, source: CommandSource, pref_name: str): entry: PrefCommandEntry = self.preferences.get(pref_name) pref: PreferenceItem = self.pref_mgr.get_preference(source, auto_add=True) current_value = getattr(pref, pref_name, None) default_value = getattr(self.pref_mgr.get_default_preference(), pref_name, None) if entry is None or current_value is None: # should never come here raise KeyError('Unknown preference {}'.format(pref_name)) def get_suggestion_text(value: str): text = RText(value, VALUE_COLOR).c( RAction.suggest_command, '{} preference {} set {}'.format(self.control_command_prefix, pref_name, value)) hover_text = RTextList( self.tr('mcdr_command.preference.item.set_suggestion_hint', RText(pref_name, PREF_COLOR), RText(value, VALUE_COLOR))) styles: List[RStyle] = [] extra_descriptions: List[RTextBase] = [] if value == current_value: styles.append(RStyle.underlined) extra_descriptions.append( self.tr('mcdr_command.preference.item.current').set_color( RColor.gray)) if value == default_value: styles.append(RStyle.bold) extra_descriptions.append( self.tr('mcdr_command.preference.item.default').set_color( RColor.gray)) if len(extra_descriptions) > 0: hover_text.append( RTextList( '\n', RText.join(RText(', ', RColor.dark_gray), extra_descriptions))) text.set_styles(styles) return text.h(hover_text) source.reply( self.tr( 'mcdr_command.preference.item.name', self.__detail_hint(RText(pref_name, PREF_COLOR), pref_name))) source.reply( self.tr('mcdr_command.preference.item.value', RText(current_value, VALUE_COLOR))) source.reply( self.tr( 'mcdr_command.preference.item.suggestions', RText.join(', ', map(get_suggestion_text, entry.suggester()))))
def set_language(self, source: CommandSource, language: str): available_languages = self.mcdr_server.translation_manager.available_languages if language not in available_languages: source.reply( self.tr('mcdr_command.set_language.not_available', language)) lang_texts = [] for lang in available_languages: lang_texts.append( RText(lang, color=RColor.yellow).c( RAction.run_command, '{} setlang {}'.format(self.control_command_prefix, lang))) source.reply( self.tr('mcdr_command.set_language.language_list', RText.join(', ', lang_texts))) else: self.mcdr_server.config.set_value('language', language) self.mcdr_server.translation_manager.set_language(language) source.reply(self.tr('mcdr_command.set_language.success', language))
def print_mcdr_status(self, source: CommandSource): def bool_formatter(bl: bool) -> RText: return RText(bl, RColor.green if bl else RColor.red) rcon_status_dict = { True: self.tr('mcdr_command.print_mcdr_status.online'), False: self.tr('mcdr_command.print_mcdr_status.offline') } source.reply( RText( self.tr('mcdr_command.print_mcdr_status.line1', core_constant.NAME, core_constant.VERSION)).c( RAction.open_url, core_constant.GITHUB_URL).h( RText(core_constant.GITHUB_URL, styles=RStyle.underlined, color=RColor.blue))) if not source.has_permission(PermissionLevel.MCDR_CONTROL_LEVEL): return source.reply( RText.join('\n', [ RText( self.tr('mcdr_command.print_mcdr_status.line2', self.tr(self.mcdr_server.mcdr_state.value))), RText( self.tr('mcdr_command.print_mcdr_status.line3', self.tr(self.mcdr_server.server_state.value))), RText( self.tr( 'mcdr_command.print_mcdr_status.line4', bool_formatter(self.mcdr_server.is_server_startup()))), RText( self.tr( 'mcdr_command.print_mcdr_status.line5', bool_formatter( self.mcdr_server.should_exit_after_stop()))), RText( self.tr( 'mcdr_command.print_mcdr_status.line6', rcon_status_dict[ self.server_interface.is_rcon_running()])), RText( self. tr('mcdr_command.print_mcdr_status.line7', self.mcdr_server.plugin_manager.get_plugin_amount())).c( RAction.suggest_command, '!!MCDR plugin list') ])) if not source.has_permission( PermissionLevel.PHYSICAL_SERVER_CONTROL_LEVEL): return source.reply( RText.join('\n', [ self.tr( 'mcdr_command.print_mcdr_status.extra_line1', self.mcdr_server.process.pid if self.mcdr_server.process is not None else '§rN/A§r'), self.tr('mcdr_command.print_mcdr_status.extra_line2', self.mcdr_server.task_executor.task_queue.qsize(), core_constant.MAX_TASK_QUEUE_SIZE), self.tr('mcdr_command.print_mcdr_status.extra_line3', threading.active_count()) ])) thread_pool_counts = 0 for thread in threading.enumerate(): name = thread.getName() if not name.startswith('ThreadPoolExecutor-'): source.reply(' §7-§r {}'.format(name)) else: thread_pool_counts += 1 if thread_pool_counts > 0: source.reply(' §7-§r ThreadPoolExecutor thread x{}'.format( thread_pool_counts))