Fix lookupname not being removed when unloading a plugin

This commit is contained in:
Frank van der Heijden 2020-06-03 13:40:11 +02:00
parent 0b4548ee28
commit beca8d4c19
No known key found for this signature in database
GPG key ID: 26DA56488D314D11
2 changed files with 13 additions and 3 deletions

View file

@ -46,6 +46,7 @@ public class PluginManager {
try {
Bukkit.getPluginManager().disablePlugin(plugin);
RSimplePluginManager.getPlugins(Bukkit.getPluginManager()).remove(plugin);
RSimplePluginManager.removeLookupName(Bukkit.getPluginManager(), plugin.getName());
} catch (Exception ex) {
ex.printStackTrace();
return Result.ERROR;

View file

@ -4,11 +4,11 @@ import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.SimplePluginManager;
import java.lang.reflect.Field;
import java.util.List;
import java.util.Map;
import java.util.*;
import static net.frankheijden.serverutils.reflection.ReflectionUtils.FieldParam.fieldOf;
import static net.frankheijden.serverutils.reflection.ReflectionUtils.VersionParam.ALL_VERSIONS;
import static net.frankheijden.serverutils.reflection.ReflectionUtils.get;
import static net.frankheijden.serverutils.reflection.ReflectionUtils.getAllFields;
public class RSimplePluginManager {
@ -20,7 +20,8 @@ public class RSimplePluginManager {
try {
simplePluginManagerClass = SimplePluginManager.class;
fields = getAllFields(simplePluginManagerClass,
fieldOf("plugins", ALL_VERSIONS));
fieldOf("plugins", ALL_VERSIONS),
fieldOf("lookupNames", ALL_VERSIONS));
} catch (Exception ex) {
ex.printStackTrace();
}
@ -30,4 +31,12 @@ public class RSimplePluginManager {
public static List<Plugin> getPlugins(Object manager) throws IllegalAccessException {
return (List<Plugin>) fields.get("plugins").get(manager);
}
@SuppressWarnings("unchecked")
public static void removeLookupName(Object manager, String name) throws IllegalAccessException {
Map<String, Plugin> lookupNames = (Map<String, Plugin>) get(fields, manager, "lookupNames");
if (lookupNames == null) return;
lookupNames.remove(name.replace(' ', '_'));
lookupNames.remove(name.replace(' ', '_').toLowerCase(Locale.ENGLISH)); // Paper
}
}