mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-18 18:23:06 +00:00
This is better
This commit is contained in:
parent
8ef75f7c34
commit
6ce37944a7
@ -31,11 +31,14 @@ import com.volmit.iris.util.plugin.VolmitSender;
|
|||||||
import com.volmit.iris.util.scheduling.J;
|
import com.volmit.iris.util.scheduling.J;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||||
|
import org.bukkit.event.server.ServerCommandEvent;
|
||||||
|
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
public class CommandSVC implements IrisService, DecreeSystem {
|
public class CommandSVC implements IrisService, DecreeSystem {
|
||||||
private final KMap<String, CompletableFuture<String>> futures = new KMap<>();
|
private final KMap<String, CompletableFuture<String>> futures = new KMap<>();
|
||||||
|
private CompletableFuture<String> consoleFuture = null;
|
||||||
private final transient AtomicCache<VirtualDecreeCommand> commandCache = new AtomicCache<>();
|
private final transient AtomicCache<VirtualDecreeCommand> commandCache = new AtomicCache<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -70,6 +73,17 @@ public class CommandSVC implements IrisService, DecreeSystem {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void on(ServerCommandEvent e) {
|
||||||
|
if (consoleFuture != null && !consoleFuture.isCancelled() && !consoleFuture.isDone()) {
|
||||||
|
if (!e.getCommand().contains(" ")) {
|
||||||
|
String pick = e.getCommand().trim().toLowerCase(Locale.ROOT);
|
||||||
|
consoleFuture.complete(pick);
|
||||||
|
e.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public VirtualDecreeCommand getRoot() {
|
public VirtualDecreeCommand getRoot() {
|
||||||
return commandCache.aquireNastyPrint(() -> VirtualDecreeCommand.createRoot(new CommandIris()));
|
return commandCache.aquireNastyPrint(() -> VirtualDecreeCommand.createRoot(new CommandIris()));
|
||||||
@ -78,4 +92,8 @@ public class CommandSVC implements IrisService, DecreeSystem {
|
|||||||
public void post(String password, CompletableFuture<String> future) {
|
public void post(String password, CompletableFuture<String> future) {
|
||||||
futures.put(password, future);
|
futures.put(password, future);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void postConsole(CompletableFuture<String> future) {
|
||||||
|
consoleFuture = future;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,6 +34,7 @@ import com.volmit.iris.util.decree.exceptions.DecreeParsingException;
|
|||||||
import com.volmit.iris.util.decree.exceptions.DecreeWhichException;
|
import com.volmit.iris.util.decree.exceptions.DecreeWhichException;
|
||||||
import com.volmit.iris.util.format.C;
|
import com.volmit.iris.util.format.C;
|
||||||
import com.volmit.iris.util.format.Form;
|
import com.volmit.iris.util.format.Form;
|
||||||
|
import com.volmit.iris.util.parallel.MultiBurst;
|
||||||
import com.volmit.iris.util.plugin.CommandDummy;
|
import com.volmit.iris.util.plugin.CommandDummy;
|
||||||
import com.volmit.iris.util.plugin.VolmitSender;
|
import com.volmit.iris.util.plugin.VolmitSender;
|
||||||
import com.volmit.iris.util.scheduling.ChronoLatch;
|
import com.volmit.iris.util.scheduling.ChronoLatch;
|
||||||
@ -518,13 +519,6 @@ 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) {
|
||||||
|
|
||||||
if (!sender.isPlayer()) {
|
|
||||||
sender.sendMessage(C.YELLOW + "There were multiple (" + validOptions.size() + ") options for '" + name + "' (of type '" + type + "'), but we selected '" + handler.toStringForce(validOptions.get(0)) + "'");
|
|
||||||
return handler.toStringForce(validOptions.get(0));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
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", "");
|
||||||
@ -535,18 +529,28 @@ public class VirtualDecreeCommand {
|
|||||||
m++;
|
m++;
|
||||||
}
|
}
|
||||||
|
|
||||||
CompletableFuture<String> future = new CompletableFuture<>();
|
if (sender.isPlayer()) {
|
||||||
Iris.service(CommandSVC.class).post(password, future);
|
CompletableFuture<String> future = new CompletableFuture<>();
|
||||||
|
Iris.service(CommandSVC.class).post(password, future);
|
||||||
|
|
||||||
if (IrisSettings.get().getGeneral().isCommandSounds() && sender.isPlayer()) {
|
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 {
|
try {
|
||||||
return future.get(15, TimeUnit.SECONDS);
|
return future.get(15, TimeUnit.SECONDS);
|
||||||
} catch (InterruptedException | ExecutionException | TimeoutException e) {
|
} catch (InterruptedException | ExecutionException | TimeoutException ignored) {
|
||||||
|
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
CompletableFuture<String> future = new CompletableFuture<>();
|
||||||
|
Iris.service(CommandSVC.class).postConsole(future);
|
||||||
|
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