diff --git a/src/main/java/world/bentobox/limits/commands/LimitsCalc.java b/src/main/java/world/bentobox/limits/commands/LimitsCalc.java index 2660067..056b414 100644 --- a/src/main/java/world/bentobox/limits/commands/LimitsCalc.java +++ b/src/main/java/world/bentobox/limits/commands/LimitsCalc.java @@ -13,6 +13,7 @@ import org.bukkit.Bukkit; import org.bukkit.ChunkSnapshot; import org.bukkit.Material; import org.bukkit.World; +import org.bukkit.block.data.BlockData; import world.bentobox.bentobox.BentoBox; import world.bentobox.bentobox.api.user.User; @@ -105,9 +106,9 @@ public class LimitsCalc { continue; } for (int y = 0; y < Objects.requireNonNull(island.getCenter().getWorld()).getMaxHeight(); y++) { - Material blockData = chunk.getBlockType(x, y, z); + BlockData blockData = chunk.getBlockData(x, y, z); // Air is free - if (!blockData.equals(Material.AIR)) { + if (!blockData.getMaterial().equals(Material.AIR)) { checkBlock(blockData); } } @@ -115,8 +116,8 @@ public class LimitsCalc { } } - private void checkBlock(Material md) { - md = bll.fixMaterial(md); + private void checkBlock(BlockData b) { + Material md = bll.fixMaterial(b); // md is limited if (bll.getMaterialLimits(world, island.getUniqueId()).containsKey(md)) { if (!blockCount.containsKey(md)) { diff --git a/src/main/java/world/bentobox/limits/listeners/BlockLimitsListener.java b/src/main/java/world/bentobox/limits/listeners/BlockLimitsListener.java index eca788a..1dbcbc6 100644 --- a/src/main/java/world/bentobox/limits/listeners/BlockLimitsListener.java +++ b/src/main/java/world/bentobox/limits/listeners/BlockLimitsListener.java @@ -15,6 +15,8 @@ import org.bukkit.Material; import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; +import org.bukkit.block.data.BlockData; +import org.bukkit.block.data.type.TechnicalPiston; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.event.Cancellable; import org.bukkit.event.Event; @@ -169,22 +171,16 @@ public class BlockLimitsListener implements Listener { private void handleBreak(Event e, Block b) { Material mat = b.getType(); - // Special handling for crops that can break in different ways - if (mat.equals(Material.WHEAT_SEEDS)) { - mat = Material.WHEAT; - } else if (mat.equals(Material.BEETROOT_SEEDS)) { - mat = Material.BEETROOT; - } // Check for stackable plants if (STACKABLE.contains(b.getType())) { // Check for blocks above Block block = b; while(block.getRelative(BlockFace.UP).getType().equals(mat) && block.getY() < b.getWorld().getMaxHeight()) { block = block.getRelative(BlockFace.UP); - process(block, false, mat); + process(block, false); } } - process(b, false, mat); + process(b, false); // Player breaks a block and there was a redstone dust/repeater/... above if (b.getRelative(BlockFace.UP).getType() == Material.REDSTONE_WIRE || b.getRelative(BlockFace.UP).getType() == Material.REPEATER || b.getRelative(BlockFace.UP).getType() == Material.COMPARATOR || b.getRelative(BlockFace.UP).getType() == Material.REDSTONE_TORCH) { process(b.getRelative(BlockFace.UP), false); @@ -278,30 +274,38 @@ public class BlockLimitsListener implements Listener { } } - private int process(Block b, boolean add) { - return process(b, add, b.getType()); - } - // Return equivalents. - public Material fixMaterial(Material b) { - if (b == Material.REDSTONE_WALL_TORCH) { + + + // Return equivalents. b can be Block/Material + public Material fixMaterial(BlockData b) { + Material mat = b.getMaterial(); + + if (mat == Material.REDSTONE_WALL_TORCH) { return Material.REDSTONE_TORCH; - } else if (b == Material.WALL_TORCH) { + } else if (mat == Material.WALL_TORCH) { return Material.TORCH; - } else if (b == Material.ZOMBIE_WALL_HEAD) { + } else if (mat == Material.ZOMBIE_WALL_HEAD) { return Material.ZOMBIE_HEAD; - } else if (b == Material.CREEPER_WALL_HEAD) { + } else if (mat == Material.CREEPER_WALL_HEAD) { return Material.CREEPER_HEAD; - } else if (b == Material.PLAYER_WALL_HEAD) { + } else if (mat == Material.PLAYER_WALL_HEAD) { return Material.PLAYER_HEAD; - } else if (b == Material.DRAGON_WALL_HEAD) { + } else if (mat == Material.DRAGON_WALL_HEAD) { return Material.DRAGON_HEAD; - } else if (b != null && b == Material.getMaterial("BAMBOO_SAPLING")) { + } else if (mat != null && mat == Material.getMaterial("BAMBOO_SAPLING")) { return Material.getMaterial("BAMBOO"); + } else if (mat == Material.PISTON_HEAD || mat == Material.MOVING_PISTON) { + TechnicalPiston tp = (TechnicalPiston) b; + if (tp.getType() == TechnicalPiston.Type.NORMAL) { + return Material.PISTON; + } else { + return Material.STICKY_PISTON; + } } - return b; - } - + return mat; + } + /** * Check if a block can be * @@ -310,8 +314,8 @@ public class BlockLimitsListener implements Listener { * @param changeTo - material this block will become * @return limit amount if over limit, or -1 if no limitation */ - private int process(Block b, boolean add, Material changeTo) { - if (DO_NOT_COUNT.contains(fixMaterial(b.getType())) || !addon.inGameModeWorld(b.getWorld())) { + private int process(Block b, boolean add) { + if (DO_NOT_COUNT.contains(fixMaterial(b.getBlockData())) || !addon.inGameModeWorld(b.getWorld())) { return -1; } // Check if on island @@ -325,24 +329,14 @@ public class BlockLimitsListener implements Listener { islandCountMap.putIfAbsent(id, new IslandBlockCount(id, gameMode)); if (add) { // Check limit - int limit = checkLimit(b.getWorld(), fixMaterial(b.getType()), id); + int limit = checkLimit(b.getWorld(), fixMaterial(b.getBlockData()), id); if (limit > -1) { return limit; } - islandCountMap.get(id).add(fixMaterial(b.getType())); + islandCountMap.get(id).add(fixMaterial(b.getBlockData())); } else { if (islandCountMap.containsKey(id)) { - // Check for changes - Material fixed = fixMaterial(changeTo); - if (!fixed.equals(fixMaterial(b.getType())) && fixed.isBlock() && !DO_NOT_COUNT.contains(fixed)) { - // Check limit - int limit = checkLimit(b.getWorld(), fixed, id); - if (limit > -1) { - return limit; - } - islandCountMap.get(id).add(fixed); - } - islandCountMap.get(id).remove(fixMaterial(b.getType())); + islandCountMap.get(id).remove(fixMaterial(b.getBlockData())); } } updateSaveMap(id); @@ -363,7 +357,7 @@ public class BlockLimitsListener implements Listener { // Invalid world return; } - islandCountMap.computeIfAbsent(id, k -> new IslandBlockCount(id, gameMode)).remove(fixMaterial(b.getType())); + islandCountMap.computeIfAbsent(id, k -> new IslandBlockCount(id, gameMode)).remove(fixMaterial(b.getBlockData())); updateSaveMap(id); }); }