/* * Copyright (C) 2024 Minecon724 * Tweaks724 is licensed under the GNU General Public License. See the LICENSE.md file * in the project root for the full license text. */ package eu.m724.tweaks.updater; import eu.m724.tweaks.updater.cache.SpigotResource; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.plugin.Plugin; import java.io.File; import java.io.IOException; import java.util.HashSet; import java.util.Set; public class PluginScanner { private final Plugin thisPlugin; PluginScanner(Plugin thisPlugin) { this.thisPlugin = thisPlugin; } public Set load() throws IOException { File installedPluginsYml = new File(thisPlugin.getDataFolder(), "installed_plugins.yml"); if (!installedPluginsYml.exists()) { thisPlugin.saveResource("installed_plugins.yml", false); } YamlConfiguration configuration = YamlConfiguration.loadConfiguration(installedPluginsYml); Plugin[] plugins = thisPlugin.getServer().getPluginManager().getPlugins(); Set spigotResources = new HashSet<>(); for (Plugin plugin : plugins) { String pluginName = plugin.getName(); if (!configuration.isSet(pluginName)) { configuration.set(pluginName, -1); continue; } int pluginId = configuration.getInt(pluginName); if (pluginId > 0) { spigotResources.add( new SpigotResource(plugin, pluginId, pluginName) ); } } configuration.save(installedPluginsYml); return spigotResources; } }