Send a debug message if category not found

This commit is contained in:
Hannes Greule 2020-05-05 10:52:28 +02:00 committed by dordsor21
parent 2c060db9c0
commit a19fa1b92c

View File

@ -26,7 +26,9 @@
package com.plotsquared.core.plot.flag.types; package com.plotsquared.core.plot.flag.types;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.plotsquared.core.PlotSquared;
import com.sk89q.worldedit.world.block.BlockCategory; import com.sk89q.worldedit.world.block.BlockCategory;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockType;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import lombok.Getter; import lombok.Getter;
@ -97,7 +99,11 @@ public class BlockTypeWrapper {
public BlockCategory getBlockCategory() { public BlockCategory getBlockCategory() {
if (this.blockCategory == null && this.blockCategoryId != null) { // only if name is available 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; return this.blockCategory;
} }
@ -117,4 +123,19 @@ public class BlockTypeWrapper {
return blockCategories.computeIfAbsent(blockCategoryId, BlockTypeWrapper::new); 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 <B extends BlockStateHolder<B>> boolean contains(B blockStateHolder) {
return false;
}
}
} }