From aa59348a9404c4b6992b7e80fc41037ad6a6a463 Mon Sep 17 00:00:00 2001 From: GJ Date: Mon, 3 Mar 2014 12:14:01 -0500 Subject: [PATCH] We only care about blocks that award XP. Also, this fixes a possible issue where blocks changed by entities other than falling blocks could have been left as tracked even after they were destroyed. --- .../nossr50/listeners/BlockListener.java | 2 +- .../nossr50/listeners/EntityListener.java | 38 +++++++++---------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/listeners/BlockListener.java b/src/main/java/com/gmail/nossr50/listeners/BlockListener.java index 0709c3909..d9fecf819 100644 --- a/src/main/java/com/gmail/nossr50/listeners/BlockListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/BlockListener.java @@ -96,7 +96,7 @@ public class BlockListener implements Listener { Block movedBlock = event.getRetractLocation().getBlock(); - if (movedBlock.getPistonMoveReaction() != PistonMoveReaction.MOVE || !mcMMO.getPlaceStore().isTrue(movedBlock)) { + if (!BlockUtils.shouldBeWatched(movedBlock.getState()) || movedBlock.getPistonMoveReaction() != PistonMoveReaction.MOVE || !mcMMO.getPlaceStore().isTrue(movedBlock)) { return; } diff --git a/src/main/java/com/gmail/nossr50/listeners/EntityListener.java b/src/main/java/com/gmail/nossr50/listeners/EntityListener.java index 1d6a5cbd3..713463fc5 100644 --- a/src/main/java/com/gmail/nossr50/listeners/EntityListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/EntityListener.java @@ -1,19 +1,11 @@ package com.gmail.nossr50.listeners; import com.gmail.nossr50.events.fake.FakeEntityTameEvent; +import com.gmail.nossr50.util.BlockUtils; import org.bukkit.OfflinePlayer; import org.bukkit.block.Block; import org.bukkit.enchantments.Enchantment; -import org.bukkit.entity.AnimalTamer; -import org.bukkit.entity.Arrow; -import org.bukkit.entity.Entity; -import org.bukkit.entity.FallingBlock; -import org.bukkit.entity.LivingEntity; -import org.bukkit.entity.Player; -import org.bukkit.entity.Projectile; -import org.bukkit.entity.TNTPrimed; -import org.bukkit.entity.Tameable; -import org.bukkit.entity.Wolf; +import org.bukkit.entity.*; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; @@ -100,21 +92,29 @@ public class EntityListener implements Listener { */ @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onEntityChangeBlock(EntityChangeBlockEvent event) { - Entity entity = event.getEntity(); + Block block = event.getBlock(); - if (!(entity instanceof FallingBlock)) { + if (!BlockUtils.shouldBeWatched(block.getState())) { return; } - Block block = event.getBlock(); - boolean isTracked = entity.hasMetadata(mcMMO.entityMetadataKey); + Entity entity = event.getEntity(); - if (mcMMO.getPlaceStore().isTrue(block) && !isTracked) { - mcMMO.getPlaceStore().setFalse(block); - entity.setMetadata(mcMMO.entityMetadataKey, mcMMO.metadataValue); + if (entity instanceof FallingBlock || entity instanceof Enderman) { + boolean isTracked = entity.hasMetadata(mcMMO.entityMetadataKey); + + if (mcMMO.getPlaceStore().isTrue(block) && !isTracked) { + mcMMO.getPlaceStore().setFalse(block); + entity.setMetadata(mcMMO.entityMetadataKey, mcMMO.metadataValue); + } + else if (isTracked) { + mcMMO.getPlaceStore().setTrue(block); + } } - else if (isTracked) { - mcMMO.getPlaceStore().setTrue(block); + else { + if (mcMMO.getPlaceStore().isTrue(block)) { + mcMMO.getPlaceStore().setFalse(block); + } } }