mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-02 14:38:26 +01:00
Make DimensionTypeManager thread-safe
Signed-off-by: TheMode <themode@outlook.fr>
This commit is contained in:
parent
1c76fd152e
commit
4b7adae382
@ -8,8 +8,8 @@ import org.jglrxavpok.hephaistos.nbt.NBTList;
|
|||||||
import org.jglrxavpok.hephaistos.nbt.NBTTypes;
|
import org.jglrxavpok.hephaistos.nbt.NBTTypes;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.CopyOnWriteArrayList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allows servers to register custom dimensions. Also used during player login to send the list of all existing dimensions.
|
* Allows servers to register custom dimensions. Also used during player login to send the list of all existing dimensions.
|
||||||
@ -18,7 +18,7 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
public final class DimensionTypeManager {
|
public final class DimensionTypeManager {
|
||||||
|
|
||||||
private final List<DimensionType> dimensionTypes = new LinkedList<>();
|
private final List<DimensionType> dimensionTypes = new CopyOnWriteArrayList<>();
|
||||||
|
|
||||||
public DimensionTypeManager() {
|
public DimensionTypeManager() {
|
||||||
addDimension(DimensionType.OVERWORLD);
|
addDimension(DimensionType.OVERWORLD);
|
||||||
@ -65,10 +65,9 @@ public final class DimensionTypeManager {
|
|||||||
* Return to a @{@link DimensionType} only if present and registered
|
* Return to a @{@link DimensionType} only if present and registered
|
||||||
*
|
*
|
||||||
* @param namespaceID The Dimension Name
|
* @param namespaceID The Dimension Name
|
||||||
* @return an a DimensionType if it present and registered
|
* @return a DimensionType if it is present and registered
|
||||||
*/
|
*/
|
||||||
@Nullable
|
public @Nullable DimensionType getDimension(@NotNull NamespaceID namespaceID) {
|
||||||
public DimensionType getDimension(@NotNull NamespaceID namespaceID) {
|
|
||||||
return unmodifiableList().stream().filter(dimensionType -> dimensionType.getName().equals(namespaceID)).filter(DimensionType::isRegistered).findFirst().orElse(null);
|
return unmodifiableList().stream().filter(dimensionType -> dimensionType.getName().equals(namespaceID)).filter(DimensionType::isRegistered).findFirst().orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,8 +76,7 @@ public final class DimensionTypeManager {
|
|||||||
*
|
*
|
||||||
* @return an unmodifiable {@link List} containing all the added dimensions
|
* @return an unmodifiable {@link List} containing all the added dimensions
|
||||||
*/
|
*/
|
||||||
@NotNull
|
public @NotNull List<DimensionType> unmodifiableList() {
|
||||||
public List<DimensionType> unmodifiableList() {
|
|
||||||
return Collections.unmodifiableList(dimensionTypes);
|
return Collections.unmodifiableList(dimensionTypes);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,8 +87,7 @@ public final class DimensionTypeManager {
|
|||||||
*
|
*
|
||||||
* @return an nbt compound containing the registered dimensions
|
* @return an nbt compound containing the registered dimensions
|
||||||
*/
|
*/
|
||||||
@NotNull
|
public @NotNull NBTCompound toNBT() {
|
||||||
public NBTCompound toNBT() {
|
|
||||||
NBTCompound dimensions = new NBTCompound();
|
NBTCompound dimensions = new NBTCompound();
|
||||||
dimensions.setString("type", "minecraft:dimension_type");
|
dimensions.setString("type", "minecraft:dimension_type");
|
||||||
NBTList<NBTCompound> dimensionList = new NBTList<>(NBTTypes.TAG_Compound);
|
NBTList<NBTCompound> dimensionList = new NBTList<>(NBTTypes.TAG_Compound);
|
||||||
|
Loading…
Reference in New Issue
Block a user