Merge pull request #664 from CocoTheOwner/validOnly

Better option picking for players & console
This commit is contained in:
Dan 2021-11-11 17:56:38 -05:00 committed by GitHub
commit 42ad8ba1ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -537,8 +537,15 @@ public class VirtualDecreeCommand {
}
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;
sender.sendHeader("Pick a " + name + " (" + type + ")");
sender.sendMessageRaw("<gradient:#1ed497:#b39427>This query will expire in 15 seconds.</gradient>");
while (tries-- > 0 && (result == null || !options.contains(result))) {
sender.sendMessage("<gradient:#1ed497:#b39427>Please pick a valid option.");
String password = UUID.randomUUID().toString().replaceAll("\\Q-\\E", "");
int m = 0;
@ -547,30 +554,32 @@ public class VirtualDecreeCommand {
m++;
}
if (sender.isPlayer()) {
CompletableFuture<String> 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);
}
try {
return future.get(15, TimeUnit.SECONDS);
} catch (InterruptedException | ExecutionException | TimeoutException ignored) {
}
} else {
CompletableFuture<String> future = new CompletableFuture<>();
Iris.service(CommandSVC.class).postConsole(future);
}
try {
return future.get(15, TimeUnit.SECONDS);
result = future.get(15, TimeUnit.SECONDS);
} catch (InterruptedException | ExecutionException | TimeoutException ignored) {
}
}
if (result != null && options.contains(result)) {
return result;
} else {
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;
}