Skip to content

Commit

Permalink
events to lumber axe
Browse files Browse the repository at this point in the history
  • Loading branch information
JustAHuman-xD committed Aug 30, 2024
1 parent a897b52 commit 7e1e0cd
Showing 1 changed file with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
import javax.annotation.ParametersAreNonnullByDefault;

import org.bukkit.Axis;
import org.bukkit.Bukkit;
import org.bukkit.Effect;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.Tag;
import org.bukkit.block.Block;
import org.bukkit.block.data.Orientable;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.inventory.ItemStack;

import io.github.bakedlibs.dough.blocks.Vein;
Expand Down Expand Up @@ -56,7 +58,11 @@ private ToolUseHandler onBlockBreak() {

for (Block b : logs) {
if (!BlockStorage.hasBlockInfo(b) && Slimefun.getProtectionManager().hasPermission(e.getPlayer(), b, Interaction.BREAK_BLOCK)) {
breakLog(b);
BlockBreakEvent event = new BlockBreakEvent(b, e.getPlayer());
Bukkit.getPluginManager().callEvent(event);
if (!event.isCancelled()) {
breakLog(b, event.isDropItems());
}
}
}
}
Expand Down Expand Up @@ -99,11 +105,13 @@ private void stripLog(@Nonnull Block b) {
b.setBlockData(orientable);
}

private void breakLog(@Nonnull Block b) {
private void breakLog(@Nonnull Block b, boolean dropItems) {
b.getWorld().playEffect(b.getLocation(), Effect.STEP_SOUND, b.getType());

for (ItemStack drop : b.getDrops(getItem())) {
b.getWorld().dropItemNaturally(b.getLocation(), drop);
if (dropItems) {
for (ItemStack drop : b.getDrops(getItem())) {
b.getWorld().dropItemNaturally(b.getLocation(), drop);
}
}

b.setType(Material.AIR);
Expand Down

0 comments on commit 7e1e0cd

Please sign in to comment.