mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-06-28 03:34:43 +02:00
Fix the issues with sticky pistons and slime blocks
This is a fix for issues #2419 and #2494
This commit is contained in:
@ -1,10 +1,14 @@
|
||||
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;
|
||||
@ -316,6 +320,32 @@ 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
|
||||
*
|
||||
|
@ -9,7 +9,6 @@ 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;
|
||||
@ -280,26 +279,4 @@ 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