diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/registry/NamespacedRegistry.java b/worldedit-core/src/main/java/com/sk89q/worldedit/registry/NamespacedRegistry.java index 5fca65799..74df3101f 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/registry/NamespacedRegistry.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/registry/NamespacedRegistry.java @@ -19,6 +19,8 @@ package com.sk89q.worldedit.registry; +import com.sk89q.worldedit.WorldEdit; + import com.fastasyncworldedit.core.registry.RegistryItem; import com.sk89q.worldedit.command.util.SuggestionHelper; @@ -47,8 +49,16 @@ public final class NamespacedRegistry extends Registry { this(name, MINECRAFT_NAMESPACE); } + public NamespacedRegistry(final String name, final boolean checkInitialized) { + this(name, MINECRAFT_NAMESPACE, checkInitialized); + } + public NamespacedRegistry(final String name, final String defaultNamespace) { - super(name); + this(name, defaultNamespace, false); + } + + public NamespacedRegistry(final String name, final String defaultNamespace, final boolean checkInitialized) { + super(name, checkInitialized); this.defaultNamespace = defaultNamespace; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/registry/Registry.java b/worldedit-core/src/main/java/com/sk89q/worldedit/registry/Registry.java index 2bb20010a..a75cb3a28 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/registry/Registry.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/registry/Registry.java @@ -19,6 +19,8 @@ package com.sk89q.worldedit.registry; +import com.sk89q.worldedit.WorldEdit; + import javax.annotation.Nullable; import java.util.Collection; import java.util.Collections; @@ -35,9 +37,15 @@ public class Registry implements Iterable { private final Map map = new HashMap<>(); private final String name; + private final boolean checkInitialized; public Registry(final String name) { + this(name, false); + } + + public Registry(final String name, final boolean checkInitialized) { this.name = name; + this.checkInitialized = checkInitialized; } public String getName() { @@ -53,6 +61,10 @@ public class Registry implements Iterable { @Nullable public V get(final String key) { checkState(key.equals(key.toLowerCase(Locale.ROOT)), "key must be lowercase: %s", key); + if (this.checkInitialized) { + checkState(WorldEdit.getInstance().getPlatformManager().isInitialized(), + "WorldEdit is not initialized yet."); + } return this.map.get(key); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/biome/BiomeType.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/biome/BiomeType.java index ab503e1fb..e8501da69 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/biome/BiomeType.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/biome/BiomeType.java @@ -32,7 +32,7 @@ import com.sk89q.worldedit.registry.NamespacedRegistry; public class BiomeType implements RegistryItem, Keyed, BiomePattern { //FAWE end - public static final NamespacedRegistry REGISTRY = new NamespacedRegistry<>("biome type"); + public static final NamespacedRegistry REGISTRY = new NamespacedRegistry<>("biome type", true); private final String id; private int legacyId = -1; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockCategory.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockCategory.java index 3ed6f7a3f..29d8ee53b 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockCategory.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockCategory.java @@ -36,7 +36,7 @@ public class BlockCategory extends Category implements Keyed { //FAWE start private boolean[] flatMap; //FAWE end - public static final NamespacedRegistry REGISTRY = new NamespacedRegistry<>("block tag"); + public static final NamespacedRegistry REGISTRY = new NamespacedRegistry<>("block tag", true); public BlockCategory(final String id) { super(id); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockType.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockType.java index 043a89bf5..bacd5fe72 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockType.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockType.java @@ -56,7 +56,7 @@ import static com.google.common.base.Preconditions.checkArgument; public class BlockType implements Keyed, Pattern { //FAWE end - public static final NamespacedRegistry REGISTRY = new NamespacedRegistry<>("block type"); + public static final NamespacedRegistry REGISTRY = new NamespacedRegistry<>("block type", true); private static final Logger LOGGER = LogManagerCompat.getLogger(); private final String id; @@ -328,8 +328,10 @@ public class BlockType implements Keyed, Pattern { /** * Gets the legacy ID. Needed for legacy reasons. + * *

* DO NOT USE THIS. + *

* * @return legacy id or 0, if unknown */ diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/entity/EntityType.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/entity/EntityType.java index 98a70b7e5..5a530c8a6 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/entity/EntityType.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/entity/EntityType.java @@ -27,7 +27,7 @@ import com.sk89q.worldedit.registry.NamespacedRegistry; public class EntityType implements RegistryItem, Keyed { //FAWE end - public static final NamespacedRegistry REGISTRY = new NamespacedRegistry<>("entity type"); + public static final NamespacedRegistry REGISTRY = new NamespacedRegistry<>("entity type", true); private final String id; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/item/ItemType.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/item/ItemType.java index 97549320d..ecba92f8b 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/item/ItemType.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/item/ItemType.java @@ -39,7 +39,7 @@ import javax.annotation.Nullable; public class ItemType implements RegistryItem, Keyed { //FAWE end - public static final NamespacedRegistry REGISTRY = new NamespacedRegistry<>("item type"); + public static final NamespacedRegistry REGISTRY = new NamespacedRegistry<>("item type", true); private final String id; @SuppressWarnings("deprecation") diff --git a/worldedit-core/src/test/java/com/sk89q/worldedit/internal/expression/BaseExpressionTest.java b/worldedit-core/src/test/java/com/sk89q/worldedit/internal/expression/BaseExpressionTest.java index 0fbf9556a..3491347a4 100644 --- a/worldedit-core/src/test/java/com/sk89q/worldedit/internal/expression/BaseExpressionTest.java +++ b/worldedit-core/src/test/java/com/sk89q/worldedit/internal/expression/BaseExpressionTest.java @@ -35,6 +35,7 @@ import java.util.stream.Collectors; import java.util.stream.Stream; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -63,6 +64,7 @@ class BaseExpressionTest { }); WorldEdit.getInstance().getPlatformManager().register(mockPlat); WorldEdit.getInstance().getEventBus().post(new PlatformsRegisteredEvent()); + assertTrue(WorldEdit.getInstance().getPlatformManager().isInitialized(), "Platform is not initialized"); WorldEdit.getInstance().getConfiguration().calculationTimeout = 1_000; } diff --git a/worldedit-core/src/test/java/com/sk89q/worldedit/util/collection/BlockMapTest.java b/worldedit-core/src/test/java/com/sk89q/worldedit/util/collection/BlockMapTest.java index 1bb09ee17..68ccae312 100644 --- a/worldedit-core/src/test/java/com/sk89q/worldedit/util/collection/BlockMapTest.java +++ b/worldedit-core/src/test/java/com/sk89q/worldedit/util/collection/BlockMapTest.java @@ -21,6 +21,7 @@ package com.sk89q.worldedit.util.collection; import com.google.common.collect.ImmutableMap; +import com.sk89q.worldedit.LocalConfiguration; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.event.platform.PlatformsRegisteredEvent; import com.sk89q.worldedit.extension.platform.Capability; @@ -87,10 +88,17 @@ class BlockMapTest { Stream.of(Capability.values()) .collect(Collectors.toMap(Function.identity(), __ -> Preference.NORMAL)) ); + when(MOCKED_PLATFORM.getConfiguration()).thenReturn(new LocalConfiguration() { + @Override + public void load() { + } + }); PlatformManager platformManager = WorldEdit.getInstance().getPlatformManager(); platformManager.register(MOCKED_PLATFORM); WorldEdit.getInstance().getEventBus().post(new PlatformsRegisteredEvent()); + assertTrue(WorldEdit.getInstance().getPlatformManager().isInitialized(), "Platform is not initialized"); + registerBlock("minecraft:air"); registerBlock("minecraft:oak_wood"); }