From dd5cd3df4a396ec24e950e8f48ba762a0fc2ad29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zhenyuan=E2=9C=A8?= Date: Sat, 4 Apr 2026 16:16:52 +0800 Subject: [PATCH 1/2] feat: Added increment-block-statistics --- src/main/java/org/milkteamc/autotreechop/Config.java | 6 ++++++ .../org/milkteamc/autotreechop/utils/TreeChopUtils.java | 9 +++++++++ src/main/resources/config.yml | 3 +++ 3 files changed, 18 insertions(+) diff --git a/src/main/java/org/milkteamc/autotreechop/Config.java b/src/main/java/org/milkteamc/autotreechop/Config.java index d39dfe5..bd1e0f3 100644 --- a/src/main/java/org/milkteamc/autotreechop/Config.java +++ b/src/main/java/org/milkteamc/autotreechop/Config.java @@ -105,6 +105,7 @@ public class Config { private int maxTreeSize; private int maxDiscoveryBlocks; private boolean callBlockBreakEvent; + private boolean incrementBlockStatistics; public Config(AutoTreeChop plugin) { this.plugin = plugin; @@ -228,6 +229,7 @@ private void loadValues() { maxTreeSize = config.getInt("max-tree-size", 500); maxDiscoveryBlocks = config.getInt("max-discovery-blocks", 1000); callBlockBreakEvent = config.getBoolean("call-block-break-event", true); + incrementBlockStatistics = config.getBoolean("increment-block-statistics", false); autoReplantEnabled = config.getBoolean("enable-auto-replant", true); replantDelayTicks = config.getLong("replant-delay-ticks", 15L); @@ -546,6 +548,10 @@ public boolean isCallBlockBreakEvent() { return callBlockBreakEvent; } + public boolean isIncrementBlockStatistics() { + return incrementBlockStatistics; + } + public int getIdleTimeoutSeconds() { return idleTimeoutSeconds; } diff --git a/src/main/java/org/milkteamc/autotreechop/utils/TreeChopUtils.java b/src/main/java/org/milkteamc/autotreechop/utils/TreeChopUtils.java index 880b618..50f3c7e 100644 --- a/src/main/java/org/milkteamc/autotreechop/utils/TreeChopUtils.java +++ b/src/main/java/org/milkteamc/autotreechop/utils/TreeChopUtils.java @@ -341,6 +341,10 @@ private void executeTreeChop( } block.breakNaturally(); + if (config.isIncrementBlockStatistics()) { + player.incrementStatistic(org.bukkit.Statistic.MINE_BLOCK, originalLogType); + } + actuallyRemovedLogs.add(location); sessionManager.trackRemovedLogForPlayer(playerUUID.toString(), location); playerConfig.incrementDailyBlocksBroken(); @@ -566,6 +570,7 @@ private boolean removeLeafBlock( EffectUtils.showLeafRemovalEffect(player, leafBlock); } + Material leafMaterial = leafBlock.getType(); if (config.getLeafRemovalDropItems()) { leafBlock.breakNaturally(); } else { @@ -577,6 +582,10 @@ private boolean removeLeafBlock( } } + if (config.isIncrementBlockStatistics()) { + player.incrementStatistic(org.bukkit.Statistic.MINE_BLOCK, leafMaterial); + } + // Update daily blocks count if needed if (config.getLeafRemovalCountsTowardsLimit()) { playerConfig.incrementDailyBlocksBroken(); diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index ed7344e..1c1217f 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -83,6 +83,9 @@ max-discovery-blocks: 1000 # Call BlockBreakEvent for each block # true = Better plugin compatibility call-block-break-event: true +# Increment player's Minecraft block-break statistic (Statistic.MINE_BLOCK) for every block broken by ATC, +# including all chain-chopped logs and leaves (if leaf removal is enabled). +increment-block-statistics: false # Protection plugins setting # If you are using Residence, you can set which Flag players have access to AutoTreeChop in residence. From f169ca658a243ff07235ea473be54ab157341f0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zhenyuan=E2=9C=A8?= Date: Sat, 4 Apr 2026 17:06:36 +0800 Subject: [PATCH 2/2] perf: Batch incrementStatistic calls by material type --- .../autotreechop/utils/TreeChopUtils.java | 26 +++++++++++++++---- src/main/resources/config.yml | 2 +- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/milkteamc/autotreechop/utils/TreeChopUtils.java b/src/main/java/org/milkteamc/autotreechop/utils/TreeChopUtils.java index 50f3c7e..fc7e1b9 100644 --- a/src/main/java/org/milkteamc/autotreechop/utils/TreeChopUtils.java +++ b/src/main/java/org/milkteamc/autotreechop/utils/TreeChopUtils.java @@ -33,6 +33,8 @@ import org.milkteamc.autotreechop.Config; import org.milkteamc.autotreechop.PlayerConfig; +import static org.bukkit.Statistic.MINE_BLOCK; + public class TreeChopUtils { private static final Random random = new Random(); @@ -303,6 +305,7 @@ private void executeTreeChop( BlockSnapshot finalLeafSnapshot = leafSnapshot; + Map logStatCounts = new HashMap<>(); batchProcessor.processBatch( blockList, 0, @@ -342,7 +345,7 @@ private void executeTreeChop( block.breakNaturally(); if (config.isIncrementBlockStatistics()) { - player.incrementStatistic(org.bukkit.Statistic.MINE_BLOCK, originalLogType); + logStatCounts.merge(originalLogType, 1, Integer::sum); } actuallyRemovedLogs.add(location); @@ -351,6 +354,11 @@ private void executeTreeChop( }, () -> { // After all logs are removed + if (config.isIncrementBlockStatistics()) { + logStatCounts.forEach((mat, count) -> + player.incrementStatistic(MINE_BLOCK, mat, count)); + } + if (config.isToolDamage()) { applyToolDamage(tool, player, totalBlocks, config); } @@ -498,6 +506,7 @@ private void executeLeafRemoval( List leafList = new ArrayList<>(leavesToRemove); int batchSize = config.getLeafRemovalBatchSize(); + Map leafStatCounts = new HashMap<>(); batchProcessor.processBatchWithTermination( leafList, @@ -515,11 +524,17 @@ private void executeLeafRemoval( Block leafBlock = location.getBlock(); // Remove the leaf block with all checks - removeLeafBlock(leafBlock, player, config, playerConfig, hooks); + removeLeafBlock(leafBlock, player, config, playerConfig, hooks, leafStatCounts); return true; // Continue processing }, () -> { + // Flush accumulated leaf statistics + if (config.isIncrementBlockStatistics()) { + leafStatCounts.forEach((mat, count) -> + player.incrementStatistic(MINE_BLOCK, mat, count)); + } + // Leaf removal complete - end session sessionManager.endLeafRemovalSession(sessionId, playerKey); }); @@ -534,7 +549,8 @@ private boolean removeLeafBlock( Player player, Config config, PlayerConfig playerConfig, - ProtectionCheckUtils.ProtectionHooks hooks) { + ProtectionCheckUtils.ProtectionHooks hooks, + Map leafStatCounts) { Location leafLocation = leafBlock.getLocation(); @@ -570,7 +586,6 @@ private boolean removeLeafBlock( EffectUtils.showLeafRemovalEffect(player, leafBlock); } - Material leafMaterial = leafBlock.getType(); if (config.getLeafRemovalDropItems()) { leafBlock.breakNaturally(); } else { @@ -583,7 +598,8 @@ private boolean removeLeafBlock( } if (config.isIncrementBlockStatistics()) { - player.incrementStatistic(org.bukkit.Statistic.MINE_BLOCK, leafMaterial); + Material leafMaterial = leafBlock.getType(); + leafStatCounts.merge(leafMaterial, 1, Integer::sum); } // Update daily blocks count if needed diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 1c1217f..8f70223 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -83,7 +83,7 @@ max-discovery-blocks: 1000 # Call BlockBreakEvent for each block # true = Better plugin compatibility call-block-break-event: true -# Increment player's Minecraft block-break statistic (Statistic.MINE_BLOCK) for every block broken by ATC, +# Increment player's Minecraft block-break statistic (Statistic.MINE_BLOCK) for every block broken by AutoTreeChop, # including all chain-chopped logs and leaves (if leaf removal is enabled). increment-block-statistics: false