Prechádzať zdrojové kódy

We can simplify this!

Didn’t realize there was a event.getBlocks() method for
BlockPistonRetractEvent as well.
TfT_02 10 rokov pred
rodič
commit
90b31a29f5

+ 5 - 7
src/main/java/com/gmail/nossr50/listeners/BlockListener.java

@@ -106,15 +106,13 @@ public class BlockListener implements Listener {
 
         // If we're pulling a slime block, it might have something attached to it!
         if (movedBlock.getRelative(direction).getState().getType() == Material.SLIME_BLOCK) {
-            // Check if any other slime blocks are attached, because they can also pull blocks
-            List<Block> adjacentBlocks = BlockUtils.getAdjacentBlocks(movedBlock.getRelative(direction), Material.SLIME_BLOCK);
-            for (Block b : adjacentBlocks) {
-                new StickyPistonTrackerTask(direction, event.getBlock(), b).runTaskLater(plugin, 2);
+            for (Block block : event.getBlocks()) {
+//            // Treat the slime blocks as if it is the sticky piston itself, because pulling
+//            // a slime block with a sticky piston is effectively the same as moving a sticky piston.
+                new StickyPistonTrackerTask(direction, event.getBlock(), block).runTaskLater(plugin, 2);
             }
 
-            // Treat the slime block as if it is the sticky piston itself, because pulling
-            // a slime block with a sticky piston is effectively the same as moving a sticky piston.
-            movedBlock = movedBlock.getRelative(direction);
+            return;
         }
 
         // Needed only because under some circumstances Minecraft doesn't move the block

+ 0 - 30
src/main/java/com/gmail/nossr50/util/BlockUtils.java

@@ -1,14 +1,10 @@
 package com.gmail.nossr50.util;
 
-import java.util.ArrayList;
 import java.util.HashSet;
-import java.util.List;
 
 import org.bukkit.CropState;
 import org.bukkit.Material;
 import org.bukkit.NetherWartsState;
-import org.bukkit.block.Block;
-import org.bukkit.block.BlockFace;
 import org.bukkit.block.BlockState;
 import org.bukkit.material.CocoaPlant;
 import org.bukkit.material.CocoaPlant.CocoaPlantSize;
@@ -320,32 +316,6 @@ public final class BlockUtils {
         return type == Material.PISTON_MOVING_PIECE || type == Material.AIR;
     }
 
-    /**
-     * Get the adjacent blocks of the base block if it is equal to a certain material
-     *
-     * @param base The base block to check
-     * @param material The Material to check for
-     * @return a list with the adjacent blocks
-     */
-    public static List<Block> getAdjacentBlocks(Block base, Material material) {
-        List<Block> blocks = new ArrayList<Block>();
-
-        if (base.getRelative(BlockFace.NORTH).getType() == material) {
-            blocks.add(base.getRelative(BlockFace.NORTH));
-        }
-        if (base.getRelative(BlockFace.EAST).getType() == material) {
-            blocks.add(base.getRelative(BlockFace.EAST));
-        }
-        if (base.getRelative(BlockFace.SOUTH).getType() == material) {
-            blocks.add(base.getRelative(BlockFace.SOUTH));
-        }
-        if (base.getRelative(BlockFace.WEST).getType() == material) {
-            blocks.add(base.getRelative(BlockFace.WEST));
-        }
-
-        return blocks;
-    }
-
     /**
      * Get a HashSet containing every transparent block
      *