From a8da827fbe615823a0ab9d93ae203f88a19e751d Mon Sep 17 00:00:00 2001 From: applenick Date: Fri, 2 Aug 2024 16:41:11 -0700 Subject: [PATCH] Add disguise check and fix nicked user bug (#1375) Signed-off-by: applenick --- .../oc/pgm/api/integration/Integration.java | 4 ++ .../pgm/listeners/ServerPingDataListener.java | 46 ++++++++----------- 2 files changed, 24 insertions(+), 26 deletions(-) diff --git a/core/src/main/java/tc/oc/pgm/api/integration/Integration.java b/core/src/main/java/tc/oc/pgm/api/integration/Integration.java index 54462e5542..aa1115c6fa 100644 --- a/core/src/main/java/tc/oc/pgm/api/integration/Integration.java +++ b/core/src/main/java/tc/oc/pgm/api/integration/Integration.java @@ -79,6 +79,10 @@ public static boolean setVanished(MatchPlayer player, boolean vanish, boolean qu return VANISH.get().setVanished(player, vanish, quiet); } + public static boolean isDisguised(Player player) { + return isVanished(player) || getNick(player) != null; + } + // No-op Implementations private static class NoopFriendIntegration implements FriendIntegration { diff --git a/core/src/main/java/tc/oc/pgm/listeners/ServerPingDataListener.java b/core/src/main/java/tc/oc/pgm/listeners/ServerPingDataListener.java index 5ce712342d..86e39cf529 100644 --- a/core/src/main/java/tc/oc/pgm/listeners/ServerPingDataListener.java +++ b/core/src/main/java/tc/oc/pgm/listeners/ServerPingDataListener.java @@ -46,19 +46,17 @@ public ServerPingDataListener(MatchManager matchManager, MapOrder mapOrder, Logg this.logger = ClassLogger.get(assertNotNull(parentLogger), ServerPingDataListener.class); this.ready = new AtomicBoolean(); this.legacySportPaper = new AtomicBoolean(); - this.matchCache = - CacheBuilder.newBuilder() - .weakKeys() - .expireAfterWrite(5L, TimeUnit.SECONDS) - .build( - new CacheLoader() { - @Override - public JsonObject load(Match match) throws Exception { - JsonObject jsonObject = new JsonObject(); - serializeMatch(match, jsonObject); - return jsonObject; - } - }); + this.matchCache = CacheBuilder.newBuilder() + .weakKeys() + .expireAfterWrite(5L, TimeUnit.SECONDS) + .build(new CacheLoader() { + @Override + public JsonObject load(Match match) throws Exception { + JsonObject jsonObject = new JsonObject(); + serializeMatch(match, jsonObject); + return jsonObject; + } + }); } @EventHandler @@ -74,25 +72,21 @@ public void onServerListPing(ServerListPingEvent event) { Iterator playerSample = event.iterator(); while (playerSample.hasNext()) { Player player = playerSample.next(); - if (Integration.isVanished(player)) { + if (Integration.isDisguised(player)) { playerSample.remove(); } } try { JsonObject root = MISC_UTILS.getServerListExtra(event, PGM.get()); - this.matchManager - .getMatches() - .forEachRemaining( - match -> { - String matchId = match.getId(); - try { - root.add(matchId, this.matchCache.get(match)); - } catch (ExecutionException e) { - this.logger.log( - Level.SEVERE, "Could not load server ping data for match: " + matchId, e); - } - }); + this.matchManager.getMatches().forEachRemaining(match -> { + String matchId = match.getId(); + try { + root.add(matchId, this.matchCache.get(match)); + } catch (ExecutionException e) { + this.logger.log(Level.SEVERE, "Could not load server ping data for match: " + matchId, e); + } + }); } catch (NoSuchMethodError ex) { legacySportPaper.compareAndSet(false, true); }