PluginBridge

internal object PluginBridge

Class lookup across the classloaders of a hybrid server (Silkard, Youer, ...), reached from MaskingClassLoader's snippet loader once nothing in the host has the name.

Reflective throughout: common links only the JDK and Minecraft, while Bukkit either exists on the game loader at runtime or does not exist at all. The reflective handles are resolved once; the plugin list never is — it is read live per lookup, so enabling, disabling or reloading a plugin needs no invalidation.

There are more loaders than plugins. Two shapes hang one off the side of a plugin loader, both CHILDREN of it, so walking parents misses both: libraryLoader (the plugin's Maven libraries:, a field on the loader) and jar-in-jar (a nested implementation jar extracted at startup, then fed downloaded dependencies at runtime — only the plugin object holds it). collectFieldLoaders finds both by reading each field VALUE and asking which loader defined it. Not the field TYPE: LuckPerms declares its bootstrap field as LoaderBootstrap, so a type-based search finds nothing.

Only loaders the host cannot already reach belong here — this runs last, after masking, the game loader and its parents have all missed. The scan subtracts that chain explicitly, because a plugin loader's JavaPluginLoader field is defined by the server loader: left in, it drags the whole server classpath along behind it.

Types

Link copied to clipboard
private fun interface Plugins

Live view of the loaders behind the currently loaded plugins.

Link copied to clipboard
private class Scan(val from: List<ClassLoader>, val all: List<ClassLoader>)

The last expand, keyed by the plugin loaders it was derived from.

Properties

Link copied to clipboard
Link copied to clipboard

Functions

Link copied to clipboard
fun classFile(internalName: String): ByteArray?

The class file behind internalName, or null when no host loader holds it — asked in the order a snippet resolves the class, so what this reads is what would load. MC_LOADER alone is not enough on a plugin host: it is the server loader, the parent of everything plugin-side. Nor is GAME_LOADER a way past it: a Bukkit plugin loader answers getResource from its own jar only, so it gives this mod's classes and neither of the others.

Link copied to clipboard
private fun collectFieldLoaders(o: Any, stopAt: Class<*>, out: MutableSet<ClassLoader>)

Every loader one field deep from o: per field, the loader that defined its value — or the value itself, when it already is a loader.

Link copied to clipboard

Bukkit's own PluginManager covers both plugin families: on Paper the legacy SimplePluginManager forwards getPlugins() to the Paper implementation, whose list holds legacy and Paper plugins alike. null when the game loader has no Bukkit, i.e. not a hybrid server.

Link copied to clipboard
private fun expand(found: Array<*>, owners: List<ClassLoader>, host: Set<ClassLoader>): List<ClassLoader>

The plugin loaders plus whatever hangs off their side, cached against the plugin loaders themselves. getPlugins() is cheap enough per lookup — that is what keeps the list live and invalidation-free — but the field scan is not. Keying on the plugin loader list keeps both: enabling, disabling or reloading a plugin changes that list, misses the cache and rescans on its own.

Link copied to clipboard
private fun fieldsOf(k: Class<*>): Array<Field>

k's declared fields, or none when they cannot be listed. Listing resolves every field's type through k's loader, so one type that does not load takes the whole table — a soft dependency left uninstalled, or anything not yet loaded once a disabled plugin's loader is closed — while the plugin itself runs on. probing, not a LinkageError catch: that closed loader throws IllegalStateException, and a hybrid's class transformers anything at all. Skipping costs only a loader held in one of those fields; every other class, and every other plugin, is still read.

Link copied to clipboard
private fun fieldValue(f: Field, o: Any): Any?

f's value on o, or null when it is closed, broken or unset.

Link copied to clipboard
fun load(name: String): Class<*>?

The class as one of those loaders DEFINES it, or null when none does — including the ordinary mod runtime, where there are no plugins at all.

Link copied to clipboard

The same loaders load searches, for PluginJarCollector's compile classpath. The two MUST agree: a name the compiler resolves and the snippet loader then cannot find is a NoClassDefFoundError, strictly worse than the compile error it replaced.