Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import org.bukkit.material.Attachable;
import org.bukkit.util.Vector;
import org.jetbrains.annotations.NotNull;
import java.util.List;

public class BlockListener implements Listener {
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
Expand Down Expand Up @@ -126,15 +127,15 @@ public void onRedstoneEvent(@NotNull BlockRedstoneEvent e) {

@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onPistonExtendEvent(@NotNull BlockPistonExtendEvent e) {
onPistonEvent(e);
onPistonEvent(e, e.getBlocks());
}

@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onPistonRetractEvent(@NotNull BlockPistonRetractEvent e) {
onPistonEvent(e);
onPistonEvent(e, e.getBlocks());
}

public void onPistonEvent(@NotNull BlockPistonEvent e) {
public void onPistonEvent(@NotNull BlockPistonEvent e, final @NotNull List<Block> affectedBlocks) {
Block block = e.getBlock();
Location location = block.getLocation();
MovecraftLocation loc = MathUtils.bukkit2MovecraftLoc(location);
Expand All @@ -143,15 +144,13 @@ public void onPistonEvent(@NotNull BlockPistonEvent e) {
continue;

if (!craft.isNotProcessing())
e.setCancelled(true); // prevent pistons on cruising crafts
if (!(e instanceof BlockPistonExtendEvent))
return;
// merge piston extensions to craft
if (craft.getType().getBoolProperty(CraftType.MERGE_PISTON_EXTENSIONS))
e.setCancelled(true); // prevent pistons on cruising crafts
// merge piston extensions to craft if the property is true
if (!craft.getType().getBoolProperty(CraftType.MERGE_PISTON_EXTENSIONS))
continue;

BitmapHitBox hitBox = new BitmapHitBox();
for (Block b : ((BlockPistonExtendEvent) e).getBlocks()) {
for (Block b : affectedBlocks) {
Vector dir = e.getDirection().getDirection();
hitBox.add(new MovecraftLocation(b.getX() + dir.getBlockX(), b.getY() + dir.getBlockY(), b.getZ() + dir.getBlockZ()));
}
Expand Down