Skip to content

Commit

Permalink
ignore own events
Browse files Browse the repository at this point in the history
  • Loading branch information
JustAHuman-xD committed Aug 30, 2024
1 parent 7e1e0cd commit b142bc6
Showing 1 changed file with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package io.github.thebusybiscuit.slimefun4.implementation.items.tools;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.annotation.Nonnull;
import javax.annotation.ParametersAreNonnullByDefault;
Expand Down Expand Up @@ -39,6 +41,7 @@
*/
public class LumberAxe extends SlimefunItem implements NotPlaceable {

private static final Set<BlockBreakEvent> IGNORE_EVENTS = new HashSet<>();
private static final int MAX_BROKEN = 100;
private static final int MAX_STRIPPED = 20;

Expand All @@ -52,13 +55,18 @@ public LumberAxe(ItemGroup itemGroup, SlimefunItemStack item, RecipeType recipeT
@Nonnull
private ToolUseHandler onBlockBreak() {
return (e, tool, fortune, drops) -> {
if (IGNORE_EVENTS.contains(e)) {
return;
}

if (!e.getPlayer().isSneaking() && Tag.LOGS.isTagged(e.getBlock().getType())) {
List<Block> logs = Vein.find(e.getBlock(), MAX_BROKEN, b -> Tag.LOGS.isTagged(b.getType()));
logs.remove(e.getBlock());

for (Block b : logs) {
if (!BlockStorage.hasBlockInfo(b) && Slimefun.getProtectionManager().hasPermission(e.getPlayer(), b, Interaction.BREAK_BLOCK)) {
BlockBreakEvent event = new BlockBreakEvent(b, e.getPlayer());
IGNORE_EVENTS.add(event);
Bukkit.getPluginManager().callEvent(event);
if (!event.isCancelled()) {
breakLog(b, event.isDropItems());
Expand Down

0 comments on commit b142bc6

Please sign in to comment.