diff --git a/Bukkit/src/main/java/net/frankheijden/serverutils/bukkit/commands/BukkitCommandPlugins.java b/Bukkit/src/main/java/net/frankheijden/serverutils/bukkit/commands/BukkitCommandPlugins.java index ca4bb41..f72ee5b 100644 --- a/Bukkit/src/main/java/net/frankheijden/serverutils/bukkit/commands/BukkitCommandPlugins.java +++ b/Bukkit/src/main/java/net/frankheijden/serverutils/bukkit/commands/BukkitCommandPlugins.java @@ -5,16 +5,12 @@ import cloud.commandframework.CommandManager; import cloud.commandframework.context.CommandContext; import net.frankheijden.serverutils.bukkit.entities.BukkitAudience; import net.frankheijden.serverutils.bukkit.entities.BukkitPlugin; +import net.frankheijden.serverutils.bukkit.entities.BukkitPluginDescription; import net.frankheijden.serverutils.common.commands.CommandPlugins; -import net.frankheijden.serverutils.common.config.MessageKey; -import net.frankheijden.serverutils.common.config.MessagesResource; -import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.TextComponent; -import net.kyori.adventure.text.minimessage.Template; import org.bukkit.plugin.Plugin; -import org.bukkit.plugin.PluginDescriptionFile; -public class BukkitCommandPlugins extends CommandPlugins { +@SuppressWarnings("LineLength") +public class BukkitCommandPlugins extends CommandPlugins { public BukkitCommandPlugins(BukkitPlugin plugin) { super(plugin); @@ -35,21 +31,6 @@ public class BukkitCommandPlugins extends CommandPlugins { - PluginDescriptionFile description = bukkitPlugin.getDescription(); - - TextComponent.Builder builder = Component.text(); - builder.append(messages.get(MessageKey.PLUGINS_FORMAT).toComponent( - Template.of("plugin", description.getName()) - )); - if (hasVersionFlag) { - builder.append(messages.get(MessageKey.PLUGINS_VERSION).toComponent( - Template.of("version", description.getVersion()) - )); - } - - return builder.build(); - }); + handlePlugins(sender, plugin.getPluginManager().getPluginsSorted(), hasVersionFlag); } } diff --git a/Bungee/src/main/java/net/frankheijden/serverutils/bungee/commands/BungeeCommandPlugins.java b/Bungee/src/main/java/net/frankheijden/serverutils/bungee/commands/BungeeCommandPlugins.java index 272c48e..c9bd7ba 100644 --- a/Bungee/src/main/java/net/frankheijden/serverutils/bungee/commands/BungeeCommandPlugins.java +++ b/Bungee/src/main/java/net/frankheijden/serverutils/bungee/commands/BungeeCommandPlugins.java @@ -5,16 +5,12 @@ import cloud.commandframework.CommandManager; import cloud.commandframework.context.CommandContext; import net.frankheijden.serverutils.bungee.entities.BungeeAudience; import net.frankheijden.serverutils.bungee.entities.BungeePlugin; +import net.frankheijden.serverutils.bungee.entities.BungeePluginDescription; import net.frankheijden.serverutils.common.commands.CommandPlugins; -import net.frankheijden.serverutils.common.config.MessageKey; -import net.frankheijden.serverutils.common.config.MessagesResource; -import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.TextComponent; -import net.kyori.adventure.text.minimessage.Template; import net.md_5.bungee.api.plugin.Plugin; -import net.md_5.bungee.api.plugin.PluginDescription; -public class BungeeCommandPlugins extends CommandPlugins { +@SuppressWarnings("LineLength") +public class BungeeCommandPlugins extends CommandPlugins { public BungeeCommandPlugins(BungeePlugin plugin) { super(plugin); @@ -37,21 +33,6 @@ public class BungeeCommandPlugins extends CommandPlugins { - PluginDescription description = bungeePlugin.getDescription(); - - TextComponent.Builder builder = Component.text(); - builder.append(messages.get(MessageKey.PLUGINS_FORMAT).toComponent( - Template.of("plugin", description.getName()) - )); - if (hasVersionFlag) { - builder.append(messages.get(MessageKey.PLUGINS_VERSION).toComponent( - Template.of("version", description.getVersion()) - )); - } - - return builder.build(); - }); + handlePlugins(sender, plugin.getPluginManager().getPluginsSorted(hasModulesFlag), hasVersionFlag); } } 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 3d94746..a87246b 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 @@ -9,12 +9,15 @@ import net.frankheijden.serverutils.common.config.MessageKey; import net.frankheijden.serverutils.common.config.MessagesResource; import net.frankheijden.serverutils.common.entities.ServerUtilsAudience; import net.frankheijden.serverutils.common.entities.ServerUtilsPlugin; +import net.frankheijden.serverutils.common.entities.ServerUtilsPluginDescription; +import net.frankheijden.serverutils.common.managers.AbstractPluginManager; import net.frankheijden.serverutils.common.utils.ListComponentBuilder; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.TextComponent; import net.kyori.adventure.text.minimessage.Template; -public abstract class CommandPlugins, P, C extends ServerUtilsAudience> +@SuppressWarnings("LineLength") +public abstract class CommandPlugins, P, C extends ServerUtilsAudience, D extends ServerUtilsPluginDescription> extends ServerUtilsCommand { protected CommandPlugins(U plugin) { @@ -29,13 +32,14 @@ public abstract class CommandPlugins, * @param plugins The plugins to be sent. * @param pluginFormat The format of the plugins to be sent. */ - protected void handlePlugins(C sender, List

plugins, ListComponentBuilder.Format

pluginFormat) { + protected void handlePlugins(C sender, List

plugins, boolean hasVersionFlag) { List

filteredPlugins = new ArrayList<>(plugins.size()); Set hiddenPlugins = new HashSet<>(plugin.getConfigResource().getConfig().getStringList( "hide-plugins-from-plugins-command" )); + AbstractPluginManager pluginManager = plugin.getPluginManager(); for (P plugin : plugins) { - if (!hiddenPlugins.contains(this.plugin.getPluginManager().getPluginId(plugin))) { + if (!hiddenPlugins.contains(pluginManager.getPluginId(plugin))) { filteredPlugins.add(plugin); } } @@ -50,7 +54,24 @@ public abstract class CommandPlugins, builder.append(ListComponentBuilder.create(filteredPlugins) .separator(messages.get(MessageKey.PLUGINS_SEPARATOR).toComponent()) .lastSeparator(messages.get(MessageKey.PLUGINS_LAST_SEPARATOR).toComponent()) - .format(pluginFormat) + .format(plugin -> { + D description = pluginManager.getLoadedPluginDescription(plugin); + + TextComponent.Builder formatBuilder = Component.text(); + MessageKey formatKey = pluginManager.isPluginEnabled(plugin) + ? MessageKey.PLUGINS_FORMAT + : MessageKey.PLUGINS_FORMAT_DISABLED; + formatBuilder.append(messages.get(formatKey).toComponent( + Template.of("plugin", description.getName()) + )); + if (hasVersionFlag) { + formatBuilder.append(messages.get(MessageKey.PLUGINS_VERSION).toComponent( + Template.of("version", description.getVersion()) + )); + } + + return formatBuilder.build(); + }) .build()); sender.sendMessage(builder.build()); sender.sendMessage(messages.get(MessageKey.PLUGININFO_FOOTER).toComponent()); diff --git a/Velocity/src/main/java/net/frankheijden/serverutils/velocity/commands/VelocityCommandPlugins.java b/Velocity/src/main/java/net/frankheijden/serverutils/velocity/commands/VelocityCommandPlugins.java index 99a9346..0142e0d 100644 --- a/Velocity/src/main/java/net/frankheijden/serverutils/velocity/commands/VelocityCommandPlugins.java +++ b/Velocity/src/main/java/net/frankheijden/serverutils/velocity/commands/VelocityCommandPlugins.java @@ -4,17 +4,13 @@ import cloud.commandframework.Command; import cloud.commandframework.CommandManager; import cloud.commandframework.context.CommandContext; import com.velocitypowered.api.plugin.PluginContainer; -import com.velocitypowered.api.plugin.PluginDescription; import net.frankheijden.serverutils.common.commands.CommandPlugins; -import net.frankheijden.serverutils.common.config.MessageKey; -import net.frankheijden.serverutils.common.config.MessagesResource; import net.frankheijden.serverutils.velocity.entities.VelocityAudience; import net.frankheijden.serverutils.velocity.entities.VelocityPlugin; -import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.TextComponent; -import net.kyori.adventure.text.minimessage.Template; +import net.frankheijden.serverutils.velocity.entities.VelocityPluginDescription; -public class VelocityCommandPlugins extends CommandPlugins { +@SuppressWarnings("LineLength") +public class VelocityCommandPlugins extends CommandPlugins { public VelocityCommandPlugins(VelocityPlugin plugin) { super(plugin); @@ -35,21 +31,6 @@ public class VelocityCommandPlugins extends CommandPlugins { - PluginDescription description = container.getDescription(); - - TextComponent.Builder builder = Component.text(); - builder.append(messages.get(MessageKey.PLUGINS_FORMAT).toComponent( - Template.of("plugin", description.getId()) - )); - if (hasVersionFlag) { - builder.append(messages.get(MessageKey.PLUGINS_VERSION).toComponent( - Template.of("version", description.getVersion().orElse("")) - )); - } - - return builder.build(); - }); + handlePlugins(sender, plugin.getPluginManager().getPluginsSorted(), hasVersionFlag); } }