Merge pull request #35 from FrankHeijden/feature/hide-plugins-from-plugins-command

Feature: hide plugins from plugins command
This commit is contained in:
Frank van der Heijden 2021-10-05 18:55:56 +02:00 committed by GitHub
commit 908e23821f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 3 deletions

View file

@ -1,7 +1,10 @@
package net.frankheijden.serverutils.common.commands; package net.frankheijden.serverutils.common.commands;
import cloud.commandframework.context.CommandContext; import cloud.commandframework.context.CommandContext;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set;
import net.frankheijden.serverutils.common.config.MessageKey; import net.frankheijden.serverutils.common.config.MessageKey;
import net.frankheijden.serverutils.common.config.MessagesResource; import net.frankheijden.serverutils.common.config.MessagesResource;
import net.frankheijden.serverutils.common.entities.ServerUtilsAudience; import net.frankheijden.serverutils.common.entities.ServerUtilsAudience;
@ -27,14 +30,24 @@ public abstract class CommandPlugins<U extends ServerUtilsPlugin<P, ?, C, ?, ?>,
* @param pluginFormat The format of the plugins to be sent. * @param pluginFormat The format of the plugins to be sent.
*/ */
protected void handlePlugins(C sender, List<P> plugins, ListComponentBuilder.Format<P> pluginFormat) { protected void handlePlugins(C sender, List<P> plugins, ListComponentBuilder.Format<P> pluginFormat) {
List<P> filteredPlugins = new ArrayList<>(plugins.size());
Set<String> 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(); MessagesResource messages = plugin.getMessagesResource();
sender.sendMessage(messages.get(MessageKey.PLUGINS_HEADER).toComponent()); sender.sendMessage(messages.get(MessageKey.PLUGINS_HEADER).toComponent());
TextComponent.Builder builder = Component.text(); TextComponent.Builder builder = Component.text();
builder.append(messages.get(MessageKey.PLUGINS_PREFIX).toComponent( 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()) .separator(messages.get(MessageKey.PLUGINS_SEPARATOR).toComponent())
.lastSeparator(messages.get(MessageKey.PLUGINS_LAST_SEPARATOR).toComponent()) .lastSeparator(messages.get(MessageKey.PLUGINS_LAST_SEPARATOR).toComponent())
.format(pluginFormat) .format(pluginFormat)

View file

@ -11,5 +11,6 @@
"unload-after-startup": { "unload-after-startup": {
"delay-ticks": 20, "delay-ticks": 20,
"plugins": [] "plugins": []
} },
"hide-plugins-from-plugins-command": []
} }