Skip to content

Commit 5f43536

Browse files
Merge branch 'Norbit4:master' into ver/1.0
2 parents 54378f0 + f06252c commit 5f43536

8 files changed

Lines changed: 73 additions & 14 deletions

File tree

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
**Cut down trees in a more realistic way! 🪓🌳**
2929

3030
<a href="https://github.com/Norbit4/TreeCuter/" target="_blank" rel="noreferrer">
31-
<img src="https://github.com/Norbit4/TreeCuter/assets/46154743/8f97482e-d239-427c-8398-c61ba2c815ed" width=50" alt="logo"/></a>
31+
<img src="https://github.com/user-attachments/assets/69402d75-9b03-4b39-9845-4f19c1de8509" width=300" alt="logo"/></a>
32+
3233
3334
⚠️**DEAFULT**: You need use **SHIFT** key to cut tree!
3435
</div>

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ plugins {
44
}
55

66
group = 'pl.norbit'
7-
version = 'v2.2.0'
7+
version = 'v2.3.1'
88

99
repositories {
1010
mavenCentral()

src/main/java/pl/norbit/treecuter/config/Settings.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ public class Settings {
4949
@Getter
5050
private static boolean shiftMining;
5151
@Getter
52+
private static boolean checkNaturalTree;
53+
@Getter
5254
private static boolean applyMiningEffect;
5355
@Getter
5456
private static boolean hideMiningEffect;
@@ -202,6 +204,7 @@ public static void loadConfig(boolean reload) {
202204

203205
maxBlocks = config.getInt("max-blocks");
204206
minBlocks = config.getInt("min-blocks");
207+
checkNaturalTree = config.getBoolean("check-natural-tree");
205208

206209
shiftMining = config.getBoolean("shift-mining");
207210

src/main/java/pl/norbit/treecuter/service/LeafDecayService.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
package pl.norbit.treecuter.service;
22

3-
import com.nexomc.nexo.api.NexoBlocks;
4-
import com.nexomc.nexo.mechanics.custom_block.CustomBlockMechanic;
53
import org.bukkit.Material;
64
import org.bukkit.block.Block;
75
import org.bukkit.block.data.type.Leaves;
8-
import org.codehaus.plexus.util.cli.StreamFeeder;
96
import pl.norbit.treecuter.config.Settings;
107
import pl.norbit.treecuter.config.model.CutShape;
118
import pl.norbit.treecuter.utils.item.ItemsAdderUtils;
@@ -87,7 +84,7 @@ public static void scanLeaves(List<Block> blocks, CutShape cutShape) {
8784
Set<String> woodBlocks = new HashSet<>(cutShape.getAcceptBlocks());
8885

8986
for (Block leaf : leaves) {
90-
if (isLeafDecaying(leaf, woodBlocks)) {
87+
if (checkBlock(leaf, woodBlocks)) {
9188
decayLeaves.add(leaf);
9289
}
9390
}
@@ -98,7 +95,7 @@ public static void scanLeaves(List<Block> blocks, CutShape cutShape) {
9895
});
9996
}
10097

101-
private static boolean isLeafDecaying(Block b, Set<String> woodBlocks) {
98+
private static boolean checkBlock(Block b, Set<String> woodBlocks) {
10299
if (b.getBlockData() instanceof Leaves leaves) {
103100

104101
if (leaves.isPersistent()) {
@@ -113,6 +110,14 @@ private static boolean isLeafDecaying(Block b, Set<String> woodBlocks) {
113110
return false;
114111
}
115112

113+
public static boolean isLeaves(Block b) {
114+
if (b.getBlockData() instanceof Leaves leaves) {
115+
116+
return !leaves.isPersistent();
117+
118+
} else return Settings.isAcceptedCustomLeavesBlock(b);
119+
}
120+
116121
private static boolean hasNearby(Block block, Set<String> materials, int[][] offsets){
117122
for (int[] off : offsets) {
118123

src/main/java/pl/norbit/treecuter/service/TreeCutService.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package pl.norbit.treecuter.service;
22

3-
import com.nexomc.nexo.api.NexoBlocks;
4-
import com.nexomc.nexo.mechanics.custom_block.CustomBlockMechanic;
53
import org.bukkit.Material;
64
import org.bukkit.block.Block;
75
import org.bukkit.entity.Player;
@@ -103,6 +101,10 @@ public static void selectTreeByBlock(Block b, Player p, CutShape shape, ItemStac
103101

104102
List<Block> blocks = BlockUtils.getWoodBlocksAround(new ArrayList<>(), b, maxBlock, shape);
105103

104+
if(blocks == null){
105+
return;
106+
}
107+
106108
if(blocks.size() < Settings.getMinBlocks()){
107109
selectedMap.remove(p.getUniqueId());
108110
return;
@@ -219,7 +221,6 @@ private static void breakBlock(Player p, Block b){
219221
}
220222

221223
private static void updateItem(Player p, int durabilityDamage){
222-
223224
PlayerInventory inventory = p.getInventory();
224225

225226
ItemStack item = inventory.getItemInMainHand();

src/main/java/pl/norbit/treecuter/utils/BlockUtils.java

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import org.bukkit.block.BlockFace;
55
import pl.norbit.treecuter.config.Settings;
66
import pl.norbit.treecuter.config.model.CutShape;
7+
import pl.norbit.treecuter.service.LeafDecayService;
78

89
import java.util.*;
910

@@ -49,7 +50,7 @@ public static List<Block> getWoodBlocksAround(List<Block> blocks, Block start, i
4950
getDiagonalBlocks(blocks, queue, visited, relative, max, woodBlocks);
5051
}
5152
}
52-
return blocks;
53+
return hasLeavesOnTop(blocks) ? blocks : null;
5354
}
5455

5556
private static void getDiagonalBlocks(List<Block> blocks,
@@ -76,6 +77,43 @@ private static void getDiagonalBlocks(List<Block> blocks,
7677
}
7778
}
7879

80+
private static boolean hasLeavesOnTop(List<Block> woodBlocks) {
81+
if (!Settings.isCheckNaturalTree()) {
82+
return true;
83+
}
84+
85+
int maxY = woodBlocks.stream()
86+
.mapToInt(Block::getY)
87+
.max()
88+
.orElse(Integer.MIN_VALUE);
89+
90+
for (Block wood : woodBlocks) {
91+
if (wood.getY() >= maxY - 2 && hasNearbyLeaves(wood)) {
92+
return true;
93+
}
94+
}
95+
96+
return false;
97+
}
98+
99+
private static boolean hasNearbyLeaves(Block block) {
100+
for (int x = -2; x <= 2; x++) {
101+
for (int y = -1; y <= 2; y++) {
102+
for (int z = -2; z <= 2; z++) {
103+
104+
if (x == 0 && y == 0 && z == 0) {
105+
continue;
106+
}
107+
108+
if (LeafDecayService.isLeaves(block.getRelative(x, y, z))) {
109+
return true;
110+
}
111+
}
112+
}
113+
}
114+
return false;
115+
}
116+
79117
private static void checkBlock(List<Block> blocks,
80118
Deque<Block> queue,
81119
Set<Block> visited,

src/main/java/pl/norbit/treecuter/utils/CoreProtectUtils.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,19 @@
77

88
public class CoreProtectUtils {
99

10-
private CoreProtectUtils() {
11-
throw new IllegalStateException("This class cannot be instantiated");
12-
}
10+
private CoreProtectUtils() {}
1311

1412
public static CoreProtectAPI getCoreProtect() {
1513
Plugin plugin = TreeCuter.getInstance().getServer().getPluginManager().getPlugin("CoreProtect");
1614

15+
if(plugin == null){
16+
return null;
17+
}
18+
19+
if(!plugin.isEnabled()){
20+
return null;
21+
}
22+
1723
// Check that CoreProtect is loaded
1824
if (!(plugin instanceof CoreProtect)) {
1925
return null;

src/main/resources/config.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ max-blocks: 150
5050
# min blocks to cut at once
5151
min-blocks: 4
5252

53+
# Beta feature - may not work correctly.
54+
# Checks if leaves are present near the top part of the detected tree.
55+
# Prevents cutting player-built log structures.
56+
check-natural-tree: true
57+
5358
# if true, the player must hold shift to cut down trees
5459
shift-mining: true # true <- recommended
5560

0 commit comments

Comments
 (0)