Class UltiToolsPlugin
- All Implemented Interfaces:
Configurable, IPlugin
- Version:
- 1.0.0
- Author:
- wisdomme
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate SimpleContainerprivate DataScopeprivate final Stringprivate static final LoggerNamed logger for module reload outcomes.private final Stringprivate final intprivate final Stringprivate TextEngine.Prepared(package private) static final StringThe partial reason in the reportreloadWithReport()returns when the call was refused because it was made off the server thread (#538).private Stringprivate TextEngineprivate final String -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static StringdescribeFailure(Throwable failure) A failure's message for a one-line report, or its class name when it carries none.private voidDiffs aConfigurable.getAllConfigs()override against what auto-registration already registered for this module (D-06 / SILENT-18 / #336), called once right after package-scan auto-registration finishes.static CommandManager<T extends AbstractConfigEntity>
TGet config by config type.<T extends AbstractConfigEntity>
TGet config by config path and config type.protected final FilegetConfigFile(String path) protected final Stringstatic ConfigManager<T extends AbstractConfigEntity>
List<T> getConfigs(Class<T> configType) final <T extends BaseDataEntity<String>>
DataOperator<T> getDataOperator(Class<T> dataClazz) Gets data operator.private InputStreamstatic ListenerManagerstatic PluginManagerprivate voidInitializes the configuration entity.booleanisNewerVersionThan(UltiToolsPlugin plugin) private org.bukkit.configuration.file.YamlConfigurationLoads the plugin configuration from plugin.ymlfinal Optional<ModuleTexts> Exposes the module's text lookup without making its prepared catalogue visible to other modules.private booleannamesConfigDirectory(String configFilePath) protected voidonReload()Extension point for a module's own reload work.protected voidonReload(ReloadReport report) Extension point for a module's own reload work, with a way to report a partial reload (#529).protected voidExtension point for a module's own unload cleanup.private StringThe framework'slanguagesetting as it is inconfig.ymlon disk now, when it differs from the value the framework runs with (#502).private ReloadReportThe body ofreloadSelf()andreloadWithReport().private voidPrepares converters and checks only enabled auto-config entities before resources are extracted.final voidPublishes an accepted candidate's prepared message catalogue before container assembly.final voidReload this plugin's configuration and language files.final ReloadReportReloads this module exactly asreloadSelf()does, and returns what its reload hook reported (#529).private StringBest-effort resolution of this module's own JAR file name, for thename:-missing refusal message only.private static <T extends Throwable>
voidrethrowUnchanged(Throwable failure) Throwsfailureitself -- the same instance, of its own type, unwrapped -- although it may be a checked exception this method's callers do not declare.final voidRestores the prior message catalogue when an accepted candidate subsequently fails to load.private voidrunReloadSteps(ReloadReport report) The reload steps, in order, ending with the module's own hook.private static ThrowablerunUnregisterStep(Throwable previousFailure, Runnable step) Runs oneunregisterSelf()cleanup step, collecting any failure ontopreviousFailureinstead of letting it replace or be replaced by another step's failure.<T extends AbstractConfigEntity>
voidsaveConfig(String path, Class<T> configType) Saves this module's configuration registered atpaththroughAbstractConfigEntity.save(): only the settings the module changed since the last load or save are written, and only where the file still holds the value the module started from; every other byte of the file stays as the operator left it, and a change that cannot be written stays in memory and is named in one warning.private voidExtracts missing bundled resources and configuration intoresourceFolderPath.voidsetContext(SimpleContainer context) Injects the IoC container created for this plugin.voidsetDataScope(DataScope scope) Injects theDataScopecredentialPluginManagerminted for this module (D-17).final voidUnloads this module's own registrations: runsonUnregister(), then unregisters this module's commands, then its listeners.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Configurable
getAllConfigsMethods inherited from interface IPlugin
registerSelf
-
Field Details
-
LOGGER
Named logger for module reload outcomes. -
RELOAD_REFUSED_OFF_THREAD_REASON
The partial reason in the reportreloadWithReport()returns when the call was refused because it was made off the server thread (#538). Not an i18n key: nothing reaches the operator through it on the framework's own reload paths, which run on the server thread; it is for a module that callsreloadWithReport()itself.- See Also:
-
textEngine
-
preparedMessages
-
version
-
pluginName
-
authors
-
loadAfter
-
minUltiToolsVersion
private final int minUltiToolsVersion -
mainClass
-
identifyString
-
resourceFolderPath
-
context
-
dataScope
-
-
Constructor Details
-
UltiToolsPlugin
protected UltiToolsPlugin()Constructor for UltiToolsPlugin. For module development only. -
UltiToolsPlugin
public UltiToolsPlugin(String pluginName, String version, List<String> authors, List<String> loadAfter, int minUltiToolsVersion, String mainClass, String resourceFolderPath) Constructor for UltiToolsPlugin. For plugin connector.- Parameters:
pluginName- the name of the pluginversion- the version of the pluginauthors- the authors of the pluginloadAfter- the plugins which should be loaded before this pluginminUltiToolsVersion- the minimum version of UltiTools required by this pluginmainClass- the main class of the pluginresourceFolderPath- the path to the resource folder
-
-
Method Details
-
publishMessageCatalogue
@Internal public final void publishMessageCatalogue()Publishes an accepted candidate's prepared message catalogue before container assembly. -
rollbackMessagePublication
@Internal public final void rollbackMessagePublication()Restores the prior message catalogue when an accepted candidate subsequently fails to load. -
loadPluginConfiguration
private org.bukkit.configuration.file.YamlConfiguration loadPluginConfiguration()Loads the plugin configuration from plugin.yml- Returns:
- YamlConfiguration object with default values if loading fails
-
setContext
Injects the IoC container created for this plugin.Called by
PluginManagerwhile a module is being loaded, beforeregisterSelf()runs. It is not part of the module-facing API — a module that calls it replaces the container the framework already wired up, losing every bean that was injected into it.Deliberately still public:
PluginManagerlives in another package, so this cannot be narrowed to package-private, and deleting it outright would remove a public method, which the compatibility policy forbids in a PATCH release. The annotation is a signal to humans and IDEs; it enforces nothing at runtime.- Parameters:
context- the container created for this plugin
-
moduleTexts
Exposes the module's text lookup without making its prepared catalogue visible to other modules.- Returns:
- an empty result when no module messages service was prepared
-
setDataScope
Injects theDataScopecredentialPluginManagerminted for this module (D-17). Called byPluginManagerright after minting, beforewireAopruns -- the same lifecycle pointsetContext(SimpleContainer)documents.Deliberately still public, for the same reason
setContext(SimpleContainer)is:PluginManagerlives in another package and cannot be narrowed to package-private, and the compatibility policy forbids removing a public method in a PATCH release. The annotation is a signal to humans and IDEs; it enforces nothing at runtime.- Parameters:
scope- the scope minted for this plugin- Since:
- 6.3.0
-
getConfigManager
- Returns:
- the config manager
-
getListenerManager
- Returns:
- the listener manager
-
getCommandManager
- Returns:
- the command manager
-
getPluginManager
- Returns:
- the plugin manager
-
prepareConfigConverters
private void prepareConfigConverters()Prepares converters and checks only enabled auto-config entities before resources are extracted. -
initConfig
Initializes the configuration entity.- Throws:
IOException
-
diffGetAllConfigsOverride
private void diffGetAllConfigsOverride()Diffs aConfigurable.getAllConfigs()override against what auto-registration already registered for this module (D-06 / SILENT-18 / #336), called once right after package-scan auto-registration finishes.An empty override (the interface default - the module never wrote
Configurable.getAllConfigs()) has nothing to compare and nothing to log. A non-empty override whose everyconfigFilePathwas already registered by the package scan is pure redundancy, logged atLevel.FINEonly. A non-empty override naming aconfigFilePaththe scan never registered is real capability loss - #336's warning-only ask cannot tell these two cases apart, so this refuses the module and names every missing entity instead of guessing.A directory-backed entity is the exception to the path comparison. Auto-registration expands a
configFilePaththat names a directory undergetResourceFolderPath()(the sameisDirectory()testConfigManager#registerapplies) into one registration per file inside it, and registers nothing for an empty directory, so the unexpanded path is never a registered key. Such an override entity counts as found when its class is among the config classes package-scan auto-registration selected - the sameConverterRegistry.prepareSelectedConfigs(UltiToolsPlugin, String[], ClassLoader)selection over the same scan packages and class loaderinitConfig()hands toConfigManager#registerAll. An entity class the scan did not select is still refused. This method only reads registrations, the selected classes and whether a path is a directory; it never writes or creates a configuration file.- Throws:
ConfigurationException- if the override names aconfigFilePathauto-registration never registered
-
namesConfigDirectory
- Parameters:
configFilePath- aconfigFilePathfrom aConfigurable.getAllConfigs()override- Returns:
- whether it names an existing directory under this module's resource folder, the
test
ConfigManager#registeruses to expand a directory-backed entity
-
getInputStream
- Throws:
IOException
-
resolveJarFileNameForError
Best-effort resolution of this module's own JAR file name, for thename:-missing refusal message only. Never throws -- falls back to the class name if the code source is unavailable (e.g. when running from unpacked classes in a test).- Returns:
- the JAR file name, or this class's name if it cannot be determined
-
getConfigFolder
-
getConfigFile
-
getConfig
Description copied from interface:ConfigurableGet config by config type.- Specified by:
getConfigin interfaceConfigurable- Type Parameters:
T- Config type- Parameters:
configType- Config type- Returns:
- Config
-
getConfig
Description copied from interface:ConfigurableGet config by config path and config type.- Specified by:
getConfigin interfaceConfigurable- Type Parameters:
T- Config type- Parameters:
path- Config pathconfigType- Config type- Returns:
- the entity registered for
path, ornullif none is registered (a registered entity of another type throwsClassCastException)
-
getConfigs
-
saveConfig
public <T extends AbstractConfigEntity> void saveConfig(String path, Class<T> configType) throws IOException Saves this module's configuration registered atpaththroughAbstractConfigEntity.save(): only the settings the module changed since the last load or save are written, and only where the file still holds the value the module started from; every other byte of the file stays as the operator left it, and a change that cannot be written stays in memory and is named in one warning. It cannot overwrite operator content: a value the operator edited, deleted or wrote unusably is never written over (maintainer decision 2026-10-04). Use it for a change the operator asked for through the module, or for shipped text re-rendered after a language switch.If no entity is registered for
pathin this module, this method throwsIllegalStateExceptionnaming the module and path without creating, registering or writing a file, even if the file already exists on disk. Register the entity first, or callAbstractConfigEntity.save()on an entity you hold. Call this method on the server thread.- Specified by:
saveConfigin interfaceConfigurable- Type Parameters:
T- the configuration entity type- Parameters:
path- the registered configuration file path, for exampleconfig/config.ymlconfigType- the configuration entity class- Throws:
IOException- if publishing the verified file failsIllegalStateException- if no configuration entity is registered forpathin this module, or if the server is running and this is called off the server threadClassCastException- if the registered entity is not an instance ofconfigType; the message names the module, path, expected type and actual type
-
saveResources
private void saveResources()Extracts missing bundled resources and configuration intoresourceFolderPath. Validates each destination before writing, leaves existing files intact, and records the hashes of extracted files in a single batch for later configuration ownership checks. -
getDataOperator
Gets data operator. Refuses outright ifdataClazzis not registered to this module (D-14) -- checked against the sameDataScopeminted for this module at load, via the same refusalDataStore.getOperator(DataScope, Class)builds, so the exception type, error code, and message shape are identical regardless of which entry point a caller reaches.02-13 (CR-03): before this,
dataScope.owns(...)was checked here inline and this method then delegated to the deprecatedgetOperator(UltiToolsPlugin, Class)overload directly -- soDataStore.getOperator(DataScope, Class), the method D-17/02-07 built specifically as the credential-typed supported path, had zero real callers anywhere in the framework. This now routes through it, so production actually uses the path it was built for.dataScopeis non-null by the time any module calls this (set byPluginManagerright after minting, beforeregisterSelf()runs). A bare instance constructed outside the normalPluginManagerload flow has no scope and is refused withENTITY_NOT_OWNED; before 6.4.0 it fell back to the deprecatedDataStore.getOperator(UltiToolsPlugin, Class)overload, which was removed in 6.4.0.- Type Parameters:
T- the type of the data entity- Parameters:
dataClazz- the class of the data entity- Returns:
- the data operator
- Throws:
DataAccessException- ifdataClazzis not registered to this module, or this module was not loaded by the framework and so holds no data scope
-
isNewerVersionThan
- Parameters:
plugin- the plugin to be checked- Returns:
- whether the plugin is newer than the given plugin
-
onUnregister
protected void onUnregister()Extension point for a module's own unload cleanup.Called by
unregisterSelf()before the framework unregisters this plugin's commands and listeners (D-02), so the module's own beans are still alive while this runs.unregisterSelf()isfinaland always calls this hook and the framework's own unregistration afterward -- a module cannot skip either by overridingunregisterSelf()itself, because that is no longer possible (D-01). The default body does nothing; override this method, notunregisterSelf(), to add cleanup work.This hook may throw anything: an unchecked exception, an
Error, or a checked exception it does not declare (Lombok@SneakyThrows, or a rethrow helper). Whatever it throws,unregisterSelf()still unregisters this module's own commands and listeners before the exception propagates -- a throwing hook is surfaced to the caller, not swallowed, but it cannot skip the framework's own cleanup the way an unguardedsupercall could. The exception reaches the caller unchanged: the same instance, of the same type, never wrapped. If a cleanup step also fails, that failure does not replace this hook's own exception: it is attached to it viaThrowable.addSuppressed(Throwable)instead, so the module author's own failure is always the one that propagates and is never silently lost behind a secondary framework failure (Codex review on #457, issue #484). -
unregisterSelf
public final void unregisterSelf()Unloads this module's own registrations: runsonUnregister(), then unregisters this module's commands, then its listeners.final, so a module cannot skip either cleanup step.Every step runs whatever an earlier step threw, including a checked exception the hook does not declare. When a step failed, the first failure, in that order, is rethrown afterwards as the same instance and type, never wrapped; every later failure is attached to it via
Throwable.addSuppressed(Throwable). A checked exception therefore reaches the caller although this method declares none.- Specified by:
unregisterSelfin interfaceIPlugin
-
runUnregisterStep
Runs oneunregisterSelf()cleanup step, collecting any failure ontopreviousFailureinstead of letting it replace or be replaced by another step's failure.onUnregister(),CommandManager#unregisterAllandListenerManager#unregisterAlldeclare no checked exceptions, but module code can still throw one without declaring it (Lombok@SneakyThrows, or a rethrow helper). Catching onlyRuntimeException | Errorlet such an exception escape this barrier and skip every later step, leaving the module's commands and listeners registered after its unload. So this catchesException | Error: everyThrowablea step can really throw (this is a deliberate cleanup barrier, not a broad catch:unregisterSelf()always runs every remaining step and always rethrows exactly one collected failure unchanged, per its own javadoc).- Parameters:
previousFailure- the failure already collected from an earlier step, ornullif every earlier step (if any) succeededstep- the cleanup step to run- Returns:
previousFailure, withstep's own failure (if any) attached to it viaThrowable.addSuppressed(Throwable); or, ifpreviousFailurewasnull,step's own failure, ornullifstepcompleted normally
-
rethrowUnchanged
Throwsfailureitself -- the same instance, of its own type, unwrapped -- although it may be a checked exception this method's callers do not declare.unregisterSelf()uses it to hand a hook's undeclared checked exception to its caller unchanged.- Type Parameters:
T- inferred as an unchecked type at the call site, so nothrowsclause is needed- Parameters:
failure- the collected failure to rethrow- Throws:
T- always:failure
-
onReload
protected void onReload()Extension point for a module's own reload work.Called by
reloadSelf()after the framework's own reload steps -- config reload, config-bound timing refresh (#531), language-catalogue refresh and@ConditionalOnConfigdrift report (D-02) -- so a real-work override sees the already-reloaded configuration rather than the stale one. The framework-owned per-module reload line (D-03) is logged only after this hook returned; if it throws, a failure line naming the module is logged instead and the exception propagates to the caller (#509).reloadSelf()isfinaland always runs its own steps first; a module cannot skip them by overridingreloadSelf()itself, because that is no longer possible (D-01). The default body does nothing; override this method, notreloadSelf(), to add reload work. -
onReload
Extension point for a module's own reload work, with a way to report a partial reload (#529).Called by
reloadSelf()andreloadWithReport()at the pointonReload()is documented to run, with a freshReloadReport. A module that reloads only part of what it should records each part that did not reload withReloadReport.partial(String)and returns normally; the framework then reports the reload as partial, naming those parts, instead of as a success. The default body callsonReload(), so a module that overrides only that method behaves exactly as before 6.3.0. Override one of the two, not both: an override of this method replaces the call toonReload()unless it callssuper.onReload(report).- Parameters:
report- the report for this reload, to record the parts that did not reload- Since:
- 6.3.0
-
reloadSelf
public final void reloadSelf()Reload this plugin's configuration and language files.Also reports (but does not act on) any
@ConditionalOnConfigdrift: the condition is evaluated once, at component-scan time during startup, so a reload can only log that a watched key has changed direction since then -- it never registers, unregisters, or rebuilds anything (issue #392, D-01). Right after the configuration reload, and only if it succeeded, the module's config-bound@Scheduledtasks and@CmdCDcooldowns pick up their reloaded values (#531; seePluginManager#applyReloadedConfigBindings); a value that step refuses and keeps, or a part of it that fails, is recorded in theReloadReportas a part that did not reload (#595).finaland always runs its own steps, then callsonReload()-- a module can no longer skip any of this by overridingreloadSelf()itself, because that override point no longer exists (D-01). The hook it calls isonReload(ReloadReport), whose default body callsonReload().Only when every step and the hook returned does it log one framework-owned line naming this module (D-03): an INFO success line, or a WARNING naming the parts that did not reload when the hook recorded any in its
ReloadReport(#529). If anything throws, it logs one SEVERE line naming the module and the cause instead, never the success line, and rethrows the failure unchanged, so a caller can report it --/ul reload <name>replies failure, and a full/ul reloadcarries on with the next module and names this one in its summary (#509).The signature is unchanged since 6.2;
reloadWithReport()runs the same reload and returns the report.- Specified by:
reloadSelfin interfaceIPlugin
-
reloadWithReport
Reloads this module exactly asreloadSelf()does, and returns what its reload hook reported (#529)./ul reloadand/ul reload <name>call this to tell the operator which parts of a module did not reload. A module's own reload command can call it for the same reason.- Returns:
- the report of this reload, never
null; empty when every part reloaded - Throws:
RuntimeException- whatever a reload step or the module's hook threw, after it was logged (a checked exception the hook threw without declaring it propagates unchanged in the same way)Error- whatever a reload step or the module's hook threw, after it was logged- Since:
- 6.3.0
-
performReload
The body ofreloadSelf()andreloadWithReport(). Private, so both public entry points always run exactly this.- Returns:
- the report the module's hook filled in; when the call was refused off the server thread (#538), a report whose only partial reason is that refusal
-
runReloadSteps
The reload steps, in order, ending with the module's own hook.- Parameters:
report- the report handed to the module's hook
-
pendingLanguageSetting
The framework'slanguagesetting as it is inconfig.ymlon disk now, when it differs from the value the framework runs with (#502).The framework reads its configuration once and re-reads it only on a full
/ul reload. A missing, unreadable or unparseable file, or one without the key, is not a pending change: that is reported, if at all, by the full reload that reads it.- Returns:
- the reason reported for a pending change, or
nullif none was detected
-
describeFailure
-
getLogger
- Returns:
- plugin logger
-