mirror of
https://github.com/songoda/UltimateTimber.git
synced 2024-11-15 14:55:46 +01:00
Fixed and modified the way the max tree block setting worked.
This commit is contained in:
parent
76e3b1fc3b
commit
4d78edcb45
@ -1,26 +1,33 @@
|
||||
package com.songoda.ultimatetimber.tree;
|
||||
|
||||
import org.bukkit.block.Block;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class TreeBlockSet<BlockType> implements Collection {
|
||||
|
||||
private final ITreeBlock<BlockType> initialLogBlock;
|
||||
private final Set<ITreeBlock<BlockType>> logBlocks, leafBlocks;
|
||||
private List<ITreeBlock<BlockType>> logBlocks;
|
||||
private final List<ITreeBlock<BlockType>> leafBlocks;
|
||||
|
||||
public TreeBlockSet() {
|
||||
this.initialLogBlock = null;
|
||||
this.logBlocks = new HashSet<>();
|
||||
this.leafBlocks = new HashSet<>();
|
||||
this.logBlocks = new LinkedList<>();
|
||||
this.leafBlocks = new LinkedList<>();
|
||||
}
|
||||
|
||||
public TreeBlockSet(ITreeBlock<BlockType> initialLogBlock) {
|
||||
this.initialLogBlock = initialLogBlock;
|
||||
this.logBlocks = new HashSet<>();
|
||||
this.leafBlocks = new HashSet<>();
|
||||
this.logBlocks = new LinkedList<>();
|
||||
this.leafBlocks = new LinkedList<>();
|
||||
|
||||
if (initialLogBlock != null)
|
||||
this.logBlocks.add(initialLogBlock);
|
||||
@ -40,8 +47,8 @@ public class TreeBlockSet<BlockType> implements Collection {
|
||||
*
|
||||
* @return A Set of TreeBlocks
|
||||
*/
|
||||
public Set<ITreeBlock<BlockType>> getLogBlocks() {
|
||||
return Collections.unmodifiableSet(this.logBlocks);
|
||||
public List<ITreeBlock<BlockType>> getLogBlocks() {
|
||||
return Collections.unmodifiableList(this.logBlocks);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -49,8 +56,8 @@ public class TreeBlockSet<BlockType> implements Collection {
|
||||
*
|
||||
* @return A Set of TreeBlocks
|
||||
*/
|
||||
public Set<ITreeBlock<BlockType>> getLeafBlocks() {
|
||||
return Collections.unmodifiableSet(this.leafBlocks);
|
||||
public List<ITreeBlock<BlockType>> getLeafBlocks() {
|
||||
return Collections.unmodifiableList(this.leafBlocks);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -160,6 +167,21 @@ public class TreeBlockSet<BlockType> implements Collection {
|
||||
return removedAll;
|
||||
}
|
||||
|
||||
public void sortAndLimit(int max) {
|
||||
if (logBlocks.size() < max)
|
||||
return;
|
||||
|
||||
logBlocks = logBlocks.stream().sorted(Comparator.comparingInt(b -> b.getLocation().getBlockY()))
|
||||
.limit(max).collect(Collectors.toList());
|
||||
|
||||
int highest = logBlocks.get(logBlocks.size() - 1).getLocation().getBlockY();
|
||||
|
||||
if (logBlocks.size() >= max)
|
||||
for (ITreeBlock<BlockType> leafBlock : new LinkedList<>(leafBlocks))
|
||||
if (leafBlock.getLocation().getY() > highest)
|
||||
leafBlocks.remove(leafBlock);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes all tree blocks of a given type
|
||||
*
|
||||
|
@ -30,7 +30,7 @@ import java.util.Set;
|
||||
public class TreeAnimationManager extends Manager implements Listener, Runnable {
|
||||
|
||||
private final Set<TreeAnimation> activeAnimations;
|
||||
private int taskId;
|
||||
private final int taskId;
|
||||
|
||||
public TreeAnimationManager(UltimateTimber ultimateTimber) {
|
||||
super(ultimateTimber);
|
||||
|
@ -16,7 +16,7 @@ public class TreeDetectionManager extends Manager {
|
||||
|
||||
private TreeDefinitionManager treeDefinitionManager;
|
||||
private PlacedBlockManager placedBlockManager;
|
||||
private int maxLogBlocksAllowed, numLeavesRequiredForTree;
|
||||
private int numLeavesRequiredForTree;
|
||||
private boolean onlyBreakLogsUpwards, entireTreeBase, destroyLeaves;
|
||||
|
||||
public TreeDetectionManager(UltimateTimber ultimateTimber) {
|
||||
@ -50,7 +50,6 @@ public class TreeDetectionManager extends Manager {
|
||||
public void reload() {
|
||||
this.treeDefinitionManager = this.plugin.getTreeDefinitionManager();
|
||||
this.placedBlockManager = this.plugin.getPlacedBlockManager();
|
||||
this.maxLogBlocksAllowed = ConfigurationManager.Setting.MAX_LOGS_PER_CHOP.getInt();
|
||||
this.numLeavesRequiredForTree = ConfigurationManager.Setting.LEAVES_REQUIRED_FOR_TREE.getInt();
|
||||
this.onlyBreakLogsUpwards = ConfigurationManager.Setting.ONLY_DETECT_LOGS_UPWARDS.getBoolean();
|
||||
this.entireTreeBase = ConfigurationManager.Setting.BREAK_ENTIRE_TREE_BASE.getBoolean();
|
||||
@ -154,9 +153,6 @@ public class TreeDetectionManager extends Manager {
|
||||
* @param startingBlockY The Y coordinate of the initial block
|
||||
*/
|
||||
private void recursiveBranchSearch(Set<TreeDefinition> treeDefinitions, List<Block> trunkBlocks, TreeBlockSet<Block> treeBlocks, Block block, int startingBlockY) {
|
||||
if (treeBlocks.size() > this.maxLogBlocksAllowed)
|
||||
return;
|
||||
|
||||
for (Vector offset : this.onlyBreakLogsUpwards ? this.VALID_BRANCH_OFFSETS : this.VALID_TRUNK_OFFSETS) {
|
||||
Block targetBlock = block.getRelative(offset.getBlockX(), offset.getBlockY(), offset.getBlockZ());
|
||||
TreeBlock treeBlock = new TreeBlock(targetBlock, TreeBlockType.LOG);
|
||||
|
@ -28,6 +28,8 @@ import java.util.stream.Collectors;
|
||||
|
||||
public class TreeFallManager extends Manager implements Listener {
|
||||
|
||||
private int maxLogBlocksAllowed;
|
||||
|
||||
public TreeFallManager(UltimateTimber ultimateTimber) {
|
||||
super(ultimateTimber);
|
||||
Bukkit.getPluginManager().registerEvents(this, ultimateTimber);
|
||||
@ -35,7 +37,7 @@ public class TreeFallManager extends Manager implements Listener {
|
||||
|
||||
@Override
|
||||
public void reload() {
|
||||
|
||||
this.maxLogBlocksAllowed = ConfigurationManager.Setting.MAX_LOGS_PER_CHOP.getInt();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -126,6 +128,8 @@ public class TreeFallManager extends Manager implements Listener {
|
||||
// Valid tree and meets all conditions past this point
|
||||
event.setCancelled(true);
|
||||
|
||||
detectedTree.getDetectedTreeBlocks().sortAndLimit(maxLogBlocksAllowed);
|
||||
|
||||
choppingManager.cooldownPlayer(player);
|
||||
|
||||
// Destroy initiated block if enabled
|
||||
|
Loading…
Reference in New Issue
Block a user