fix(progress): count logs from disrupted trees
Release / release (push) Successful in 2m16s
CI / build (push) Successful in 59s

This commit is contained in:
dmg
2026-08-11 18:35:04 -04:00
parent e7a5a14529
commit f26b7d0f0d
6 changed files with 27 additions and 8 deletions
@@ -43,12 +43,16 @@ public final class TreeProgressListener implements Listener {
|| automaticBreaks.isMarked(event.getBlock())) {
return;
}
Optional<TreeStructure> detected = detector.detect(event.getBlock());
if (detected.isEmpty()) {
Optional<TreeSpecies> classified = TreeTaxonomy.directSpecies(event.getBlock().getType());
if (classified.isEmpty()
&& event.getBlock().getType() == org.bukkit.Material.MUSHROOM_STEM) {
classified = detector.detect(event.getBlock()).map(TreeStructure::species);
}
if (classified.isEmpty()) {
return;
}
TreeSpecies species = detected.orElseThrow().species();
TreeSpecies species = classified.orElseThrow();
PlayerTreeFellerState state = states.load(player.getUniqueId())
.orElseGet(() -> PlayerTreeFellerState.initial(
player.getUniqueId(), player.getName()));
@@ -19,7 +19,7 @@ import org.junit.jupiter.api.Test;
class TreeProgressListenerTest {
@Test
void recordsManualSurvivalBreaksWithAnEmptyHandOrAnyToolFromValidatedTrees() throws Exception {
void recordsNaturalTrunkMaterialAfterTheTreeStructureIsNoLongerIntact() throws Exception {
UUID playerId = UUID.randomUUID();
Player player = mock(Player.class);
PlayerInventory inventory = mock(PlayerInventory.class);
@@ -31,15 +31,15 @@ class TreeProgressListenerTest {
when(player.getInventory()).thenReturn(inventory);
when(inventory.getItemInMainHand()).thenReturn(new ItemStack(Material.IRON_AXE));
when(block.getWorld()).thenReturn(world);
when(block.getType()).thenReturn(Material.OAK_LOG);
when(world.getUID()).thenReturn(UUID.randomUUID());
when(block.getX()).thenReturn(1);
when(block.getY()).thenReturn(64);
when(block.getZ()).thenReturn(2);
TreeStructure tree = new TreeStructure(TreeSpecies.OAK, List.of(new BlockPoint(0, 0, 0)));
InMemoryStateStore states = new InMemoryStateStore();
AutomaticBreakRegistry automaticBreaks = new AutomaticBreakRegistry();
TreeProgressListener listener = new TreeProgressListener(
ignored -> Optional.of(tree),
ignored -> Optional.empty(),
states,
ignored -> 100,
automaticBreaks,
@@ -26,5 +26,8 @@ class TreeTaxonomyTest {
expected.forEach((material, species) ->
assertEquals(species, TreeTaxonomy.directSpecies(material).orElseThrow()));
assertTrue(TreeTaxonomy.directSpecies(Material.BAMBOO).isEmpty());
assertTrue(TreeTaxonomy.directSpecies(Material.OAK_WOOD).isEmpty());
assertTrue(TreeTaxonomy.directSpecies(Material.STRIPPED_OAK_LOG).isEmpty());
assertTrue(TreeTaxonomy.directSpecies(Material.CRIMSON_HYPHAE).isEmpty());
}
}