From e2df3491b33f97cf321b84c1bb8cc58e0d26b3de Mon Sep 17 00:00:00 2001 From: Anton Wiblishauser <79146501+btwonion@users.noreply.github.com> Date: Wed, 11 Feb 2026 12:13:21 +0100 Subject: [PATCH 1/3] add magnetic compat --- build.gradle | 2 + .../timberz/handler/TreeAnimationHandler.java | 4 +- .../timberz/listener/LeafBreakListener.java | 3 +- .../timberz/service/TreeFellerService.java | 9 +++-- .../service/magnetic/BreakingHelper.java | 40 +++++++++++++++++++ src/main/resources/paper-plugin.yml | 4 ++ 6 files changed, 55 insertions(+), 7 deletions(-) create mode 100644 src/main/java/com/zetaplugins/timberz/service/magnetic/BreakingHelper.java diff --git a/build.gradle b/build.gradle index 7bc327d..d92a9e0 100644 --- a/build.gradle +++ b/build.gradle @@ -32,6 +32,7 @@ repositories { maven { url "https://maven.enginehub.org/repo/" } maven { url = 'https://repo.extendedclip.com/releases/' } maven { url = "https://maven.zetaplugins.com/" } + maven { url "https://repo.nyon.dev/releases" } } def targetJavaVersion = 21 @@ -77,6 +78,7 @@ dependencies { compileOnly 'com.sk89q.worldguard:worldguard-bukkit:7.0.13' compileOnly 'me.clip:placeholderapi:2.11.6' compileOnly 'dev.aurelium:auraskills-api-bukkit:2.2.4' + compileOnly 'dev.nyon:magnetic:3.9.1-1.21.6+paper' implementation "com.fasterxml.jackson.core:jackson-databind:2.16.1" shadow "com.zetaplugins:zetacore:1.7.1" diff --git a/src/main/java/com/zetaplugins/timberz/handler/TreeAnimationHandler.java b/src/main/java/com/zetaplugins/timberz/handler/TreeAnimationHandler.java index d023d62..9b3c66c 100644 --- a/src/main/java/com/zetaplugins/timberz/handler/TreeAnimationHandler.java +++ b/src/main/java/com/zetaplugins/timberz/handler/TreeAnimationHandler.java @@ -1,6 +1,7 @@ package com.zetaplugins.timberz.handler; import com.zetaplugins.timberz.TimberZ; +import com.zetaplugins.timberz.service.magnetic.BreakingHelper; import org.bukkit.*; import org.bukkit.block.Block; import org.bukkit.entity.Player; @@ -51,8 +52,7 @@ public void run() { createBreakEffect(player, block, direction); // Break the block naturally to drop items - Material blockType = block.getType(); - block.breakNaturally(player.getInventory().getItemInMainHand()); + BreakingHelper.breakBlock(block, player, player.getInventory().getItemInMainHand(), true); // Random chance to spawn floating wood chips if (random.nextInt(5) == 0) { diff --git a/src/main/java/com/zetaplugins/timberz/listener/LeafBreakListener.java b/src/main/java/com/zetaplugins/timberz/listener/LeafBreakListener.java index 79006fc..988e578 100644 --- a/src/main/java/com/zetaplugins/timberz/listener/LeafBreakListener.java +++ b/src/main/java/com/zetaplugins/timberz/listener/LeafBreakListener.java @@ -3,6 +3,7 @@ import com.zetaplugins.timberz.TimberZ; import com.zetaplugins.timberz.service.MaterialTypeChecks; import com.zetaplugins.timberz.service.PlayerStateService; +import com.zetaplugins.timberz.service.magnetic.BreakingHelper; import com.zetaplugins.zetacore.annotations.AutoRegisterListener; import org.bukkit.Material; import org.bukkit.Sound; @@ -42,7 +43,7 @@ public void onBlockBreak(BlockDamageEvent event) { ItemStack tool = player.getInventory().getItemInMainHand(); if (tool.getType() == Material.AIR || !MaterialTypeChecks.isValidAxe(tool, plugin)) return; - brokenBlock.breakNaturally(tool); + BreakingHelper.breakBlock(brokenBlock, player, tool, true); player.playSound(player.getLocation(), Sound.BLOCK_GRASS_BREAK, 1.0f, 1.0f); } diff --git a/src/main/java/com/zetaplugins/timberz/service/TreeFellerService.java b/src/main/java/com/zetaplugins/timberz/service/TreeFellerService.java index 695b79c..89eeea4 100644 --- a/src/main/java/com/zetaplugins/timberz/service/TreeFellerService.java +++ b/src/main/java/com/zetaplugins/timberz/service/TreeFellerService.java @@ -3,6 +3,7 @@ import com.zetaplugins.timberz.TimberZ; import com.zetaplugins.timberz.handler.SaplingReplanter; import com.zetaplugins.timberz.handler.TreeAnimationHandler; +import com.zetaplugins.timberz.service.magnetic.BreakingHelper; import org.bukkit.Material; import org.bukkit.Particle; import org.bukkit.Sound; @@ -49,7 +50,7 @@ public void fellTree(Player player, Block sourceBlock, Set treeBlocks, It // Schedule leaf decay if (!leafBlocks.isEmpty() && plugin.getConfig().getBoolean("instantLeafDecay")) { - scheduleLeafDecay(leafBlocks); + scheduleLeafDecay(leafBlocks, player, tool); } boolean shouldReplant = plugin.getConfig().getBoolean("replant"); @@ -149,7 +150,7 @@ private Set collectLeaves(Set treeBlocks, List leafType) /** * Schedules leaf decay with a natural-looking pattern */ - private void scheduleLeafDecay(Set leafBlocks) { + private void scheduleLeafDecay(Set leafBlocks, Player player, ItemStack tool) { List sortedLeaves = new ArrayList<>(leafBlocks); // Sort leaves from bottom to top for more natural decay @@ -178,8 +179,8 @@ public void run() { Sound.BLOCK_GRASS_BREAK, 0.6f, pitch); - // Break the leaf naturally - leaf.breakNaturally(); + // Break the leaf + BreakingHelper.breakBlock(leaf, player, tool, false); } } }.runTaskLater(plugin, 5 + random.nextInt(40)); // Random delay between 5-45 ticks diff --git a/src/main/java/com/zetaplugins/timberz/service/magnetic/BreakingHelper.java b/src/main/java/com/zetaplugins/timberz/service/magnetic/BreakingHelper.java new file mode 100644 index 0000000..f84a5b7 --- /dev/null +++ b/src/main/java/com/zetaplugins/timberz/service/magnetic/BreakingHelper.java @@ -0,0 +1,40 @@ +package com.zetaplugins.timberz.service.magnetic; + +import org.apache.commons.lang3.mutable.MutableInt; +import org.bukkit.*; +import org.bukkit.block.Block; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +import java.util.List; + +public class BreakingHelper { + + public static void breakBlock(Block block, Player player, ItemStack tool, boolean shouldDamage) { + // If magnetic is not present, simply break naturally + if (!Bukkit.getPluginManager().isPluginEnabled("magnetic")) { + block.breakNaturally(tool); + return; + } + + // Create magnetic drop event + List drops = block.getDrops(tool, player).stream().toList(); + dev.nyon.magnetic.DropEvent dropEvent = new dev.nyon.magnetic.DropEvent(drops, new MutableInt(0), player, block.getLocation()); + dropEvent.callEvent(); + + // Drop the remaining items that were not handled by magnetic + List remainingItems = dropEvent.getItems(); + World world = block.getWorld(); + Location location = block.getLocation(); + remainingItems.forEach(stack -> world.dropItem(location, stack)); + + // Play effects on break + world.playSound(location.toCenterLocation(), block.getBlockSoundGroup().getBreakSound(), 1f, 1f); + + // Actually destroy block + block.setType(Material.AIR); + + // Damage tool if tool is damageable + if (!tool.isEmpty() && tool.getType().getMaxDurability() > 0 && shouldDamage) tool.damage(1, player); + } +} diff --git a/src/main/resources/paper-plugin.yml b/src/main/resources/paper-plugin.yml index e6b8bf2..d83c34f 100644 --- a/src/main/resources/paper-plugin.yml +++ b/src/main/resources/paper-plugin.yml @@ -22,6 +22,10 @@ dependencies: load: BEFORE required: false join-classpath: true + magnetic: + load: BEFORE + required: false + join-classpath: true permissions: timberz.admin: From e258e5d54503bf575d6678b66d7fb77a2451bad4 Mon Sep 17 00:00:00 2001 From: btwonion <79146501+btwonion@users.noreply.github.com> Date: Sat, 28 Feb 2026 16:02:15 +0100 Subject: [PATCH 2/3] fix UnsupportedOperationException --- .../zetaplugins/timberz/service/magnetic/BreakingHelper.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/zetaplugins/timberz/service/magnetic/BreakingHelper.java b/src/main/java/com/zetaplugins/timberz/service/magnetic/BreakingHelper.java index f84a5b7..5babc1e 100644 --- a/src/main/java/com/zetaplugins/timberz/service/magnetic/BreakingHelper.java +++ b/src/main/java/com/zetaplugins/timberz/service/magnetic/BreakingHelper.java @@ -6,6 +6,7 @@ import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; +import java.util.ArrayList; import java.util.List; public class BreakingHelper { @@ -18,7 +19,7 @@ public static void breakBlock(Block block, Player player, ItemStack tool, boolea } // Create magnetic drop event - List drops = block.getDrops(tool, player).stream().toList(); + ArrayList drops = new ArrayList<>(block.getDrops(tool, player)); dev.nyon.magnetic.DropEvent dropEvent = new dev.nyon.magnetic.DropEvent(drops, new MutableInt(0), player, block.getLocation()); dropEvent.callEvent(); From 287e5825b0b8429726b7aba8e5f0ba2ce6872b77 Mon Sep 17 00:00:00 2001 From: btwonion <79146501+btwonion@users.noreply.github.com> Date: Sat, 28 Feb 2026 16:02:32 +0100 Subject: [PATCH 3/3] update magnetic dependency --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index d92a9e0..70ad262 100644 --- a/build.gradle +++ b/build.gradle @@ -78,7 +78,7 @@ dependencies { compileOnly 'com.sk89q.worldguard:worldguard-bukkit:7.0.13' compileOnly 'me.clip:placeholderapi:2.11.6' compileOnly 'dev.aurelium:auraskills-api-bukkit:2.2.4' - compileOnly 'dev.nyon:magnetic:3.9.1-1.21.6+paper' + compileOnly 'dev.nyon:magnetic:3.10.0-1.21.6+paper' implementation "com.fasterxml.jackson.core:jackson-databind:2.16.1" shadow "com.zetaplugins:zetacore:1.7.1"