Make the rank clearing async to avoid lag. #2504

This commit is contained in:
tastybento 2024-09-14 16:43:25 -07:00
parent f5abdd4c78
commit 0965e07d93
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());
}