Add %ajqueue_status_<server>% placeholder

This commit is contained in:
ajgeiss0702
2022-07-08 10:54:20 -05:00
parent 35f07ab760
commit a5771d03c3
13 changed files with 102 additions and 17 deletions
+1 -1
View File
@@ -18,7 +18,7 @@ dependencies {
implementation("net.kyori:adventure-text-serializer-plain:4.9.3")
compileOnly("com.google.guava:guava:30.1.1-jre")
compileOnly("us.ajg0702:ajUtils:1.1.22")
compileOnly("us.ajg0702:ajUtils:1.2.10")
}
publishing {
@@ -36,6 +36,20 @@ public interface QueueServer {
*/
String getStatusString();
/**
* Get the status of the server as a string (not from the messages file)
* @param p The player that you are checking for. Used for checking restricted servers
* @return The status of the server as a string
*/
String getStatus(AdaptedPlayer p);
/**
* Get the status of the server as a string (not from the messages file)
* Does not check if the player has access using restricted mode. May show online if it is restricted
* @return The status of the server as a string
*/
String getStatus();
/**
* Sends a server ping and uses the response to update online status, player count status, and whitelist status
*/
+1 -1
View File
@@ -18,7 +18,7 @@ dependencies {
compileOnly("net.kyori:adventure-text-serializer-plain:4.9.3")
compileOnly("com.google.guava:guava:30.1.1-jre")
compileOnly("us.ajg0702:ajUtils:1.1.22")
compileOnly("us.ajg0702:ajUtils:1.2.10")
compileOnly("org.slf4j:slf4j-log4j12:1.7.29")
@@ -116,6 +116,17 @@ public class EventHandlerImpl implements EventHandler {
if(server == null) return;
main.getPlatformMethods().sendPluginMessage(recievingPlayer, "queuedfor", srv, server.getQueue().size()+"");
}
if(subchannel.equals("status")) {
String srv = in.readUTF();
QueueServer server = main.getQueueManager().findServer(srv);
if(server == null) return;
main.getPlatformMethods().sendPluginMessage(
recievingPlayer,
"status",
srv,
main.getMessages().getRawString("placeholders.status."+server.getStatus(recievingPlayer))
);
}
if(subchannel.equals("leavequeue")) {
String[] args = new String[1];
try {
@@ -180,7 +180,7 @@ public class QueueMain extends AjQueueAPI {
}
private void constructMessages() {
LinkedHashMap<String, String> d = new LinkedHashMap<>();
LinkedHashMap<String, Object> d = new LinkedHashMap<>();
d.put("status.offline.base", "&c{SERVER} is {STATUS}. &7You are in position &f{POS}&7 of &f{LEN}&7.");
@@ -237,6 +237,14 @@ public class QueueMain extends AjQueueAPI {
d.put("placeholders.position.none", "None");
d.put("placeholders.estimated_time.none", "None");
d.put("placeholders.status.online", "&aOnline");
d.put("placeholders.status.offline", "&cOffline");
d.put("placeholders.status.restarting", "&cRestarting");
d.put("placeholders.status.full", "&eFull");
d.put("placeholders.status.restricted", "&eRestricted");
d.put("placeholders.status.paused", "&ePaused");
d.put("placeholders.status.whitelisted", "&eWhitelisted");
d.put("title.title", "");
d.put("title.subtitle", "<gold>You are <green>#{POS} <gold>in the queue!");
@@ -157,6 +157,40 @@ public class QueueServerImpl implements QueueServer {
return getStatusString(null);
}
@Override
public String getStatus(AdaptedPlayer p) {
if(getOfflineTime() > main.getConfig().getInt("offline-time")) {
return "offline";
}
if(!isOnline()) {
return "restarting";
}
if(isPaused()) {
return "paused";
}
if(p != null && isWhitelisted() && !getWhitelistedPlayers().contains(p.getUniqueId())) {
return "whitelisted";
}
if(isFull() && !canJoinFull(p)) {
return "full";
}
if(p != null && !canAccess(p)) {
return "restricted";
}
return "online";
}
@Override
public String getStatus() {
return null;
}
@Override
public void updatePing() {
boolean pingerDebug = main.getConfig().getBoolean("pinger-debug");
+1 -1
View File
@@ -18,7 +18,7 @@ dependencies {
compileOnly("com.google.guava:guava:30.1.1-jre")
compileOnly("org.spongepowered:configurate-yaml:4.0.0")
implementation("us.ajg0702:ajUtils:1.1.22")
implementation("us.ajg0702:ajUtils:1.2.10")
implementation(project(":platforms:velocity"))
implementation(project(":platforms:bungeecord"))
+1 -1
View File
@@ -16,7 +16,7 @@ repositories {
dependencies {
compileOnly("net.kyori:adventure-api:4.9.3")
compileOnly("com.google.guava:guava:30.1.1-jre")
compileOnly("us.ajg0702:ajUtils:1.1.22")
compileOnly("us.ajg0702:ajUtils:1.2.10")
compileOnly("net.md-5:bungeecord-api:1.16-R0.4")
+1 -1
View File
@@ -16,7 +16,7 @@ repositories {
dependencies {
compileOnly("net.kyori:adventure-api:4.9.3")
compileOnly("com.google.guava:guava:30.1.1-jre")
compileOnly("us.ajg0702:ajUtils:1.1.22")
compileOnly("us.ajg0702:ajUtils:1.2.10")
compileOnly("com.velocitypowered:velocity-api:3.0.0")
annotationProcessor("com.velocitypowered:velocity-api:3.0.0")
+1 -1
View File
@@ -23,7 +23,7 @@ dependencies {
compileOnly("me.TechsCode:FakeUltraPerms:1.0.2")
compileOnly("us.ajg0702:ajUtils:1.1.22")
compileOnly("us.ajg0702:ajUtils:1.2.10")
compileOnly("net.kyori:adventure-api:4.9.3")
+1 -1
View File
@@ -24,7 +24,7 @@ dependencies {
compileOnly("org.spongepowered:configurate-yaml:4.0.0")
compileOnly("us.ajg0702:ajUtils:1.1.22")
compileOnly("us.ajg0702:ajUtils:1.2.10")
compileOnly(group = "org.spigotmc", name = "spigot", version = "1.16.5-R0.1-SNAPSHOT")
compileOnly("me.clip:placeholderapi:2.10.4")
@@ -175,6 +175,9 @@ public class Placeholders extends PlaceholderExpansion {
if(identifier.matches("queuedfor_*.*")) {
return "0";
}
if(identifier.matches("status_*.*")) {
return "Loading";
}
}
@@ -185,21 +188,24 @@ public class Placeholders extends PlaceholderExpansion {
private String parsePlaceholder(Player player, String identifier) {
if(identifier.equalsIgnoreCase("queued")) {
plugin.sendMessage(player, "queuename", "");
}
} else
if(identifier.equalsIgnoreCase("position")) {
plugin.sendMessage(player, "position", "");
}
} else
if(identifier.equalsIgnoreCase("of")) {
plugin.sendMessage(player, "positionof", "");
}
} else
if(identifier.equalsIgnoreCase("inqueue")) {
plugin.sendMessage(player, "inqueue", "");
}
} else
if(identifier.equalsIgnoreCase("estimated_time")) {
plugin.sendMessage(player, "estimated_time", "");
}
} else
if(identifier.matches("queuedfor_*.*")) {
plugin.sendMessage(player, "queuedfor", identifier.split("_")[1]);
} else
if(identifier.matches("status_*.*")) {
plugin.sendMessage(player, "status", identifier.split("_")[1]);
}
@@ -178,6 +178,20 @@ public class SpigotMain extends JavaPlugin implements PluginMessageListener,List
phs.put("estimated_time", time);
placeholders.responseCache.put(p, phs);
}
if(subchannel.equals("status")) {
String playername = in.readUTF();
String server = in.readUTF();
Player p = Bukkit.getPlayer(playername);
if(p == null) return;
if(!p.isOnline()) return;
String status = in.readUTF();
HashMap<String, String> phs = placeholders.responseCache.get(p);
if(phs == null) phs = new HashMap<>();
phs.put("status_"+server, status+"");
placeholders.responseCache.put(p, phs);
}
}
@@ -207,9 +221,7 @@ public class SpigotMain extends JavaPlugin implements PluginMessageListener,List
@EventHandler
public void onJoin(PlayerJoinEvent e) {
if(hasProxy) return;
Bukkit.getScheduler().runTask(this, () -> {
sendMessage(e.getPlayer(), "ack", "");
});
Bukkit.getScheduler().runTask(this, () -> sendMessage(e.getPlayer(), "ack", ""));
}
@EventHandler(priority = EventPriority.HIGH)