Fix lookupname not being removed when unloading a plugin
This commit is contained in:
parent
0b4548ee28
commit
beca8d4c19
2 changed files with 13 additions and 3 deletions
|
|
@ -46,6 +46,7 @@ public class PluginManager {
|
||||||
try {
|
try {
|
||||||
Bukkit.getPluginManager().disablePlugin(plugin);
|
Bukkit.getPluginManager().disablePlugin(plugin);
|
||||||
RSimplePluginManager.getPlugins(Bukkit.getPluginManager()).remove(plugin);
|
RSimplePluginManager.getPlugins(Bukkit.getPluginManager()).remove(plugin);
|
||||||
|
RSimplePluginManager.removeLookupName(Bukkit.getPluginManager(), plugin.getName());
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
return Result.ERROR;
|
return Result.ERROR;
|
||||||
|
|
|
||||||
|
|
@ -4,11 +4,11 @@ import org.bukkit.plugin.Plugin;
|
||||||
import org.bukkit.plugin.SimplePluginManager;
|
import org.bukkit.plugin.SimplePluginManager;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.util.List;
|
import java.util.*;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import static net.frankheijden.serverutils.reflection.ReflectionUtils.FieldParam.fieldOf;
|
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.VersionParam.ALL_VERSIONS;
|
||||||
|
import static net.frankheijden.serverutils.reflection.ReflectionUtils.get;
|
||||||
import static net.frankheijden.serverutils.reflection.ReflectionUtils.getAllFields;
|
import static net.frankheijden.serverutils.reflection.ReflectionUtils.getAllFields;
|
||||||
|
|
||||||
public class RSimplePluginManager {
|
public class RSimplePluginManager {
|
||||||
|
|
@ -20,7 +20,8 @@ public class RSimplePluginManager {
|
||||||
try {
|
try {
|
||||||
simplePluginManagerClass = SimplePluginManager.class;
|
simplePluginManagerClass = SimplePluginManager.class;
|
||||||
fields = getAllFields(simplePluginManagerClass,
|
fields = getAllFields(simplePluginManagerClass,
|
||||||
fieldOf("plugins", ALL_VERSIONS));
|
fieldOf("plugins", ALL_VERSIONS),
|
||||||
|
fieldOf("lookupNames", ALL_VERSIONS));
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
@ -30,4 +31,12 @@ public class RSimplePluginManager {
|
||||||
public static List<Plugin> getPlugins(Object manager) throws IllegalAccessException {
|
public static List<Plugin> getPlugins(Object manager) throws IllegalAccessException {
|
||||||
return (List<Plugin>) fields.get("plugins").get(manager);
|
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue