Improve feedback for invalid patterns (#3818)

improve feedback for invalid patterns
This commit is contained in:
Hannes Greule 2022-10-02 22:22:08 +02:00 committed by GitHub
parent d1a85982fb
commit 35abae99ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -28,13 +28,17 @@ import com.plotsquared.core.inject.annotations.WorldConfig;
import com.plotsquared.core.plot.BlockBucket;
import com.plotsquared.core.plot.PlotId;
import com.plotsquared.core.queue.GlobalBlockQueue;
import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.world.block.BlockTypes;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.checkerframework.checker.nullness.qual.NonNull;
import javax.annotation.Nullable;
@SuppressWarnings("WeakerAccess")
public abstract class ClassicPlotWorld extends SquarePlotWorld {
private static final Logger LOGGER = LogManager.getLogger("PlotSquared/" + ClassicPlotWorld.class.getSimpleName());
public int ROAD_HEIGHT = 62;
public int PLOT_HEIGHT = 62;
@ -121,15 +125,15 @@ public abstract class ClassicPlotWorld extends SquarePlotWorld {
super.loadConfiguration(config);
this.PLOT_BEDROCK = config.getBoolean("plot.bedrock");
this.PLOT_HEIGHT = Math.min(getMaxGenHeight(), config.getInt("plot.height"));
this.MAIN_BLOCK = new BlockBucket(config.getString("plot.filling"));
this.TOP_BLOCK = new BlockBucket(config.getString("plot.floor"));
this.WALL_BLOCK = new BlockBucket(config.getString("wall.block"));
this.MAIN_BLOCK = createCheckedBlockBucket(config.getString("plot.filling"), MAIN_BLOCK);
this.TOP_BLOCK = createCheckedBlockBucket(config.getString("plot.floor"), TOP_BLOCK);
this.WALL_BLOCK = createCheckedBlockBucket(config.getString("wall.block"), WALL_BLOCK);
this.ROAD_HEIGHT = Math.min(getMaxGenHeight(), config.getInt("road.height"));
this.ROAD_BLOCK = new BlockBucket(config.getString("road.block"));
this.WALL_FILLING = new BlockBucket(config.getString("wall.filling"));
this.ROAD_BLOCK = createCheckedBlockBucket(config.getString("road.block"), ROAD_BLOCK);
this.WALL_FILLING = createCheckedBlockBucket(config.getString("wall.filling"), WALL_FILLING);
this.PLACE_TOP_BLOCK = config.getBoolean("wall.place_top_block");
this.WALL_HEIGHT = Math.min(getMaxGenHeight() - (PLACE_TOP_BLOCK ? 1 : 0), config.getInt("wall.height"));
this.CLAIMED_WALL_BLOCK = new BlockBucket(config.getString("wall.block_claimed"));
this.CLAIMED_WALL_BLOCK = createCheckedBlockBucket(config.getString("wall.block_claimed"), CLAIMED_WALL_BLOCK);
}
int schematicStartHeight() {
@ -140,4 +144,19 @@ public abstract class ClassicPlotWorld extends SquarePlotWorld {
return Math.min(WALL_HEIGHT, plotRoadMin);
}
private static BlockBucket createCheckedBlockBucket(String input, BlockBucket def) {
final BlockBucket bucket = new BlockBucket(input);
Pattern pattern = null;
try {
pattern = bucket.toPattern();
} catch (Exception ignore) {
}
if (pattern == null) {
LOGGER.error("Failed to parse pattern '{}', check your worlds.yml", input);
LOGGER.error("Falling back to {}", def);
return def;
}
return bucket;
}
}