Bladeren bron

Fixed duplication bug with sticky pistons

bm01 13 jaren geleden
bovenliggende
commit
f18a9bdcc7

+ 1 - 0
Changelog.txt

@@ -13,6 +13,7 @@ Version 1.3.10-dev
  + Added Ability API functions
  + Added 50% & 150% XP boost perks
  + Added "lucky" perk for donors
+ = Fixed duplication bug with sticky pistons
  = Fixed "GenericLabel belonging to mcMMO..." message
  = Fixed menu exit button not working
  = Fixed Repair enchant downgrade not working

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

@@ -28,6 +28,7 @@ import com.gmail.nossr50.datatypes.ToolType;
 import com.gmail.nossr50.events.fake.FakeBlockBreakEvent;
 import com.gmail.nossr50.events.fake.FakeBlockDamageEvent;
 import com.gmail.nossr50.events.fake.FakePlayerAnimationEvent;
+import com.gmail.nossr50.runnables.StickyPistonTracker;
 import com.gmail.nossr50.skills.gathering.Excavation;
 import com.gmail.nossr50.skills.gathering.Herbalism;
 import com.gmail.nossr50.skills.gathering.Mining;
@@ -99,11 +100,9 @@ public class BlockListener implements Listener {
      */
     @EventHandler(priority = EventPriority.MONITOR)
     public void onBlockPistonRetract(BlockPistonRetractEvent event) {
-        Block block = event.getRetractLocation().getBlock();
-
-        if (event.isSticky() && mcMMO.placeStore.isTrue(block)) {
-            mcMMO.placeStore.setFalse(block);
-            mcMMO.placeStore.setTrue(event.getBlock().getRelative(event.getDirection()));
+        if (event.isSticky()) {
+            //Needed only because under some circumstances Minecraft doesn't move the block
+            plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new StickyPistonTracker(event), 0);
         }
     }
 

+ 27 - 0
src/main/java/com/gmail/nossr50/runnables/StickyPistonTracker.java

@@ -0,0 +1,27 @@
+package com.gmail.nossr50.runnables;
+
+import org.bukkit.Material;
+import org.bukkit.block.Block;
+import org.bukkit.event.block.BlockPistonRetractEvent;
+
+import com.gmail.nossr50.mcMMO;
+
+public class StickyPistonTracker implements Runnable {
+    BlockPistonRetractEvent event;
+
+    public StickyPistonTracker(BlockPistonRetractEvent event) {
+        this.event = event;
+    }
+
+    @Override
+    public void run() {
+        Block originalBlock = event.getRetractLocation().getBlock();
+
+        if (originalBlock.getType() == Material.AIR && mcMMO.placeStore.isTrue(originalBlock)) {
+            Block newBlock = originalBlock.getRelative(event.getDirection().getOppositeFace());
+
+            mcMMO.placeStore.setFalse(originalBlock);
+            mcMMO.placeStore.setTrue(newBlock);
+        }
+    }
+}