feat(04-04): add list/delete/toggle subcommands (CommandBase, CMD-03/04/05)
- GravityFlipListSubCommand: iterate registry.all(), format 'name : (min) -> (max) [state]' - GravityFlipDeleteSubCommand: registry.remove + save, clear error on unknown name - GravityFlipToggleSubCommand: read current enabled, flip via setEnabled, save, report new state - All three extend CommandBase (works from server console, not just player) - Save-failure path: keep in-memory change, truthful message (mirror define pattern)
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
package com.mythlane.gravityflip.command;
|
||||
|
||||
import com.hypixel.hytale.server.core.Message;
|
||||
import com.hypixel.hytale.server.core.command.system.CommandContext;
|
||||
import com.hypixel.hytale.server.core.command.system.arguments.system.RequiredArg;
|
||||
import com.hypixel.hytale.server.core.command.system.arguments.types.ArgTypes;
|
||||
import com.hypixel.hytale.server.core.command.system.basecommands.CommandBase;
|
||||
import com.mythlane.gravityflip.GravityFlipPlugin;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.logging.Level;
|
||||
|
||||
/**
|
||||
* {@code /gravityflip delete <name>} — supprime la région nommée et persiste.
|
||||
*
|
||||
* <p>Étend {@link CommandBase} pour permettre l'usage depuis la console serveur
|
||||
* (opération admin, pas besoin d'un joueur caller).
|
||||
*
|
||||
* <p>Flow :
|
||||
* <ol>
|
||||
* <li>{@code registry.remove(name)} — renvoie {@code false} si nom inconnu → message
|
||||
* d'erreur clair et retour précoce (pas de save inutile).</li>
|
||||
* <li>{@code configHolder.save().join()} force la durabilité. Même pattern que
|
||||
* {@code GravityFlipDefineSubCommand} : sur échec disque, on reporte truthfully
|
||||
* ("en mémoire OK, persistance échouée") plutôt que silent rollback.</li>
|
||||
* </ol>
|
||||
*/
|
||||
public final class GravityFlipDeleteSubCommand extends CommandBase {
|
||||
|
||||
private final GravityFlipPlugin plugin;
|
||||
|
||||
private final RequiredArg<String> nameArg =
|
||||
this.withRequiredArg("name", "Nom de la région à supprimer", ArgTypes.STRING);
|
||||
|
||||
public GravityFlipDeleteSubCommand(GravityFlipPlugin plugin) {
|
||||
super("delete", "Supprime une région Gravity Flip");
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void executeSync(@Nonnull CommandContext ctx) {
|
||||
String name = nameArg.get(ctx);
|
||||
if (!plugin.regions().remove(name)) {
|
||||
ctx.sendMessage(Message.raw("[gravityflip] Région '" + name + "' introuvable."));
|
||||
return;
|
||||
}
|
||||
try {
|
||||
plugin.configHolder().save().join();
|
||||
} catch (Throwable th) {
|
||||
plugin.getLogger().at(Level.WARNING).withCause(th)
|
||||
.log("[delete] save failed for region '" + name + "'");
|
||||
ctx.sendMessage(Message.raw(
|
||||
"[gravityflip] Suppression en mémoire OK, persistance échouée — voir logs."));
|
||||
return;
|
||||
}
|
||||
ctx.sendMessage(Message.raw("[gravityflip] Région '" + name + "' supprimée."));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user