Added entity kill operation cache.

This commit is contained in:
2025-05-25 00:13:13 +01:00
parent d0e1eb1a2f
commit 008960ba57
2 changed files with 17 additions and 0 deletions

View File

@ -131,6 +131,7 @@ public final class Config {
private static void onConfigReload() {
// Clear cache
OperationCache.clearBlockBreakCache();
OperationCache.clearEntityKillCache();
// Parse all block break global operations
blockBreakGlobalOperationItems = new ArrayList<>();

View File

@ -7,11 +7,16 @@ import java.util.List;
public class OperationCache {
private static HashMap<String, List<OperationItem>> blockBreakCache;
private static HashMap<String, List<OperationItem>> entityKillCache;
public static void clearBlockBreakCache() {
blockBreakCache = new HashMap<>();
}
public static void clearEntityKillCache() {
entityKillCache = new HashMap<>();
}
public static @Nullable List<OperationItem> getBlockBreakCacheEntry(String key) {
if (blockBreakCache.containsKey(key)) {
return new ArrayList<>(blockBreakCache.get(key));
@ -19,7 +24,18 @@ public class OperationCache {
return null;
}
public static @Nullable List<OperationItem> getEntityKillCacheEntry(String key) {
if (entityKillCache.containsKey(key)) {
return new ArrayList<>(entityKillCache.get(key));
}
return null;
}
public static void addBlockBreakCacheEntry(String key, List<OperationItem> value) {
blockBreakCache.putIfAbsent(key, new ArrayList<>(value));
}
public static void addEntityKillCacheEntry(String key, List<OperationItem> value) {
entityKillCache.putIfAbsent(key, new ArrayList<>(value));
}
}