mirror of
https://github.com/songoda/FabledSkyBlock.git
synced 2024-11-22 02:08:34 +01:00
Add caching for roles to avoid reading the files all the time
This commit is contained in:
parent
8425d995c0
commit
54688b7b73
@ -61,6 +61,7 @@ public class Island {
|
||||
private final List<IslandLocation> islandLocations = new ArrayList<>();
|
||||
private final Map<UUID, IslandCoop> coopPlayers = new HashMap<>();
|
||||
private final Set<UUID> whitelistedPlayers = new HashSet<>();
|
||||
private final Map<IslandRole, Set<UUID>> roleCache = new HashMap<>();
|
||||
|
||||
private UUID islandUUID;
|
||||
private UUID ownerUUID;
|
||||
@ -599,6 +600,11 @@ public class Island {
|
||||
}
|
||||
|
||||
public Set<UUID> getRole(IslandRole role) {
|
||||
|
||||
if (roleCache.containsKey(role)) {
|
||||
return new HashSet<>(roleCache.get(role)); // Return a copy to avoid external modification
|
||||
}
|
||||
|
||||
Set<UUID> islandRoles = new HashSet<>();
|
||||
|
||||
if (role == IslandRole.OWNER) {
|
||||
@ -615,6 +621,8 @@ public class Island {
|
||||
}
|
||||
}
|
||||
|
||||
roleCache.put(role, islandRoles);
|
||||
|
||||
return islandRoles;
|
||||
}
|
||||
|
||||
@ -673,6 +681,9 @@ public class Island {
|
||||
|
||||
getVisit().setMembers(getRole(IslandRole.MEMBER).size() + getRole(IslandRole.OPERATOR).size() + 1);
|
||||
|
||||
//Update role cache
|
||||
roleCache.remove(role);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -699,6 +710,9 @@ public class Island {
|
||||
|
||||
getVisit().setMembers(getRole(IslandRole.MEMBER).size() + getRole(IslandRole.OPERATOR).size() + 1);
|
||||
|
||||
//Update role cache
|
||||
roleCache.remove(role);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -170,13 +170,13 @@ public class InteractListeners implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
Optional<XMaterial> material = block == null ? Optional.empty() : CompatibleMaterial.getMaterial(block.getType());
|
||||
|
||||
// Check permissions.
|
||||
if (!this.plugin.getPermissionManager().processPermission(event, player, island)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Optional<XMaterial> material = block == null ? Optional.empty() : CompatibleMaterial.getMaterial(block.getType());
|
||||
|
||||
if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
|
||||
final Optional<XMaterial> blockType = CompatibleMaterial.getMaterial(event.getClickedBlock().getType());
|
||||
final XMaterial heldType;
|
||||
|
Loading…
Reference in New Issue
Block a user