Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/main/java/org/milkteamc/autotreechop/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -546,6 +548,10 @@ public boolean isCallBlockBreakEvent() {
return callBlockBreakEvent;
}

public boolean isIncrementBlockStatistics() {
return incrementBlockStatistics;
}

public int getIdleTimeoutSeconds() {
return idleTimeoutSeconds;
}
Expand Down
29 changes: 27 additions & 2 deletions src/main/java/org/milkteamc/autotreechop/utils/TreeChopUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
import org.milkteamc.autotreechop.Config;
import org.milkteamc.autotreechop.PlayerConfig;

import static org.bukkit.Statistic.MINE_BLOCK;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import org.bukkit.Statistic, don't use static


public class TreeChopUtils {

private static final Random random = new Random();
Expand Down Expand Up @@ -303,6 +305,7 @@ private void executeTreeChop(

BlockSnapshot finalLeafSnapshot = leafSnapshot;

Map<Material, Integer> logStatCounts = new HashMap<>();
batchProcessor.processBatch(
blockList,
0,
Expand Down Expand Up @@ -341,12 +344,21 @@ private void executeTreeChop(
}
block.breakNaturally();

if (config.isIncrementBlockStatistics()) {
logStatCounts.merge(originalLogType, 1, Integer::sum);
}

actuallyRemovedLogs.add(location);
sessionManager.trackRemovedLogForPlayer(playerUUID.toString(), location);
playerConfig.incrementDailyBlocksBroken();
},
() -> {
// 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);
}
Expand Down Expand Up @@ -494,6 +506,7 @@ private void executeLeafRemoval(

List<Location> leafList = new ArrayList<>(leavesToRemove);
int batchSize = config.getLeafRemovalBatchSize();
Map<Material, Integer> leafStatCounts = new HashMap<>();

batchProcessor.processBatchWithTermination(
leafList,
Expand All @@ -511,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);
});
Expand All @@ -530,7 +549,8 @@ private boolean removeLeafBlock(
Player player,
Config config,
PlayerConfig playerConfig,
ProtectionCheckUtils.ProtectionHooks hooks) {
ProtectionCheckUtils.ProtectionHooks hooks,
Map<Material, Integer> leafStatCounts) {

Location leafLocation = leafBlock.getLocation();

Expand Down Expand Up @@ -577,6 +597,11 @@ private boolean removeLeafBlock(
}
}

if (config.isIncrementBlockStatistics()) {
Material leafMaterial = leafBlock.getType();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will always return AIR

leafStatCounts.merge(leafMaterial, 1, Integer::sum);
}

// Update daily blocks count if needed
if (config.getLeafRemovalCountsTowardsLimit()) {
playerConfig.incrementDailyBlocksBroken();
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 AutoTreeChop,
# 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.
Expand Down