fancydialogs: Add confirmation dialog to destructive commands

This commit is contained in:
Oliver
2025-06-19 17:04:43 +02:00
parent 3aaa364b58
commit 6cdd77daba
2 changed files with 43 additions and 1 deletions

View File

@@ -126,6 +126,18 @@ public final class FancyDialogsCMD {
public void storageReload(
final BukkitCommandActor actor
) {
if (actor.isPlayer()) {
new ConfirmationDialog("Are you sure you want to reload all dialog data from the storage? This will clear the dialog registry and overwrite any existing dialogs.")
.withTitle("Confirm reload")
.withOnConfirm(() -> reloadStorage(actor))
.withOnCancel(() -> translator.translate("commands.fancydialogs.storage.reload.cancelled").send(actor.sender()))
.ask(actor.asPlayer());
} else {
reloadStorage(actor);
}
}
private void reloadStorage(BukkitCommandActor actor) {
plugin.getDialogRegistry().clear();
Collection<DialogData> dialogs = plugin.getDialogStorage().loadAll();
@@ -169,6 +181,18 @@ public final class FancyDialogsCMD {
public void registryClear(
final BukkitCommandActor actor
) {
if (actor.isPlayer()) {
new ConfirmationDialog("Are you sure you want to clear the dialog registry? This will remove all registered dialogs.")
.withTitle("Confirm clear")
.withOnConfirm(() -> clearRegistry(actor))
.withOnCancel(() -> translator.translate("commands.fancydialogs.registry.clear.cancelled").send(actor.sender()))
.ask(actor.asPlayer());
} else {
clearRegistry(actor);
}
}
private void clearRegistry(BukkitCommandActor actor) {
plugin.getDialogRegistry().clear();
translator.translate("commands.fancydialogs.registry.clear.success").send(actor.sender());
}
@@ -179,6 +203,21 @@ public final class FancyDialogsCMD {
public void registryUnregister(
final BukkitCommandActor actor,
final Dialog dialog
) {
if (actor.isPlayer()) {
new ConfirmationDialog("Are you sure you want to unregister the dialog with ID '" + dialog.getId() + "'? This will remove it from the registry.")
.withTitle("Confirm unregister")
.withOnConfirm(() -> unregisterDialog(actor, dialog))
.withOnCancel(() -> translator.translate("commands.fancydialogs.registry.unregister.cancelled").send(actor.sender()))
.ask(actor.asPlayer());
} else {
unregisterDialog(actor, dialog);
}
}
private void unregisterDialog(
final BukkitCommandActor actor,
final Dialog dialog
) {
plugin.getDialogRegistry().unregister(dialog.getId());
translator.translate("commands.fancydialogs.registry.unregister.success")

View File

@@ -25,8 +25,11 @@ messages:
cancelled: "<dark_gray> <gray>Loading dialogs from storage was cancelled."
reload:
success: "<dark_gray> <gray>Successfully reloaded {warningColor}{count}<gray> dialogs from the storage."
cancelled: "<dark_gray> <gray>Reloading dialogs from storage was cancelled."
registry:
clear:
success: "<dark_gray> <gray>Successfully cleared all registered dialogs."
cancelled: "<dark_gray> <gray>Clearing registered dialogs was cancelled."
unregister:
success: "<dark_gray> <gray>Successfully unregistered dialog {warningColor}{id}<gray>."
success: "<dark_gray> <gray>Successfully unregistered dialog {warningColor}{id}<gray>."
cancelled: "<dark_gray> <gray>Unregistering dialog {warningColor}{id}<gray> was cancelled."