mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-06-28 03:34:43 +02:00
Workaround a CB bug by tracking piston events
There is a bug in Craftbukkit that causes piston events to fire multiple times. We need to keep track of the extend and retract events to see which piston events should be processed.
This commit is contained in:
@ -8,6 +8,7 @@ import org.bukkit.entity.Fish;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.PlayerFishEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.metadata.FixedMetadataValue;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
@ -194,4 +195,26 @@ public class EventUtils {
|
||||
|
||||
return event;
|
||||
}
|
||||
|
||||
/**
|
||||
* There is a bug in CraftBukkit that causes piston events to
|
||||
* fire multiple times. Check this method to see if the piston event
|
||||
* should be processed.
|
||||
*
|
||||
* @param block Block object of the piston block
|
||||
* @param isExtendEvent should be true when called from BlockPistonExtendEvent
|
||||
*
|
||||
* @return true if the PistonEvent should be processed, false otherwise
|
||||
*/
|
||||
public static boolean shouldProcessEvent(Block block, boolean isExtendEvent) {
|
||||
String pistonAction = isExtendEvent ? "EXTEND" : "RETRACT";
|
||||
String lastAction = block.hasMetadata(mcMMO.pistonDataKey) ? block.getMetadata(mcMMO.pistonDataKey).get(0).asString() : "";
|
||||
|
||||
if (!lastAction.equals(pistonAction)) {
|
||||
block.setMetadata(mcMMO.pistonDataKey, new FixedMetadataValue(mcMMO.p, pistonAction));
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user