Skip to content
Open
Show file tree
Hide file tree
Changes from all 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 @@ -104,6 +104,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 @@ -227,6 +228,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 @@ -537,6 +539,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 @@ -34,6 +34,8 @@
import org.milkteamc.autotreechop.MessageKeys;
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 @@ -304,6 +306,7 @@ private void executeTreeChop(

BlockSnapshot finalLeafSnapshot = leafSnapshot;

Map<Material, Integer> logStatCounts = new HashMap<>();
batchProcessor.processBatch(
blockList,
0,
Expand Down Expand Up @@ -342,12 +345,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 @@ -495,6 +507,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 @@ -512,11 +525,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 @@ -531,7 +550,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 @@ -573,6 +593,11 @@ private boolean removeLeafBlock(
leafBlock.setType(XMaterial.AIR.get(), false);
}

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