mirror of
https://github.com/Minestom/Minestom.git
synced 2024-12-30 21:17:53 +01:00
Code review
This commit is contained in:
parent
1e5dc8d870
commit
6c76baa940
@ -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<String, BlockHandler> 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user