mirror of
https://github.com/Minestom/Minestom.git
synced 2025-03-10 05:39:11 +01:00
Do not spam dummy handler warning (only once per namespace)
Signed-off-by: TheMode <themode@outlook.fr>
This commit is contained in:
parent
e53c0a68fb
commit
8410de18d2
@ -12,18 +12,19 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class BlockManager {
|
||||
public final class BlockManager {
|
||||
private final static Logger LOGGER = LoggerFactory.getLogger(BlockManager.class);
|
||||
|
||||
// Namespace -> handler supplier
|
||||
private final Map<String, Supplier<BlockHandler>> blockHandlerMap = new ConcurrentHashMap<>();
|
||||
|
||||
// block id -> block placement rule
|
||||
private final Int2ObjectMap<BlockPlacementRule> placementRuleMap = new Int2ObjectOpenHashMap<>();
|
||||
|
||||
private final Set<String> dummyWarning = ConcurrentHashMap.newKeySet(); // Prevent warning spam
|
||||
|
||||
public void registerHandler(@NotNull String namespace, @NotNull Supplier<@NotNull BlockHandler> handlerSupplier) {
|
||||
blockHandlerMap.put(namespace, handlerSupplier);
|
||||
}
|
||||
@ -41,7 +42,11 @@ public class BlockManager {
|
||||
public @NotNull BlockHandler getHandlerOrDummy(@NotNull String namespace) {
|
||||
BlockHandler handler = getHandler(namespace);
|
||||
if (handler == null) {
|
||||
LOGGER.warn("Block {} does not have any corresponding handler, default to dummy.", namespace);
|
||||
if (dummyWarning.add(namespace)) {
|
||||
LOGGER.warn("""
|
||||
Block {} does not have any corresponding handler, default to dummy.
|
||||
You may want to register a handler for this namespace to prevent any data loss.""", namespace);
|
||||
}
|
||||
handler = BlockHandler.Dummy.get(namespace);
|
||||
}
|
||||
return handler;
|
||||
|
Loading…
Reference in New Issue
Block a user