Skip to content

Commit

Permalink
Add disguise check and fix nicked user bug (#1375)
Browse files Browse the repository at this point in the history
Signed-off-by: applenick <[email protected]>
  • Loading branch information
applenick authored Aug 2, 2024
1 parent 8ceb978 commit a8da827
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 26 deletions.
4 changes: 4 additions & 0 deletions core/src/main/java/tc/oc/pgm/api/integration/Integration.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
46 changes: 20 additions & 26 deletions core/src/main/java/tc/oc/pgm/listeners/ServerPingDataListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Match, JsonObject>() {
@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<Match, JsonObject>() {
@Override
public JsonObject load(Match match) throws Exception {
JsonObject jsonObject = new JsonObject();
serializeMatch(match, jsonObject);
return jsonObject;
}
});
}

@EventHandler
Expand All @@ -74,25 +72,21 @@ public void onServerListPing(ServerListPingEvent event) {
Iterator<Player> 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);
}
Expand Down

0 comments on commit a8da827

Please sign in to comment.