From 6eb0159ea1552dd48f968aa82122f6ab3ddef553 Mon Sep 17 00:00:00 2001 From: GJ Date: Sun, 27 May 2012 10:21:00 -0400 Subject: [PATCH] More tracking of falling sand/gravel. (WIP) --- .../nossr50/listeners/BlockListener.java | 30 +++++++++++++++++-- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/listeners/BlockListener.java b/src/main/java/com/gmail/nossr50/listeners/BlockListener.java index 9232e9521..ad0d8b7ad 100644 --- a/src/main/java/com/gmail/nossr50/listeners/BlockListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/BlockListener.java @@ -37,6 +37,7 @@ import org.bukkit.event.block.BlockPistonExtendEvent; import org.bukkit.event.block.BlockPistonRetractEvent; import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.inventory.ItemStack; +import org.bukkit.metadata.FixedMetadataValue; import org.getspout.spoutapi.sound.SoundEffect; @@ -58,11 +59,17 @@ public class BlockListener implements Listener { BlockFace direction = event.getDirection(); for (Block b : blocks) { - mcMMO.placeStore.setFalse(b); + if (mcMMO.placeStore.isTrue(b)) { + b.getRelative(direction).setMetadata("pistonTrack", new FixedMetadataValue(plugin, true)); + mcMMO.placeStore.setFalse(b); + } } for (Block b : blocks) { - mcMMO.placeStore.setTrue(b.getRelative(direction)); + if (b.getRelative(direction).hasMetadata("pistonTrack")) { + mcMMO.placeStore.setTrue(b.getRelative(direction)); + b.getRelative(direction).removeMetadata("pistonTrack", plugin); + } } } @@ -114,6 +121,20 @@ public class BlockListener implements Listener { int id = block.getTypeId(); Material type = block.getType(); + /* Code to prevent issues with placed falling Sand/Gravel not being tracked */ + if (type.equals(Material.SAND) || type.equals(Material.GRAVEL)) { + for (int y = -1; y + block.getY() >= 0; y--) { + if (block.getRelative(0, y, 0).getType().equals(Material.AIR)) { + continue; + } + else { + Block newLocation = block.getRelative(0, y + 1, 0); + mcMMO.placeStore.setTrue(newLocation); + break; + } + } + } + /* Check if the blocks placed should be monitored so they do not give out XP in the future */ if (BlockChecks.shouldBeWatched(block)) { if (!((type == Material.SAND || type == Material.GRAVEL) && block.getRelative(BlockFace.DOWN).getType() == Material.AIR)) { //Don't wanna track sand that's gonna fall. @@ -218,13 +239,16 @@ public class BlockListener implements Listener { Material aboveType = block.getRelative(BlockFace.UP).getType(); if (aboveType == Material.SAND || aboveType == Material.GRAVEL) { - for (int y = 1; block.getY() + y <= block.getWorld().getHighestBlockYAt(block.getX(), block.getZ()); y++) { + for (int y = 1; block.getY() + y <= block.getWorld().getMaxHeight(); y++) { Block relative = block.getRelative(0, y, 0); Material relativeType = relative.getType(); if ((relativeType == Material.SAND || relativeType == Material.GRAVEL) && mcMMO.placeStore.isTrue(relative)) { mcMMO.placeStore.setFalse(relative); } + else if (!BlockChecks.shouldBeWatched(relative) && mcMMO.placeStore.isTrue(relative)){ + mcMMO.placeStore.setFalse(relative); + } else { break; }