From 972a5b1d8da17b9728eb8970e627d792eca67bbb Mon Sep 17 00:00:00 2001 From: jobsonmarinho Date: Fri, 20 Sep 2024 13:09:26 -0300 Subject: [PATCH 1/4] fix: Update version of PlaceholderAPI to 2.11.6 in pom.xml --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index d820ae1..72ed4ef 100644 --- a/pom.xml +++ b/pom.xml @@ -35,7 +35,7 @@ me.clip placeholderapi - 2.10.6 + 2.11.6 provided From c6c5579bf4fae4a26faa07e8c8f75d3cd51bb063 Mon Sep 17 00:00:00 2001 From: jobsonmarinho Date: Fri, 20 Sep 2024 13:09:39 -0300 Subject: [PATCH 2/4] feat: Add functionality to check if a server is online in onRequest method --- .../extendedclip/papi/bungeeexpansion/BungeeExpansion.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/com/extendedclip/papi/bungeeexpansion/BungeeExpansion.java b/src/main/java/com/extendedclip/papi/bungeeexpansion/BungeeExpansion.java index e53cb4e..be66276 100644 --- a/src/main/java/com/extendedclip/papi/bungeeexpansion/BungeeExpansion.java +++ b/src/main/java/com/extendedclip/papi/bungeeexpansion/BungeeExpansion.java @@ -73,6 +73,11 @@ public Map getDefaults() { public String onRequest(final OfflinePlayer player, String identifier) { final int value; + if (identifier.startsWith("online_")) { + final String server = identifier.substring(7).toLowerCase(); + return counts.containsKey(server) ? "§aOnline" : "§cOffline"; + } + switch (identifier.toLowerCase()) { case "all": case "total": From 884817356fda9e01a23520d1d61910c28101a1f2 Mon Sep 17 00:00:00 2001 From: jobsonmarinho Date: Fri, 20 Sep 2024 13:55:10 -0300 Subject: [PATCH 3/4] fix: Fix configuration section retrieval and update default online and offline values. --- .../papi/bungeeexpansion/BungeeExpansion.java | 41 +++++++++++++------ 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/extendedclip/papi/bungeeexpansion/BungeeExpansion.java b/src/main/java/com/extendedclip/papi/bungeeexpansion/BungeeExpansion.java index be66276..8a84cdd 100644 --- a/src/main/java/com/extendedclip/papi/bungeeexpansion/BungeeExpansion.java +++ b/src/main/java/com/extendedclip/papi/bungeeexpansion/BungeeExpansion.java @@ -10,6 +10,7 @@ import me.clip.placeholderapi.expansion.Taskable; import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; +import org.bukkit.configuration.ConfigurationSection; import org.bukkit.entity.Player; import org.bukkit.plugin.messaging.PluginMessageListener; import org.bukkit.scheduler.BukkitTask; @@ -33,10 +34,12 @@ public final class BungeeExpansion extends PlaceholderExpansion implements Plugi private static final Splitter SPLITTER = Splitter.on(",").trimResults(); - - private final Map counts = new HashMap<>(); + private final Map counts = new HashMap<>(); private final AtomicReference cached = new AtomicReference<>(); + private String online = "Online"; + private String offline = "Offline"; + private static Field inputField; static { @@ -75,7 +78,7 @@ public String onRequest(final OfflinePlayer player, String identifier) { if (identifier.startsWith("online_")) { final String server = identifier.substring(7).toLowerCase(); - return counts.containsKey(server) ? "§aOnline" : "§cOffline"; + return counts.containsKey(server) ? online : offline; } switch (identifier.toLowerCase()) { @@ -93,12 +96,16 @@ public String onRequest(final OfflinePlayer player, String identifier) { @Override public void start() { + if (hasString("online")) + this.online = getString("online", "Online"); + if (hasString("offline")) + this.offline = getString("offline", "Offline"); + final BukkitTask task = Bukkit.getScheduler().runTaskTimer(getPlaceholderAPI(), () -> { if (counts.isEmpty()) { sendServersChannelMessage(); - } - else { + } else { counts.keySet().forEach(this::sendPlayersChannelMessage); } @@ -114,6 +121,13 @@ public void start() { } } + private boolean hasString(String path) { + ConfigurationSection section = this.getConfigSection(); + if (section == null) + return false; + return section.contains(path); + } + @Override public void stop() { final BukkitTask prev = cached.getAndSet(null); @@ -140,13 +154,13 @@ public void onPluginMessageReceived(final String channel, final Player player, f try { DataInputStream stream = (DataInputStream) inputField.get(in); switch (in.readUTF()) { - case PLAYERS_CHANNEL: - if (stream.available() == 0) return; // how ? - final String server = in.readUTF(); - if (stream.available() == 0) { // how ? x2 - getPlaceholderAPI().getLogger().log(Level.SEVERE, String.format("[%s] Could not get the player count from server %s.", getName(), server)); - counts.put(server.toLowerCase(), 0); - } else counts.put(server.toLowerCase(), in.readInt()); + case PLAYERS_CHANNEL: + if (stream.available() == 0) return; // how ? + final String server = in.readUTF(); + if (stream.available() == 0) { // how ? x2 + getPlaceholderAPI().getLogger().log(Level.SEVERE, String.format("[%s] Could not get the player count from server %s.", getName(), server)); + counts.put(server.toLowerCase(), 0); + } else counts.put(server.toLowerCase(), in.readInt()); break; case SERVERS_CHANNEL: SPLITTER.split(in.readUTF()).forEach(serverName -> counts.putIfAbsent(serverName.toLowerCase(), 0)); @@ -159,7 +173,8 @@ public void onPluginMessageReceived(final String channel, final Player player, f private void sendServersChannelMessage() { - sendMessage(SERVERS_CHANNEL, out -> { }); + sendMessage(SERVERS_CHANNEL, out -> { + }); } private void sendPlayersChannelMessage(final String serverName) { From 80a7cff0546be91aaffcac8ee5e7f66331d1bd51 Mon Sep 17 00:00:00 2001 From: jobsonmarinho Date: Sat, 21 Sep 2024 15:17:25 -0300 Subject: [PATCH 4/4] chore: Update version to 2.4 and add default values for online and offline configurations --- .../papi/bungeeexpansion/BungeeExpansion.java | 21 +++++++------------ 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/extendedclip/papi/bungeeexpansion/BungeeExpansion.java b/src/main/java/com/extendedclip/papi/bungeeexpansion/BungeeExpansion.java index 8a84cdd..76e24ce 100644 --- a/src/main/java/com/extendedclip/papi/bungeeexpansion/BungeeExpansion.java +++ b/src/main/java/com/extendedclip/papi/bungeeexpansion/BungeeExpansion.java @@ -63,12 +63,16 @@ public String getAuthor() { @Override public String getVersion() { - return "2.3"; + return "2.4"; } @Override public Map getDefaults() { - return Collections.singletonMap(CONFIG_INTERVAL, 30); + Map defaults = new HashMap<>(); + defaults.put(CONFIG_INTERVAL, 30); + defaults.put("online", "Online"); + defaults.put("offline", "Offline"); + return defaults; } @@ -96,10 +100,8 @@ public String onRequest(final OfflinePlayer player, String identifier) { @Override public void start() { - if (hasString("online")) - this.online = getString("online", "Online"); - if (hasString("offline")) - this.offline = getString("offline", "Offline"); + this.online = getString("online", "Online"); + this.offline = getString("offline", "Offline"); final BukkitTask task = Bukkit.getScheduler().runTaskTimer(getPlaceholderAPI(), () -> { @@ -121,13 +123,6 @@ public void start() { } } - private boolean hasString(String path) { - ConfigurationSection section = this.getConfigSection(); - if (section == null) - return false; - return section.contains(path); - } - @Override public void stop() { final BukkitTask prev = cached.getAndSet(null);