diff --git a/src/main/java/net/minestom/server/instance/block/BlockHandler.java b/src/main/java/net/minestom/server/instance/block/BlockHandler.java index 50d1510a5..dd40ae834 100644 --- a/src/main/java/net/minestom/server/instance/block/BlockHandler.java +++ b/src/main/java/net/minestom/server/instance/block/BlockHandler.java @@ -296,15 +296,22 @@ public interface BlockHandler { * in order to do not lose the information while saving, and for runtime debugging purpose. */ @ApiStatus.Internal - final class Dummy extends BlockHandlerBase { + final class Dummy implements BlockHandler { private static final Map DUMMY_CACHE = new ConcurrentHashMap<>(); public static @NotNull BlockHandler get(@NotNull String namespace) { return DUMMY_CACHE.computeIfAbsent(namespace, Dummy::new); } + private final NamespaceID namespace; + private Dummy(String name) { - super(name); + namespace = NamespaceID.from(name); + } + + @Override + public @NotNull NamespaceID getNamespaceId() { + return namespace; } } } diff --git a/src/main/java/net/minestom/server/instance/block/BlockHandlerBase.java b/src/main/java/net/minestom/server/instance/block/BlockHandlerBase.java deleted file mode 100644 index 3d7f2aaf2..000000000 --- a/src/main/java/net/minestom/server/instance/block/BlockHandlerBase.java +++ /dev/null @@ -1,18 +0,0 @@ -package net.minestom.server.instance.block; - -import net.minestom.server.utils.NamespaceID; -import org.jetbrains.annotations.NotNull; - -public class BlockHandlerBase implements BlockHandler { - - private final NamespaceID namespace; - - public BlockHandlerBase(String name) { - namespace = NamespaceID.from(name); - } - - @Override - public @NotNull NamespaceID getNamespaceId() { - return namespace; - } -} diff --git a/src/main/java/net/minestom/server/instance/block/BlockManager.java b/src/main/java/net/minestom/server/instance/block/BlockManager.java index 118bee34a..ed7c29799 100644 --- a/src/main/java/net/minestom/server/instance/block/BlockManager.java +++ b/src/main/java/net/minestom/server/instance/block/BlockManager.java @@ -3,6 +3,7 @@ package net.minestom.server.instance.block; import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; import net.minestom.server.instance.block.rule.BlockPlacementRule; +import net.minestom.server.utils.NamespaceID; import net.minestom.server.utils.validate.Check; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; @@ -27,6 +28,10 @@ public class BlockManager { blockHandlerMap.put(namespace, handlerSupplier); } + public void registerHandler(@NotNull NamespaceID namespace, @NotNull Supplier<@NotNull BlockHandler> handlerSupplier) { + registerHandler(namespace.toString(), handlerSupplier); + } + public @Nullable BlockHandler getHandler(@NotNull String namespace) { final var handler = blockHandlerMap.get(namespace); return handler != null ? handler.get() : null;