Class Register
Primary path: reads the compile-time @AutoRegister index written by the
singularitylib-processor annotation processor from every
META-INF/singularitylib/auto-register-index.properties resource visible on
the runtime classpath, instantiates each listed class via its no-arg constructor
and sorts it into listeners, commands and custom items.
Fallback path: if no index resource exists (legacy consumers compiled without the
processor), scanAndCollect(String) performs the old slow Reflections
classpath scan. Both paths share the same classification logic.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringClasspath resource path of the compile-time auto-register index. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionGets the collected commands.Gets the collected custom items.Set<org.bukkit.event.Listener> Gets the collected listeners.booleanLoads the compile-time@AutoRegisterindex from every resource named "META-INF/singularitylib/auto-register-index.properties" on the runtime classpath and collects the listed classes for registration.booleanloadFromIndex(ClassLoader classLoader) Loads the compile-time@AutoRegisterindex using an explicit classloader.voidExplicitly registers component CLASSES (no index, no classpath scanning).voidExplicitly registers component INSTANCES (already constructed by the caller) — the fastest path, with no reflection at all.voidregisterAll(org.bukkit.plugin.Plugin plugin) Registers all collected components with the specified plugin.static voidResets the cross-process dedupe set.voidscanAndCollect(String packageName) Deprecated.
-
Field Details
-
INDEX_RESOURCE
Classpath resource path of the compile-time auto-register index. Kept in sync withAutoRegisterProcessor#INDEX_RESOURCEin thesingularitylib-processormodule.- See Also:
-
-
Constructor Details
-
Register
public Register()Default constructor for Register.
-
-
Method Details
-
resetDedupe
public static void resetDedupe()Resets the cross-process dedupe set. Used by tests between runs; not intended for production use. -
loadFromIndex
public boolean loadFromIndex()Loads the compile-time@AutoRegisterindex from every resource named "META-INF/singularitylib/auto-register-index.properties" on the runtime classpath and collects the listed classes for registration.The classpath is resolved from
Thread.currentThread().getContextClassLoader(), which on a Paper server is thePluginClassLoaderof the plugin doing the lookup. Because the library plugin declaresjoin-classpath: truein itspaper-plugin.yml, every consumer plugin can also see the library's own jar (and thus its index).- Returns:
trueif at least one index was found and processed,falseif no index resource exists anywhere on the classpath
-
loadFromIndex
Loads the compile-time@AutoRegisterindex using an explicit classloader.- Parameters:
classLoader- the classloader to resolve index resources with- Returns:
trueif at least one index was found and processed,falseif no index resource exists
-
register
Explicitly registers component CLASSES (no index, no classpath scanning). Each class is instantiated via its no-arg constructor and classified into listeners / commands / custom items — the fast, explicit path.- Parameters:
classes- the component classes to register (must have a no-arg constructor)
-
register
Explicitly registers component INSTANCES (already constructed by the caller) — the fastest path, with no reflection at all.- Parameters:
instances- the component instances to register
-
scanAndCollect
Deprecated.Scans the specified package for annotated classes and collects them for registration.Deprecated: the compile-time index (
loadFromIndex()) replaces the Reflections classpath scan. Consumers compiled with thesingularitylib-processorannotation processor do not need to call this method at all —loadFromIndex()covers them. This fallback only exists for legacy consumers whose jars were built without an index.- Parameters:
packageName- the package name to scan
-
registerAll
public void registerAll(org.bukkit.plugin.Plugin plugin) Registers all collected components with the specified plugin.- Parameters:
plugin- the plugin to register components with
-
getListeners
Gets the collected listeners.- Returns:
- set of listeners
-
getCommands
-
getCustomItems
Gets the collected custom items.- Returns:
- list of custom items
-