From 76aa1a7f8392b4f889d7b57bd916dcddfda2dcdd Mon Sep 17 00:00:00 2001 From: Frank van der Heijden Date: Tue, 5 Oct 2021 18:51:04 +0200 Subject: [PATCH] Feature: hide plugins from plugins command --- .../common/commands/CommandPlugins.java | 17 +++++++++++++++-- Common/src/main/resources/config.json | 3 ++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/Common/src/main/java/net/frankheijden/serverutils/common/commands/CommandPlugins.java b/Common/src/main/java/net/frankheijden/serverutils/common/commands/CommandPlugins.java index 1b34de4..3d94746 100644 --- a/Common/src/main/java/net/frankheijden/serverutils/common/commands/CommandPlugins.java +++ b/Common/src/main/java/net/frankheijden/serverutils/common/commands/CommandPlugins.java @@ -1,7 +1,10 @@ package net.frankheijden.serverutils.common.commands; import cloud.commandframework.context.CommandContext; +import java.util.ArrayList; +import java.util.HashSet; import java.util.List; +import java.util.Set; import net.frankheijden.serverutils.common.config.MessageKey; import net.frankheijden.serverutils.common.config.MessagesResource; import net.frankheijden.serverutils.common.entities.ServerUtilsAudience; @@ -27,14 +30,24 @@ public abstract class CommandPlugins, * @param pluginFormat The format of the plugins to be sent. */ protected void handlePlugins(C sender, List

plugins, ListComponentBuilder.Format

pluginFormat) { + List

filteredPlugins = new ArrayList<>(plugins.size()); + Set hiddenPlugins = new HashSet<>(plugin.getConfigResource().getConfig().getStringList( + "hide-plugins-from-plugins-command" + )); + for (P plugin : plugins) { + if (!hiddenPlugins.contains(this.plugin.getPluginManager().getPluginId(plugin))) { + filteredPlugins.add(plugin); + } + } + MessagesResource messages = plugin.getMessagesResource(); sender.sendMessage(messages.get(MessageKey.PLUGINS_HEADER).toComponent()); TextComponent.Builder builder = Component.text(); builder.append(messages.get(MessageKey.PLUGINS_PREFIX).toComponent( - Template.of("count", String.valueOf(plugins.size())) + Template.of("count", String.valueOf(filteredPlugins.size())) )); - builder.append(ListComponentBuilder.create(plugins) + builder.append(ListComponentBuilder.create(filteredPlugins) .separator(messages.get(MessageKey.PLUGINS_SEPARATOR).toComponent()) .lastSeparator(messages.get(MessageKey.PLUGINS_LAST_SEPARATOR).toComponent()) .format(pluginFormat) diff --git a/Common/src/main/resources/config.json b/Common/src/main/resources/config.json index 879f5ad..8b1dd35 100644 --- a/Common/src/main/resources/config.json +++ b/Common/src/main/resources/config.json @@ -7,5 +7,6 @@ "download-updates-login": false, "install-updates-boot": false, "install-updates-login": false - } + }, + "hide-plugins-from-plugins-command": [] }