3 tries + either valid or null

This commit is contained in:
CocoTheOwner 2021-09-27 15:33:45 +02:00
parent 85fe65612e
commit 1c03a7fc5c

View File

@ -518,6 +518,11 @@ public class VirtualDecreeCommand {
} }
private String pickValidOption(VolmitSender sender, KList<?> validOptions, DecreeParameterHandler<?> handler, String name, String type) { private String pickValidOption(VolmitSender sender, KList<?> validOptions, DecreeParameterHandler<?> handler, String name, String type) {
int tries = 3;
KList<String> options = validOptions.convert(handler::toStringForce);
String result = null;
while (tries-- > 0 && (result == null || !options.contains(result))) {
sender.sendHeader("Pick a " + name + " (" + type + ")"); sender.sendHeader("Pick a " + name + " (" + type + ")");
sender.sendMessageRaw("<gradient:#1ed497:#b39427>This query will expire in 15 seconds.</gradient>"); sender.sendMessageRaw("<gradient:#1ed497:#b39427>This query will expire in 15 seconds.</gradient>");
String password = UUID.randomUUID().toString().replaceAll("\\Q-\\E", ""); String password = UUID.randomUUID().toString().replaceAll("\\Q-\\E", "");
@ -528,31 +533,29 @@ public class VirtualDecreeCommand {
m++; m++;
} }
if (sender.isPlayer()) {
CompletableFuture<String> future = new CompletableFuture<>(); CompletableFuture<String> future = new CompletableFuture<>();
if (sender.isPlayer()) {
Iris.service(CommandSVC.class).post(password, future); Iris.service(CommandSVC.class).post(password, future);
if (IrisSettings.get().getGeneral().isCommandSounds()) { 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_AMETHYST_CLUSTER_BREAK, 0.77f, 0.65f);
(sender.player()).playSound((sender.player()).getLocation(), Sound.BLOCK_BEACON_DEACTIVATE, 0.125f, 1.99f); (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) {
}
} else { } else {
CompletableFuture<String> future = new CompletableFuture<>();
Iris.service(CommandSVC.class).postConsole(future); Iris.service(CommandSVC.class).postConsole(future);
}
try { try {
String result = future.get(15, TimeUnit.SECONDS); result = future.get(15, TimeUnit.SECONDS);
return validOptions.convert(handler::toStringForce).contains(result) ? result : null;
} catch (InterruptedException | ExecutionException | TimeoutException ignored) { } catch (InterruptedException | ExecutionException | TimeoutException ignored) {
} }
} }
if (result != null && options.contains(result)) {
return result;
}
return null; return null;
} }