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