diff --git a/build.gradle.kts b/build.gradle.kts index 08598ef..5e689b1 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -2,7 +2,7 @@ plugins { id("java") } -version = "2.6.7" +version = "2.6.8" allprojects { repositories { diff --git a/core/src/main/java/fr/aerwyn81/headblocks/services/StorageService.java b/core/src/main/java/fr/aerwyn81/headblocks/services/StorageService.java index 883d80a..eaff4ad 100644 --- a/core/src/main/java/fr/aerwyn81/headblocks/services/StorageService.java +++ b/core/src/main/java/fr/aerwyn81/headblocks/services/StorageService.java @@ -21,6 +21,7 @@ import java.nio.file.Files; import java.time.LocalDate; import java.util.*; +import java.util.concurrent.CompletableFuture; import java.util.concurrent.ConcurrentHashMap; import java.util.stream.Collectors; @@ -311,7 +312,7 @@ public static void close() { } public static boolean hasHead(UUID playerUuid, UUID headUuid) throws InternalException { - if (_cacheHeads.containsKey(playerUuid) && !_cacheHeads.get(playerUuid).isEmpty()) + if (_cacheHeads.containsKey(playerUuid)) return _cacheHeads.get(playerUuid).contains(headUuid); return storage.hasHead(playerUuid, headUuid); @@ -321,7 +322,11 @@ public static void addHead(UUID playerUuid, UUID headUuid) throws InternalExcept storage.addHead(playerUuid, headUuid); database.addHead(playerUuid, headUuid); - StorageService.invalidateCachePlayer(playerUuid); + _cacheHeads.get(playerUuid).add(headUuid); + + if (!_cacheTop.isEmpty()) { + _cacheTop.clear(); + } } public static Boolean containsPlayer(UUID playerUuid) throws InternalException { @@ -329,11 +334,11 @@ public static Boolean containsPlayer(UUID playerUuid) throws InternalException { } public static BukkitFutureResult> getHeadsPlayer(UUID playerUuid) { + if (_cacheHeads.containsKey(playerUuid)) + return BukkitFutureResult.of(HeadBlocks.getInstance(), CompletableFuture.completedFuture(_cacheHeads.get(playerUuid))); + return CompletableBukkitFuture.supplyAsync(HeadBlocks.getInstance(), () -> { try { - if (_cacheHeads.containsKey(playerUuid) && !_cacheHeads.get(playerUuid).isEmpty()) - return _cacheHeads.get(playerUuid); - var headsUuid = database.getHeadsPlayer(playerUuid); _cacheHeads.compute(playerUuid, (key, playerHeads) -> { if (playerHeads == null) {