From e724bbb52d00094460cb511906ddfb0a2c3f4d10 Mon Sep 17 00:00:00 2001 From: A5H73Y Date: Sun, 24 Dec 2023 12:53:53 +0000 Subject: [PATCH] Fixed issue with Placeholders displaying blank values Hopefully fixed permission exception Bump dependency versions --- pom.xml | 14 +++++++------- .../github/a5h73y/parkour/ParkourPlaceholders.java | 6 +----- .../type/player/session/ParkourSessionConfig.java | 3 ++- .../a5h73y/parkour/utility/cache/GenericCache.java | 7 ++++++- 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/pom.xml b/pom.xml index 5c966b32..b52a5cf2 100644 --- a/pom.xml +++ b/pom.xml @@ -91,7 +91,7 @@ me.clip placeholderapi - 2.11.3 + 2.11.5 provided @@ -138,7 +138,7 @@ com.github.cryptomorin XSeries - 9.5.0 + 9.8.0 compile @@ -152,7 +152,7 @@ com.github.simplix-softworks simplixstorage - 3.2.6 + 3.2.7 @@ -187,7 +187,7 @@ org.apache.maven.plugins maven-compiler-plugin - 3.11.0 + 3.12.0 ${java.version} ${java.version} @@ -206,7 +206,7 @@ org.apache.maven.plugins maven-shade-plugin - 3.5.0 + 3.5.1 false true @@ -280,7 +280,7 @@ org.apache.maven.plugins maven-checkstyle-plugin - 3.3.0 + 3.3.1 src/main/resources/parkourCheckstyles.xml true @@ -291,7 +291,7 @@ com.puppycrawl.tools checkstyle - 10.9.1 + 10.12.6 diff --git a/src/main/java/io/github/a5h73y/parkour/ParkourPlaceholders.java b/src/main/java/io/github/a5h73y/parkour/ParkourPlaceholders.java index 28f29486..15b130ba 100644 --- a/src/main/java/io/github/a5h73y/parkour/ParkourPlaceholders.java +++ b/src/main/java/io/github/a5h73y/parkour/ParkourPlaceholders.java @@ -568,11 +568,7 @@ private String getCheckpointHologramMessage(ParkourSession session, String cours private String getOrRetrieveCache(Supplier callback, String... keys) { String key = generateCacheKey(keys); // check if the key exists or its 'get' is about to expire. - if (!cache.containsKey(key) || cache.get(key).isEmpty()) { - cache.put(key, callback.get()); - } - - return cache.get(key).orElse(NO_TIME_RECORDED); + return cache.computeIfAbsent(key, k -> cache.createCacheValue(callback.get())); } private String getTimeValue(long milliseconds) { diff --git a/src/main/java/io/github/a5h73y/parkour/type/player/session/ParkourSessionConfig.java b/src/main/java/io/github/a5h73y/parkour/type/player/session/ParkourSessionConfig.java index 915d448c..dd2ec0b3 100644 --- a/src/main/java/io/github/a5h73y/parkour/type/player/session/ParkourSessionConfig.java +++ b/src/main/java/io/github/a5h73y/parkour/type/player/session/ParkourSessionConfig.java @@ -37,7 +37,8 @@ public static File getPlayerParkourSessionFile(OfflinePlayer player, String cour } public static boolean hasParkourSessionConfig(OfflinePlayer player, String courseName) { - return getPlayerParkourSessionFile(player, courseName).exists(); + File file = getPlayerParkourSessionFile(player, courseName); + return file.exists() && file.canWrite(); } public static ParkourSessionConfig getConfig(OfflinePlayer player, String courseName) { diff --git a/src/main/java/io/github/a5h73y/parkour/utility/cache/GenericCache.java b/src/main/java/io/github/a5h73y/parkour/utility/cache/GenericCache.java index 09c1c643..9d5eddcb 100644 --- a/src/main/java/io/github/a5h73y/parkour/utility/cache/GenericCache.java +++ b/src/main/java/io/github/a5h73y/parkour/utility/cache/GenericCache.java @@ -6,6 +6,7 @@ import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; +import java.util.function.Function; import java.util.stream.Collectors; /** @@ -78,7 +79,11 @@ public void put(K key, V value) { this.cacheMap.put(key, this.createCacheValue(value)); } - protected CacheValue createCacheValue(V value) { + public V computeIfAbsent(K key, Function> boop) { + return this.cacheMap.computeIfAbsent(key, boop).getValue(); + } + + public CacheValue createCacheValue(V value) { LocalDateTime now = LocalDateTime.now(); return new CacheValue<>() { @Override