Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the rank clearing async to avoid lag. #2504 #2505

Merged
merged 1 commit into from
Sep 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1650,6 +1650,10 @@ public void clearArea(Location loc) {
* @param uniqueId - UUID of player
*/
public void clearRank(int rank, UUID uniqueId) {
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> clearRankSync(rank, uniqueId));
}

void clearRankSync(int rank, UUID uniqueId) {
islandCache.getCachedIslands().forEach(
i -> i.getMembers().entrySet().removeIf(e -> e.getKey().equals(uniqueId) && e.getValue() == rank));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1111,9 +1111,9 @@ public void testClearRank() {
UUID coopUUID = UUID.randomUUID();
members.put(coopUUID, RanksManager.COOP_RANK);
// Clear a random user
im.clearRank(RanksManager.COOP_RANK, UUID.randomUUID());
im.clearRankSync(RanksManager.COOP_RANK, UUID.randomUUID());
assertEquals(14, members.size());
im.clearRank(RanksManager.COOP_RANK, coopUUID);
im.clearRankSync(RanksManager.COOP_RANK, coopUUID);
assertEquals(13, members.size());
}

Expand Down
Loading