Skip to content
This repository has been archived by the owner on Feb 24, 2024. It is now read-only.

use a ConcurrentHashMap for BiomeManager #39

Merged
merged 1 commit into from
Aug 5, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions src/main/java/net/minestom/server/world/biomes/BiomeManager.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -10,6 +8,7 @@
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;


/**
Expand All @@ -18,7 +17,7 @@
* Contains {@link Biome#PLAINS} by default but can be removed.
*/
public final class BiomeManager {
private final Int2ObjectMap<Biome> biomes = new Int2ObjectOpenHashMap<>();
private final Map<Integer, Biome> biomes = new ConcurrentHashMap<>();

public BiomeManager() {
addBiome(Biome.PLAINS);
Expand All @@ -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);
}

Expand All @@ -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());
}

Expand All @@ -47,7 +46,7 @@ public synchronized void removeBiome(Biome biome) {
*
* @return an immutable copy of the biomes already registered
*/
public synchronized Collection<Biome> unmodifiableCollection() {
public Collection<Biome> unmodifiableCollection() {
return Collections.unmodifiableCollection(biomes.values());
}

Expand All @@ -57,11 +56,11 @@ public synchronized Collection<Biome> 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)) {
Expand All @@ -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())));
Expand Down
Loading