diff --git a/src/main/java/me/ryanhamshire/GriefPrevention/AutoExtendClaimTask.java b/src/main/java/me/ryanhamshire/GriefPrevention/AutoExtendClaimTask.java index 3427dcd..8370048 100644 --- a/src/main/java/me/ryanhamshire/GriefPrevention/AutoExtendClaimTask.java +++ b/src/main/java/me/ryanhamshire/GriefPrevention/AutoExtendClaimTask.java @@ -7,6 +7,8 @@ import org.bukkit.World.Environment; import org.bukkit.block.Biome; import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; import java.util.Set; //automatically extends a claim downward based on block types detected @@ -15,6 +17,7 @@ class AutoExtendClaimTask implements Runnable private final Claim claim; private final ArrayList chunks; private final Environment worldType; + private final Map> biomeMaterials = new HashMap<>(); public AutoExtendClaimTask(Claim claim, ArrayList chunks, Environment worldType) { @@ -39,73 +42,42 @@ class AutoExtendClaimTask implements Runnable if (this.yTooSmall(y)) return y; - try + for (ChunkSnapshot chunk : this.chunks) { - for (ChunkSnapshot chunk : this.chunks) + boolean ychanged = true; + while (!this.yTooSmall(y) && ychanged) { - Biome biome = chunk.getBiome(0, 0); - Set playerBlockIDs = RestoreNatureProcessingTask.getPlayerBlocks(this.worldType, biome); - - boolean ychanged = true; - while (!this.yTooSmall(y) && ychanged) + ychanged = false; + for (int x = 0; x < 16; x++) { - ychanged = false; - for (int x = 0; x < 16; x++) + for (int z = 0; z < 16; z++) { - for (int z = 0; z < 16; z++) + Material blockType = chunk.getBlockType(x, y, z); + Biome biome = chunk.getBiome(x, y, z); + while (!this.yTooSmall(y) && this.getBiomeBlocks(biome).contains(blockType)) { - Material blockType = chunk.getBlockType(x, y, z); - while (!this.yTooSmall(y) && playerBlockIDs.contains(blockType)) - { - ychanged = true; - blockType = chunk.getBlockType(x, --y, z); - } - - if (this.yTooSmall(y)) return y; + ychanged = true; + blockType = chunk.getBlockType(x, --y, z); + biome = chunk.getBiome(x, y, z); } + + if (this.yTooSmall(y)) return y; } } - - if (this.yTooSmall(y)) return y; - } - } - catch (NoSuchMethodError e) - { - GriefPrevention.instance.getLogger().severe("You are running an outdated build of Craftbukkit/Spigot/Paper. Please update."); - for (ChunkSnapshot chunk : this.chunks) - { - Biome biome = chunk.getBiome(0, 0); - Set playerBlockIDs = RestoreNatureProcessingTask.getPlayerBlocks(this.worldType, biome); - - boolean ychanged = true; - while (!this.yTooSmall(y) && ychanged) - { - ychanged = false; - for (int x = 0; x < 16; x++) - { - for (int z = 0; z < 16; z++) - { - Material blockType = chunk.getBlockType(x, y, z); - while (!this.yTooSmall(y) && playerBlockIDs.contains(blockType)) - { - ychanged = true; - blockType = chunk.getBlockType(x, --y, z); - } - - if (this.yTooSmall(y)) return y; - } - } - } - - if (this.yTooSmall(y)) return y; } + if (this.yTooSmall(y)) return y; } return y; } + private Set getBiomeBlocks(Biome biome) + { + return biomeMaterials.computeIfAbsent(biome, newBiome -> RestoreNatureProcessingTask.getPlayerBlocks(this.worldType, newBiome)); + } + private boolean yTooSmall(int y) { return y == 0 || y <= GriefPrevention.instance.config_claims_maxDepth;