|
1 | 1 | # Examples |
2 | 2 |
|
3 | | -The runnable example plugins in this repository still target the EasyLibrary |
4 | | -3.0-dev module runtime. |
| 3 | +The `examples/` directory now belongs to `LibModule` and targets the |
| 4 | +`imperazim\module` authoring API: |
5 | 5 |
|
6 | | -Each example plugin declares: |
| 6 | +- modules extend `imperazim\module\BaseModule`; |
| 7 | +- lifecycle hooks receive `imperazim\module\ModuleContext`; |
| 8 | +- module-owned native commands extend `imperazim\module\command\BaseModuleCommand`; |
| 9 | +- listeners extend `imperazim\module\event\BaseModuleListener`; |
| 10 | +- services, capabilities, cleanup callbacks and diagnostics use |
| 11 | + `ModuleContext`/`ModuleRuntime`. |
7 | 12 |
|
8 | | -```yaml |
9 | | -depend: |
10 | | - - EasyLibrary |
11 | | -``` |
| 13 | +These examples are intentionally no longer written against EasyLibrary's legacy |
| 14 | +`ModuleManager` helpers. |
| 15 | + |
| 16 | +## Current Host Status |
| 17 | + |
| 18 | +OP-68H moves the authoring examples and docs into `LibModule`. The examples are |
| 19 | +authoring references for the new API, not a stable copy-into-server promise yet. |
| 20 | + |
| 21 | +During the rest of OP-68, EasyLibrary still owns part of the PMMP host adapter: |
12 | 22 |
|
13 | | -That dependency is correct for these examples until OP-68H migrates them. |
| 23 | +- plugin/module source discovery; |
| 24 | +- YAML reading through the PocketMine environment; |
| 25 | +- PMMP command, listener and task registration; |
| 26 | +- compatibility with old `ModuleManager`-centric modules. |
14 | 27 |
|
15 | | -The public authoring API already exists in `LibModule` after OP-68B. The |
16 | | -examples still need a separate pass because they also exercise filesystem |
17 | | -discovery, command/listener/task registration and full server smoke behavior. |
| 28 | +That means a host must explicitly wire these examples into a `ModuleRuntime` |
| 29 | +session and register any PMMP resources it wants to expose. The files under |
| 30 | +`examples/` show the module shape and the runtime contracts that the host will |
| 31 | +load once OP-68I removes the remaining EasyLibrary legacy runtime. |
18 | 32 |
|
19 | 33 | ## Included Examples |
20 | 34 |
|
21 | | -- `01-basic-plugin`: minimal module discovery, command, listener, service and |
22 | | - task usage. |
23 | | -- `02-economy-provider-plugin`: module-owned service and capability provider. |
24 | | -- `03-farm-consumer-plugin`: module consuming a service from another example. |
25 | | -- `04-diagnostics-plugin`: intentionally broken modules for doctor/failure |
26 | | - command testing. |
| 35 | +- `01-basic-plugin`: basic service/capability provider, health reporting, |
| 36 | + cleanup and optional command/listener/task classes. |
| 37 | +- `02-economy-provider-plugin`: module-owned economy service and capability |
| 38 | + provider. |
| 39 | +- `03-farm-consumer-plugin`: consumer module waiting on the economy service and |
| 40 | + capability, plus optional hello-service usage. |
| 41 | +- `04-diagnostics-plugin`: intentionally disabled/missing-dependency modules |
| 42 | + for doctor/failure output. |
| 43 | + |
| 44 | +## Module Shape |
| 45 | + |
| 46 | +Minimal module: |
| 47 | + |
| 48 | +```php |
| 49 | +<?php |
| 50 | + |
| 51 | +declare(strict_types=1); |
27 | 52 |
|
28 | | -## Manual Test Flow |
| 53 | +namespace vendor\plugin\modules\farm; |
29 | 54 |
|
30 | | -1. Install EasyLibrary 3.0-dev on a PocketMine-MP test server. |
31 | | -2. Copy one example plugin directory into `plugins/`. |
32 | | -3. Start the server. |
33 | | -4. Run: |
| 55 | +use imperazim\module\BaseModule; |
| 56 | +use imperazim\module\ModuleContext; |
34 | 57 |
|
35 | | -```text |
36 | | -/easymodule list |
37 | | -/easymodule doctor |
38 | | -/easymodule info <module-id> |
| 58 | +final class FarmModule extends BaseModule { |
| 59 | + protected function onEnable(ModuleContext $context): void { |
| 60 | + $this->provideService('vendor:farm-service', new FarmService()); |
| 61 | + $this->addCleanup(static function(): void { |
| 62 | + // Close runtime resources here. |
| 63 | + }); |
| 64 | + } |
| 65 | +} |
39 | 66 | ``` |
40 | 67 |
|
41 | | -The command names may change when the LibModule extraction reaches the command |
42 | | -provider phase. |
| 68 | +Minimal manifest: |
| 69 | + |
| 70 | +```yaml |
| 71 | +id: vendor:farm |
| 72 | +name: Farm System |
| 73 | +version: 1.0.0 |
| 74 | +loader: FarmModule |
| 75 | +namespace: vendor\plugin\modules\farm |
| 76 | + |
| 77 | +provides: |
| 78 | + services: |
| 79 | + - vendor:farm-service |
| 80 | + capabilities: |
| 81 | + - vendor.farm |
| 82 | +``` |
| 83 | +
|
| 84 | +## Host Registration Boundary |
| 85 | +
|
| 86 | +`BaseModule` deliberately does not hide PMMP command/listener/task registration. |
| 87 | +That work belongs to the active host adapter, because `LibModule` also needs to |
| 88 | +support non-EasyLibrary consumers and pure runtime tests. |
| 89 | + |
| 90 | +A host can: |
| 91 | + |
| 92 | +1. scan `module.yml` files with `ModuleManifestPathScanner`; |
| 93 | +2. normalize them with `ModuleManifestNormalizer`; |
| 94 | +3. load classes with `ModuleClassFileLoader`; |
| 95 | +4. validate classes with `ModuleRuntimeClassValidator`; |
| 96 | +5. register module instances in `ModuleRuntime`; |
| 97 | +6. register optional PMMP resources such as `BaseModuleCommand`, |
| 98 | + `BaseModuleListener` or `Task` instances. |
| 99 | + |
| 100 | +The current examples include command/listener/task classes so the host adapter |
| 101 | +has realistic resources to register, but the modules themselves only use the |
| 102 | +portable API. |
0 commit comments