Skip to content

Commit

Permalink
Fix predicate check
Browse files Browse the repository at this point in the history
  • Loading branch information
tastybento committed Jan 14, 2024
1 parent 7bba0f6 commit 6d55f44
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 87 deletions.

This file was deleted.

22 changes: 6 additions & 16 deletions src/main/java/world/bentobox/twerk/listeners/TreeGrowListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import java.util.Map;
import java.util.Random;
import java.util.Set;
import java.util.function.Predicate;
import java.util.stream.Collectors;

import org.bukkit.Bukkit;
Expand All @@ -21,7 +20,6 @@
import org.bukkit.World.Environment;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.BlockState;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
Expand Down Expand Up @@ -125,7 +123,9 @@ protected void growTree(Block b) {
TreeType type = SAPLING_TO_TREE_TYPE.getOrDefault(b.getType(), TreeType.TREE);
b.setType(Material.AIR);

if (b.getWorld().generateTree(b.getLocation(), RAND, type, this::canSetBlock)) {
if (b.getWorld().generateTree(b.getLocation(), RAND, type,
bs -> Flags.TREES_GROWING_OUTSIDE_RANGE.isSetForWorld(bs.getWorld())
|| addon.getIslands().getProtectedIslandAt(bs.getLocation()).isPresent())) {
if (addon.getSettings().isEffectsEnabled()) {
showSparkles(b);
}
Expand All @@ -140,18 +140,6 @@ protected void growTree(Block b) {
}
}

/**
* Checks if a block can be made at location or not
* @param bs - BlockState
* @return true if it can
*/
private Predicate<Boolean> canSetBlock(BlockState bs) {
return input -> {
return Flags.TREES_GROWING_OUTSIDE_RANGE.isSetForWorld(bs.getWorld())
|| addon.getIslands().getProtectedIslandAt(bs.getLocation()).isPresent();
};
}

protected boolean bigTreeSaplings(Block b) {
Material treeType = b.getType();
TreeType type = SAPLING_TO_BIG_TREE_TYPE.get(treeType);
Expand All @@ -161,7 +149,9 @@ protected boolean bigTreeSaplings(Block b) {
q.stream().map(b::getRelative).forEach(c -> c.setType(Material.AIR));
// Get the tree planting location
Location l = b.getRelative(q.get(0)).getLocation();
if (b.getWorld().generateTree(l, RAND, type, this::canSetBlock)) {
if (b.getWorld().generateTree(l, RAND, type,
bs -> Flags.TREES_GROWING_OUTSIDE_RANGE.isSetForWorld(bs.getWorld())
|| addon.getIslands().getProtectedIslandAt(bs.getLocation()).isPresent())) {
if (addon.getSettings().isEffectsEnabled()) {
showSparkles(b);
}
Expand Down

0 comments on commit 6d55f44

Please sign in to comment.