From 6c76baa9404681565381861f45cece2c8379483f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A8=D0=B0=D0=BD=D0=B4=D1=83=D1=80=D0=B5=D0=BD=D0=BA?= =?UTF-8?q?=D0=BE=20=D0=9A=D0=BE=D0=BD=D1=81=D1=82=D0=B0=D0=BD=D1=82=D0=B8?= =?UTF-8?q?=D0=BD=20=D0=92=D0=BB=D0=B0=D0=B4=D0=B8=D0=BC=D0=B8=D1=80=D0=BE?= =?UTF-8?q?=D0=B2=D0=B8=D1=87?= Date: Fri, 10 Sep 2021 19:08:39 +0300 Subject: [PATCH] Code review --- .../server/instance/block/BlockHandler.java | 11 +++++++++-- .../instance/block/BlockHandlerBase.java | 18 ------------------ .../server/instance/block/BlockManager.java | 5 +++++ 3 files changed, 14 insertions(+), 20 deletions(-) delete mode 100644 src/main/java/net/minestom/server/instance/block/BlockHandlerBase.java 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;