mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-18 10:12:53 +00:00
Merge pull request #664 from CocoTheOwner/validOnly
Better option picking for players & console
This commit is contained in:
commit
42ad8ba1ee
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user