Skip to content

Commit

Permalink
Fixed block spread cache not always being properly utilized
Browse files Browse the repository at this point in the history
  • Loading branch information
Intelli committed Apr 20, 2024
1 parent a239b51 commit 32688c5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
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 {

Expand Down Expand Up @@ -81,14 +82,14 @@ else if (Config.getConfig(event.getBlock().getWorld()).SCULK_SPREAD && BlockGrou
}

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);
}
}
4 changes: 2 additions & 2 deletions src/main/java/net/coreprotect/thread/CacheHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class CacheHandler implements Runnable {
public static Map<String, Object[]> interactCache = Collections.synchronizedMap(new HashMap<>());
public static Map<String, Object[]> entityCache = Collections.synchronizedMap(new HashMap<>());
public static ConcurrentHashMap<String, Object[]> pistonCache = new ConcurrentHashMap<>(16, 0.75f, 2);
public static ConcurrentHashMap<Location, Object[]> spreadCache = new ConcurrentHashMap<>(16, 0.75f, 2);
public static ConcurrentHashMap<String, Object[]> spreadCache = new ConcurrentHashMap<>(16, 0.75f, 2);
public static ConcurrentHashMap<Location, Object[]> redstoneCache = new ConcurrentHashMap<>(16, 0.75f, 2);

@SuppressWarnings({ "unchecked", "rawtypes" })
Expand All @@ -41,7 +41,7 @@ public void run() {
break;
case 3:
cache = CacheHandler.spreadCache;
scanTime = 900; // 15 minutes
scanTime = 1800; // 30 minutes
break;
case 4:
cache = CacheHandler.interactCache;
Expand Down

0 comments on commit 32688c5

Please sign in to comment.