mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-18 18:23:06 +00:00
Merge pull request #547 from CocoTheOwner/noSelfDistruct
This doesnt get used yeet
This commit is contained in:
commit
7118261fee
@ -59,99 +59,6 @@ public abstract class VolmitPlugin extends JavaPlugin implements Listener {
|
|||||||
private KList<IController> cachedControllers;
|
private KList<IController> cachedControllers;
|
||||||
private KMap<Class<? extends IController>, IController> cachedClassControllers;
|
private KMap<Class<? extends IController>, IController> cachedClassControllers;
|
||||||
|
|
||||||
public void selfDistruct() {
|
|
||||||
HandlerList.unregisterAll((Plugin) this);
|
|
||||||
getServer().getScheduler().cancelTasks(this);
|
|
||||||
File me = getFile();
|
|
||||||
Plugin plugin = this;
|
|
||||||
String name = plugin.getName();
|
|
||||||
SimpleCommandMap commandMap = null;
|
|
||||||
List<Plugin> plugins = null;
|
|
||||||
Map<String, Plugin> names = null;
|
|
||||||
Map<String, Command> commands = null;
|
|
||||||
Map<Event, SortedSet<RegisteredListener>> listeners = null;
|
|
||||||
|
|
||||||
try {
|
|
||||||
|
|
||||||
Field pluginsField = Bukkit.getPluginManager().getClass().getDeclaredField("plugins");
|
|
||||||
pluginsField.setAccessible(true);
|
|
||||||
//noinspection unchecked
|
|
||||||
plugins = (List<Plugin>) pluginsField.get(getServer().getPluginManager());
|
|
||||||
Field lookupNamesField = Bukkit.getPluginManager().getClass().getDeclaredField("lookupNames");
|
|
||||||
lookupNamesField.setAccessible(true);
|
|
||||||
//noinspection unchecked
|
|
||||||
names = (Map<String, Plugin>) lookupNamesField.get(getServer().getPluginManager());
|
|
||||||
|
|
||||||
try {
|
|
||||||
Field listenersField = Bukkit.getPluginManager().getClass().getDeclaredField("listeners");
|
|
||||||
listenersField.setAccessible(true);
|
|
||||||
//noinspection unchecked
|
|
||||||
listeners = (Map<Event, SortedSet<RegisteredListener>>) listenersField.get(getServer().getPluginManager());
|
|
||||||
} catch (Throwable e) {
|
|
||||||
Iris.reportError(e);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
Field commandMapField = Bukkit.getPluginManager().getClass().getDeclaredField("commandMap");
|
|
||||||
commandMapField.setAccessible(true);
|
|
||||||
commandMap = (SimpleCommandMap) commandMapField.get(getServer().getPluginManager());
|
|
||||||
Field knownCommandsField = SimpleCommandMap.class.getDeclaredField("knownCommands");
|
|
||||||
knownCommandsField.setAccessible(true);
|
|
||||||
//noinspection unchecked
|
|
||||||
commands = (Map<String, Command>) knownCommandsField.get(commandMap);
|
|
||||||
|
|
||||||
} catch (Throwable e) {
|
|
||||||
Iris.reportError(e);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
getServer().getPluginManager().disablePlugin(plugin);
|
|
||||||
plugins.remove(plugin);
|
|
||||||
names.remove(name);
|
|
||||||
|
|
||||||
if (listeners != null) {
|
|
||||||
for (SortedSet<RegisteredListener> set : listeners.values()) {
|
|
||||||
set.removeIf(value -> value.getPlugin().equals(plugin));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (Iterator<Map.Entry<String, Command>> it = commands.entrySet().iterator(); it.hasNext(); ) {
|
|
||||||
Map.Entry<String, Command> entry = it.next();
|
|
||||||
if (entry.getValue() instanceof PluginCommand c) {
|
|
||||||
if (c.getPlugin() == plugin) {
|
|
||||||
c.unregister(commandMap);
|
|
||||||
it.remove();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
new Thread(() -> {
|
|
||||||
// Attempt to close the classloader to unlock any handles on the
|
|
||||||
// plugin's
|
|
||||||
// jar file.
|
|
||||||
ClassLoader cl = plugin.getClass().getClassLoader();
|
|
||||||
|
|
||||||
if (cl instanceof URLClassLoader) {
|
|
||||||
try {
|
|
||||||
((URLClassLoader) cl).close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
Iris.reportError(e);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Will not work on processes started with the -XX:+DisableExplicitGC
|
|
||||||
// flag,
|
|
||||||
// but lets try it anyway. This tries to get around the issue where
|
|
||||||
// Windows
|
|
||||||
// refuses to unlock jar files that were previously loaded into the JVM.
|
|
||||||
System.gc();
|
|
||||||
if (!me.delete()) {
|
|
||||||
me.deleteOnExit();
|
|
||||||
}
|
|
||||||
}).start();
|
|
||||||
}
|
|
||||||
|
|
||||||
public File getJarFile() {
|
public File getJarFile() {
|
||||||
return getFile();
|
return getFile();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user