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 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 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_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 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 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