Skip to content

Commit

Permalink
Merge pull request #3 from myavuzokumus/main
Browse files Browse the repository at this point in the history
Fixed piston not working which is the micro feature.
  • Loading branch information
alvindimas05 authored Aug 12, 2024
2 parents 381abfe + bfc0523 commit 569eaf1
Showing 1 changed file with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@
import org.alvindimas05.lagassist.Main;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Effect;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.BlockState;
import org.bukkit.block.data.BlockData;
import org.bukkit.block.data.Directional;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
Expand All @@ -38,6 +41,7 @@ private static void runTask() {
Bukkit.getScheduler().runTaskTimer(Main.p, () -> {
for (BlockState b : breakables) {
b.getBlock().breakNaturally();
b.getWorld().playEffect(b.getLocation(), Effect.STEP_SOUND, b.getBlockData());
}

breakables.clear();
Expand All @@ -51,7 +55,7 @@ private static void runTask() {

private static List<BlockState> breakables = new ArrayList<>();
private static final List<BlockFace> growablefaces = Arrays.asList(BlockFace.EAST, BlockFace.WEST, BlockFace.NORTH,
BlockFace.SOUTH);
BlockFace.SOUTH, BlockFace.DOWN, BlockFace.UP);

@EventHandler(priority = EventPriority.HIGHEST)
public void onGrowableGrow(BlockGrowEvent e) {
Expand All @@ -73,8 +77,17 @@ public void onGrowableGrow(BlockGrowEvent e) {

for (BlockFace face : growablefaces) {
Block piston = b.getBlock().getRelative(face);
if(piston.getType() != Material.PISTON) continue;

//Block frontBlock = piston.getRelative(piston.getFace(b.getBlock()).getOppositeFace());
BlockData blockData = piston.getBlockData();
if (blockData instanceof Directional directional) {
BlockFace facing = directional.getFacing();
if (facing != face.getOppositeFace()) {
continue;
}
}

if(piston.getType() != Material.PISTON || face.getOppositeFace() != face) continue;
breakables.add(b);

return;
Expand Down

0 comments on commit 569eaf1

Please sign in to comment.