From 32688c55cfbd5bdf49c59247586008ee0528fd6d Mon Sep 17 00:00:00 2001 From: Intelli Date: Fri, 19 Apr 2024 19:17:35 -0600 Subject: [PATCH] Fixed block spread cache not always being properly utilized --- .../listener/block/BlockSpreadListener.java | 15 ++++++++------- .../java/net/coreprotect/thread/CacheHandler.java | 4 ++-- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/main/java/net/coreprotect/listener/block/BlockSpreadListener.java b/src/main/java/net/coreprotect/listener/block/BlockSpreadListener.java index 0bbea3e..5769efc 100644 --- a/src/main/java/net/coreprotect/listener/block/BlockSpreadListener.java +++ b/src/main/java/net/coreprotect/listener/block/BlockSpreadListener.java @@ -14,6 +14,7 @@ import net.coreprotect.config.Config; import net.coreprotect.consumer.Queue; import net.coreprotect.model.BlockGroup; import net.coreprotect.thread.CacheHandler; +import net.coreprotect.utility.Util; public final class BlockSpreadListener extends Queue implements Listener { @@ -81,14 +82,14 @@ public final class BlockSpreadListener extends Queue implements Listener { } private boolean checkCacheData(Block block, Material type) { - Location location = block.getLocation(); - int timestamp = (int) (System.currentTimeMillis() / 1000L); - Object[] cacheData = CacheHandler.spreadCache.get(location); - CacheHandler.spreadCache.put(location, new Object[] { timestamp, type }); - if (cacheData != null && ((Material) cacheData[1]) == type) { - return true; + int log = 0; + String cacheId = block.getX() + "." + block.getY() + "." + block.getZ() + "." + Util.getWorldId(block.getWorld().getName()) + "." + type.name(); + if (CacheHandler.spreadCache.get(cacheId) == null) { + log = 1; } + int timestamp = (int) (System.currentTimeMillis() / 1000L); + CacheHandler.spreadCache.put(cacheId, new Object[] { timestamp }); - return false; + return (log == 0); } } diff --git a/src/main/java/net/coreprotect/thread/CacheHandler.java b/src/main/java/net/coreprotect/thread/CacheHandler.java index 32b5055..45dbe0b 100755 --- a/src/main/java/net/coreprotect/thread/CacheHandler.java +++ b/src/main/java/net/coreprotect/thread/CacheHandler.java @@ -18,7 +18,7 @@ public class CacheHandler implements Runnable { public static Map interactCache = Collections.synchronizedMap(new HashMap<>()); public static Map entityCache = Collections.synchronizedMap(new HashMap<>()); public static ConcurrentHashMap pistonCache = new ConcurrentHashMap<>(16, 0.75f, 2); - public static ConcurrentHashMap spreadCache = new ConcurrentHashMap<>(16, 0.75f, 2); + public static ConcurrentHashMap spreadCache = new ConcurrentHashMap<>(16, 0.75f, 2); public static ConcurrentHashMap redstoneCache = new ConcurrentHashMap<>(16, 0.75f, 2); @SuppressWarnings({ "unchecked", "rawtypes" }) @@ -41,7 +41,7 @@ public class CacheHandler implements Runnable { break; case 3: cache = CacheHandler.spreadCache; - scanTime = 900; // 15 minutes + scanTime = 1800; // 30 minutes break; case 4: cache = CacheHandler.interactCache;