mirror of
https://github.com/songoda/UltimateTimber.git
synced 2025-02-03 05:11:20 +01:00
Merge branch 'development'
This commit is contained in:
commit
cfc53d5b72
@ -3,7 +3,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.songoda</groupId>
|
<groupId>com.songoda</groupId>
|
||||||
<artifactId>UltimateTimber</artifactId>
|
<artifactId>UltimateTimber</artifactId>
|
||||||
<version>2.2.2</version>
|
<version>2.2.3</version>
|
||||||
<relativePath>../../</relativePath>
|
<relativePath>../../</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
@ -1,26 +1,33 @@
|
|||||||
package com.songoda.ultimatetimber.tree;
|
package com.songoda.ultimatetimber.tree;
|
||||||
|
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.Comparator;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class TreeBlockSet<BlockType> implements Collection {
|
public class TreeBlockSet<BlockType> implements Collection {
|
||||||
|
|
||||||
private final ITreeBlock<BlockType> initialLogBlock;
|
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() {
|
public TreeBlockSet() {
|
||||||
this.initialLogBlock = null;
|
this.initialLogBlock = null;
|
||||||
this.logBlocks = new HashSet<>();
|
this.logBlocks = new LinkedList<>();
|
||||||
this.leafBlocks = new HashSet<>();
|
this.leafBlocks = new LinkedList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public TreeBlockSet(ITreeBlock<BlockType> initialLogBlock) {
|
public TreeBlockSet(ITreeBlock<BlockType> initialLogBlock) {
|
||||||
this.initialLogBlock = initialLogBlock;
|
this.initialLogBlock = initialLogBlock;
|
||||||
this.logBlocks = new HashSet<>();
|
this.logBlocks = new LinkedList<>();
|
||||||
this.leafBlocks = new HashSet<>();
|
this.leafBlocks = new LinkedList<>();
|
||||||
|
|
||||||
if (initialLogBlock != null)
|
if (initialLogBlock != null)
|
||||||
this.logBlocks.add(initialLogBlock);
|
this.logBlocks.add(initialLogBlock);
|
||||||
@ -40,8 +47,8 @@ public class TreeBlockSet<BlockType> implements Collection {
|
|||||||
*
|
*
|
||||||
* @return A Set of TreeBlocks
|
* @return A Set of TreeBlocks
|
||||||
*/
|
*/
|
||||||
public Set<ITreeBlock<BlockType>> getLogBlocks() {
|
public List<ITreeBlock<BlockType>> getLogBlocks() {
|
||||||
return Collections.unmodifiableSet(this.logBlocks);
|
return Collections.unmodifiableList(this.logBlocks);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -49,8 +56,8 @@ public class TreeBlockSet<BlockType> implements Collection {
|
|||||||
*
|
*
|
||||||
* @return A Set of TreeBlocks
|
* @return A Set of TreeBlocks
|
||||||
*/
|
*/
|
||||||
public Set<ITreeBlock<BlockType>> getLeafBlocks() {
|
public List<ITreeBlock<BlockType>> getLeafBlocks() {
|
||||||
return Collections.unmodifiableSet(this.leafBlocks);
|
return Collections.unmodifiableList(this.leafBlocks);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -160,6 +167,21 @@ public class TreeBlockSet<BlockType> implements Collection {
|
|||||||
return removedAll;
|
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
|
* Removes all tree blocks of a given type
|
||||||
*
|
*
|
||||||
|
BIN
UltimateTimber/Plugin/.DS_Store
vendored
Normal file
BIN
UltimateTimber/Plugin/.DS_Store
vendored
Normal file
Binary file not shown.
@ -3,7 +3,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.songoda</groupId>
|
<groupId>com.songoda</groupId>
|
||||||
<artifactId>UltimateTimber</artifactId>
|
<artifactId>UltimateTimber</artifactId>
|
||||||
<version>2.2.2</version>
|
<version>2.2.3</version>
|
||||||
<relativePath>../../</relativePath>
|
<relativePath>../../</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
@ -75,7 +75,6 @@ public class UltimateTimber extends SongodaPlugin {
|
|||||||
this.treeDetectionManager = this.registerManager(TreeDetectionManager.class);
|
this.treeDetectionManager = this.registerManager(TreeDetectionManager.class);
|
||||||
this.treeFallManager = this.registerManager(TreeFallManager.class);
|
this.treeFallManager = this.registerManager(TreeFallManager.class);
|
||||||
|
|
||||||
// Load version adapter and managers
|
|
||||||
this.reloadConfig();
|
this.reloadConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ import java.util.Set;
|
|||||||
public class TreeAnimationManager extends Manager implements Listener, Runnable {
|
public class TreeAnimationManager extends Manager implements Listener, Runnable {
|
||||||
|
|
||||||
private final Set<TreeAnimation> activeAnimations;
|
private final Set<TreeAnimation> activeAnimations;
|
||||||
private int taskId;
|
private final int taskId;
|
||||||
|
|
||||||
public TreeAnimationManager(UltimateTimber ultimateTimber) {
|
public TreeAnimationManager(UltimateTimber ultimateTimber) {
|
||||||
super(ultimateTimber);
|
super(ultimateTimber);
|
||||||
|
@ -16,7 +16,7 @@ public class TreeDetectionManager extends Manager {
|
|||||||
|
|
||||||
private TreeDefinitionManager treeDefinitionManager;
|
private TreeDefinitionManager treeDefinitionManager;
|
||||||
private PlacedBlockManager placedBlockManager;
|
private PlacedBlockManager placedBlockManager;
|
||||||
private int maxLogBlocksAllowed, numLeavesRequiredForTree;
|
private int numLeavesRequiredForTree;
|
||||||
private boolean onlyBreakLogsUpwards, entireTreeBase, destroyLeaves;
|
private boolean onlyBreakLogsUpwards, entireTreeBase, destroyLeaves;
|
||||||
|
|
||||||
public TreeDetectionManager(UltimateTimber ultimateTimber) {
|
public TreeDetectionManager(UltimateTimber ultimateTimber) {
|
||||||
@ -50,7 +50,6 @@ public class TreeDetectionManager extends Manager {
|
|||||||
public void reload() {
|
public void reload() {
|
||||||
this.treeDefinitionManager = this.plugin.getTreeDefinitionManager();
|
this.treeDefinitionManager = this.plugin.getTreeDefinitionManager();
|
||||||
this.placedBlockManager = this.plugin.getPlacedBlockManager();
|
this.placedBlockManager = this.plugin.getPlacedBlockManager();
|
||||||
this.maxLogBlocksAllowed = ConfigurationManager.Setting.MAX_LOGS_PER_CHOP.getInt();
|
|
||||||
this.numLeavesRequiredForTree = ConfigurationManager.Setting.LEAVES_REQUIRED_FOR_TREE.getInt();
|
this.numLeavesRequiredForTree = ConfigurationManager.Setting.LEAVES_REQUIRED_FOR_TREE.getInt();
|
||||||
this.onlyBreakLogsUpwards = ConfigurationManager.Setting.ONLY_DETECT_LOGS_UPWARDS.getBoolean();
|
this.onlyBreakLogsUpwards = ConfigurationManager.Setting.ONLY_DETECT_LOGS_UPWARDS.getBoolean();
|
||||||
this.entireTreeBase = ConfigurationManager.Setting.BREAK_ENTIRE_TREE_BASE.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
|
* @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) {
|
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) {
|
for (Vector offset : this.onlyBreakLogsUpwards ? this.VALID_BRANCH_OFFSETS : this.VALID_TRUNK_OFFSETS) {
|
||||||
Block targetBlock = block.getRelative(offset.getBlockX(), offset.getBlockY(), offset.getBlockZ());
|
Block targetBlock = block.getRelative(offset.getBlockX(), offset.getBlockY(), offset.getBlockZ());
|
||||||
TreeBlock treeBlock = new TreeBlock(targetBlock, TreeBlockType.LOG);
|
TreeBlock treeBlock = new TreeBlock(targetBlock, TreeBlockType.LOG);
|
||||||
|
@ -28,6 +28,8 @@ import java.util.stream.Collectors;
|
|||||||
|
|
||||||
public class TreeFallManager extends Manager implements Listener {
|
public class TreeFallManager extends Manager implements Listener {
|
||||||
|
|
||||||
|
private int maxLogBlocksAllowed;
|
||||||
|
|
||||||
public TreeFallManager(UltimateTimber ultimateTimber) {
|
public TreeFallManager(UltimateTimber ultimateTimber) {
|
||||||
super(ultimateTimber);
|
super(ultimateTimber);
|
||||||
Bukkit.getPluginManager().registerEvents(this, ultimateTimber);
|
Bukkit.getPluginManager().registerEvents(this, ultimateTimber);
|
||||||
@ -35,7 +37,7 @@ public class TreeFallManager extends Manager implements Listener {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void reload() {
|
public void reload() {
|
||||||
|
this.maxLogBlocksAllowed = ConfigurationManager.Setting.MAX_LOGS_PER_CHOP.getInt();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -126,6 +128,8 @@ public class TreeFallManager extends Manager implements Listener {
|
|||||||
// Valid tree and meets all conditions past this point
|
// Valid tree and meets all conditions past this point
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
|
|
||||||
|
detectedTree.getDetectedTreeBlocks().sortAndLimit(maxLogBlocksAllowed);
|
||||||
|
|
||||||
choppingManager.cooldownPlayer(player);
|
choppingManager.cooldownPlayer(player);
|
||||||
|
|
||||||
// Destroy initiated block if enabled
|
// Destroy initiated block if enabled
|
||||||
|
7
pom.xml
7
pom.xml
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
<groupId>com.songoda</groupId>
|
<groupId>com.songoda</groupId>
|
||||||
<artifactId>UltimateTimber</artifactId>
|
<artifactId>UltimateTimber</artifactId>
|
||||||
<version>2.2.2</version>
|
<version>2.2.3</version>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
|
|
||||||
@ -63,11 +63,6 @@
|
|||||||
<outputDirectory>jars</outputDirectory>
|
<outputDirectory>jars</outputDirectory>
|
||||||
<stripVersion>true</stripVersion>
|
<stripVersion>true</stripVersion>
|
||||||
<artifactItems>
|
<artifactItems>
|
||||||
<artifactItem>
|
|
||||||
<groupId>${project.groupId}</groupId>
|
|
||||||
<artifactId>LegacyAdapter</artifactId>
|
|
||||||
<version>${project.version}</version>
|
|
||||||
</artifactItem>
|
|
||||||
<artifactItem>
|
<artifactItem>
|
||||||
<groupId>${project.groupId}</groupId>
|
<groupId>${project.groupId}</groupId>
|
||||||
<artifactId>McMMO</artifactId>
|
<artifactId>McMMO</artifactId>
|
||||||
|
Loading…
Reference in New Issue
Block a user