def show_plugin_info(self, source: CommandSource, plugin_id: str): plugin = self.mcdr_server.plugin_manager.get_plugin_from_id(plugin_id) if plugin is None: source.reply(self.tr('mcdr_command.invalid_plugin_id', plugin_id)) else: meta = plugin.get_metadata() source.reply( RTextList( RText(meta.name).set_color(RColor.yellow).set_styles( RStyle.bold).h(plugin), ' ', RText('v{}'.format(meta.version), color=RColor.gray))) source.reply('ID: {}'.format(meta.id)) if meta.author is not None: source.reply('Authors: {}'.format(', '.join(meta.author))) if meta.link is not None: source.reply( RTextList( 'Link: ', RText(meta.link, color=RColor.blue, styles=RStyle.underlined).c( RAction.open_url, meta.link))) if meta.description is not None: source.reply( meta.get_description( self.__mcdr_server.translation_manager.language))
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 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
def process_help_command(self, source: CommandSource, context: CommandContext): page = context.get('page') source.reply(self.tr('mcdr_command.help_message.title')) matched = [] # type: List[HelpMessage] for msg in self.mcdr_server.plugin_manager.registry_storage.help_messages: # type: HelpMessage if source.has_permission(msg.permission): matched.append(msg) matched_count = len(matched) if page is not None: left, right = ( page - 1) * HELP_MESSAGE_PER_PAGE, page * HELP_MESSAGE_PER_PAGE else: left, right = 0, matched_count for i in range(left, right): if 0 <= i < matched_count: msg = matched[i] source.reply( RTextList( RText(msg.prefix, color=RColor.gray).c(RAction.suggest_command, msg.prefix), ': ', translation_util.translate_from_dict( msg.message, self.server_interface.get_mcdr_language(), default=''))) if page is not None: has_prev = 0 < left < matched_count has_next = 0 < right < matched_count color = {False: RColor.dark_gray, True: RColor.gray} prev_page = RText('<-', color=color[has_prev]) if has_prev: prev_page.c(RAction.run_command, '{} {}'.format( self.help_command_prefix, page - 1)).h( self.tr( 'mcdr_command.help_message.previous_page_hover')) next_page = RText('->', color=color[has_next]) if has_next: next_page.c(RAction.run_command, '{} {}'.format( self.help_command_prefix, page + 1)).h( self.tr('mcdr_command.help_message.next_page_hover')) source.reply( RTextList( prev_page, ' {} '.format( self.tr('mcdr_command.help_message.page_number', page)), next_page))
def show_preference_list(self, source: CommandSource): pref = self.pref_mgr.get_preference(source, auto_add=True) source.reply(self.tr('mcdr_command.preference.list.title')) for pref_name in pref.get_annotations_fields().keys(): value = getattr(pref, pref_name, RText('N/A', RColor.gray)) source.reply( self.__detail_hint( RTextList(RText('- ', RColor.gray), RText(pref_name, PREF_COLOR), RText(': ', RColor.gray), RText(value, VALUE_COLOR)), pref_name))
def list_permission(self, source: CommandSource, target_value: Optional[str]): specified_level = PermissionLevel.get_level(target_value) if specified_level is None: # show default level information if target permission not specified source.reply( RText( self.tr( 'mcdr_command.list_permission.show_default', self.mcdr_server.permission_manager. get_default_permission_level())).c( RAction.suggest_command, '{} permission setdefault '.format( self.control_command_prefix)). h(self.tr('mcdr_command.list_permission.suggest_setdefault'))) for permission_level in PermissionLevel.INSTANCES: if specified_level is None or permission_level == specified_level: source.reply( RText('§7[§e{}§7]§r'.format(permission_level.name)).c( RAction.run_command, '{} permission list {}'.format( self.control_command_prefix, permission_level.name) ).h( self.tr('mcdr_command.list_permission.suggest_list', permission_level.name))) for player in self.mcdr_server.permission_manager.get_permission_group_list( permission_level.name): texts = RText('§7-§r {}'.format(player)) if self.can_see_rtext(source): texts += RTextList( RText(' [✎]', color=RColor.gray).c( RAction.suggest_command, '{} permission set {} '.format( self.control_command_prefix, string_util.auto_quotes(player))). h( self.tr( 'mcdr_command.list_permission.suggest_set', player)), RText(' [×]', color=RColor.gray).c( RAction.suggest_command, '{} permission remove {}'.format( self.control_command_prefix, string_util.auto_quotes(player))). h( self.tr( 'mcdr_command.list_permission.suggest_disable', player)), ) source.reply(texts)
def list_points(src: CommandSource, dim: Any): reply_text = '' dim_id = None try: dim_id = int(dim) except ValueError: pass if dim_id == None: try: dim_id = Waypoint.get_dim_id(dim) except KeyError: if dim != 'all': src.reply('§b[Waypoints]§r 找不到指定的维度') return if dim_id == None: # dim == all dim_id_list = Waypoint.get_dim_id_list() else: dim_id_list = [dim_id] reply_text_list = RTextList() for i in dim_id_list: count = 0 dim_text_list = RTextList() for _, point in waypoint_config['waypoints'].items(): if point.dim_id != i: continue dim_text_list.append(point.get_rtext_list(), '\n') count += 1 reply_text_list.append( '维度 §2{}§r 共有 §4{}§r 个路径点:\n'.format(Waypoint.get_dim_str(i), count), dim_text_list) reply_text_list = RTextList( '§b[Waypoints]§r wp list {} 结果如下:\n'.format(dim), reply_text_list) src.reply(reply_text_list)
def get_help_message(self, translation_key): lst = RTextList() for line in self.tr(translation_key).splitlines(keepends=True): prefix = re.search(r'(?<=§7)!!MCDR[\w ]*(?=§)', line) if prefix is not None: lst.append( RText(line).c(RAction.suggest_command, prefix.group())) else: lst.append(line) return lst
def search_point(src: CommandSource, content: str): reply_rtext_list = RTextList() count = 0 for _, point in waypoint_config['waypoints'].items(): if content not in point.name: continue reply_rtext_list.append(point.get_rtext_list(), '\n') count += 1 reply_rtext_list = RTextList( '§b[Waypoints]§r 共有 §b{}§r 个名字包含 §b{}§r 的路径点:\n'.format( count, content), reply_rtext_list) src.reply(reply_rtext_list)
def list_permission(self, source: CommandSource, target_value): specified_level = PermissionLevel.get_level(target_value) if specified_level is None: # show default level information if target permission not specified source.reply( RText( self.tr( 'mcdr_command.list_permission.show_default', self.mcdr_server.permission_manager. get_default_permission_level())).c( RAction.suggest_command, '!!MCDR permission setdefault '). h(self.tr('mcdr_command.list_permission.suggest_setdefault'))) for permission_level in PermissionLevel.INSTANCES: if specified_level is None or permission_level == specified_level: source.reply( RText('§7[§e{}§7]§r'.format(permission_level.name)).c( RAction.run_command, '!!MCDR permission list {}'. format(permission_level.name)).h( self.tr( 'mcdr_command.list_permission.suggest_list', permission_level.name))) for player in self.mcdr_server.permission_manager.get_permission_group_list( permission_level.name): texts = RText('§7-§r {}'.format(player)) if self.should_display_buttons(source): texts += RTextList( RText(' [✎]', color=RColor.gray).c( RAction.suggest_command, '!!MCDR permission set {} '.format(player)). h( self.tr( 'mcdr_command.list_permission.suggest_set', player)), RText(' [×]', color=RColor.gray).c( RAction.suggest_command, '!!MCDR permission remove {}'.format(player)). h( self.tr( 'mcdr_command.list_permission.suggest_disable', player)), ) source.reply(texts)
def get_help_message(self, source: CommandSource, translation_key: str): lst = RTextList() with source.preferred_language_context(): for line in self.tr(translation_key).to_plain_text().splitlines( keepends=True): prefix = re.search( r'(?<=§7)' + self.control_command_prefix + r'[\w ]*(?=§)', line) if prefix is not None: lst.append( RText(line).c(RAction.suggest_command, prefix.group())) else: lst.append(line) return lst
def list_plugin(self, source: CommandSource): not_loaded_plugin_list = self.get_files_in_plugin_directories( lambda fp: fp.endswith(plugin_constant.SOLO_PLUGIN_FILE_SUFFIX) and not self.mcdr_server.plugin_manager.contains_plugin_file( fp)) # type: List[str] disabled_plugin_list = self.get_files_in_plugin_directories( lambda fp: fp.endswith(plugin_constant.DISABLED_PLUGIN_FILE_SUFFIX) ) # type: List[str] current_plugins = list(self.mcdr_server.plugin_manager.get_all_plugins( )) # type: List[AbstractPlugin] source.reply( self.tr('mcdr_command.list_plugin.info_loaded_plugin', len(current_plugins))) for plugin in current_plugins: meta = plugin.get_metadata() displayed_name = RText(meta.name) if not self.can_see_rtext(source): displayed_name += RText(' ({})'.format( plugin.get_identifier()), color=RColor.gray) texts = RTextList( '§7-§r ', displayed_name.c( RAction.run_command, '{} plugin info {}'.format( self.control_command_prefix, meta.id)).h( self.tr('mcdr_command.list_plugin.suggest_info', plugin.get_identifier()))) if self.can_see_rtext(source) and not plugin.is_permanent(): texts.append( ' ', RText('[↻]', color=RColor.gray).c( RAction.run_command, '{} plugin reload {}'.format( self.control_command_prefix, meta.id)).h( self.tr( 'mcdr_command.list_plugin.suggest_reload', meta.id)), ' ', RText('[↓]', color=RColor.gray).c( RAction.run_command, '{} plugin unload {}'.format( self.control_command_prefix, meta.id)).h( self.tr( 'mcdr_command.list_plugin.suggest_unload', meta.id)), ' ', RText('[×]', color=RColor.gray).c( RAction.run_command, '{} plugin disable {}'.format( self.control_command_prefix, meta.id)).h( self.tr( 'mcdr_command.list_plugin.suggest_disable', meta.id))) source.reply(texts) def get_file_name(fp) -> Tuple[str, RText]: name = os.path.basename(fp) name_text = RText(name) if source.has_permission( PermissionLevel.PHYSICAL_SERVER_CONTROL_LEVEL): name_text.h(fp) return name, name_text source.reply( self.tr('mcdr_command.list_plugin.info_disabled_plugin', len(disabled_plugin_list))) for file_path in disabled_plugin_list: file_name, file_name_text = get_file_name(file_path) texts = RTextList(RText('- ', color=RColor.gray), file_name_text) if self.can_see_rtext(source): texts.append( ' ', RText('[✔]', color=RColor.gray).c( RAction.run_command, '{} plugin enable {}'.format( self.control_command_prefix, file_name)).h( self.tr( 'mcdr_command.list_plugin.suggest_enable', file_name))) source.reply(texts) source.reply( self.tr('mcdr_command.list_plugin.info_not_loaded_plugin', len(not_loaded_plugin_list))) for file_path in not_loaded_plugin_list: file_name, file_name_text = get_file_name(file_path) texts = RTextList(RText('- ', color=RColor.gray), file_name_text) if self.can_see_rtext(source): texts.append( ' ', RText('[↑]', color=RColor.gray).c( RAction.run_command, '{} plugin load {}'.format( self.control_command_prefix, file_name)).h( self.tr( 'mcdr_command.list_plugin.suggest_load', file_name))) source.reply(texts)
def print_mcdr_status(self, source: CommandSource): def bool_formatter(bl): return '{}{}§r'.format('§a' if bl else '§7', bl) rcon_status_dict = { True: self.tr('mcdr_command.print_mcdr_status.online'), False: self.tr('mcdr_command.print_mcdr_status.offline') } source.reply( RTextList( 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)), '\n', RText( self.tr('mcdr_command.print_mcdr_status.line2', self.tr(self.mcdr_server.mcdr_state.value))), '\n', RText( self.tr('mcdr_command.print_mcdr_status.line3', self.tr(self.mcdr_server.server_state.value))), '\n', RText( self.tr( 'mcdr_command.print_mcdr_status.line4', bool_formatter(self.mcdr_server.is_server_startup()))), '\n', RText( self.tr( 'mcdr_command.print_mcdr_status.line5', bool_formatter( self.mcdr_server.should_exit_after_stop()))), '\n', RText( self.tr( 'mcdr_command.print_mcdr_status.line6', rcon_status_dict[ self.server_interface.is_rcon_running()])), '\n', 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 source.has_permission( PermissionLevel.PHYSICAL_SERVER_CONTROL_LEVEL): source.reply( RTextList( 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'), '\n', self.tr('mcdr_command.print_mcdr_status.extra_line2', self.mcdr_server.task_executor.task_queue.qsize(), core_constant.MAX_TASK_QUEUE_SIZE), '\n', self.tr('mcdr_command.print_mcdr_status.extra_line3', threading.active_count()))) for thread in threading.enumerate(): source.reply(' §r-§r {}'.format(thread.getName()))
def add_element(msg: RTextList, element): msg.append(element) msg.append('; ')
def get_rtext_list(self): voxel_command = '/newWaypoint [name:{}, x:{}, y:{}, z:{}, dim:{}, world:{}]'.format( self.name, self.x, self.y, self.z, self.get_dim_str(self.dim_id), waypoint_config['world']) xaero_command = 'xaero_waypoint_add:{}:{}:{}:{}:{}:6:false:0:Internal_{}_waypoints'.format( self.name.replace(':', '^col^'), self.name[0], self.x, self.y, self.z, self.get_dim_str(self.dim_id).replace('minecraft:', '')) ret = RTextList( RText('[+V]', color=RColor.gold).h( '§6Voxemapl§r: 左键高亮路径点, ctrl + 左键点击添加路径点').c( RAction.run_command, voxel_command), RText('[+X] ', color=RColor.gold).h('§6Xaeros Minimap§r: 点击添加路径点').c( RAction.run_command, xaero_command)) ret.append(self.name + ' ') ret.append( RText('({}, {}, {})'.format(self.x, self.y, self.z), color=self.color_map[self.dim_id])) ret.append(' ') ret.append(self.get_dim_rtext(self.dim_id)) if self.dim_id == 0: ret.append(' -> ') ret.append( RText('({}, {}, {})'.format(self.x // 8, self.y // 8, self.z // 8), color=self.color_map[-1])) ret.append(' ') ret.append(self.get_dim_rtext(-1)) elif self.dim_id == -1: ret.append(' -> ') ret.append( RText('({}, {}, {})'.format(self.x * 8, self.y * 8, self.z * 8), color=self.color_map[0])) ret.append(' ') ret.append(self.get_dim_rtext(0)) return ret