Added %ajqueue_status_<server>_player%
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
package us.ajg0702.queue.api;
|
||||
|
||||
public interface QueueHolder {
|
||||
boolean isAvailable();
|
||||
|
||||
}
|
||||
@@ -30,6 +30,7 @@ public class PlaceholderExpansion extends me.clip.placeholderapi.expansion.Place
|
||||
placeholders.add(new Queued(plugin));
|
||||
placeholders.add(new QueuedFor(plugin));
|
||||
placeholders.add(new Status(plugin));
|
||||
placeholders.add(new StatusPlayer(plugin));
|
||||
|
||||
}
|
||||
|
||||
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
package us.ajg0702.queue.spigot.placeholders.placeholders;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import us.ajg0702.queue.api.spigot.AjQueueSpigotAPI;
|
||||
import us.ajg0702.queue.api.spigot.MessagedResponse;
|
||||
import us.ajg0702.queue.spigot.SpigotMain;
|
||||
import us.ajg0702.queue.spigot.placeholders.Placeholder;
|
||||
import us.ajg0702.queue.spigot.utils.UUIDStringKey;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.logging.Level;
|
||||
import java.util.regex.Matcher;
|
||||
|
||||
public class StatusPlayer extends Placeholder {
|
||||
public StatusPlayer(SpigotMain plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
private final Map<UUIDStringKey, String> cache = new ConcurrentHashMap<>();
|
||||
|
||||
@Override
|
||||
public String getRegex() {
|
||||
return "status_(.*)_player";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String parse(Matcher matcher, OfflinePlayer p) {
|
||||
String queue = matcher.group(1);
|
||||
UUIDStringKey key = new UUIDStringKey(p.getUniqueId(), queue);
|
||||
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
try {
|
||||
String response = AjQueueSpigotAPI.getInstance()
|
||||
.getServerStatusString(queue, p.getUniqueId())
|
||||
.get(30, TimeUnit.SECONDS);
|
||||
|
||||
cache.put(key, response);
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (TimeoutException e) {
|
||||
plugin.getLogger().log(Level.WARNING, "Timed out while trying to get placeholder data from proxy: ", e);
|
||||
}
|
||||
});
|
||||
|
||||
return cache.getOrDefault(key, "...");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cleanCache(Player player) {
|
||||
cache.entrySet().removeIf(entry -> entry.getKey().getUuid().equals(player.getUniqueId()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package us.ajg0702.queue.spigot.utils;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
||||
public class UUIDStringKey {
|
||||
|
||||
private final UUID uuid;
|
||||
private final String string;
|
||||
|
||||
public UUIDStringKey(UUID uuid, String string) {
|
||||
this.uuid = uuid;
|
||||
this.string = string;
|
||||
}
|
||||
|
||||
public UUID getUuid() {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
public String getString() {
|
||||
return string;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof UUIDStringKey)) return false;
|
||||
UUIDStringKey that = (UUIDStringKey) o;
|
||||
return uuid.equals(that.uuid) && string.equals(that.string);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(uuid, string);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user