diff --git a/src/main/java/com/volmit/iris/util/decree/virtual/VirtualDecreeCommand.java b/src/main/java/com/volmit/iris/util/decree/virtual/VirtualDecreeCommand.java index bd0edb049..054786ee2 100644 --- a/src/main/java/com/volmit/iris/util/decree/virtual/VirtualDecreeCommand.java +++ b/src/main/java/com/volmit/iris/util/decree/virtual/VirtualDecreeCommand.java @@ -537,38 +537,47 @@ public class VirtualDecreeCommand { } private String pickValidOption(VolmitSender sender, KList validOptions, DecreeParameterHandler handler, String name, String type) { + int tries = 3; + KList options = validOptions.convert(handler::toStringForce); + String result = null; + sender.sendHeader("Pick a " + name + " (" + type + ")"); sender.sendMessageRaw("This query will expire in 15 seconds."); - String password = UUID.randomUUID().toString().replaceAll("\\Q-\\E", ""); - int m = 0; - for (String i : validOptions.convert(handler::toStringForce)) { - sender.sendMessage("'>" + "- " + gradients[m % gradients.length] + i + ""); - m++; + while (tries-- > 0 && (result == null || !options.contains(result))) { + sender.sendMessage("Please pick a valid option."); + String password = UUID.randomUUID().toString().replaceAll("\\Q-\\E", ""); + int m = 0; + + for (String i : validOptions.convert(handler::toStringForce)) { + sender.sendMessage("'>" + "- " + gradients[m % gradients.length] + i + ""); + m++; + } + + CompletableFuture future = new CompletableFuture<>(); + if (sender.isPlayer()) { + Iris.service(CommandSVC.class).post(password, future); + + if (IrisSettings.get().getGeneral().isCommandSounds()) { + (sender.player()).playSound((sender.player()).getLocation(), Sound.BLOCK_AMETHYST_CLUSTER_BREAK, 0.77f, 0.65f); + (sender.player()).playSound((sender.player()).getLocation(), Sound.BLOCK_BEACON_DEACTIVATE, 0.125f, 1.99f); + } + } else { + Iris.service(CommandSVC.class).postConsole(future); + } + + try { + result = future.get(15, TimeUnit.SECONDS); + } catch (InterruptedException | ExecutionException | TimeoutException ignored) { + + } } - if (sender.isPlayer()) { - CompletableFuture future = new CompletableFuture<>(); - Iris.service(CommandSVC.class).post(password, future); - - if (IrisSettings.get().getGeneral().isCommandSounds()) { - (sender.player()).playSound((sender.player()).getLocation(), Sound.BLOCK_AMETHYST_CLUSTER_BREAK, 0.77f, 0.65f); - (sender.player()).playSound((sender.player()).getLocation(), Sound.BLOCK_BEACON_DEACTIVATE, 0.125f, 1.99f); - } - - try { - return future.get(15, TimeUnit.SECONDS); - } catch (InterruptedException | ExecutionException | TimeoutException ignored) { - - } + if (result != null && options.contains(result)) { + return result; } else { - CompletableFuture future = new CompletableFuture<>(); - Iris.service(CommandSVC.class).postConsole(future); - try { - return future.get(15, TimeUnit.SECONDS); - } catch (InterruptedException | ExecutionException | TimeoutException ignored) { - - } + sender.sendMessage(C.RED + "You did not enter a correct option within 3 tries."); + sender.sendMessage(C.RED + "Please double-check your arguments & option picking."); } return null;