From db1c0647ed3f1d1ea365019cc2cfeeecd22933c0 Mon Sep 17 00:00:00 2001 From: GJ Date: Thu, 17 Jan 2013 23:26:18 -0500 Subject: [PATCH] Fix issue with tracking falling sand & gravel. --- Changelog.txt | 1 + .../nossr50/listeners/BlockListener.java | 61 +------------------ .../nossr50/listeners/EntityListener.java | 23 +++++++ src/main/java/com/gmail/nossr50/mcMMO.java | 40 ++++++++++++ 4 files changed, 65 insertions(+), 60 deletions(-) diff --git a/Changelog.txt b/Changelog.txt index 762a67bd5..0c1a2d154 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -19,6 +19,7 @@ Version 1.3.13-dev + Added wooden button to the list of items that shouldn't trigger abilities + Added a new feature to fishing. Players will have +10% chance of finding enchanted items when fishing while it's raining + Added displaying bonus perks on skill commands + = Fix issue with Sand/Gravel tracking = Fix possible NPE when using the PartyAPI to add a player to a party that doesn't exist. = Fix mcremove command for mySQL = Impact now works with mobs wearing armor diff --git a/src/main/java/com/gmail/nossr50/listeners/BlockListener.java b/src/main/java/com/gmail/nossr50/listeners/BlockListener.java index 95f14cdde..73ed898b6 100644 --- a/src/main/java/com/gmail/nossr50/listeners/BlockListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/BlockListener.java @@ -78,29 +78,6 @@ public class BlockListener implements Listener { } } - - /** - * Monitor BlockPhysics events. - * - * @param event The event to monitor - */ - // Disabled until a better patch can be applied. This does nothing but flag the wrong block. - /* - @EventHandler(priority = EventPriority.MONITOR) - public void onBlockPhysics(BlockPhysicsEvent event) { - //TODO: Figure out how to REMOVE metadata from the location the sand/gravel fell from. - Material type = event.getChangedType(); - - if (type == Material.GRAVEL || type == Material.SAND) { - Block fallenBlock = event.getBlock().getRelative(BlockFace.UP); - - if (fallenBlock.getType() == type) { - mcMMO.placeStore.setTrue(fallenBlock); - } - } - } - */ - /** * Monitor BlockPistonRetract events. * @@ -126,28 +103,12 @@ public class BlockListener implements Listener { Block block = event.getBlock(); Player player = event.getPlayer(); int id = block.getTypeId(); - Material type = block.getType(); if (player.hasMetadata("NPC")) return; // Check if this player is a Citizens NPC - /* 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; - } - - 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. - mcMMO.placeStore.setTrue(block); - } + mcMMO.placeStore.setTrue(block); } if (id == configInstance.getRepairAnvilId() && configInstance.getRepairAnvilMessagesEnabled()) { @@ -246,26 +207,6 @@ public class BlockListener implements Listener { if (BlockChecks.shouldBeWatched(block)) { mcMMO.placeStore.setFalse(block); } - - //Remove metadata from fallen sand/gravel - Material aboveType = block.getRelative(BlockFace.UP).getType(); - - if (aboveType == Material.SAND || aboveType == Material.GRAVEL) { - 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; - } - } - } } /** diff --git a/src/main/java/com/gmail/nossr50/listeners/EntityListener.java b/src/main/java/com/gmail/nossr50/listeners/EntityListener.java index 71ccc65e8..742567818 100644 --- a/src/main/java/com/gmail/nossr50/listeners/EntityListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/EntityListener.java @@ -1,9 +1,11 @@ package com.gmail.nossr50.listeners; import org.bukkit.Material; +import org.bukkit.block.Block; import org.bukkit.entity.AnimalTamer; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; +import org.bukkit.entity.FallingBlock; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.entity.Projectile; @@ -15,6 +17,7 @@ import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.entity.CreatureSpawnEvent; import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason; +import org.bukkit.event.entity.EntityChangeBlockEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityDamageEvent.DamageCause; @@ -50,6 +53,26 @@ public class EntityListener implements Listener { this.plugin = plugin; } + @EventHandler(priority = EventPriority.MONITOR) + public void onEntityChangeBlockEvent(EntityChangeBlockEvent event) { + Entity entity = event.getEntity(); + + if (entity instanceof FallingBlock) { + int entityID = entity.getEntityId(); + Block block = event.getBlock(); + + if (mcMMO.placeStore.isTrue(block)) { + plugin.addToFallingBlockTracker(entityID, block); + } + + if (plugin.fallingBlockIsTracked(entityID) && block.getType() == Material.AIR) { + mcMMO.placeStore.setFalse(plugin.getSourceBlock(entityID)); + mcMMO.placeStore.setTrue(block); + plugin.removeFromFallingBlockTracker(entityID); + } + } + } + /** * Monitor EntityDamageByEntity events. * diff --git a/src/main/java/com/gmail/nossr50/mcMMO.java b/src/main/java/com/gmail/nossr50/mcMMO.java index aeaac9cab..c2f2c0eb9 100644 --- a/src/main/java/com/gmail/nossr50/mcMMO.java +++ b/src/main/java/com/gmail/nossr50/mcMMO.java @@ -9,6 +9,7 @@ import java.util.List; import net.shatteredlands.shatt.backup.ZipLibrary; import org.bukkit.OfflinePlayer; +import org.bukkit.block.Block; import org.bukkit.entity.Player; import org.bukkit.plugin.PluginDescriptionFile; import org.bukkit.plugin.PluginManager; @@ -96,6 +97,7 @@ public class mcMMO extends JavaPlugin { private HashMap aliasMap = new HashMap(); //Alias - Command private HashMap tntTracker = new HashMap(); + private HashMap fallingBlockTracker = new HashMap(); private static Database database; public static mcMMO p; @@ -519,6 +521,44 @@ public class mcMMO extends JavaPlugin { tntTracker.remove(tntID); } + /** + * Add an ID value to the FallingBlock tracker. + * + * @param fallingBlockID The EntityID of the FallingBlock + */ + public void addToFallingBlockTracker(int fallingBlockID, Block sourceBlock) { + fallingBlockTracker.put(fallingBlockID, sourceBlock); + } + + /** + * Check to see if a given FallingBlock Entity is tracked. + * + * @param tntID The EntityID of the FallingBlock + * @return true if the FallingBlock is being tracked, false otherwise + */ + public boolean fallingBlockIsTracked(int fallingBlockID) { + return fallingBlockTracker.containsKey(fallingBlockID); + } + + /** + * Get the initial location of the FallingBlock. + * + * @param fallingBlockID The EntityID of the FallingBlock + * @return the Player who detonated it + */ + public Block getSourceBlock(int fallingBlockID) { + return fallingBlockTracker.get(fallingBlockID); + } + + /** + * Remove FallingBlock from the tracker after it lands. + * + * @param fallingBlockID The EntityID of the FallingBlock + */ + public void removeFromFallingBlockTracker(int fallingBlockID) { + fallingBlockTracker.remove(fallingBlockID); + } + public static String getMainDirectory() { return mainDirectory; }