mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-04 14:38:53 +00:00
Add confirmation prompts to /delhome all and /delwarp all
This commit is contained in:
1 parent
d3b325c56b
commit
fde3736eb3
2 files changed
+38
-15
No files matched your search
@@ -23,17 +23,21 @@ public class DelHomeCommand extends CommandBase implements TabCompletable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onExecute(@NotNull OnlineUser onlineUser, @NotNull String[] args) {
|
public void onExecute(@NotNull OnlineUser onlineUser, @NotNull String[] args) {
|
||||||
switch (args.length) {
|
if (args.length == 0) {
|
||||||
case 0 -> plugin.getDatabase().getHomes(onlineUser).thenAccept(homes -> {
|
plugin.getDatabase().getHomes(onlineUser).thenAccept(homes -> {
|
||||||
if (homes.size() == 1) {
|
if (homes.size() == 1) {
|
||||||
homes.stream().findFirst().ifPresent(home -> deletePlayerHome(onlineUser, onlineUser, home.meta.name));
|
homes.stream().findFirst().ifPresent(home -> deletePlayerHome(onlineUser, onlineUser, home.meta.name, false));
|
||||||
} else {
|
} else {
|
||||||
plugin.getLocales().getLocale("error_invalid_syntax", "/delhome <name>")
|
plugin.getLocales().getLocale("error_invalid_syntax", "/delhome <name>")
|
||||||
.ifPresent(onlineUser::sendMessage);
|
.ifPresent(onlineUser::sendMessage);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
case 1 -> {
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args.length <= 2) {
|
||||||
final String homeName = args[0];
|
final String homeName = args[0];
|
||||||
|
final boolean confirm = args.length == 2 && args[1].equalsIgnoreCase("confirm");
|
||||||
RegexUtil.matchDisambiguatedHomeIdentifier(homeName).ifPresentOrElse(homeIdentifier ->
|
RegexUtil.matchDisambiguatedHomeIdentifier(homeName).ifPresentOrElse(homeIdentifier ->
|
||||||
plugin.getDatabase().getUserDataByName(homeIdentifier.ownerName()).thenAccept(
|
plugin.getDatabase().getUserDataByName(homeIdentifier.ownerName()).thenAccept(
|
||||||
optionalUserData -> optionalUserData.ifPresentOrElse(userData -> {
|
optionalUserData -> optionalUserData.ifPresentOrElse(userData -> {
|
||||||
@@ -44,16 +48,17 @@ public class DelHomeCommand extends CommandBase implements TabCompletable {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
deletePlayerHome(onlineUser, userData.user(), homeIdentifier.homeName());
|
deletePlayerHome(onlineUser, userData.user(), homeIdentifier.homeName(), confirm);
|
||||||
},
|
},
|
||||||
() -> plugin.getLocales().getLocale("error_home_invalid_other",
|
() -> plugin.getLocales().getLocale("error_home_invalid_other",
|
||||||
homeIdentifier.ownerName(), homeIdentifier.homeName()).ifPresent(onlineUser::sendMessage))),
|
homeIdentifier.ownerName(), homeIdentifier.homeName()).ifPresent(onlineUser::sendMessage))),
|
||||||
() -> deletePlayerHome(onlineUser, onlineUser, homeName));
|
() -> deletePlayerHome(onlineUser, onlineUser, homeName, confirm));
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
default -> plugin.getLocales().getLocale("error_invalid_syntax", "/delhome <name>")
|
|
||||||
|
plugin.getLocales().getLocale("error_invalid_syntax", "/delhome <name>")
|
||||||
.ifPresent(onlineUser::sendMessage);
|
.ifPresent(onlineUser::sendMessage);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete a player's home
|
* Delete a player's home
|
||||||
@@ -61,8 +66,10 @@ public class DelHomeCommand extends CommandBase implements TabCompletable {
|
|||||||
* @param deleter the player who is deleting the home
|
* @param deleter the player who is deleting the home
|
||||||
* @param homeOwner The player who owns the home
|
* @param homeOwner The player who owns the home
|
||||||
* @param homeName The home name to delete
|
* @param homeName The home name to delete
|
||||||
|
* @param delHomeAllConfirm Whether to skip the confirmation prompt for deleting all homes
|
||||||
*/
|
*/
|
||||||
private void deletePlayerHome(@NotNull OnlineUser deleter, @NotNull User homeOwner, @NotNull String homeName) {
|
private void deletePlayerHome(@NotNull OnlineUser deleter, @NotNull User homeOwner, @NotNull String homeName,
|
||||||
|
final boolean delHomeAllConfirm) {
|
||||||
plugin.getSavedPositionManager().deleteHome(homeOwner, homeName).thenAccept(deleted -> {
|
plugin.getSavedPositionManager().deleteHome(homeOwner, homeName).thenAccept(deleted -> {
|
||||||
if (deleter.uuid.equals(homeOwner.uuid)) {
|
if (deleter.uuid.equals(homeOwner.uuid)) {
|
||||||
if (deleted) {
|
if (deleted) {
|
||||||
@@ -70,7 +77,7 @@ public class DelHomeCommand extends CommandBase implements TabCompletable {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (homeName.equals("all")) {
|
if (homeName.equals("all")) {
|
||||||
deleteAllHomes(deleter, homeOwner);
|
deleteAllHomes(deleter, homeOwner, delHomeAllConfirm);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
plugin.getLocales().getLocale("error_home_invalid", homeName).ifPresent(deleter::sendMessage);
|
plugin.getLocales().getLocale("error_home_invalid", homeName).ifPresent(deleter::sendMessage);
|
||||||
@@ -80,7 +87,7 @@ public class DelHomeCommand extends CommandBase implements TabCompletable {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (homeName.equals("all")) {
|
if (homeName.equals("all")) {
|
||||||
deleteAllHomes(deleter, homeOwner);
|
deleteAllHomes(deleter, homeOwner, delHomeAllConfirm);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
plugin.getLocales().getLocale("error_home_invalid_other", homeOwner.username, homeName).ifPresent(deleter::sendMessage);
|
plugin.getLocales().getLocale("error_home_invalid_other", homeOwner.username, homeName).ifPresent(deleter::sendMessage);
|
||||||
@@ -93,8 +100,10 @@ public class DelHomeCommand extends CommandBase implements TabCompletable {
|
|||||||
*
|
*
|
||||||
* @param deleter the player who is deleting the homes
|
* @param deleter the player who is deleting the homes
|
||||||
* @param homeOwner the player who owns the homes
|
* @param homeOwner the player who owns the homes
|
||||||
|
* @param confirm whether to skip the confirmation prompt
|
||||||
*/
|
*/
|
||||||
private void deleteAllHomes(@NotNull OnlineUser deleter, @NotNull User homeOwner) {
|
private void deleteAllHomes(@NotNull OnlineUser deleter, @NotNull User homeOwner,
|
||||||
|
final boolean confirm) {
|
||||||
plugin.getDatabase().getHomes(homeOwner).thenAccept(homes -> {
|
plugin.getDatabase().getHomes(homeOwner).thenAccept(homes -> {
|
||||||
if (homes.isEmpty()) {
|
if (homes.isEmpty()) {
|
||||||
plugin.getLocales().getLocale("error_no_warps_set")
|
plugin.getLocales().getLocale("error_no_warps_set")
|
||||||
@@ -102,6 +111,12 @@ public class DelHomeCommand extends CommandBase implements TabCompletable {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!confirm) {
|
||||||
|
plugin.getLocales().getLocale("delete_all_homes_confirm")
|
||||||
|
.ifPresent(deleter::sendMessage);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
final List<CompletableFuture<Boolean>> homeDeletionFuture = new ArrayList<>();
|
final List<CompletableFuture<Boolean>> homeDeletionFuture = new ArrayList<>();
|
||||||
for (final Home toDelete : homes) {
|
for (final Home toDelete : homes) {
|
||||||
homeDeletionFuture.add(plugin.getSavedPositionManager().deleteHome(homeOwner, toDelete.meta.name));
|
homeDeletionFuture.add(plugin.getSavedPositionManager().deleteHome(homeOwner, toDelete.meta.name));
|
||||||
|
|||||||
@@ -21,8 +21,9 @@ public class DelWarpCommand extends CommandBase implements TabCompletable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onExecute(@NotNull OnlineUser onlineUser, @NotNull String[] args) {
|
public void onExecute(@NotNull OnlineUser onlineUser, @NotNull String[] args) {
|
||||||
if (args.length == 1) { //todo delwarp all
|
if (args.length <= 2) {
|
||||||
final String warpName = args[0];
|
final String warpName = args[0];
|
||||||
|
final boolean confirm = args.length == 2 && args[1].equalsIgnoreCase("confirm");
|
||||||
plugin.getSavedPositionManager().deleteWarp(warpName).thenAccept(deleted -> {
|
plugin.getSavedPositionManager().deleteWarp(warpName).thenAccept(deleted -> {
|
||||||
if (deleted) {
|
if (deleted) {
|
||||||
plugin.getLocales().getLocale("warp_deleted", warpName)
|
plugin.getLocales().getLocale("warp_deleted", warpName)
|
||||||
@@ -30,7 +31,7 @@ public class DelWarpCommand extends CommandBase implements TabCompletable {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (warpName.equals("all")) {
|
if (warpName.equals("all")) {
|
||||||
deleteAllWarps(onlineUser);
|
deleteAllWarps(onlineUser, confirm);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -47,8 +48,9 @@ public class DelWarpCommand extends CommandBase implements TabCompletable {
|
|||||||
* Delete all the server warps
|
* Delete all the server warps
|
||||||
*
|
*
|
||||||
* @param deleter the player who is deleting the warps
|
* @param deleter the player who is deleting the warps
|
||||||
|
* @param confirm whether to skip the confirmation prompt
|
||||||
*/
|
*/
|
||||||
private void deleteAllWarps(@NotNull OnlineUser deleter) {
|
private void deleteAllWarps(@NotNull OnlineUser deleter, final boolean confirm) {
|
||||||
plugin.getDatabase().getWarps().thenAccept(warps -> {
|
plugin.getDatabase().getWarps().thenAccept(warps -> {
|
||||||
if (warps.isEmpty()) {
|
if (warps.isEmpty()) {
|
||||||
plugin.getLocales().getLocale("error_no_warps_set")
|
plugin.getLocales().getLocale("error_no_warps_set")
|
||||||
@@ -56,6 +58,12 @@ public class DelWarpCommand extends CommandBase implements TabCompletable {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!confirm) {
|
||||||
|
plugin.getLocales().getLocale("confirm_delete_all_warps")
|
||||||
|
.ifPresent(deleter::sendMessage);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
final List<CompletableFuture<Boolean>> homeDeletionFuture = new ArrayList<>();
|
final List<CompletableFuture<Boolean>> homeDeletionFuture = new ArrayList<>();
|
||||||
for (final Warp toDelete : warps) {
|
for (final Warp toDelete : warps) {
|
||||||
homeDeletionFuture.add(plugin.getSavedPositionManager().deleteWarp(toDelete.meta.name));
|
homeDeletionFuture.add(plugin.getSavedPositionManager().deleteWarp(toDelete.meta.name));
|
||||||
|
|||||||
Reference in new issue
Block a user