From 64e82dc1ce5d9c0bf9c4210d5d9a5f18a787f56e Mon Sep 17 00:00:00 2001 From: Matt Worzala <35708499+mworzala@users.noreply.github.com> Date: Sat, 5 Aug 2023 10:21:05 -0400 Subject: [PATCH] hollow-cube/biome-manager-concurrency (#39) Co-authored-by: tahmid-23 <60953955+tahmid-23@users.noreply.github.com> See https://github.com/Minestom/Minestom/pull/1917 (cherry picked from commit ef37e40cd8ae44d118be91af2e6a84aaa646555a) --- .../server/world/biomes/BiomeManager.java | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/main/java/net/minestom/server/world/biomes/BiomeManager.java b/src/main/java/net/minestom/server/world/biomes/BiomeManager.java index 61c63ecf123..3c7ffdbe624 100644 --- a/src/main/java/net/minestom/server/world/biomes/BiomeManager.java +++ b/src/main/java/net/minestom/server/world/biomes/BiomeManager.java @@ -1,7 +1,5 @@ package net.minestom.server.world.biomes; -import it.unimi.dsi.fastutil.ints.Int2ObjectMap; -import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; import net.minestom.server.utils.NamespaceID; import org.jglrxavpok.hephaistos.nbt.NBT; import org.jglrxavpok.hephaistos.nbt.NBTCompound; @@ -10,6 +8,7 @@ import java.util.Collection; import java.util.Collections; import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; /** @@ -18,7 +17,7 @@ * Contains {@link Biome#PLAINS} by default but can be removed. */ public final class BiomeManager { - private final Int2ObjectMap biomes = new Int2ObjectOpenHashMap<>(); + private final Map biomes = new ConcurrentHashMap<>(); public BiomeManager() { addBiome(Biome.PLAINS); @@ -29,7 +28,7 @@ public BiomeManager() { * * @param biome the biome to add */ - public synchronized void addBiome(Biome biome) { + public void addBiome(Biome biome) { this.biomes.put(biome.id(), biome); } @@ -38,7 +37,7 @@ public synchronized void addBiome(Biome biome) { * * @param biome the biome to remove */ - public synchronized void removeBiome(Biome biome) { + public void removeBiome(Biome biome) { this.biomes.remove(biome.id()); } @@ -47,7 +46,7 @@ public synchronized void removeBiome(Biome biome) { * * @return an immutable copy of the biomes already registered */ - public synchronized Collection unmodifiableCollection() { + public Collection unmodifiableCollection() { return Collections.unmodifiableCollection(biomes.values()); } @@ -57,11 +56,11 @@ public synchronized Collection unmodifiableCollection() { * @param id the id of the biome * @return the {@link Biome} linked to this id */ - public synchronized Biome getById(int id) { + public Biome getById(int id) { return biomes.get(id); } - public synchronized Biome getByName(NamespaceID namespaceID) { + public Biome getByName(NamespaceID namespaceID) { Biome biome = null; for (final Biome biomeT : biomes.values()) { if (biomeT.name().equals(namespaceID)) { @@ -72,7 +71,7 @@ public synchronized Biome getByName(NamespaceID namespaceID) { return biome; } - public synchronized NBTCompound toNBT() { + public NBTCompound toNBT() { return NBT.Compound(Map.of( "type", NBT.String("minecraft:worldgen/biome"), "value", NBT.List(NBTType.TAG_Compound, biomes.values().stream().map(Biome::toNbt).toList())));