Skip to content

Commit

Permalink
Fixes #330
Browse files Browse the repository at this point in the history
  • Loading branch information
Thorinwasher committed Feb 18, 2024
1 parent 4aa2a7e commit 0ac16f4
Showing 1 changed file with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.data.Directional;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
Expand Down Expand Up @@ -213,7 +215,9 @@ public void onSignChange(SignChangeEvent event) {
*/
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onPistonExtend(BlockPistonExtendEvent event) {
BlockEventHelper.onAnyMultiBlockChangeEvent(event, BlockEventType.BLOCK_PISTON_EXTEND, event.getBlocks(), stargateAPI);
onPistonEvent(event.getBlocks(), event.getDirection(), BlockEventType.BLOCK_PISTON_EXTEND, event);
BlockEventHelper.onAnyBlockChangeEvent(event, BlockEventType.BLOCK_PISTON_EXTEND, event.getBlock()
.getRelative(event.getDirection()).getLocation(), stargateAPI);
}

/**
Expand All @@ -223,7 +227,16 @@ public void onPistonExtend(BlockPistonExtendEvent event) {
*/
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onPistonRetract(BlockPistonRetractEvent event) {
BlockEventHelper.onAnyMultiBlockChangeEvent(event, BlockEventType.BLOCK_PISTON_RETRACT, event.getBlocks(), stargateAPI);
onPistonEvent(event.getBlocks(), event.getDirection(), BlockEventType.BLOCK_PISTON_RETRACT, event);
}

private void onPistonEvent(List<Block> blocks, BlockFace blockFace, BlockEventType type, Cancellable event) {
BlockEventHelper.onAnyMultiBlockChangeEvent(event, type, blocks, stargateAPI);
if (event.isCancelled()) {
return;
}
List<Block> movedBlocks = blocks.stream().map(block -> block.getRelative(blockFace)).toList();
BlockEventHelper.onAnyMultiBlockChangeEvent(event, type, movedBlocks, stargateAPI);
}

/**
Expand Down

0 comments on commit 0ac16f4

Please sign in to comment.