Explorar o código

Passing events is bad.

GJ %!s(int64=12) %!d(string=hai) anos
pai
achega
fe89c19969

+ 1 - 2
src/main/java/com/gmail/nossr50/listeners/BlockListener.java

@@ -58,7 +58,6 @@ public class BlockListener implements Listener {
      */
     @EventHandler(priority = EventPriority.MONITOR)
     public void onBlockPistonExtend(BlockPistonExtendEvent event) {
-
         List<Block> blocks = event.getBlocks();
         BlockFace direction = event.getDirection();
         Block futureEmptyBlock = event.getBlock().getRelative(direction); // Block that would be air after piston is finished
@@ -89,7 +88,7 @@ public class BlockListener implements Listener {
     public void onBlockPistonRetract(BlockPistonRetractEvent event) {
         if (event.isSticky()) {
             // Needed only because under some circumstances Minecraft doesn't move the block
-            new StickyPistonTrackerTask(event).runTaskLater(plugin, 2);
+            new StickyPistonTrackerTask(event.getDirection(), event.getBlock()).runTaskLater(plugin, 2);
         }
     }
 

+ 9 - 11
src/main/java/com/gmail/nossr50/runnables/StickyPistonTrackerTask.java

@@ -2,28 +2,26 @@ package com.gmail.nossr50.runnables;
 
 import org.bukkit.Material;
 import org.bukkit.block.Block;
-import org.bukkit.event.block.BlockPistonRetractEvent;
+import org.bukkit.block.BlockFace;
 import org.bukkit.scheduler.BukkitRunnable;
 
 import com.gmail.nossr50.mcMMO;
 
 public class StickyPistonTrackerTask extends BukkitRunnable {
-    BlockPistonRetractEvent event;
+    private BlockFace direction;
+    private Block block;
 
-    public StickyPistonTrackerTask(BlockPistonRetractEvent event) {
-        this.event = event;
+    public StickyPistonTrackerTask(BlockFace direction, Block block) {
+        this.direction = direction;
+        this.block = block;
     }
 
     @Override
     public void run() {
-        Block newBlock = event.getBlock().getRelative(event.getDirection());
-        Block originalBlock = newBlock.getRelative(event.getDirection());
+        Block newBlock = block.getRelative(direction);
+        Block originalBlock = newBlock.getRelative(direction);
 
-        if (originalBlock.getType() != Material.AIR) {
-            return;
-        }
-
-        if (!mcMMO.placeStore.isTrue(originalBlock)) {
+        if (originalBlock.getType() != Material.AIR || !mcMMO.placeStore.isTrue(originalBlock)) {
             return;
         }