Skip to content

Commit b37c906

Browse files
Integrations and Fixes
1 parent 06a8c83 commit b37c906

8 files changed

Lines changed: 73 additions & 6 deletions

File tree

src/main/java/com/syntaxphoenix/spigot/smoothtimber/compatibility/blockylog/BlockyLogResolver_v2_x.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,14 @@ public List<Location> resolve(final Location start, final int radius, final List
5353

5454
@Override
5555
public boolean isPlayerPlaced(final Location location) {
56-
return api.isPlayerPlaced(location);
56+
// Check BlockyLog if enabled in config, otherwise fall back to PDC tracking
57+
// PDC auto-removes on block break, so it's safe as a fallback
58+
if (com.syntaxphoenix.spigot.smoothtimber.config.config.CutterConfig.USE_BLOCKYLOG_TRACKING) {
59+
if (api.isPlayerPlaced(location)) {
60+
return true;
61+
}
62+
}
63+
return com.syntaxphoenix.spigot.smoothtimber.utilities.locate.PlacedBlockTracker.isPlayerPlaced(location);
5764
}
5865

5966
}

src/main/java/com/syntaxphoenix/spigot/smoothtimber/compatibility/coreprotect/CoreCompat_v1_13_x.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,15 @@ public boolean isPlayerPlaced(BlockState state) {
3434
if (parseResult.getPlayer().isEmpty() || parseResult.getPlayer().startsWith("#") || parseResult.isRolledBack()) {
3535
return false;
3636
}
37-
return parseResult.getActionId() != 0;
37+
38+
// Check if it's a placement action (actionId != 0)
39+
if (parseResult.getActionId() == 0) {
40+
return false;
41+
}
42+
43+
// Verify the placed block type matches the current block type
44+
// This prevents false positives when saplings grow into trees
45+
return parseResult.getType().equals(state.getType());
3846
}
3947

4048
}

src/main/java/com/syntaxphoenix/spigot/smoothtimber/compatibility/coreprotect/CoreCompat_v1_8_x.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,15 @@ public boolean isPlayerPlaced(BlockState state) {
3838
if (parseResult.getPlayer().isEmpty() || parseResult.getPlayer().startsWith("#") || parseResult.isRolledBack()) {
3939
return false;
4040
}
41-
return parseResult.getActionId() != 0;
41+
42+
// Check if it's a placement action (actionId != 0)
43+
if (parseResult.getActionId() == 0) {
44+
return false;
45+
}
46+
47+
// Verify the placed block type matches the current block type
48+
// This prevents false positives when saplings grow into trees
49+
return parseResult.getType().equals(state.getType());
4250
}
4351

4452
}

src/main/java/com/syntaxphoenix/spigot/smoothtimber/compatibility/coreprotect/CoreProtectResolver.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,14 @@ public boolean isPlayerPlaced(final Location location) {
9292
if (block == null) {
9393
return false;
9494
}
95-
return compat.isPlayerPlaced(block);
95+
// Check CoreProtect if enabled in config, otherwise fall back to PDC tracking
96+
// PDC auto-removes on block break, so it's safe as a fallback
97+
if (com.syntaxphoenix.spigot.smoothtimber.config.config.CutterConfig.USE_COREPROTECT_TRACKING) {
98+
if (compat.isPlayerPlaced(block)) {
99+
return true;
100+
}
101+
}
102+
return com.syntaxphoenix.spigot.smoothtimber.utilities.locate.PlacedBlockTracker.isPlayerPlaced(location);
96103
}
97104

98105
}

src/main/java/com/syntaxphoenix/spigot/smoothtimber/compatibility/logblock/LogBlockResolver.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,14 @@ public boolean isPlayerPlaced(final BlockState block) {
9494

9595
@Override
9696
public boolean isPlayerPlaced(final Location location) {
97-
return databaseAccessor.isPlayerPlaced(Locator.getBlockState(location));
97+
// Check LogBlock if enabled in config, otherwise fall back to PDC tracking
98+
// PDC auto-removes on block break, so it's safe as a fallback
99+
if (com.syntaxphoenix.spigot.smoothtimber.config.config.CutterConfig.USE_LOGBLOCK_TRACKING) {
100+
if (databaseAccessor.isPlayerPlaced(Locator.getBlockState(location))) {
101+
return true;
102+
}
103+
}
104+
return com.syntaxphoenix.spigot.smoothtimber.utilities.locate.PlacedBlockTracker.isPlayerPlaced(location);
98105
}
99106

100107
}

src/main/java/com/syntaxphoenix/spigot/smoothtimber/config/config/CutterConfig.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ public final class CutterConfig extends STConfig {
6262
public static boolean ENABLE_ANIMATION = true;
6363
public static boolean INSTANT_COLLECT = false;
6464

65+
public static boolean USE_COREPROTECT_TRACKING = false;
66+
public static boolean USE_LOGBLOCK_TRACKING = false;
67+
public static boolean USE_BLOCKYLOG_TRACKING = false;
68+
6569
/*
6670
*
6771
*/
@@ -110,6 +114,10 @@ protected void onLoad() {
110114
ENABLE_ANIMATION = check("options.animation", ENABLE_ANIMATION);
111115
INSTANT_COLLECT = check("options.collect-instantly", INSTANT_COLLECT);
112116

117+
USE_COREPROTECT_TRACKING = check("options.tracking.coreprotect", USE_COREPROTECT_TRACKING);
118+
USE_LOGBLOCK_TRACKING = check("options.tracking.logblock", USE_LOGBLOCK_TRACKING);
119+
USE_BLOCKYLOG_TRACKING = check("options.tracking.blockylog", USE_BLOCKYLOG_TRACKING);
120+
113121
ENABLE_WOOD_PERMISSIONS = check("options.permission.wood-type", ENABLE_WOOD_PERMISSIONS);
114122
ENABLE_CUTTER_PERMISSIONS = check("options.permission.cutter-type", ENABLE_CUTTER_PERMISSIONS);
115123

src/main/java/com/syntaxphoenix/spigot/smoothtimber/listener/BlockPlaceListener.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55
import org.bukkit.event.Listener;
66
import org.bukkit.event.block.BlockPlaceEvent;
77

8+
import com.syntaxphoenix.spigot.smoothtimber.compatibility.CompatibilityHandler;
9+
import com.syntaxphoenix.spigot.smoothtimber.compatibility.blockylog.BlockyLog;
10+
import com.syntaxphoenix.spigot.smoothtimber.compatibility.coreprotect.CoreProtectAddon;
11+
import com.syntaxphoenix.spigot.smoothtimber.compatibility.logblock.LogBlock;
12+
import com.syntaxphoenix.spigot.smoothtimber.config.config.CutterConfig;
813
import com.syntaxphoenix.spigot.smoothtimber.utilities.PluginUtils;
914
import com.syntaxphoenix.spigot.smoothtimber.utilities.locate.PlacedBlockTracker;
1015
import com.syntaxphoenix.spigot.smoothtimber.version.manager.VersionChanger;
@@ -15,6 +20,15 @@ public class BlockPlaceListener implements Listener {
1520
public void onBlockPlace(BlockPlaceEvent event) {
1621
VersionChanger changer = PluginUtils.CHANGER;
1722
if (changer.isWoodBlock(event.getBlock().getState())) {
23+
// Skip marking if any enabled logging plugin is active
24+
boolean useExternalTracking =
25+
(CutterConfig.USE_COREPROTECT_TRACKING && CompatibilityHandler.getAddon(CoreProtectAddon.class).isPresent()) ||
26+
(CutterConfig.USE_LOGBLOCK_TRACKING && CompatibilityHandler.getAddon(LogBlock.class).isPresent()) ||
27+
(CutterConfig.USE_BLOCKYLOG_TRACKING && CompatibilityHandler.getAddon(BlockyLog.class).isPresent());
28+
29+
if (useExternalTracking) {
30+
return;
31+
}
1832
PlacedBlockTracker.markAsPlaced(event.getBlock());
1933
}
2034
}

src/main/java/com/syntaxphoenix/spigot/smoothtimber/utilities/locate/DefaultResolver.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ public List<Location> resolve(final Location start, final int radius, final List
3636
if (current.contains(location)) {
3737
continue;
3838
}
39+
// Skip player-placed blocks
40+
if (isPlayerPlaced(location)) {
41+
continue;
42+
}
3943
current.add(location);
4044
counter.increment();
4145
resolved.add(location);
@@ -47,7 +51,11 @@ public List<Location> resolve(final Location start, final int radius, final List
4751

4852
@Override
4953
public boolean isPlayerPlaced(final Location location) {
50-
return PlacedBlockTracker.isPlayerPlaced(location);
54+
// Check CoreProtect first if available
55+
return com.syntaxphoenix.spigot.smoothtimber.compatibility.CompatibilityHandler.getAddon(
56+
com.syntaxphoenix.spigot.smoothtimber.compatibility.coreprotect.CoreProtectAddon.class)
57+
.map(addon -> addon.getLocationResolver().isPlayerPlaced(location))
58+
.orElseGet(() -> PlacedBlockTracker.isPlayerPlaced(location));
5159
}
5260

5361
}

0 commit comments

Comments
 (0)