diff --git a/rpgregions/src/main/java/net/islandearth/rpgregions/managers/data/SQLCommonStorage.java b/rpgregions/src/main/java/net/islandearth/rpgregions/managers/data/SQLCommonStorage.java index 01154dc..7bcdfcb 100644 --- a/rpgregions/src/main/java/net/islandearth/rpgregions/managers/data/SQLCommonStorage.java +++ b/rpgregions/src/main/java/net/islandearth/rpgregions/managers/data/SQLCommonStorage.java @@ -36,14 +36,14 @@ public abstract class SQLCommonStorage implements IStorageManager { public SQLCommonStorage(RPGRegions plugin) { this.plugin = plugin; this.cachedAccounts = Caffeine.newBuilder() - .maximumSize(1_000) + .maximumSize(1_000) // Realistically no server can support higher than this, even Folia .scheduler(Scheduler.systemScheduler()) .expireAfterAccess(plugin.getConfig().getInt("settings.storage.cache-expiry-time", 180), TimeUnit.SECONDS) .removalListener((k, v, c) -> { plugin.debug("Removed user from cache, cause: " + c.name()); // If the user was manually removed, don't save, let other code handle how it wants - if (c == RemovalCause.EXPLICIT) return; - removeCachedAccount(((RPGRegionsAccount) v).getUuid()); + if (v == null || c == RemovalCause.EXPLICIT) return; + saveAccount(((RPGRegionsAccount) v)); }) .buildAsync((key, executor) -> getAccount(key)); } diff --git a/rpgregions/src/main/java/net/islandearth/rpgregions/managers/data/yml/YamlStorage.java b/rpgregions/src/main/java/net/islandearth/rpgregions/managers/data/yml/YamlStorage.java index 12d86ee..ca8e61f 100644 --- a/rpgregions/src/main/java/net/islandearth/rpgregions/managers/data/yml/YamlStorage.java +++ b/rpgregions/src/main/java/net/islandearth/rpgregions/managers/data/yml/YamlStorage.java @@ -35,14 +35,14 @@ public class YamlStorage implements IStorageManager { File dataFile = new File(plugin.getDataFolder() + "/accounts/"); dataFile.mkdirs(); this.cachedAccounts = Caffeine.newBuilder() - .maximumSize(1_000) + .maximumSize(1_000) // Realistically no server can support higher than this, even Folia .scheduler(Scheduler.systemScheduler()) .expireAfterAccess(plugin.getConfig().getInt("settings.storage.cache-expiry-time", 180), TimeUnit.SECONDS) .removalListener((k, v, c) -> { plugin.debug("Removed user from cache, cause: " + c.name()); // If the user was manually removed, don't save, let other code handle how it wants - if (c == RemovalCause.EXPLICIT) return; - removeCachedAccount(((RPGRegionsAccount) v).getUuid()); + if (v == null || c == RemovalCause.EXPLICIT) return; + saveAccount(((RPGRegionsAccount) v)); }) .buildAsync((key, executor) -> getAccount(key)); }