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,38 +537,47 @@ 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;
|
||||||
|
|
||||||
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", "");
|
|
||||||
int m = 0;
|
|
||||||
|
|
||||||
for (String i : validOptions.convert(handler::toStringForce)) {
|
while (tries-- > 0 && (result == null || !options.contains(result))) {
|
||||||
sender.sendMessage("<hover:show_text:'" + gradients[m % gradients.length] + i + "</gradient>'><click:run_command:/irisdecree " + password + " " + i + ">" + "- " + gradients[m % gradients.length] + i + "</gradient></click></hover>");
|
sender.sendMessage("<gradient:#1ed497:#b39427>Please pick a valid option.");
|
||||||
m++;
|
String password = UUID.randomUUID().toString().replaceAll("\\Q-\\E", "");
|
||||||
|
int m = 0;
|
||||||
|
|
||||||
|
for (String i : validOptions.convert(handler::toStringForce)) {
|
||||||
|
sender.sendMessage("<hover:show_text:'" + gradients[m % gradients.length] + i + "</gradient>'><click:run_command:/irisdecree " + password + " " + i + ">" + "- " + gradients[m % gradients.length] + i + "</gradient></click></hover>");
|
||||||
|
m++;
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Iris.service(CommandSVC.class).postConsole(future);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
result = future.get(15, TimeUnit.SECONDS);
|
||||||
|
} catch (InterruptedException | ExecutionException | TimeoutException ignored) {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sender.isPlayer()) {
|
if (result != null && options.contains(result)) {
|
||||||
CompletableFuture<String> future = new CompletableFuture<>();
|
return result;
|
||||||
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 {
|
} else {
|
||||||
CompletableFuture<String> future = new CompletableFuture<>();
|
sender.sendMessage(C.RED + "You did not enter a correct option within 3 tries.");
|
||||||
Iris.service(CommandSVC.class).postConsole(future);
|
sender.sendMessage(C.RED + "Please double-check your arguments & option picking.");
|
||||||
try {
|
|
||||||
return future.get(15, TimeUnit.SECONDS);
|
|
||||||
} catch (InterruptedException | ExecutionException | TimeoutException ignored) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user