feat: moderation feature skeleton (/core admin + mod mode + tools)
New feature fr.luc.crcore.features.moderation, opt-in via CRCoreConfig.setupModeration() (also enabled by setupAll()). Core abstractions: - ModerationState: full player snapshot (inv + armor + offhand, XP, health, food, location, gamemode, allowFlight/flying, walk/fly speed). Immutable, restoreTo(player) restores everything. - ModerationService interface + ModerationServiceImpl (with protected onAfterEnter/onAfterExit hooks) + BukkitEventFiringModerationServiceImpl (fires ModerationEnterEvent / ModerationExitEvent). - ModerationRepository interface + InMemoryModerationRepository (skeleton — SQLite impl with BukkitObjectOutputStream serialization planned). - ModeratorTool interface: getKey/getSlot(0..8)/buildIcon + onLeftClick/onRightClick/onInteractEntity. ModeratorToolRegistry preserves registration order, slot collision = replace. - Exceptions: ModerationException base + AlreadyActive + NotActive. - Events: ModerationEvent base + Enter + Exit. 5 skeleton tools in the hotbar: - slot 0: TeleportRandomPlayerTool (compass, right-click → tp random) - slot 1: InventorySpyTool (chest, right-click on player → open inv) - slot 2: FreezeTool (ice, right-click on player → toggle freeze) - slot 7: VanishToggleTool (ender eye, click → toggle vanish) - slot 8: ExitTool (barrier, click → exit mod mode) Slots 3-6 free for custom tools. ModerationListener routes interactions and locks hotbar: - PlayerInteractEvent → tool.onLeftClick / onRightClick (with cancel). - PlayerInteractEntityEvent → tool.onInteractEntity (with cancel). - PlayerDropItemEvent / PlayerSwapHandItemsEvent: cancel for mods. - InventoryClickEvent: cancel only when top inv is the mod's own inv (preserves InventorySpyTool's ability to manipulate target's inv). - PlayerJoinEvent: re-applies vanish for already-vanished mods. - PlayerQuitEvent: cleanup freeze state. - PlayerMoveEvent: cancel block-position changes for frozen players, keeping head rotation free. Mod mode lifecycle: - enter: snapshot + clear inv + populate hotbar + CREATIVE + allowFlight + vanish + ModerationEnterEvent. - exit: state.restoreTo(player) + unvanish + unfreeze + repo delete + ModerationExitEvent. /core admin (perm crcore.admin, player-only): toggle on/off. Messages moderation.enter.success / moderation.exit.success added to crcore-messages.yml. CRCoreConfig.setupModeration() + isModerationEnabled() flag. CRCore: buildModerationService() and registerDefaultModeratorTools() override points, moderation() / getModerationService() getters with IllegalStateException guard. Builds + registers ModerationListener at enable() when feature on. CoreCommand extended to take ModerationService; registers AdminToggleSubCommand only when service non-null. Skeleton limitations documented in features.md: - In-memory repo only (server crash = lost inv) — SQLite planned. - InventorySpyTool opens real inv (no read-only wrapping yet). - TeleportRandomPlayerTool is a placeholder for a future player-picker GUI. - No moderation.*.broadcast keys yet. - No /core admin <player> (self-toggle only). Docs: section 11 in features.md, decision logged in decisions.md (skeleton scope + rationale), setup.md snippet updated, new moderation-class-diagram.puml, README.md updated. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -367,6 +367,45 @@ Format léger : une décision = un titre + contexte + choix + raison.
|
||||
bases existantes, ALTER TABLE manuel ou suppression du fichier
|
||||
(les bases d'event sont jetables).
|
||||
|
||||
## 2026-06-10 — Feature modération (skeleton)
|
||||
|
||||
- **Choix** : nouveau module `fr.luc.crcore.features.moderation`,
|
||||
opt-in via `CRCoreConfig.setupModeration()`. Skeleton complet :
|
||||
- `ModerationState` (snapshot total : inv, armor, offhand, XP, health,
|
||||
food, location, gamemode, flight/fly speed)
|
||||
- `ModerationService` (interface) + `ModerationServiceImpl` +
|
||||
`BukkitEventFiringModerationServiceImpl` (tire `ModerationEnterEvent`
|
||||
/ `ModerationExitEvent`)
|
||||
- `ModeratorTool` interface + `ModeratorToolRegistry`
|
||||
- 5 outils squelette (slots 0, 1, 2, 7, 8) :
|
||||
`TeleportRandomPlayerTool`, `InventorySpyTool`, `FreezeTool`,
|
||||
`VanishToggleTool`, `ExitTool`
|
||||
- `ModerationListener` unique : route les clics → tool, lock hotbar
|
||||
(drop, swap, inventory click sur self), vanish-on-join,
|
||||
freeze (PlayerMoveEvent cancel)
|
||||
- `/core admin` toggle on/off (perm `crcore.admin`, player-only)
|
||||
- **Vanish** : `Player.hidePlayer(plugin, vanished)` — propre, sans
|
||||
modif visuelle, pas de fake-quit. Le listener re-applique
|
||||
automatiquement aux joueurs qui join.
|
||||
- **Persistance in-memory uniquement** (skeleton). Si le serveur crash
|
||||
pendant qu'un mod est en mod mode, son inventaire est perdu. Une
|
||||
impl `SqliteModerationRepository` avec sérialisation
|
||||
`BukkitObjectOutputStream` → base64 est prévue pour plus tard. Pas
|
||||
bloquant pour la première itération.
|
||||
- **Mod mode → CREATIVE + allowFlight** par défaut. Choisi pour la
|
||||
visibilité totale + mobility. Override possible en sous-classant
|
||||
`ModerationServiceImpl.enter()`.
|
||||
- **Outils en slots fixes** plutôt qu'avec PersistentDataContainer.
|
||||
Plus simple ; le `ModerationListener` annule tout drop/swap pour
|
||||
garantir que les outils restent en place. Pour identification croisée
|
||||
(NBT) on pourra ajouter plus tard.
|
||||
- **Tools extensibles** : `core.moderation().getToolRegistry().register(...)`
|
||||
côté game plugin. Les slots libres (3, 4, 5, 6) sont prêts pour les
|
||||
outils custom.
|
||||
- **Listener responsibilities** : un seul `ModerationListener`
|
||||
centralise toutes les hooks (clicks, freeze, vanish, lock hotbar).
|
||||
Évite de disperser dans 5 listeners séparés.
|
||||
|
||||
## 2026-06-10 — Réorganisation : `util/` (toujours) vs `features/` (opt-in)
|
||||
|
||||
- **Choix** : séparation nette en deux couches :
|
||||
|
||||
Reference in New Issue
Block a user