Add implementation for paper (paper really likes to do crap)
This commit is contained in:
parent
4fc4f7fdd3
commit
fd161ddef1
1 changed files with 46 additions and 11 deletions
|
|
@ -4,26 +4,47 @@ import dev.frankheijden.minecraftreflection.MinecraftReflection;
|
|||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Pattern;
|
||||
import dev.frankheijden.minecraftreflection.exceptions.MinecraftReflectionException;
|
||||
import net.frankheijden.serverutils.bukkit.ServerUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.PluginLoader;
|
||||
import org.bukkit.plugin.SimplePluginManager;
|
||||
|
||||
public class RSimplePluginManager {
|
||||
private static final MinecraftReflection reflection = MinecraftReflection.of(Bukkit.getPluginManager().getClass());
|
||||
private static final MinecraftReflection paperPluginManagerReflection;
|
||||
private static final MinecraftReflection paperInstanceManagerReflection;
|
||||
|
||||
private static final MinecraftReflection reflection = MinecraftReflection.of(SimplePluginManager.class);
|
||||
static {
|
||||
MinecraftReflection pluginManagerReflection;
|
||||
MinecraftReflection instanceManagerReflection;
|
||||
try {
|
||||
pluginManagerReflection =
|
||||
MinecraftReflection.of("io.papermc.paper.plugin.manager.PaperPluginManagerImpl");
|
||||
instanceManagerReflection =
|
||||
MinecraftReflection.of("io.papermc.paper.plugin.manager.PaperPluginInstanceManager");
|
||||
} catch (MinecraftReflectionException e) {
|
||||
pluginManagerReflection = null;
|
||||
instanceManagerReflection = null;
|
||||
}
|
||||
paperPluginManagerReflection = pluginManagerReflection;
|
||||
paperInstanceManagerReflection = instanceManagerReflection;
|
||||
}
|
||||
|
||||
public static MinecraftReflection getReflection() {
|
||||
return reflection;
|
||||
}
|
||||
|
||||
public static Map<Pattern, PluginLoader> getFileAssociations(Object manager) throws IllegalAccessException {
|
||||
return reflection.get(manager, "fileAssociations");
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a list of plugins.
|
||||
* @param manager The SimplePluginManager instance to get plugins from.
|
||||
* @return list of plugins.
|
||||
*/
|
||||
public static List<Plugin> getPlugins(Object manager) {
|
||||
if (paperPluginManagerReflection == null) {
|
||||
return reflection.get(manager, "plugins");
|
||||
}
|
||||
return paperInstanceManagerReflection.get(getInstanceManager(manager), "plugins");
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the lookup name of the plugin.
|
||||
|
|
@ -32,9 +53,23 @@ public class RSimplePluginManager {
|
|||
* @param name The name of the plugin to remove.
|
||||
*/
|
||||
public static void removeLookupName(Object manager, String name) {
|
||||
Map<String, Plugin> lookupNames = reflection.get(manager, "lookupNames");
|
||||
if (lookupNames == null) return;
|
||||
Map<String, Plugin> lookupNames;
|
||||
if (paperPluginManagerReflection == null) {
|
||||
lookupNames = reflection.get(manager, "lookupNames");
|
||||
} else {
|
||||
lookupNames = paperInstanceManagerReflection.get(getInstanceManager(manager), "lookupNames");
|
||||
}
|
||||
if (lookupNames == null) {
|
||||
ServerUtils.getInstance().getLogger()
|
||||
.warning("Cannot remove lookup name '" + name + "' because lookupNames is null");
|
||||
return;
|
||||
}
|
||||
lookupNames.remove(name.replace(' ', '_'));
|
||||
lookupNames.remove(name.replace(' ', '_').toLowerCase(Locale.ENGLISH)); // Paper
|
||||
}
|
||||
|
||||
private static Object getInstanceManager(Object manager) {
|
||||
Object paperPluginManager = reflection.get(manager, "paperPluginManager");
|
||||
return paperPluginManagerReflection.get(paperPluginManager, "instanceManager");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue