Merge pull request #2505 from BentoBoxWorld/2504_lag_on_logout

Make the rank clearing async to avoid lag. #2504
This commit is contained in:
tastybento 2024-09-14 16:45:22 -07:00 committed by GitHub
commit 060e700fce
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 2 deletions

View File

@ -1650,6 +1650,10 @@ public class IslandsManager {
* @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));
}

View File

@ -1111,9 +1111,9 @@ public class IslandsManagerTest extends AbstractCommonSetup {
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());
}