package net.tylermurphy.hideAndSeek.command; import net.tylermurphy.hideAndSeek.command.util.ICommand; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; import java.util.*; import java.util.function.Consumer; import static net.tylermurphy.hideAndSeek.configuration.Config.errorPrefix; import static net.tylermurphy.hideAndSeek.configuration.Localization.message; public class Confirm implements ICommand { public static final Map confirmations = new HashMap<>(); public void execute(Player sender, String[] args) { Confirmation confirmation = confirmations.get(sender.getUniqueId()); confirmations.remove(sender.getUniqueId()); if(confirmation == null) { sender.sendMessage(errorPrefix + message("NO_CONFIRMATION")); } else { long now = System.currentTimeMillis(); float secs = (now - confirmation.start) / 1000F; if(secs > 10) { sender.sendMessage(errorPrefix + message("CONFIRMATION_TIMED_OUT")); return; } confirmation.callback.accept(confirmation.data); } } public String getLabel() { return "confirm"; } public String getUsage() { return ""; } public String getDescription() { return "Confirm another command if required"; } public List autoComplete(@NotNull String parameter, @NotNull String typed) { return null; } public static class Confirmation { public final Consumer callback; public final String data; public final long start; public Confirmation(String data, Consumer callback) { this.callback = callback; this.data = data; this.start = System.currentTimeMillis(); } } }