From 76afccf2854299067e4f738ddff87ff2947330ef Mon Sep 17 00:00:00 2001 From: LabodiDavid Date: Sat, 29 Mar 2025 19:29:33 +0100 Subject: [PATCH] Deleted old plugin manager code --- .../handlers/DitPluginManager.java | 185 ------------------ 1 file changed, 185 deletions(-) delete mode 100644 src/main/java/hu/ditservices/handlers/DitPluginManager.java diff --git a/src/main/java/hu/ditservices/handlers/DitPluginManager.java b/src/main/java/hu/ditservices/handlers/DitPluginManager.java deleted file mode 100644 index 95b8b5f..0000000 --- a/src/main/java/hu/ditservices/handlers/DitPluginManager.java +++ /dev/null @@ -1,185 +0,0 @@ -package hu.ditservices.handlers; -/* -import hu.ditservices.DITSystem; -import org.bukkit.Bukkit; -import org.bukkit.command.Command; -import org.bukkit.command.PluginCommand; -import org.bukkit.command.SimpleCommandMap; -import org.bukkit.event.Event; -import org.bukkit.plugin.*; -import java.io.File; -import java.lang.reflect.Field; -import java.util.*; - - -public class DitPluginManager { - private static DITSystem plugin; - public DitPluginManager(DITSystem instance){ - plugin = instance; - } - - public static int load(final String pluginName) { - PluginManager pm = Bukkit.getServer().getPluginManager(); - boolean there = false; - for (Plugin pl : pm.getPlugins()){ - if (pl.getName().toLowerCase().startsWith(pluginName)){ - there = true; - } - } - - - if (there) - { return 1;} //plugin already exists - else { - String name = ""; - String path = plugin.getDataFolder().getParent(); - File folder = new File(path); - ArrayList files = new ArrayList(); - File[] listOfFiles = folder.listFiles(); - for (File compare : listOfFiles) { - if (compare.isFile()) { - try { - name = plugin.getPluginLoader().getPluginDescription(compare).getName(); - } catch (InvalidDescriptionException e) { - plugin.getLogger().warning("[Loading Plugin] " + compare.getName() + " didn't match"); - } - if (name.toLowerCase().startsWith(pluginName.toLowerCase())) { - files.add(compare); - try { - Bukkit.getServer().getPluginManager().loadPlugin(compare); - } catch (UnknownDependencyException e) { - return 2; //missing dependent plugin - } catch (InvalidPluginException e) { - return -1; //not a plugin - } catch (InvalidDescriptionException e) { - return 3; //invalid description - } - } - } - } - - Plugin[] plugins = pm.getPlugins(); - for (Plugin pl : plugins) { - for (File compare : files) { - try { - if (pl.getName().equalsIgnoreCase(plugin.getPluginLoader().getPluginDescription(compare).getName())) - if (!pl.isEnabled()){ - pm.enablePlugin(pl); - }else { return 5; } - } catch (InvalidDescriptionException e) { - e.printStackTrace(); - } - } - } - } - return 0; //success - } - - - @SuppressWarnings("unchecked") - public static int unload(String pluginName) { - pluginName = pluginName.toLowerCase().trim(); - PluginManager manager = Bukkit.getServer().getPluginManager(); - SimplePluginManager spm = (SimplePluginManager) manager; - SimpleCommandMap commandMap = null; - List plugins = null; - Map lookupNames = null; - Map knownCommands = null; - Map> listeners = null; - boolean reloadlisteners = true; - try { - if (spm != null) { - Field pluginsField = spm.getClass().getDeclaredField("plugins"); - pluginsField.setAccessible(true); - plugins = (List) pluginsField.get(spm); - - Field lookupNamesField = spm.getClass().getDeclaredField("lookupNames"); - lookupNamesField.setAccessible(true); - lookupNames = (Map) lookupNamesField.get(spm); - - try { - Field listenersField = spm.getClass().getDeclaredField("listeners"); - listenersField.setAccessible(true); - listeners = (Map>) listenersField.get(spm); - } catch (Exception e) { - reloadlisteners = false; - } - - Field commandMapField = spm.getClass().getDeclaredField("commandMap"); - commandMapField.setAccessible(true); - commandMap = (SimpleCommandMap) commandMapField.get(spm); - - Field knownCommandsField = commandMap.getClass().getDeclaredField("knownCommands"); - knownCommandsField.setAccessible(true); - knownCommands = (Map) knownCommandsField.get(commandMap); - } - } catch (Exception e) { - e.printStackTrace(); - } - boolean in = false; - - for (Plugin pl : Bukkit.getServer().getPluginManager().getPlugins()) { - if (in) - break; - if (pl.getName().toLowerCase().startsWith(pluginName.toLowerCase())) { - if (pl.isEnabled()) { - manager.disablePlugin(pl); - if (plugins != null && plugins.contains(pl)) - plugins.remove(pl); - - if (lookupNames != null && lookupNames.containsKey(pl.getName())) { - lookupNames.remove(pl.getName()); - } - - if (listeners != null && reloadlisteners) { - for (SortedSet set : listeners.values()) { - for (Iterator it = set.iterator(); it.hasNext(); ) { - RegisteredListener value = it.next(); - - if (value.getPlugin() == pl) { - it.remove(); - } - } - } - } - - if (commandMap != null) { - - for (Iterator> it = knownCommands.entrySet().iterator(); it.hasNext(); ) { - Map.Entry entry = it.next(); - if (entry.getValue() instanceof PluginCommand) { - PluginCommand c = (PluginCommand) entry.getValue(); - if (c.getPlugin() == pl) { - c.unregister(commandMap); - it.remove(); - } - } - } - } - for (Plugin plu : Bukkit.getServer().getPluginManager().getPlugins()) { - if (plu.getDescription().getDepend() != null) { - for (String depend : plu.getDescription().getDepend()) { - if (depend.equalsIgnoreCase(pl.getName())) { - plugin.getLogger().info("[Unloading Plugin] " + plu.getName() + " must be disabled!"); - unload(plu.getName()); - return 1; //dependencies also disabled - } - } - } - } - in = true; - } else { return 5; } - } - } - if (!in) { - plugin.getLogger().info("Not an existing plugin"); - return -1; //non-existent - } - System.gc(); - return 0; //success - } - - - -} -*/