Ajout des fonctionnalités de validation de commandes/arguments, confirmation préalable (double validation) et répétition cadencée (CommandRepeater)
This commit is contained in:
@@ -18,7 +18,10 @@ Une bibliothèque Java moderne, fluide et événementielle permettant de créer,
|
||||
- [1. Commande de Démonstration Complète (`/commande-demo`)](#1-commande-de-démonstration-complète-commande-demo)
|
||||
- [2. Sous-Commandes Imbriquées](#2-sous-commandes-imbriquées)
|
||||
- [3. Arguments Gourmands (Greedy String)](#3-arguments-gourmands-greedy-string)
|
||||
- [4. Temps de Recharge (Cooldowns)](#4-temps-de-recharge-cooldowns)
|
||||
- [4. Système de Validation Métier (Pré-requis)](#4-système-de-validation-métier-pré-requis)
|
||||
- [5. Confirmation Préalable & Double Validation (`.requireConfirmation`)](#5-confirmation-préalable--double-validation-requireconfirmation)
|
||||
- [6. Répétition & Cadence de Commandes (`CommandRepeater`)](#6-répétition--cadence-de-commandes-commandrepeater)
|
||||
- [7. Temps de Recharge (Cooldowns)](#7-temps-de-recharge-cooldowns)
|
||||
- [🧩 Catalogue des Arguments Typés](#-catalogue-des-arguments-typés)
|
||||
- [🎯 Système d'Événements & Cycle de Vie](#-système-dévénements--cycle-de-vie)
|
||||
- [Liste des Événements Disponibles](#liste-des-événements-disponibles)
|
||||
@@ -31,6 +34,11 @@ Une bibliothèque Java moderne, fluide et événementielle permettant de créer,
|
||||
|
||||
- **DSL Fluide & Déclaratif** : Déclaration intuitive basée sur le pattern Builder chainable (`BetterMcCommands.builder("ma-commande")`).
|
||||
- **Zéro `plugin.yml`** : Injection directe par réflexion dans la `CommandMap` du serveur Minecraft avec support du dé-enregistrement à chaud.
|
||||
- **Validation Métier Directe & Extensible** :
|
||||
- Validateurs au niveau commande (`.validate(ctx -> condition, "Erreur...")`)
|
||||
- Validateurs au niveau argument (`argument.validate(val -> condition, "Erreur...")`)
|
||||
- **Confirmation Préalable (Double validation)** : Sécurisation des commandes critiques (`/disband`, `/delete-data`) avec expiration (`.requireConfirmation(Duration.ofSeconds(15))`).
|
||||
- **Répétition & Tâches Cadencées (`CommandRepeater`)** : Répétition automatique d'une action à intervalles réguliers avec suivi de progression et annulation.
|
||||
- **Système d'Arguments Typés & Auto-complétion** :
|
||||
- Conversion et validation automatiques avec messages d'erreurs clairs.
|
||||
- Auto-complétion dynamique (Tab-Complete) intelligente selon le type de chaque argument.
|
||||
@@ -58,10 +66,16 @@ flowchart TD
|
||||
PermCheck -- Valide --> CoolCheck{"Vérification Cooldown"}
|
||||
CoolCheck -- Actif --> EvtCool["Dispatch CommandCooldownEvent"]
|
||||
|
||||
CoolCheck -- Inactif --> ArgParse{"Parsing des Arguments Typés"}
|
||||
ArgParse -- Erreur format / manquant --> EvtSyntax["Dispatch CommandSyntaxErrorEvent"]
|
||||
CoolCheck -- Inactif --> ArgParse{"Parsing & Validation des Arguments"}
|
||||
ArgParse -- Erreur format / invalide --> EvtSyntax["Dispatch CommandSyntaxErrorEvent"]
|
||||
|
||||
ArgParse -- Succès --> EvtPre{"Dispatch CommandPreExecuteEvent"}
|
||||
ArgParse -- Succès --> ConfCheck{"Confirmation Requise ?"}
|
||||
ConfCheck -- Non confirmée --> EvtConf["Dispatch ConfirmationRequiredEvent & Invite à retaper"]
|
||||
|
||||
ConfCheck -- Confirmée ou Non requise --> ValCheck{"Validateurs (CommandValidator)"}
|
||||
ValCheck -- Invalide --> ValErr["Envoi Message d'Erreur & Arrêt"]
|
||||
|
||||
ValCheck -- Valide --> EvtPre{"Dispatch CommandPreExecuteEvent"}
|
||||
EvtPre -- Annulé (setCancelled) --> Cancelled["Arrêt de l'exécution"]
|
||||
|
||||
EvtPre -- Non annulé --> Exec["Exécution du CommandExecutor métier"]
|
||||
@@ -220,7 +234,75 @@ BetterMcCommands.builder("broadcast")
|
||||
|
||||
---
|
||||
|
||||
### 4. Temps de Recharge (Cooldowns)
|
||||
### 4. Système de Validation Métier (Pré-requis)
|
||||
|
||||
Vous pouvez attacher des validateurs à vos commandes et arguments :
|
||||
|
||||
```java
|
||||
// Validation au niveau de la commande
|
||||
BetterMcCommands.builder("level-reward")
|
||||
.playerOnly()
|
||||
.validate(ctx -> ctx.getPlayer().getLevel() >= 10, "Vous devez être niveau 10 minimum !")
|
||||
.executes(ctx -> {
|
||||
ctx.replySuccess("Récompense de niveau réclamée !");
|
||||
})
|
||||
.register();
|
||||
|
||||
// Validation au niveau d'un argument
|
||||
BetterMcCommands.builder("setprice")
|
||||
.argument(Arguments.decimal("prix").validate(prix -> prix > 0, "Le prix doit être strictement positif !"))
|
||||
.executes(ctx -> {
|
||||
double prix = ctx.getDouble("prix");
|
||||
ctx.replySuccess("Prix configuré à " + prix + " €.");
|
||||
})
|
||||
.register();
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 5. Confirmation Préalable & Double Validation (`.requireConfirmation`)
|
||||
|
||||
Sécurisez les commandes destructrices ou sensibles. Le joueur doit ré-exécuter la commande dans le temps imparti pour confirmer l'action :
|
||||
|
||||
```java
|
||||
BetterMcCommands.builder("disband")
|
||||
.description("Dissout votre guilde")
|
||||
.playerOnly()
|
||||
.requireConfirmation(Duration.ofSeconds(15), "<red><bold>ATTENTION</bold> : Cette action est irréversible ! Retapez <yellow>/disband</yellow> dans les 15s pour confirmer.</red>")
|
||||
.executes(context -> {
|
||||
context.replySuccess("Votre guilde a été dissoute.");
|
||||
})
|
||||
.register();
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 6. Répétition & Cadence de Commandes (`CommandRepeater`)
|
||||
|
||||
Permet de répéter une action à intervalle régulier (ex: compte à rebours, diffusion répétée, téléportation avec pulsation) :
|
||||
|
||||
```java
|
||||
BetterMcCommands.builder("countdown")
|
||||
.playerOnly()
|
||||
.executes(context -> {
|
||||
// Répète 5 fois toutes les 1 seconde
|
||||
CommandRepeater.repeat(monPlugin, context, 5, Duration.ofSeconds(1),
|
||||
progress -> {
|
||||
int restants = progress.getTotalRuns() - progress.getCurrentRun() + 1;
|
||||
context.reply("<gold>Lancement dans <yellow>" + restants + "</yellow>...</gold>");
|
||||
},
|
||||
() -> {
|
||||
// Action finale
|
||||
context.replySuccess("<bold>PARTEZ !</bold>");
|
||||
}
|
||||
);
|
||||
})
|
||||
.register();
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 7. Temps de Recharge (Cooldowns)
|
||||
|
||||
```java
|
||||
BetterMcCommands.builder("kit")
|
||||
@@ -264,6 +346,7 @@ BetterMcCommands.builder("kit")
|
||||
|---|---|:---:|
|
||||
| `CommandPreExecuteEvent` | Déclenché juste avant l'exécution métier. Permet d'annuler ou modifier l'action. | ✅ Oui |
|
||||
| `CommandPostExecuteEvent` | Déclenché après l'exécution. Contient la durée d'exécution et le statut final. | ❌ Non |
|
||||
| `CommandConfirmationRequiredEvent` | Déclenché lors d'une demande de confirmation préalable pour personnaliser l'invite. | ✅ Oui |
|
||||
| `CommandPermissionDeniedEvent` | Déclenché si la permission est manquante ou si l'émetteur n'est pas autorisé. | ✅ Oui |
|
||||
| `CommandSyntaxErrorEvent` | Déclenché lors d'une erreur de syntaxe ou argument manquant. | ✅ Oui |
|
||||
| `CommandCooldownEvent` | Déclenché lorsqu'un joueur tente d'exécuter une commande sous cooldown actif. | ✅ Oui |
|
||||
@@ -333,11 +416,22 @@ fr.luc.bettermccommands/
|
||||
│ ├── ArgumentType.java
|
||||
│ ├── Arguments.java (Factory d'arguments)
|
||||
│ └── type/ (String, Integer, Player, Duration, Enum, etc.)
|
||||
├── validation/ (Moteur de validation de commande et d'argument)
|
||||
│ ├── CommandValidator.java
|
||||
│ ├── ArgumentValidator.java
|
||||
│ └── ValidationResult.java
|
||||
├── confirmation/ (Système de confirmation / Double validation)
|
||||
│ ├── ConfirmationManager.java
|
||||
│ └── PendingConfirmation.java
|
||||
├── repeat/ (Tâches répétées & cadence de commandes)
|
||||
│ ├── CommandRepeater.java
|
||||
│ └── CommandRepeatProgress.java
|
||||
├── event/ (Bus d'événements & Lifecycle)
|
||||
│ ├── CommandEvent.java
|
||||
│ ├── CancellableCommandEvent.java
|
||||
│ ├── CommandPreExecuteEvent.java
|
||||
│ ├── CommandPostExecuteEvent.java
|
||||
│ ├── CommandConfirmationRequiredEvent.java
|
||||
│ ├── CommandPermissionDeniedEvent.java
|
||||
│ ├── CommandSyntaxErrorEvent.java
|
||||
│ ├── CommandCooldownEvent.java
|
||||
|
||||
Reference in New Issue
Block a user