Skip to content

Commit 7afd065

Browse files
committed
lazy waterloggable cache
1 parent 6efd533 commit 7afd065

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

shared/src/main/java/me/xginko/aef/utils/BlockUtil.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import de.tr7zw.changeme.nbtapi.NBT;
44
import de.tr7zw.changeme.nbtapi.iface.ReadableNBT;
5+
import me.xginko.aef.utils.models.Lazy;
56
import org.bukkit.Material;
67
import org.bukkit.block.BlockState;
78
import org.bukkit.block.data.Waterlogged;
@@ -23,10 +24,10 @@ public static boolean isWaterloggedAvailable() {
2324
return WATERLOGGED_AVAILABLE;
2425
}
2526

26-
private static final Map<Material, Boolean> IS_WATERLOGGABLE_CACHE = new EnumMap<>(Material.class);
27+
private static final Lazy<Map<Material, Boolean>> IS_WATERLOGGABLE_CACHE = Lazy.of(() -> new EnumMap<>(Material.class));
2728
public static boolean isWaterlogged(@Nullable BlockState blockState) {
2829
return blockState != null
29-
&& IS_WATERLOGGABLE_CACHE.computeIfAbsent(blockState.getType(), k -> blockState.getBlockData() instanceof Waterlogged)
30+
&& IS_WATERLOGGABLE_CACHE.get().computeIfAbsent(blockState.getType(), k -> blockState.getBlockData() instanceof Waterlogged)
3031
&& ((Waterlogged) blockState.getBlockData()).isWaterlogged();
3132
}
3233

0 commit comments

Comments
 (0)