From 10e7318d2bcbc0e9a4ec3109dbaeda406c8f8b8b Mon Sep 17 00:00:00 2001 From: Auxilor Date: Sun, 19 Nov 2023 16:12:17 +0000 Subject: [PATCH] Improved Condition syncMetCache --- .../libreforge/conditions/ConditionBlock.kt | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/core/src/main/kotlin/com/willfp/libreforge/conditions/ConditionBlock.kt b/core/src/main/kotlin/com/willfp/libreforge/conditions/ConditionBlock.kt index f4390e9d5..79ce15cc7 100644 --- a/core/src/main/kotlin/com/willfp/libreforge/conditions/ConditionBlock.kt +++ b/core/src/main/kotlin/com/willfp/libreforge/conditions/ConditionBlock.kt @@ -46,16 +46,18 @@ class ConditionBlock internal constructor( if (!Bukkit.isPrimaryThread()) { /* - - Assume true if not on main thread, because most calls when not on the main thread - will be from packet processing threads, for things like not-met-lines, which - should default to conditions being met to avoid players being shown incorrect - information. - - UPDATE: The default state is now configurable in the config. - + If the value isn't cached, then submit a task to cache it to avoid desync. */ + if (!syncMetCache.asMap().containsKey(player.uniqueId)) { + plugin.scheduler.run { + // Double check that it isn't cached by the time we run + if (!syncMetCache.asMap().containsKey(player.uniqueId)) { + syncMetCache.put(player.uniqueId, isMet(player, holder)) + } + } + } + return syncMetCache.getIfPresent(player.uniqueId) ?: plugin.configYml.getBool("conditions.default-state-off-main-thread") }