From a19fa1b92c48b524a8c316fe4e145926a5f23a44 Mon Sep 17 00:00:00 2001 From: Hannes Greule Date: Tue, 5 May 2020 10:52:28 +0200 Subject: [PATCH] Send a debug message if category not found --- .../plot/flag/types/BlockTypeWrapper.java | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/Core/src/main/java/com/plotsquared/core/plot/flag/types/BlockTypeWrapper.java b/Core/src/main/java/com/plotsquared/core/plot/flag/types/BlockTypeWrapper.java index 964e990b7..537515f0a 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/flag/types/BlockTypeWrapper.java +++ b/Core/src/main/java/com/plotsquared/core/plot/flag/types/BlockTypeWrapper.java @@ -26,7 +26,9 @@ package com.plotsquared.core.plot.flag.types; import com.google.common.base.Preconditions; +import com.plotsquared.core.PlotSquared; import com.sk89q.worldedit.world.block.BlockCategory; +import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockType; import lombok.EqualsAndHashCode; import lombok.Getter; @@ -97,7 +99,11 @@ public class BlockTypeWrapper { public BlockCategory getBlockCategory() { if (this.blockCategory == null && this.blockCategoryId != null) { // only if name is available - this.blockCategory = Preconditions.checkNotNull(BlockCategory.REGISTRY.get(this.blockCategoryId)); + this.blockCategory = BlockCategory.REGISTRY.get(this.blockCategoryId); + if (this.blockCategory == null) { + PlotSquared.debug("- Block category #" + this.blockCategoryId + " does not exist"); + this.blockCategory = new NullBlockCategory(this.blockCategoryId); + } } return this.blockCategory; } @@ -117,4 +123,19 @@ public class BlockTypeWrapper { return blockCategories.computeIfAbsent(blockCategoryId, BlockTypeWrapper::new); } + /** + * Prevents exceptions when loading/saving block categories + */ + private static class NullBlockCategory extends BlockCategory { + + public NullBlockCategory(String id) { + super(id); + } + + @Override + public > boolean contains(B blockStateHolder) { + return false; + } + } + }