Merge branch 'development'

This commit is contained in:
Brianna 2021-02-19 17:31:07 -06:00
commit cfc53d5b72
9 changed files with 41 additions and 25 deletions

View File

@ -3,7 +3,7 @@
<parent>
<groupId>com.songoda</groupId>
<artifactId>UltimateTimber</artifactId>
<version>2.2.2</version>
<version>2.2.3</version>
<relativePath>../../</relativePath>
</parent>

View File

@ -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
*

BIN
UltimateTimber/Plugin/.DS_Store vendored Normal file

Binary file not shown.

View File

@ -3,7 +3,7 @@
<parent>
<groupId>com.songoda</groupId>
<artifactId>UltimateTimber</artifactId>
<version>2.2.2</version>
<version>2.2.3</version>
<relativePath>../../</relativePath>
</parent>

View File

@ -75,7 +75,6 @@ public class UltimateTimber extends SongodaPlugin {
this.treeDetectionManager = this.registerManager(TreeDetectionManager.class);
this.treeFallManager = this.registerManager(TreeFallManager.class);
// Load version adapter and managers
this.reloadConfig();
}

View File

@ -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);

View File

@ -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);

View File

@ -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

View File

@ -2,7 +2,7 @@
<groupId>com.songoda</groupId>
<artifactId>UltimateTimber</artifactId>
<version>2.2.2</version>
<version>2.2.3</version>
<modelVersion>4.0.0</modelVersion>
<packaging>pom</packaging>
@ -63,11 +63,6 @@
<outputDirectory>jars</outputDirectory>
<stripVersion>true</stripVersion>
<artifactItems>
<artifactItem>
<groupId>${project.groupId}</groupId>
<artifactId>LegacyAdapter</artifactId>
<version>${project.version}</version>
</artifactItem>
<artifactItem>
<groupId>${project.groupId}</groupId>
<artifactId>McMMO</artifactId>