mirror of
https://github.com/EngineHub/WorldEdit.git
synced 2025-02-11 13:10:15 +08:00
Make the BukkitAdapter thread-safe
This commit is contained in:
parent
65fe8a69a6
commit
298b641a8b
@ -47,6 +47,7 @@
|
||||
import com.sk89q.worldedit.world.item.ItemType;
|
||||
import com.sk89q.worldedit.world.item.ItemTypes;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMaps;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
@ -57,11 +58,12 @@
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.EnumMap;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
@ -361,8 +363,10 @@ public static GameMode adapt(org.bukkit.GameMode gameMode) {
|
||||
return GameModes.get(gameMode.name().toLowerCase(Locale.ROOT));
|
||||
}
|
||||
|
||||
private static final EnumMap<Biome, BiomeType> biomeBiomeTypeCache = new EnumMap<>(Biome.class);
|
||||
private static final Map<BiomeType, Biome> biomeTypeBiomeCache = new HashMap<>();
|
||||
private static final Map<Biome, BiomeType> biomeBiomeTypeCache = Collections.synchronizedMap(
|
||||
new EnumMap<>(Biome.class)
|
||||
);
|
||||
private static final Map<BiomeType, Biome> biomeTypeBiomeCache = new ConcurrentHashMap<>();
|
||||
|
||||
/**
|
||||
* Create a WorldEdit BiomeType from a Bukkit one.
|
||||
@ -408,8 +412,12 @@ public static org.bukkit.entity.EntityType adapt(EntityType entityType) {
|
||||
return org.bukkit.entity.EntityType.fromName(entityType.getId().substring(10));
|
||||
}
|
||||
|
||||
private static final EnumMap<Material, BlockType> materialBlockTypeCache = new EnumMap<>(Material.class);
|
||||
private static final EnumMap<Material, ItemType> materialItemTypeCache = new EnumMap<>(Material.class);
|
||||
private static final Map<Material, BlockType> materialBlockTypeCache = Collections.synchronizedMap(
|
||||
new EnumMap<>(Material.class)
|
||||
);
|
||||
private static final Map<Material, ItemType> materialItemTypeCache = Collections.synchronizedMap(
|
||||
new EnumMap<>(Material.class)
|
||||
);
|
||||
|
||||
/**
|
||||
* Converts a Material to a BlockType.
|
||||
@ -435,8 +443,10 @@ public static ItemType asItemType(Material material) {
|
||||
return materialItemTypeCache.computeIfAbsent(material, input -> ItemTypes.get(material.getKey().toString()));
|
||||
}
|
||||
|
||||
private static final Int2ObjectMap<BlockState> blockStateCache = new Int2ObjectOpenHashMap<>();
|
||||
private static final Map<String, BlockState> blockStateStringCache = new HashMap<>();
|
||||
private static final Int2ObjectMap<BlockState> blockStateCache = Int2ObjectMaps.synchronize(
|
||||
new Int2ObjectOpenHashMap<>()
|
||||
);
|
||||
private static final Map<String, BlockState> blockStateStringCache = new ConcurrentHashMap<>();
|
||||
|
||||
/**
|
||||
* Create a WorldEdit BlockState from a Bukkit BlockData.
|
||||
@ -473,7 +483,7 @@ public static BlockState adapt(BlockData blockData) {
|
||||
}
|
||||
}
|
||||
|
||||
private static final Int2ObjectMap<BlockData> blockDataCache = new Int2ObjectOpenHashMap<>();
|
||||
private static final Int2ObjectMap<BlockData> blockDataCache = Int2ObjectMaps.synchronize(new Int2ObjectOpenHashMap<>());
|
||||
|
||||
/**
|
||||
* Create a Bukkit BlockData from a WorldEdit BlockStateHolder.
|
||||
|
@ -71,7 +71,7 @@ public void setInternalId(BlockState blockState, int internalId) {
|
||||
/**
|
||||
* The internal ID of the block state.
|
||||
*/
|
||||
private int internalId = BlockStateIdAccess.invalidId();
|
||||
private volatile int internalId = BlockStateIdAccess.invalidId();
|
||||
|
||||
BlockState(BlockType blockType) {
|
||||
this.blockType = blockType;
|
||||
|
Loading…
Reference in New Issue
Block a user