Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions docs/src/guide/advanced/external-plugin-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@ On registration failure, UltiTools rolls back its registrations, including parti

As of v7.1.0, `connect` rejects conflicting entity ownership or data folders before creating any components. A message namespace conflict is still refused before component scanning, as in v7.0.0: storage is not opened and the plugin data folder is not created. If scanning itself fails (for example, because a service needs a proxy but its class is `final`), storage may already be open.

As of v7.2.0, `disconnect` waits for in-flight framework async command bodies within the [command wait allowance](../essentials/cmd-executor#execution-threads-and-unload), then releases registrations and destroys managed beans. A cleanup failure does not skip subsequent cleanup.
As of v7.2.0, call `disconnect` on the server thread. If you call it off the server thread, the UI teardown step fails. UltiTools logs the failure, but the remaining cleanup continues.

On explicit disconnect or automatic disconnect at disable, UltiTools waits for in-flight framework async command bodies within the [command wait allowance](../essentials/cmd-executor#execution-threads-and-unload). It then ends the connection's `UiService` sessions, retires its `Scheduler`, releases registrations and runs `@PreDestroy` on managed beans. The retired scheduler rejects new submissions with `RejectedExecutionException`; reconnecting gives the plugin a new scheduler and UI service.

As of v7.2.0, if you call `PluginManager.registerExternal` directly, use a new `ExternalPluginAdapter` for every attempt. Reusing an adapter throws `IllegalStateException`, even if the previous registration failed. `UltiToolsAPI.connect` already creates a fresh adapter when connecting, so callers of that API need no change.

During framework shutdown, UltiTools still attempts external disconnections before unloading its modules. As of v7.2.0, it logs each teardown failure by plugin or module name and continues, so a failed disconnect no longer prevents module unload.

Expand All @@ -84,7 +88,7 @@ When sharing a compiled output directory, use disjoint packages. For example, a
| `@Service` | Creates a managed bean with constructor or `@Autowired` field injection. As of v7.1.0, requesting `Plugin` or any class from the runtime class through `PluginBase` gives you the plugin itself. See [Plugin injection types](#plugin-injection). |
| `@CmdExecutor` | An annotated `BaseCommandExecutor` bean is compiled into a Brigadier tree unless `manualRegister = true`. The framework also discovers managed `BrigadierCommand` beans. |
| `@EventListener` | A bean implementing Bukkit `Listener` is registered unless `manualRegister = true`. Use Bukkit `@EventHandler` on its methods. |
| `@Scheduled` | Scheduled methods on managed beans use the framework scheduler and are cancelled on disconnect. Use literal `delay` and `period`; an asynchronous literal period is measured in wall-clock time at 50 ms per configured tick. |
| `@Scheduled` | As of v7.2.0, scheduled methods on managed beans use the same scheduler as work submitted through the connection's injected `Scheduler`. Disconnect cancels pending and repeating work from both sources. Use literal `delay` and `period`; an asynchronous literal period is measured in wall-clock time at 50 ms per configured tick. |
| `@PlayerCache` | Registers per-player cache fields for quit handling, including any configured save hook; the fields stop being tracked on disconnect. |
| `@ModuleEventHandler` | A public method on a managed bean with one `ModuleEvent` parameter (or a subtype) subscribes to the shared EventBus. Publish with `UltiToolsAPI.getEventBus().publish(event)`. |

Expand All @@ -102,9 +106,13 @@ As of v7.1.0, the following rules apply to an external plugin that calls `UltiTo
| `JavaPlugin`, the plugin's main class, its runtime class | The same plugin instance. Code already injecting `JavaPlugin` or the main class needs no change. |
| An author-defined base class between the main class and `JavaPlugin` | The same plugin instance. In v7.0.0 an unbound intermediate class could not be injected. |
| `CommandExecutor`, `TabExecutor`, `TabCompleter` | As of v7.2.0, resolved only from assignable components in the plugin's own container. If none match, an optional dependency stays absent and a required dependency fails. In v7.1.0, these types could fall back to UltiTools. |
| `LifecycleEventOwner`, `Namespaced` | These interfaces are not bound to the connected plugin. With no matching local component, the lookup can still return UltiTools through the parent container. |
| `LifecycleEventOwner`, `Namespaced` | As of v7.2.0, an assignable local component wins; otherwise, injection gives you the connected plugin. In v7.1.0, the fallback could return UltiTools. |
| `UltiTools` (concrete class) | As of v7.2.0, the framework plugin is no longer a by-type fallback. Without a matching local component, an optional dependency stays absent and a required dependency fails the connection. |
| `Scheduler`, `UiService` | As of v7.2.0, each connection receives its own [scheduler](./scheduled-tasks#scheduler-api) and [UI service](./ui-service). |

As of v7.2.0, when a by-type lookup falls back to the framework plugin, the container substitutes the connected plugin if it matches the requested type. Otherwise the dependency is absent. Other framework beans remain available. `getBeanNamesForType` still lists the `ultiTools` bean for matching types, and lookup by name (`getBean("ultiTools")`) still returns the framework plugin. Replace `@Autowired UltiTools` used to obtain the framework plugin with `Bukkit.getPluginManager().getPlugin("UltiTools")`.

The fallback in the last row remains a [known limitation (#1129)](https://github.com/UltiKits/UltiTools-Reborn/issues/1129). Declare a component implementing the required command callback interface to inject your own handler. To obtain the connected plugin, inject `Plugin` or the main class. Paper marks `LifecycleEventOwner` as non-extendable, so use the plugin rather than implementing it in a component. To obtain UltiTools explicitly, use `Bukkit.getPluginManager().getPlugin("UltiTools")`. A `@Bean` product is registered by its concrete class: declaring the method's return type as `Plugin` or another bound type does not change what is injected for that type.
Declare a component implementing the required command callback interface to inject your own handler. To obtain the connected plugin, inject `Plugin` or the main class. Paper marks `LifecycleEventOwner` as non-extendable, so use the plugin rather than implementing it in a component. A `@Bean` product is registered by its concrete class: declaring the method's return type as `Plugin` or another bound type does not change what is injected for that type.

### Migration from v7.0.0

Expand Down Expand Up @@ -181,8 +189,12 @@ A namespace conflict is refused before component scanning and does not create th

`[ULTI-6001] External plugin 'MatchingProbe' cannot use message namespace 'matchingprobe': it is already used by module 'MatchingProbe'`

Catalogue preparation can also fail with a runtime exception, such as `InvalidPathException` for an invalid path or `SecurityException` when signature verification fails while reading a signed JAR. These errors do not necessarily have a catalogue-specific `ULTI-` code. Check the cause of the `connect` exception, and inspect the packaged JAR and its path.

Call `UltiToolsAPI.reloadMessages(this)` from your own reload command to reread the bundled files and overrides. It can run on any thread, but performs synchronous file I/O under the text engine lock. Call it after `connect` returns successfully, not during bean initialization. Before connection, during registration or after disconnect, it throws `IllegalStateException` with `Plugin <name> is not connected to UltiTools`. A connected plugin without a bundled catalogue gets a no-op. Malformed override files warn in the console and are ignored; bundled text remains the fallback. `/ul reload` does not refresh external catalogues.

Do not retain a plugin-owned `Messages` view across disconnection. See [External plugin messages](/guide/essentials/messages#external-plugin-messages) for the lifetime of that view.

## Module-only features

| Feature | External plugin |
Expand Down
6 changes: 4 additions & 2 deletions docs/src/guide/advanced/scheduled-tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ The 7.0 module descriptor must declare an integer `api-version` of at least `700

## Scheduler API {#scheduler-api}

Each module instance owns one `Scheduler`. Inject it into a module bean:
Each module instance owns one `Scheduler`. As of v7.2.0, each external plugin connection also owns a `Scheduler`. Inject it into a managed bean:

```java
@Service
Expand Down Expand Up @@ -207,6 +207,8 @@ An async delay is not a deadline: the actual start depends on the server’s asy

Unloading a module retires its scheduler before `onUnregister()` or `@PreDestroy`: queued work and repeating tasks are cancelled, and a running one-shot may finish. Submission to a retired owner throws `RejectedExecutionException`, so perform cleanup directly in those callbacks. A failed module load also retires the instance’s scheduler, including work submitted in bean construction, `@PostConstruct` or `registerSelf()`. Neither path cancels another module instance’s work or direct Bukkit tasks.

As of v7.2.0, an external plugin's `@Scheduled` methods and work submitted through its injected `Scheduler` share the connection's scheduler. Disconnect cancels queued and repeating tasks from both sources before `@PreDestroy`; a task body already running can finish. After disconnect, submissions through the old scheduler throw `RejectedExecutionException`. Reconnecting gives you a new scheduler. See [External Plugin API](./external-plugin-api) for the disconnect order.

### Framework-scheduled work {#framework-scheduled-work}

As of v7.0.0, the framework schedules its own background and main-thread work on a framework-owned `Scheduler` whose owner name is `UltiTools`, with the same contexts and rules as a module's scheduler ([#963](https://github.com/UltiKits/UltiTools-Reborn/pull/963)). Module code does not change; the differences you can observe are these:
Expand All @@ -231,7 +233,7 @@ As of v7.0.0, async command bodies (`@RunAsync`, `@AsyncCommand`) and the comman

## Automatic Lifecycle

UltiTools schedules eligible bean methods after `registerSelf()` succeeds. When the module unloads or the server stops, the owning scheduler cancels pending and repeating tasks; a running method can finish. If an annotated method throws, the framework logs a WARNING naming the method. A repeating annotation continues on subsequent triggers. This warning comes from the annotation handler, not from the direct `Scheduler` task-failure contract above.
For a module, UltiTools schedules eligible bean methods after `registerSelf()` succeeds. For an external plugin, it schedules them during `connect`. When the module unloads or the plugin disconnects, the owning scheduler cancels pending and repeating tasks; a running method can finish. If an annotated method throws, the framework logs a WARNING naming the method. A repeating annotation continues on subsequent triggers. This warning comes from the annotation handler, not from the direct `Scheduler` task-failure contract above.

## Requirements

Expand Down
Loading