BlockHandlerBase

This commit is contained in:
Шандуренко Константин Владимирович 2021-09-10 16:50:38 +03:00
parent e3600525fa
commit 98fc704139
2 changed files with 23 additions and 12 deletions

View File

@ -295,23 +295,16 @@ public interface BlockHandler {
* Handler used for loaded blocks with unknown namespace
* in order to do not lose the information while saving, and for runtime debugging purpose.
*/
class Dummy implements BlockHandler {
@ApiStatus.Internal
final class Dummy extends BlockHandlerBase {
private static final Map<String, BlockHandler> DUMMY_CACHE = new ConcurrentHashMap<>();
@ApiStatus.Internal
public static @NotNull BlockHandler get(@NotNull String namespace) {
return DUMMY_CACHE.computeIfAbsent(namespace, s -> new Dummy(NamespaceID.from(namespace)));
return DUMMY_CACHE.computeIfAbsent(namespace, Dummy::new);
}
private final NamespaceID namespaceID;
private Dummy(NamespaceID namespaceID) {
this.namespaceID = namespaceID;
}
@Override
public @NotNull NamespaceID getNamespaceId() {
return namespaceID;
private Dummy(String name) {
super(name);
}
}
}

View File

@ -0,0 +1,18 @@
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;
}
}