From 63069ff9ec30d37148e6a1e6b280f302ab555977 Mon Sep 17 00:00:00 2001 From: Nathan Curran <30569566+Focusvity@users.noreply.github.com> Date: Sun, 23 May 2021 00:40:55 +1000 Subject: [PATCH] Calculate the player count without offline players (FS-247) (#68) Co-authored-by: Ryan --- .../totalfreedommod/command/Command_list.java | 3 +-- .../totalfreedommod/httpd/module/Module_list.java | 4 +--- .../me/totalfreedom/totalfreedommod/util/FUtil.java | 13 +++++++++++++ 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_list.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_list.java index 336bae57..996ac302 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_list.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_list.java @@ -101,8 +101,7 @@ public class Command_list extends FreedomCommand } else { - int count = server.getOnlinePlayers().size() - AdminList.vanished.size(); - onlineStats.append(ChatColor.BLUE).append("There are ").append(ChatColor.RED).append(count < 0 ? 0 : count) + onlineStats.append(ChatColor.BLUE).append("There are ").append(ChatColor.RED).append(FUtil.getFakePlayerCount()) .append(ChatColor.BLUE) .append(" out of a maximum ") .append(ChatColor.RED) diff --git a/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_list.java b/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_list.java index ef40114c..8ee00487 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_list.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_list.java @@ -88,8 +88,6 @@ public class Module_list extends HTTPDModule } } - int count = server.getOnlinePlayers().size() - AdminList.vanished.size(); - // for future refernce - any multi-worded ranks are to be delimited by underscores in the json; eg. senior_admins responseObject.put("owners", owners); responseObject.put("executives", executives); @@ -99,7 +97,7 @@ public class Module_list extends HTTPDModule responseObject.put("master_builders", masterbuilders); responseObject.put("operators", operators); responseObject.put("imposters", imposters); - responseObject.put("online", count < 0 ? 0 : count); + responseObject.put("online", FUtil.getFakePlayerCount()); responseObject.put("max", server.getMaxPlayers()); final NanoHTTPD.Response response = new NanoHTTPD.Response(NanoHTTPD.Response.Status.OK, NanoHTTPD.MIME_JSON, responseObject.toString()); diff --git a/src/main/java/me/totalfreedom/totalfreedommod/util/FUtil.java b/src/main/java/me/totalfreedom/totalfreedommod/util/FUtil.java index 195384db..5afb206a 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/util/FUtil.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/util/FUtil.java @@ -838,6 +838,19 @@ public class FUtil }.runTaskLater(TotalFreedomMod.getPlugin(), delay); } + public static int getFakePlayerCount() + { + int i = TotalFreedomMod.getPlugin().al.vanished.size(); + for (String name : TotalFreedomMod.getPlugin().al.vanished) + { + if (Bukkit.getPlayer(name) == null) + { + i--; + } + } + return getServer().getOnlinePlayers().size() - i; + } + public static class PaginationList extends ArrayList { private final int epp;