diff --git a/src/main/java/net/coreprotect/thread/CacheHandler.java b/src/main/java/net/coreprotect/thread/CacheHandler.java index 872aa89b7..c5e6611b0 100755 --- a/src/main/java/net/coreprotect/thread/CacheHandler.java +++ b/src/main/java/net/coreprotect/thread/CacheHandler.java @@ -1,7 +1,5 @@ package net.coreprotect.thread; -import java.util.Collections; -import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.Map.Entry; @@ -15,18 +13,18 @@ public class CacheHandler implements Runnable { - public static Map lookupCache = Collections.synchronizedMap(new HashMap<>()); - public static Map breakCache = Collections.synchronizedMap(new HashMap<>()); - 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 containerDuplicateCache = new ConcurrentHashMap<>(16, 0.75f, 2); - public static ConcurrentHashMap flowDuplicateCache = new ConcurrentHashMap<>(16, 0.75f, 2); - public static ConcurrentHashMap bonemealDuplicateCache = new ConcurrentHashMap<>(16, 0.75f, 2); - public static ConcurrentHashMap entityKillDuplicateCache = new ConcurrentHashMap<>(16, 0.75f, 2); - public static ConcurrentHashMap redstoneCache = new ConcurrentHashMap<>(16, 0.75f, 2); - public static ConcurrentHashMap fallingBlockSpawnCache = new ConcurrentHashMap<>(16, 0.75f, 2); + public static Map lookupCache = new ConcurrentHashMap<>(); + public static Map breakCache = new ConcurrentHashMap<>(); + public static Map interactCache = new ConcurrentHashMap<>(); + public static Map entityCache = new ConcurrentHashMap<>(); + public static ConcurrentHashMap pistonCache = new ConcurrentHashMap<>(); + public static ConcurrentHashMap spreadCache = new ConcurrentHashMap<>(); + public static ConcurrentHashMap containerDuplicateCache = new ConcurrentHashMap<>(); + public static ConcurrentHashMap flowDuplicateCache = new ConcurrentHashMap<>(); + public static ConcurrentHashMap bonemealDuplicateCache = new ConcurrentHashMap<>(); + public static ConcurrentHashMap entityKillDuplicateCache = new ConcurrentHashMap<>(); + public static ConcurrentHashMap redstoneCache = new ConcurrentHashMap<>(); + public static ConcurrentHashMap fallingBlockSpawnCache = new ConcurrentHashMap<>(); private static volatile Thread thread; @@ -156,25 +154,15 @@ public void run() { } int timestamp = (int) (System.currentTimeMillis() / 1000L) - scanTime; - Iterator iterator = cache.entrySet().iterator(); - while (iterator.hasNext()) { + cache.values().removeIf(value -> { try { - Map.Entry entry = iterator.next(); - Object[] data = (Object[]) entry.getValue(); + Object[] data = (Object[]) value; int time = (data[0] instanceof Long) ? (int) ((long) data[0] / 1000L) : (int) data[0]; - - if (time < timestamp) { - try { - iterator.remove(); - } - catch (Exception e) { - } - } - } - catch (Exception e) { - break; + return time < timestamp; + } catch (Exception e) { + return true; // malformed entry } - } + }); } } catch (InterruptedException e) {