瀏覽代碼

Fixed falling sand/gravel stuff not being tracked

GJ 13 年之前
父節點
當前提交
5c9371c575
共有 2 個文件被更改,包括 26 次插入15 次删除
  1. 1 0
      Changelog.txt
  2. 25 15
      src/main/java/com/gmail/nossr50/listeners/BlockListener.java

+ 1 - 0
Changelog.txt

@@ -11,6 +11,7 @@ Version 1.3.09
  = Fixed issue with NoCheatPlus and Serrated Strikes / Skull Splitter (fight.noswing)
  = Fixed bug where you could receive Archery XP from Potions
  = Fixed bug with duping blocks via piston pushing
+ = Fixed bug with falling sand/gravel not being tracked
  ! Changed Spout settings to be in their own config file (spout.yml)
 
 Version 1.3.08

+ 25 - 15
src/main/java/com/gmail/nossr50/listeners/BlockListener.java

@@ -32,6 +32,7 @@ import org.bukkit.event.EventPriority;
 import org.bukkit.event.Listener;
 import org.bukkit.event.block.BlockBreakEvent;
 import org.bukkit.event.block.BlockDamageEvent;
+import org.bukkit.event.block.BlockPhysicsEvent;
 import org.bukkit.event.block.BlockPistonExtendEvent;
 import org.bukkit.event.block.BlockPistonRetractEvent;
 import org.bukkit.event.block.BlockPlaceEvent;
@@ -72,6 +73,25 @@ public class BlockListener implements Listener {
         }
     }
 
+    /**
+     * Monitor BlockPhysics events.
+     *
+     * @param event The event to monitor
+     */
+    @EventHandler(priority = EventPriority.MONITOR)
+    public void onBlockPhysics(BlockPhysicsEvent event) {
+        //TODO: Figure out how to REMOVE metadata from the location the sand 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.
      *
@@ -99,21 +119,6 @@ public class BlockListener implements Listener {
         Block block = event.getBlock();
         Player player = event.getPlayer();
         int id = block.getTypeId();
-        Material mat = block.getType();
-
-        /* Code to prevent issues with placed falling Sand/Gravel not being tracked */
-        if (mat.equals(Material.SAND) || mat.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)) {
@@ -144,6 +149,11 @@ public class BlockListener implements Listener {
             return;
         }
 
+        //DEBUG MESSAGES
+        if (!mcMMO.placeStore.isTrue(block) && BlockChecks.shouldBeWatched(block)) {
+            player.sendMessage("Why aren't you watching me?");
+        }
+
         /* HERBALISM */
         if (BlockChecks.canBeGreenTerra(block)) {
             /* Green Terra */