From 9b4d341ebbde565e6bf8af1309df47af8743fe73 Mon Sep 17 00:00:00 2001 From: Octavia Togami Date: Fri, 1 Nov 2024 01:11:23 -0700 Subject: [PATCH] [Bukkit] Stop using EnumMap for potential registry types Biome broke in 1.21.3, Material could break in the future --- .../com/sk89q/worldedit/bukkit/BukkitAdapter.java | 14 +++----------- .../worldedit/bukkit/BukkitBlockRegistry.java | 4 ++-- 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitAdapter.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitAdapter.java index 4e53ff7606..dbc7de708d 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitAdapter.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitAdapter.java @@ -60,8 +60,6 @@ import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; -import java.util.Collections; -import java.util.EnumMap; import java.util.Locale; import java.util.Map; import java.util.Objects; @@ -362,9 +360,7 @@ public static GameMode adapt(org.bukkit.GameMode gameMode) { return GameModes.get(gameMode.name().toLowerCase(Locale.ROOT)); } - private static final Map biomeBiomeTypeCache = Collections.synchronizedMap( - new EnumMap<>(Biome.class) - ); + private static final Map biomeBiomeTypeCache = new ConcurrentHashMap<>(); private static final Map biomeTypeBiomeCache = new ConcurrentHashMap<>(); /** @@ -408,12 +404,8 @@ public static org.bukkit.entity.EntityType adapt(EntityType entityType) { return Registry.ENTITY_TYPE.get(entityKey); } - private static final Map materialBlockTypeCache = Collections.synchronizedMap( - new EnumMap<>(Material.class) - ); - private static final Map materialItemTypeCache = Collections.synchronizedMap( - new EnumMap<>(Material.class) - ); + private static final Map materialBlockTypeCache = new ConcurrentHashMap<>(); + private static final Map materialItemTypeCache = new ConcurrentHashMap<>(); /** * Converts a Material to a BlockType. diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitBlockRegistry.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitBlockRegistry.java index 4407ca3d69..b6b7cece12 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitBlockRegistry.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitBlockRegistry.java @@ -28,13 +28,13 @@ import com.sk89q.worldedit.world.registry.PassthroughBlockMaterial; import org.bukkit.Material; -import java.util.EnumMap; +import java.util.HashMap; import java.util.Map; import java.util.OptionalInt; import javax.annotation.Nullable; public class BukkitBlockRegistry extends BundledBlockRegistry { - private final Map materialMap = new EnumMap<>(Material.class); + private final Map materialMap = new HashMap<>(); @Override public Component getRichName(BlockType blockType) {