9
9
import java .util .Map ;
10
10
import java .util .Random ;
11
11
import java .util .Set ;
12
+ import java .util .function .Predicate ;
12
13
import java .util .stream .Collectors ;
13
14
14
15
import org .bukkit .Bukkit ;
20
21
import org .bukkit .World .Environment ;
21
22
import org .bukkit .block .Block ;
22
23
import org .bukkit .block .BlockFace ;
24
+ import org .bukkit .block .BlockState ;
23
25
import org .bukkit .entity .Player ;
24
26
import org .bukkit .event .EventHandler ;
25
27
import org .bukkit .event .EventPriority ;
32
34
33
35
import com .google .common .base .Enums ;
34
36
37
+ import world .bentobox .bentobox .BentoBox ;
35
38
import world .bentobox .bentobox .database .objects .Island ;
36
39
import world .bentobox .bentobox .lists .Flags ;
37
40
import world .bentobox .bentobox .util .Util ;
@@ -132,18 +135,16 @@ protected void growTree(Block b) {
132
135
}
133
136
if (SAPLING_TO_TREE_TYPE .containsKey (t )) {
134
137
TreeType type = SAPLING_TO_TREE_TYPE .getOrDefault (b .getType (), TreeType .TREE );
138
+ BentoBox .getInstance ().logDebug ("Setting " + b + " mat " + t + " to air" );
135
139
b .setType (Material .AIR );
136
-
137
- if (b .getWorld ().generateTree (b .getLocation (), RAND , type ,
138
- bs -> bs .getType () != Material .DIRT
139
- && (Flags .TREES_GROWING_OUTSIDE_RANGE .isSetForWorld (bs .getWorld ())
140
- || addon .getIslands ().getProtectedIslandAt (bs .getLocation ()).isPresent ()))) {
140
+ if (b .getWorld ().generateTree (b .getLocation (), RAND , type , (Predicate <BlockState >) this ::checkPlace )) {
141
141
if (addon .getSettings ().isEffectsEnabled ()) {
142
142
showSparkles (b );
143
143
}
144
144
if (addon .getSettings ().isSoundsEnabled ()) {
145
145
b .getWorld ().playSound (b .getLocation (), addon .getSettings ().getSoundsGrowingSmallTreeSound (),
146
- (float )addon .getSettings ().getSoundsGrowingSmallTreeVolume (), (float )addon .getSettings ().getSoundsGrowingSmallTreePitch ());
146
+ (float ) addon .getSettings ().getSoundsGrowingSmallTreeVolume (),
147
+ (float ) addon .getSettings ().getSoundsGrowingSmallTreePitch ());
147
148
}
148
149
} else {
149
150
// Tree generation failed, so reset block
@@ -152,6 +153,16 @@ protected void growTree(Block b) {
152
153
}
153
154
}
154
155
156
+ private Boolean checkPlace (BlockState bs ) {
157
+ System .out .println ("Not Dirt " + (bs .getType () != Material .DIRT ));
158
+ System .out .println ("Outside range flag set? " + Flags .TREES_GROWING_OUTSIDE_RANGE .isSetForWorld (bs .getWorld ()));
159
+ System .out .println ("Inside island? " + addon .getIslands ().getProtectedIslandAt (bs .getLocation ()).isPresent ());
160
+ System .out .println ("Overall = " + (bs .getType () != Material .DIRT && (Flags .TREES_GROWING_OUTSIDE_RANGE .isSetForWorld (bs .getWorld ())
161
+ || addon .getIslands ().getProtectedIslandAt (bs .getLocation ()).isPresent ())));
162
+ return bs .getType () != Material .DIRT && (Flags .TREES_GROWING_OUTSIDE_RANGE .isSetForWorld (bs .getWorld ())
163
+ || addon .getIslands ().getProtectedIslandAt (bs .getLocation ()).isPresent ());
164
+ }
165
+
155
166
protected boolean bigTreeSaplings (Block b ) {
156
167
Material treeType = b .getType ();
157
168
TreeType type = SAPLING_TO_BIG_TREE_TYPE .get (treeType );
0 commit comments