mirror of
https://github.com/songoda/UltimateTimber.git
synced 2024-09-27 13:22:39 +02:00
Heavy code style changes and slight refactoring
This commit is contained in:
parent
ea940d573d
commit
b1cb59b7e8
@ -2,6 +2,7 @@ package com.songoda.ultimatetimber;
|
|||||||
|
|
||||||
import com.songoda.core.SongodaCore;
|
import com.songoda.core.SongodaCore;
|
||||||
import com.songoda.core.SongodaPlugin;
|
import com.songoda.core.SongodaPlugin;
|
||||||
|
import com.songoda.core.commands.CommandManager;
|
||||||
import com.songoda.core.compatibility.CompatibleMaterial;
|
import com.songoda.core.compatibility.CompatibleMaterial;
|
||||||
import com.songoda.core.configuration.Config;
|
import com.songoda.core.configuration.Config;
|
||||||
import com.songoda.core.hooks.LogManager;
|
import com.songoda.core.hooks.LogManager;
|
||||||
@ -18,19 +19,16 @@ import com.songoda.ultimatetimber.manager.TreeDefinitionManager;
|
|||||||
import com.songoda.ultimatetimber.manager.TreeDetectionManager;
|
import com.songoda.ultimatetimber.manager.TreeDetectionManager;
|
||||||
import com.songoda.ultimatetimber.manager.TreeFallManager;
|
import com.songoda.ultimatetimber.manager.TreeFallManager;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class UltimateTimber extends SongodaPlugin {
|
public class UltimateTimber extends SongodaPlugin {
|
||||||
|
private final Set<Manager> managers = new HashSet<>();
|
||||||
private static UltimateTimber INSTANCE;
|
|
||||||
|
|
||||||
private Set<Manager> managers;
|
|
||||||
|
|
||||||
private ChoppingManager choppingManager;
|
private ChoppingManager choppingManager;
|
||||||
private ConfigurationManager configurationManager;
|
private ConfigurationManager configurationManager;
|
||||||
private com.songoda.core.commands.CommandManager commandManager;
|
|
||||||
private PlacedBlockManager placedBlockManager;
|
private PlacedBlockManager placedBlockManager;
|
||||||
private SaplingManager saplingManager;
|
private SaplingManager saplingManager;
|
||||||
private TreeAnimationManager treeAnimationManager;
|
private TreeAnimationManager treeAnimationManager;
|
||||||
@ -38,13 +36,16 @@ public class UltimateTimber extends SongodaPlugin {
|
|||||||
private TreeDetectionManager treeDetectionManager;
|
private TreeDetectionManager treeDetectionManager;
|
||||||
private TreeFallManager treeFallManager;
|
private TreeFallManager treeFallManager;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated Use {@link #getPlugin(Class)} instead
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
public static UltimateTimber getInstance() {
|
public static UltimateTimber getInstance() {
|
||||||
return INSTANCE;
|
return getPlugin(UltimateTimber.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPluginLoad() {
|
public void onPluginLoad() {
|
||||||
INSTANCE = this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -56,8 +57,8 @@ public class UltimateTimber extends SongodaPlugin {
|
|||||||
LogManager.load();
|
LogManager.load();
|
||||||
|
|
||||||
// Setup plugin commands
|
// Setup plugin commands
|
||||||
this.commandManager = new com.songoda.core.commands.CommandManager(this);
|
CommandManager commandManager = new CommandManager(this);
|
||||||
this.commandManager.addMainCommand("ut")
|
commandManager.addMainCommand("ut")
|
||||||
.addSubCommands(
|
.addSubCommands(
|
||||||
new CommandReload(this),
|
new CommandReload(this),
|
||||||
new CommandToggle(this),
|
new CommandToggle(this),
|
||||||
@ -65,7 +66,6 @@ public class UltimateTimber extends SongodaPlugin {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Register managers
|
// Register managers
|
||||||
this.managers = new HashSet<>();
|
|
||||||
this.choppingManager = this.registerManager(ChoppingManager.class);
|
this.choppingManager = this.registerManager(ChoppingManager.class);
|
||||||
this.configurationManager = new ConfigurationManager(this);
|
this.configurationManager = new ConfigurationManager(this);
|
||||||
this.placedBlockManager = this.registerManager(PlacedBlockManager.class);
|
this.placedBlockManager = this.registerManager(PlacedBlockManager.class);
|
||||||
@ -80,7 +80,8 @@ public class UltimateTimber extends SongodaPlugin {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPluginDisable() {
|
public void onPluginDisable() {
|
||||||
this.disable();
|
this.configurationManager.disable();
|
||||||
|
this.managers.forEach(Manager::disable);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -96,15 +97,7 @@ public class UltimateTimber extends SongodaPlugin {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Config> getExtraConfig() {
|
public List<Config> getExtraConfig() {
|
||||||
return null;
|
return Collections.emptyList();
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Disables most of the plugin
|
|
||||||
*/
|
|
||||||
public void disable() {
|
|
||||||
this.configurationManager.disable();
|
|
||||||
this.managers.forEach(Manager::disable);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -125,76 +118,35 @@ public class UltimateTimber extends SongodaPlugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the chopping manager
|
|
||||||
*
|
|
||||||
* @return The ChoppingManager instance
|
|
||||||
*/
|
|
||||||
public ChoppingManager getChoppingManager() {
|
public ChoppingManager getChoppingManager() {
|
||||||
return this.choppingManager;
|
return this.choppingManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the configuration manager
|
|
||||||
*
|
|
||||||
* @return The ConfigurationManager instance
|
|
||||||
*/
|
|
||||||
public ConfigurationManager getConfigurationManager() {
|
public ConfigurationManager getConfigurationManager() {
|
||||||
return this.configurationManager;
|
return this.configurationManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the placed block manager
|
|
||||||
*
|
|
||||||
* @return The PlacedBlockManager instance
|
|
||||||
*/
|
|
||||||
public PlacedBlockManager getPlacedBlockManager() {
|
public PlacedBlockManager getPlacedBlockManager() {
|
||||||
return this.placedBlockManager;
|
return this.placedBlockManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the sapling manager
|
|
||||||
*
|
|
||||||
* @return The SaplingManager instance
|
|
||||||
*/
|
|
||||||
public SaplingManager getSaplingManager() {
|
public SaplingManager getSaplingManager() {
|
||||||
return this.saplingManager;
|
return this.saplingManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the tree animation manager
|
|
||||||
*
|
|
||||||
* @return The TreeAnimationManager instance
|
|
||||||
*/
|
|
||||||
public TreeAnimationManager getTreeAnimationManager() {
|
public TreeAnimationManager getTreeAnimationManager() {
|
||||||
return this.treeAnimationManager;
|
return this.treeAnimationManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the tree definition manager
|
|
||||||
*
|
|
||||||
* @return The TreeDefinitionManager instance
|
|
||||||
*/
|
|
||||||
public TreeDefinitionManager getTreeDefinitionManager() {
|
public TreeDefinitionManager getTreeDefinitionManager() {
|
||||||
return this.treeDefinitionManager;
|
return this.treeDefinitionManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the tree detection manager
|
|
||||||
*
|
|
||||||
* @return The TreeDetectionManager instance
|
|
||||||
*/
|
|
||||||
public TreeDetectionManager getTreeDetectionManager() {
|
public TreeDetectionManager getTreeDetectionManager() {
|
||||||
return this.treeDetectionManager;
|
return this.treeDetectionManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the tree fall manager
|
|
||||||
*
|
|
||||||
* @return The TreeFallManager instance
|
|
||||||
*/
|
|
||||||
public TreeFallManager getTreeFallManager() {
|
public TreeFallManager getTreeFallManager() {
|
||||||
return this.treeFallManager;
|
return this.treeFallManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,6 @@ import com.songoda.ultimatetimber.tree.ITreeBlock;
|
|||||||
import com.songoda.ultimatetimber.tree.TreeBlock;
|
import com.songoda.ultimatetimber.tree.TreeBlock;
|
||||||
import com.songoda.ultimatetimber.tree.TreeBlockSet;
|
import com.songoda.ultimatetimber.tree.TreeBlockSet;
|
||||||
import com.songoda.ultimatetimber.utils.BlockUtils;
|
import com.songoda.ultimatetimber.utils.BlockUtils;
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
@ -19,7 +18,6 @@ import org.bukkit.entity.Player;
|
|||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
public abstract class TreeAnimation {
|
public abstract class TreeAnimation {
|
||||||
|
|
||||||
protected final TreeAnimationType treeAnimationType;
|
protected final TreeAnimationType treeAnimationType;
|
||||||
protected final DetectedTree detectedTree;
|
protected final DetectedTree detectedTree;
|
||||||
protected final Player player;
|
protected final Player player;
|
||||||
|
@ -24,7 +24,6 @@ import java.util.Comparator;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class TreeAnimationCrumble extends TreeAnimation {
|
public class TreeAnimationCrumble extends TreeAnimation {
|
||||||
|
|
||||||
public TreeAnimationCrumble(DetectedTree detectedTree, Player player) {
|
public TreeAnimationCrumble(DetectedTree detectedTree, Player player) {
|
||||||
super(TreeAnimationType.CRUMBLE, detectedTree, player);
|
super(TreeAnimationType.CRUMBLE, detectedTree, player);
|
||||||
}
|
}
|
||||||
@ -64,30 +63,36 @@ public class TreeAnimationCrumble extends TreeAnimation {
|
|||||||
List<ITreeBlock<Block>> partition = treeBlocks.get(0);
|
List<ITreeBlock<Block>> partition = treeBlocks.get(0);
|
||||||
for (int i = 0; i < 3 && !partition.isEmpty(); i++) {
|
for (int i = 0; i < 3 && !partition.isEmpty(); i++) {
|
||||||
ITreeBlock<Block> treeBlock = partition.remove(0);
|
ITreeBlock<Block> treeBlock = partition.remove(0);
|
||||||
if (treeBlock.getTreeBlockType().equals(TreeBlockType.LOG)) {
|
if (treeBlock.getTreeBlockType() == TreeBlockType.LOG) {
|
||||||
if (td.getLogMaterial().stream().noneMatch(x -> x.equals(CompatibleMaterial.getMaterial(treeBlock.getBlock()))))
|
if (td.getLogMaterial().stream().noneMatch(x -> x == CompatibleMaterial.getMaterial(treeBlock.getBlock()))) {
|
||||||
continue;
|
continue;
|
||||||
} else if (treeBlock.getTreeBlockType().equals(TreeBlockType.LEAF)) {
|
}
|
||||||
if (td.getLeafMaterial().stream().noneMatch(x -> x.equals(CompatibleMaterial.getMaterial(treeBlock.getBlock()))))
|
} else if (treeBlock.getTreeBlockType() == TreeBlockType.LEAF) {
|
||||||
|
if (td.getLeafMaterial().stream().noneMatch(x -> x == CompatibleMaterial.getMaterial(treeBlock.getBlock()))) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
FallingTreeBlock fallingTreeBlock = TreeAnimationCrumble.this.convertToFallingBlock((TreeBlock) treeBlock);
|
FallingTreeBlock fallingTreeBlock = TreeAnimationCrumble.this.convertToFallingBlock((TreeBlock) treeBlock);
|
||||||
if (fallingTreeBlock == null)
|
if (fallingTreeBlock == null) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
BlockUtils.toggleGravityFallingBlock(fallingTreeBlock.getBlock(), true);
|
BlockUtils.toggleGravityFallingBlock(fallingTreeBlock.getBlock(), true);
|
||||||
fallingTreeBlock.getBlock().setVelocity(Vector.getRandom().setY(0).subtract(new Vector(0.5, 0, 0.5)).multiply(0.15));
|
fallingTreeBlock.getBlock().setVelocity(Vector.getRandom().setY(0).subtract(new Vector(0.5, 0, 0.5)).multiply(0.15));
|
||||||
TreeAnimationCrumble.this.fallingTreeBlocks.add(fallingTreeBlock);
|
TreeAnimationCrumble.this.fallingTreeBlocks.add(fallingTreeBlock);
|
||||||
|
|
||||||
if (TreeAnimationCrumble.this.fallingTreeBlocks == null)
|
if (TreeAnimationCrumble.this.fallingTreeBlocks == null) {
|
||||||
TreeAnimationCrumble.this.fallingTreeBlocks = new TreeBlockSet<>(fallingTreeBlock);
|
TreeAnimationCrumble.this.fallingTreeBlocks = new TreeBlockSet<>(fallingTreeBlock);
|
||||||
|
}
|
||||||
|
|
||||||
if (useCustomSound)
|
if (useCustomSound) {
|
||||||
SoundUtils.playLandingSound(treeBlock);
|
SoundUtils.playLandingSound(treeBlock);
|
||||||
if (useCustomParticles)
|
}
|
||||||
|
if (useCustomParticles) {
|
||||||
ParticleUtils.playFallingParticles(treeBlock);
|
ParticleUtils.playFallingParticles(treeBlock);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (partition.isEmpty()) {
|
if (partition.isEmpty()) {
|
||||||
treeBlocks.remove(0);
|
treeBlocks.remove(0);
|
||||||
@ -102,4 +107,3 @@ public class TreeAnimationCrumble extends TreeAnimation {
|
|||||||
}.runTaskTimer(ultimateTimber, 0, 1);
|
}.runTaskTimer(ultimateTimber, 0, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,7 +23,6 @@ import java.util.Comparator;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class TreeAnimationDisintegrate extends TreeAnimation {
|
public class TreeAnimationDisintegrate extends TreeAnimation {
|
||||||
|
|
||||||
public TreeAnimationDisintegrate(DetectedTree detectedTree, Player player) {
|
public TreeAnimationDisintegrate(DetectedTree detectedTree, Player player) {
|
||||||
super(TreeAnimationType.DISINTEGRATE, detectedTree, player);
|
super(TreeAnimationType.DISINTEGRATE, detectedTree, player);
|
||||||
}
|
}
|
||||||
@ -71,20 +70,24 @@ public class TreeAnimationDisintegrate extends TreeAnimation {
|
|||||||
|
|
||||||
if (!toDestroy.isEmpty()) {
|
if (!toDestroy.isEmpty()) {
|
||||||
ITreeBlock<Block> first = toDestroy.get(0);
|
ITreeBlock<Block> first = toDestroy.get(0);
|
||||||
if (useCustomSound)
|
if (useCustomSound) {
|
||||||
SoundUtils.playLandingSound(first);
|
SoundUtils.playLandingSound(first);
|
||||||
|
|
||||||
for (ITreeBlock<Block> treeBlock : toDestroy) {
|
|
||||||
if (treeBlock.getTreeBlockType().equals(TreeBlockType.LOG)) {
|
|
||||||
if (td.getLogMaterial().stream().noneMatch(x -> x.equals(CompatibleMaterial.getMaterial(treeBlock.getBlock()))))
|
|
||||||
continue;
|
|
||||||
} else if (treeBlock.getTreeBlockType().equals(TreeBlockType.LEAF)) {
|
|
||||||
if (td.getLeafMaterial().stream().noneMatch(x -> x.equals(CompatibleMaterial.getMaterial(treeBlock.getBlock()))))
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (useCustomParticles)
|
for (ITreeBlock<Block> treeBlock : toDestroy) {
|
||||||
|
if (treeBlock.getTreeBlockType() == TreeBlockType.LOG) {
|
||||||
|
if (td.getLogMaterial().stream().noneMatch(x -> x == CompatibleMaterial.getMaterial(treeBlock.getBlock()))) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
} else if (treeBlock.getTreeBlockType() == TreeBlockType.LEAF) {
|
||||||
|
if (td.getLeafMaterial().stream().noneMatch(x -> x == CompatibleMaterial.getMaterial(treeBlock.getBlock()))) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (useCustomParticles) {
|
||||||
ParticleUtils.playFallingParticles(treeBlock);
|
ParticleUtils.playFallingParticles(treeBlock);
|
||||||
|
}
|
||||||
treeDefinitionManager.dropTreeLoot(td, treeBlock, p, hst, false);
|
treeDefinitionManager.dropTreeLoot(td, treeBlock, p, hst, false);
|
||||||
TreeAnimationDisintegrate.this.replaceBlock((TreeBlock) treeBlock);
|
TreeAnimationDisintegrate.this.replaceBlock((TreeBlock) treeBlock);
|
||||||
}
|
}
|
||||||
@ -95,5 +98,4 @@ public class TreeAnimationDisintegrate extends TreeAnimation {
|
|||||||
}
|
}
|
||||||
}.runTaskTimer(ultimateTimber, 0, 1);
|
}.runTaskTimer(ultimateTimber, 0, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,6 @@ import org.bukkit.scheduler.BukkitRunnable;
|
|||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
public class TreeAnimationFancy extends TreeAnimation {
|
public class TreeAnimationFancy extends TreeAnimation {
|
||||||
|
|
||||||
public TreeAnimationFancy(DetectedTree detectedTree, Player player) {
|
public TreeAnimationFancy(DetectedTree detectedTree, Player player) {
|
||||||
super(TreeAnimationType.FANCY, detectedTree, player);
|
super(TreeAnimationType.FANCY, detectedTree, player);
|
||||||
}
|
}
|
||||||
@ -33,22 +32,25 @@ public class TreeAnimationFancy extends TreeAnimation {
|
|||||||
ITreeBlock<Block> initialTreeBlock = this.detectedTree.getDetectedTreeBlocks().getInitialLogBlock();
|
ITreeBlock<Block> initialTreeBlock = this.detectedTree.getDetectedTreeBlocks().getInitialLogBlock();
|
||||||
FallingTreeBlock initialFallingBlock = this.convertToFallingBlock((TreeBlock) this.detectedTree.getDetectedTreeBlocks().getInitialLogBlock());
|
FallingTreeBlock initialFallingBlock = this.convertToFallingBlock((TreeBlock) this.detectedTree.getDetectedTreeBlocks().getInitialLogBlock());
|
||||||
|
|
||||||
if (useCustomSound)
|
if (useCustomSound) {
|
||||||
SoundUtils.playFallingSound(initialTreeBlock);
|
SoundUtils.playFallingSound(initialTreeBlock);
|
||||||
|
}
|
||||||
|
|
||||||
Vector velocityVector = initialTreeBlock.getLocation().clone().subtract(this.player.getLocation().clone()).toVector().normalize().setY(0);
|
Vector velocityVector = initialTreeBlock.getLocation().clone().subtract(this.player.getLocation().clone()).toVector().normalize().setY(0);
|
||||||
|
|
||||||
this.fallingTreeBlocks = new TreeBlockSet<>(initialFallingBlock);
|
this.fallingTreeBlocks = new TreeBlockSet<>(initialFallingBlock);
|
||||||
for (ITreeBlock<Block> treeBlock : this.detectedTree.getDetectedTreeBlocks().getAllTreeBlocks()) {
|
for (ITreeBlock<Block> treeBlock : this.detectedTree.getDetectedTreeBlocks().getAllTreeBlocks()) {
|
||||||
FallingTreeBlock fallingTreeBlock = this.convertToFallingBlock((TreeBlock) treeBlock);
|
FallingTreeBlock fallingTreeBlock = this.convertToFallingBlock((TreeBlock) treeBlock);
|
||||||
if (fallingTreeBlock == null)
|
if (fallingTreeBlock == null) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
FallingBlock fallingBlock = fallingTreeBlock.getBlock();
|
FallingBlock fallingBlock = fallingTreeBlock.getBlock();
|
||||||
this.fallingTreeBlocks.add(fallingTreeBlock);
|
this.fallingTreeBlocks.add(fallingTreeBlock);
|
||||||
|
|
||||||
if (useCustomParticles)
|
if (useCustomParticles) {
|
||||||
ParticleUtils.playFallingParticles(treeBlock);
|
ParticleUtils.playFallingParticles(treeBlock);
|
||||||
|
}
|
||||||
|
|
||||||
double multiplier = (treeBlock.getLocation().getY() - this.player.getLocation().getY()) * 0.05;
|
double multiplier = (treeBlock.getLocation().getY() - this.player.getLocation().getY()) * 0.05;
|
||||||
fallingBlock.setVelocity(velocityVector.clone().multiply(multiplier));
|
fallingBlock.setVelocity(velocityVector.clone().multiply(multiplier));
|
||||||
@ -83,13 +85,13 @@ public class TreeAnimationFancy extends TreeAnimation {
|
|||||||
|
|
||||||
if (this.timer > 4 * 20) {
|
if (this.timer > 4 * 20) {
|
||||||
TreeAnimationManager treeAnimationManager = ultimateTimber.getTreeAnimationManager();
|
TreeAnimationManager treeAnimationManager = ultimateTimber.getTreeAnimationManager();
|
||||||
for (ITreeBlock<FallingBlock> fallingTreeBlock : TreeAnimationFancy.this.fallingTreeBlocks.getAllTreeBlocks())
|
for (ITreeBlock<FallingBlock> fallingTreeBlock : TreeAnimationFancy.this.fallingTreeBlocks.getAllTreeBlocks()) {
|
||||||
treeAnimationManager.runFallingBlockImpact(TreeAnimationFancy.this, fallingTreeBlock);
|
treeAnimationManager.runFallingBlockImpact(TreeAnimationFancy.this, fallingTreeBlock);
|
||||||
|
}
|
||||||
whenFinished.run();
|
whenFinished.run();
|
||||||
this.cancel();
|
this.cancel();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}.runTaskTimer(ultimateTimber, 20L, 1L);
|
}.runTaskTimer(ultimateTimber, 20L, 1L);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,6 @@ import org.bukkit.block.Block;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
public class TreeAnimationNone extends TreeAnimation {
|
public class TreeAnimationNone extends TreeAnimation {
|
||||||
|
|
||||||
public TreeAnimationNone(DetectedTree detectedTree, Player player) {
|
public TreeAnimationNone(DetectedTree detectedTree, Player player) {
|
||||||
super(TreeAnimationType.NONE, detectedTree, player);
|
super(TreeAnimationType.NONE, detectedTree, player);
|
||||||
}
|
}
|
||||||
@ -35,5 +34,4 @@ public class TreeAnimationNone extends TreeAnimation {
|
|||||||
|
|
||||||
whenFinished.run();
|
whenFinished.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -4,10 +4,7 @@ package com.songoda.ultimatetimber.animation;
|
|||||||
* The types of tree animations that are available
|
* The types of tree animations that are available
|
||||||
*/
|
*/
|
||||||
public enum TreeAnimationType {
|
public enum TreeAnimationType {
|
||||||
FANCY,
|
FANCY, DISINTEGRATE, CRUMBLE, NONE;
|
||||||
DISINTEGRATE,
|
|
||||||
CRUMBLE,
|
|
||||||
NONE;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets a TreeAnimationType from a given string
|
* Gets a TreeAnimationType from a given string
|
||||||
@ -16,9 +13,12 @@ public enum TreeAnimationType {
|
|||||||
* @return The TreeAnimationType, returns FANCY if the string is an invalid type
|
* @return The TreeAnimationType, returns FANCY if the string is an invalid type
|
||||||
*/
|
*/
|
||||||
public static TreeAnimationType fromString(String string) {
|
public static TreeAnimationType fromString(String string) {
|
||||||
for (TreeAnimationType value : values())
|
for (TreeAnimationType value : values()) {
|
||||||
if (value.name().equalsIgnoreCase(string))
|
if (value.name().equalsIgnoreCase(string)) {
|
||||||
return value;
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return TreeAnimationType.FANCY;
|
return TreeAnimationType.FANCY;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,6 @@ import org.bukkit.inventory.ItemStack;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class CommandGiveAxe extends AbstractCommand {
|
public class CommandGiveAxe extends AbstractCommand {
|
||||||
|
|
||||||
private final UltimateTimber plugin;
|
private final UltimateTimber plugin;
|
||||||
|
|
||||||
public CommandGiveAxe(UltimateTimber plugin) {
|
public CommandGiveAxe(UltimateTimber plugin) {
|
||||||
@ -21,43 +20,44 @@ public class CommandGiveAxe extends AbstractCommand {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ReturnType runCommand(CommandSender sender, String... args) {
|
protected ReturnType runCommand(CommandSender sender, String... args) {
|
||||||
|
if (args.length < 1) {
|
||||||
if (args.length < 1)
|
|
||||||
return ReturnType.SYNTAX_ERROR;
|
return ReturnType.SYNTAX_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
Player player = Bukkit.getPlayer(args[0]);
|
Player player = Bukkit.getPlayer(args[0]);
|
||||||
if (player == null) {
|
if (player == null) {
|
||||||
if (args[0].trim().equalsIgnoreCase("me")) {
|
if (args[0].trim().equalsIgnoreCase("me")) {
|
||||||
if (!(sender instanceof Player))
|
if (!(sender instanceof Player)) {
|
||||||
return ReturnType.NEEDS_PLAYER;
|
return ReturnType.NEEDS_PLAYER;
|
||||||
|
}
|
||||||
player = (Player) sender;
|
player = (Player) sender;
|
||||||
} else {
|
} else {
|
||||||
plugin.getLocale().getMessageOrDefault("command.give.not-a-player", "&cNot a player.")
|
this.plugin.getLocale().getMessageOrDefault("command.give.not-a-player", "&cNot a player.")
|
||||||
.sendPrefixedMessage(sender);
|
.sendPrefixedMessage(sender);
|
||||||
return ReturnType.FAILURE;
|
return ReturnType.FAILURE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ItemStack axe = plugin.getTreeDefinitionManager().getRequiredAxe();
|
ItemStack axe = this.plugin.getTreeDefinitionManager().getRequiredAxe();
|
||||||
|
|
||||||
if (axe == null) {
|
if (axe == null) {
|
||||||
plugin.getLocale().getMessageOrDefault("command.give.no-axe", "&cThe axe could not be loaded.")
|
this.plugin.getLocale().getMessageOrDefault("command.give.no-axe", "&cThe axe could not be loaded.")
|
||||||
.sendPrefixedMessage(sender);
|
.sendPrefixedMessage(sender);
|
||||||
return ReturnType.FAILURE;
|
return ReturnType.FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
player.getInventory().addItem(axe);
|
player.getInventory().addItem(axe);
|
||||||
plugin.getLocale().getMessageOrDefault("command.give.given", "&fAxe given to &a%player%")
|
this.plugin.getLocale().getMessageOrDefault("command.give.given", "&fAxe given to &a%player%")
|
||||||
.processPlaceholder("player", player.getName())
|
.processPlaceholder("player", player.getName())
|
||||||
.sendPrefixedMessage(sender);
|
.sendPrefixedMessage(sender);
|
||||||
return ReturnType.SUCCESS;
|
return ReturnType.SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected List<String> onTab(CommandSender commandSender, String... args) {
|
protected List<String> onTab(CommandSender sender, String... args) {
|
||||||
List<String> suggestions = null;
|
List<String> suggestions = null;
|
||||||
if (args.length == 1) {
|
if (args.length == 1) {
|
||||||
suggestions = PlayerUtils.getVisiblePlayerNames(commandSender, args[0]);
|
suggestions = PlayerUtils.getVisiblePlayerNames(sender, args[0]);
|
||||||
suggestions.add("me");
|
suggestions.add("me");
|
||||||
}
|
}
|
||||||
return suggestions;
|
return suggestions;
|
||||||
|
@ -7,7 +7,6 @@ import org.bukkit.command.CommandSender;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class CommandReload extends AbstractCommand {
|
public class CommandReload extends AbstractCommand {
|
||||||
|
|
||||||
private final UltimateTimber plugin;
|
private final UltimateTimber plugin;
|
||||||
|
|
||||||
public CommandReload(UltimateTimber plugin) {
|
public CommandReload(UltimateTimber plugin) {
|
||||||
@ -17,8 +16,8 @@ public class CommandReload extends AbstractCommand {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ReturnType runCommand(CommandSender sender, String... args) {
|
protected ReturnType runCommand(CommandSender sender, String... args) {
|
||||||
plugin.reloadConfig();
|
this.plugin.reloadConfig();
|
||||||
plugin.getLocale().getMessage("command.reload.reloaded").sendPrefixedMessage(sender);
|
this.plugin.getLocale().getMessage("command.reload.reloaded").sendPrefixedMessage(sender);
|
||||||
return ReturnType.SUCCESS;
|
return ReturnType.SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -39,7 +38,6 @@ public class CommandReload extends AbstractCommand {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getDescription() {
|
public String getDescription() {
|
||||||
return plugin.getLocale().getMessage("command.reload.description").getMessage();
|
return this.plugin.getLocale().getMessage("command.reload.description").getMessage();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,6 @@ import org.bukkit.entity.Player;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class CommandToggle extends AbstractCommand {
|
public class CommandToggle extends AbstractCommand {
|
||||||
|
|
||||||
private final UltimateTimber plugin;
|
private final UltimateTimber plugin;
|
||||||
|
|
||||||
public CommandToggle(UltimateTimber plugin) {
|
public CommandToggle(UltimateTimber plugin) {
|
||||||
@ -18,10 +17,10 @@ public class CommandToggle extends AbstractCommand {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ReturnType runCommand(CommandSender sender, String... args) {
|
protected ReturnType runCommand(CommandSender sender, String... args) {
|
||||||
if (UltimateTimber.getInstance().getChoppingManager().togglePlayer((Player) sender)) {
|
if (this.plugin.getChoppingManager().togglePlayer((Player) sender)) {
|
||||||
plugin.getLocale().getMessage("command.toggle.enabled").sendPrefixedMessage(sender);
|
this.plugin.getLocale().getMessage("command.toggle.enabled").sendPrefixedMessage(sender);
|
||||||
} else {
|
} else {
|
||||||
plugin.getLocale().getMessage("command.toggle.disabled").sendPrefixedMessage(sender);
|
this.plugin.getLocale().getMessage("command.toggle.disabled").sendPrefixedMessage(sender);
|
||||||
}
|
}
|
||||||
return ReturnType.SUCCESS;
|
return ReturnType.SUCCESS;
|
||||||
}
|
}
|
||||||
@ -43,7 +42,7 @@ public class CommandToggle extends AbstractCommand {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getDescription() {
|
public String getDescription() {
|
||||||
return plugin.getLocale().getMessage("command.toggle.description").getMessage();
|
return this.plugin.getLocale().getMessage("command.toggle.description").getMessage();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -8,11 +8,10 @@ import org.bukkit.event.player.PlayerEvent;
|
|||||||
* Abstract tree event containing tree's blocks and broke block
|
* Abstract tree event containing tree's blocks and broke block
|
||||||
*/
|
*/
|
||||||
public abstract class TreeEvent extends PlayerEvent {
|
public abstract class TreeEvent extends PlayerEvent {
|
||||||
|
|
||||||
protected final DetectedTree detectedTree;
|
protected final DetectedTree detectedTree;
|
||||||
|
|
||||||
public TreeEvent(Player player, DetectedTree detectedTree) {
|
public TreeEvent(Player who, DetectedTree detectedTree) {
|
||||||
super(player);
|
super(who);
|
||||||
this.detectedTree = detectedTree;
|
this.detectedTree = detectedTree;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -24,5 +23,4 @@ public abstract class TreeEvent extends PlayerEvent {
|
|||||||
public DetectedTree getDetectedTree() {
|
public DetectedTree getDetectedTree() {
|
||||||
return this.detectedTree;
|
return this.detectedTree;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -9,22 +9,18 @@ import org.bukkit.event.HandlerList;
|
|||||||
* Called when a tree will fall
|
* Called when a tree will fall
|
||||||
*/
|
*/
|
||||||
public class TreeFallEvent extends TreeEvent implements Cancellable {
|
public class TreeFallEvent extends TreeEvent implements Cancellable {
|
||||||
|
private static final HandlerList HANDLERS = new HandlerList();
|
||||||
|
|
||||||
private boolean cancelled = false;
|
private boolean cancelled = false;
|
||||||
|
|
||||||
public TreeFallEvent(Player player, DetectedTree detectedTree) {
|
public TreeFallEvent(Player who, DetectedTree detectedTree) {
|
||||||
super(player, detectedTree);
|
super(who, detectedTree);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final HandlerList handlers = new HandlerList();
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public HandlerList getHandlers() {
|
public HandlerList getHandlers() {
|
||||||
return handlers;
|
return HANDLERS;
|
||||||
}
|
|
||||||
|
|
||||||
public static HandlerList getHandlerList() {
|
|
||||||
return handlers;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -33,8 +29,11 @@ public class TreeFallEvent extends TreeEvent implements Cancellable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setCancelled(boolean cancelled) {
|
public void setCancelled(boolean cancel) {
|
||||||
this.cancelled = cancelled;
|
this.cancelled = cancel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static HandlerList getHandlerList() {
|
||||||
|
return HANDLERS;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,20 +8,18 @@ import org.bukkit.event.HandlerList;
|
|||||||
* Called when a tree fell
|
* Called when a tree fell
|
||||||
*/
|
*/
|
||||||
public class TreeFellEvent extends TreeEvent {
|
public class TreeFellEvent extends TreeEvent {
|
||||||
|
private static final HandlerList HANDLERS = new HandlerList();
|
||||||
|
|
||||||
public TreeFellEvent(Player player, DetectedTree detectedTree) {
|
public TreeFellEvent(Player who, DetectedTree detectedTree) {
|
||||||
super(player, detectedTree);
|
super(who, detectedTree);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final HandlerList handlers = new HandlerList();
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public HandlerList getHandlers() {
|
public HandlerList getHandlers() {
|
||||||
return handlers;
|
return HANDLERS;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static HandlerList getHandlerList() {
|
public static HandlerList getHandlerList() {
|
||||||
return handlers;
|
return HANDLERS;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -11,14 +11,13 @@ import java.util.Set;
|
|||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class ChoppingManager extends Manager {
|
public class ChoppingManager extends Manager {
|
||||||
|
|
||||||
private final Set<UUID> disabledPlayers;
|
private final Set<UUID> disabledPlayers;
|
||||||
private final Map<UUID, Boolean> cooldownedPlayers;
|
private final Map<UUID, Boolean> cooldownedPlayers;
|
||||||
private boolean useCooldown;
|
private boolean useCooldown;
|
||||||
private int cooldownAmount;
|
private int cooldownAmount;
|
||||||
|
|
||||||
public ChoppingManager(UltimateTimber ultimateTimber) {
|
public ChoppingManager(UltimateTimber plugin) {
|
||||||
super(ultimateTimber);
|
super(plugin);
|
||||||
this.disabledPlayers = new HashSet<>();
|
this.disabledPlayers = new HashSet<>();
|
||||||
this.cooldownedPlayers = new HashMap<>();
|
this.cooldownedPlayers = new HashMap<>();
|
||||||
}
|
}
|
||||||
@ -72,8 +71,7 @@ public class ChoppingManager extends Manager {
|
|||||||
|
|
||||||
this.cooldownedPlayers.put(player.getUniqueId(), false);
|
this.cooldownedPlayers.put(player.getUniqueId(), false);
|
||||||
|
|
||||||
Bukkit.getScheduler().scheduleSyncDelayedTask(UltimateTimber.getInstance(), () ->
|
Bukkit.getScheduler().scheduleSyncDelayedTask(this.plugin, () -> this.cooldownedPlayers.remove(player.getUniqueId()), this.cooldownAmount * 20L);
|
||||||
this.cooldownedPlayers.remove(player.getUniqueId()), this.cooldownAmount * 20L);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -90,5 +88,4 @@ public class ChoppingManager extends Manager {
|
|||||||
}
|
}
|
||||||
return cooldowned;
|
return cooldowned;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,6 @@ import java.io.File;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class ConfigurationManager extends Manager {
|
public class ConfigurationManager extends Manager {
|
||||||
|
|
||||||
public enum Setting {
|
public enum Setting {
|
||||||
SERVER_TYPE(SettingType.STRING),
|
SERVER_TYPE(SettingType.STRING),
|
||||||
LOCALE(SettingType.STRING),
|
LOCALE(SettingType.STRING),
|
||||||
@ -49,7 +48,7 @@ public class ConfigurationManager extends Manager {
|
|||||||
SCATTER_TREE_BLOCKS_ON_GROUND(SettingType.BOOLEAN),
|
SCATTER_TREE_BLOCKS_ON_GROUND(SettingType.BOOLEAN),
|
||||||
FRAGILE_BLOCKS(SettingType.STRING_LIST);
|
FRAGILE_BLOCKS(SettingType.STRING_LIST);
|
||||||
|
|
||||||
private SettingType settingType;
|
private final SettingType settingType;
|
||||||
private Object value = null;
|
private Object value = null;
|
||||||
|
|
||||||
Setting(SettingType settingType) {
|
Setting(SettingType settingType) {
|
||||||
@ -118,10 +117,11 @@ public class ConfigurationManager extends Manager {
|
|||||||
* Loads the value from the config and caches it if it isn't set yet
|
* Loads the value from the config and caches it if it isn't set yet
|
||||||
*/
|
*/
|
||||||
private void loadValue() {
|
private void loadValue() {
|
||||||
if (this.value != null)
|
if (this.value != null) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
FileConfiguration config = UltimateTimber.getInstance().getConfigurationManager().getConfig();
|
FileConfiguration config = UltimateTimber.getPlugin(UltimateTimber.class).getConfigurationManager().getConfig();
|
||||||
switch (this.settingType) {
|
switch (this.settingType) {
|
||||||
case BOOLEAN:
|
case BOOLEAN:
|
||||||
this.value = config.getBoolean(this.getNameAsKey());
|
this.value = config.getBoolean(this.getNameAsKey());
|
||||||
@ -161,8 +161,8 @@ public class ConfigurationManager extends Manager {
|
|||||||
|
|
||||||
private YamlConfiguration configuration;
|
private YamlConfiguration configuration;
|
||||||
|
|
||||||
public ConfigurationManager(UltimateTimber ultimateTimber) {
|
public ConfigurationManager(UltimateTimber plugin) {
|
||||||
super(ultimateTimber);
|
super(plugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -171,7 +171,7 @@ public class ConfigurationManager extends Manager {
|
|||||||
|
|
||||||
File configFile = new File(this.plugin.getDataFolder() + "/config.yml");
|
File configFile = new File(this.plugin.getDataFolder() + "/config.yml");
|
||||||
|
|
||||||
// If an old config still exists, rename it so it doesn't interfere
|
// If an old config still exists, rename it, so it doesn't interfere
|
||||||
if (configFile.exists() && this.plugin.getConfig().get("server-type") == null) {
|
if (configFile.exists() && this.plugin.getConfig().get("server-type") == null) {
|
||||||
File renameConfigTo = new File(this.plugin.getDataFolder() + "/config-old.yml");
|
File renameConfigTo = new File(this.plugin.getDataFolder() + "/config-old.yml");
|
||||||
configFile.renameTo(renameConfigTo);
|
configFile.renameTo(renameConfigTo);
|
||||||
@ -188,15 +188,17 @@ public class ConfigurationManager extends Manager {
|
|||||||
|
|
||||||
this.configuration = YamlConfiguration.loadConfiguration(configFile);
|
this.configuration = YamlConfiguration.loadConfiguration(configFile);
|
||||||
|
|
||||||
for (Setting setting : Setting.values())
|
for (Setting setting : Setting.values()) {
|
||||||
setting.reset();
|
setting.reset();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void disable() {
|
public void disable() {
|
||||||
for (Setting setting : Setting.values())
|
for (Setting setting : Setting.values()) {
|
||||||
setting.reset();
|
setting.reset();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the config.yml as a YamlConfiguration
|
* Gets the config.yml as a YamlConfiguration
|
||||||
@ -206,5 +208,4 @@ public class ConfigurationManager extends Manager {
|
|||||||
public YamlConfiguration getConfig() {
|
public YamlConfiguration getConfig() {
|
||||||
return this.configuration;
|
return this.configuration;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,6 @@ package com.songoda.ultimatetimber.manager;
|
|||||||
import com.songoda.ultimatetimber.UltimateTimber;
|
import com.songoda.ultimatetimber.UltimateTimber;
|
||||||
|
|
||||||
public abstract class Manager {
|
public abstract class Manager {
|
||||||
|
|
||||||
protected UltimateTimber plugin;
|
protected UltimateTimber plugin;
|
||||||
|
|
||||||
Manager(UltimateTimber plugin) {
|
Manager(UltimateTimber plugin) {
|
||||||
@ -19,5 +18,4 @@ public abstract class Manager {
|
|||||||
* Cleans up the Manager's resources
|
* Cleans up the Manager's resources
|
||||||
*/
|
*/
|
||||||
public abstract void disable();
|
public abstract void disable();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
package com.songoda.ultimatetimber.manager;
|
package com.songoda.ultimatetimber.manager;
|
||||||
|
|
||||||
|
import com.songoda.core.compatibility.CompatibleMaterial;
|
||||||
import com.songoda.ultimatetimber.UltimateTimber;
|
import com.songoda.ultimatetimber.UltimateTimber;
|
||||||
import com.songoda.ultimatetimber.events.TreeFellEvent;
|
import com.songoda.ultimatetimber.events.TreeFellEvent;
|
||||||
import com.songoda.ultimatetimber.tree.ITreeBlock;
|
import com.songoda.ultimatetimber.tree.ITreeBlock;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.BlockState;
|
import org.bukkit.block.BlockState;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
@ -22,14 +22,13 @@ import java.util.Map;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class PlacedBlockManager extends Manager implements Listener {
|
public class PlacedBlockManager extends Manager implements Listener {
|
||||||
|
|
||||||
private Set<Location> placedBlocks;
|
private Set<Location> placedBlocks;
|
||||||
private boolean ignorePlacedBlocks;
|
private boolean ignorePlacedBlocks;
|
||||||
private int maxPlacedBlockMemorySize;
|
private int maxPlacedBlockMemorySize;
|
||||||
|
|
||||||
public PlacedBlockManager(UltimateTimber ultimateTimber) {
|
public PlacedBlockManager(UltimateTimber plugin) {
|
||||||
super(ultimateTimber);
|
super(plugin);
|
||||||
Bukkit.getPluginManager().registerEvents(this, ultimateTimber);
|
Bukkit.getPluginManager().registerEvents(this, plugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -53,57 +52,66 @@ public class PlacedBlockManager extends Manager implements Listener {
|
|||||||
|
|
||||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||||
public void onBlockPlaced(BlockPlaceEvent event) {
|
public void onBlockPlaced(BlockPlaceEvent event) {
|
||||||
if (!this.ignorePlacedBlocks)
|
if (!this.ignorePlacedBlocks) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Ignore stripping logs
|
// Ignore stripping logs
|
||||||
if (event.getBlockPlaced().getType().name().contains("STRIPPED") && !event.getBlockReplacedState().getType().equals(Material.AIR))
|
if (event.getBlockPlaced().getType().name().contains("STRIPPED") && !CompatibleMaterial.getMaterial(event.getBlockReplacedState().getType()).isAir()) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
this.internalProtect(event.getBlock(), true);
|
this.internalProtect(event.getBlock(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||||
public void onBlockBreak(BlockBreakEvent event) {
|
public void onBlockBreak(BlockBreakEvent event) {
|
||||||
if (!this.ignorePlacedBlocks)
|
if (!this.ignorePlacedBlocks) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
this.internalProtect(event.getBlock(), false);
|
this.internalProtect(event.getBlock(), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||||
public void onLeafDecay(LeavesDecayEvent event) {
|
public void onLeafDecay(LeavesDecayEvent event) {
|
||||||
if (!this.ignorePlacedBlocks)
|
if (!this.ignorePlacedBlocks) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
this.internalProtect(event.getBlock(), false);
|
this.internalProtect(event.getBlock(), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||||
public void onStructureGrow(StructureGrowEvent event) {
|
public void onStructureGrow(StructureGrowEvent event) {
|
||||||
if (!this.ignorePlacedBlocks)
|
if (!this.ignorePlacedBlocks) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
for (BlockState blockState : event.getBlocks())
|
for (BlockState blockState : event.getBlocks()) {
|
||||||
this.internalProtect(blockState.getBlock(), false);
|
this.internalProtect(blockState.getBlock(), false);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||||
public void onTreeFell(TreeFellEvent event) {
|
public void onTreeFell(TreeFellEvent event) {
|
||||||
if (!this.ignorePlacedBlocks)
|
if (!this.ignorePlacedBlocks) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
for (ITreeBlock<Block> treeBlock : event.getDetectedTree().getDetectedTreeBlocks().getAllTreeBlocks())
|
for (ITreeBlock<Block> treeBlock : event.getDetectedTree().getDetectedTreeBlocks().getAllTreeBlocks()) {
|
||||||
this.internalProtect(treeBlock.getBlock(), false);
|
this.internalProtect(treeBlock.getBlock(), false);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles when a block is placed/broken
|
* Handles when a block is placed/broken
|
||||||
*/
|
*/
|
||||||
private void internalProtect(Block block, boolean isPlaced) {
|
private void internalProtect(Block block, boolean isPlaced) {
|
||||||
if (isPlaced) {
|
if (isPlaced) {
|
||||||
if (this.isBlockPlaced(block))
|
if (this.isBlockPlaced(block)) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
this.placedBlocks.add(block.getLocation());
|
this.placedBlocks.add(block.getLocation());
|
||||||
} else {
|
} else {
|
||||||
@ -120,5 +128,4 @@ public class PlacedBlockManager extends Manager implements Listener {
|
|||||||
public boolean isBlockPlaced(Block block) {
|
public boolean isBlockPlaced(Block block) {
|
||||||
return this.placedBlocks.contains(block.getLocation());
|
return this.placedBlocks.contains(block.getLocation());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -16,24 +16,21 @@ import java.util.Random;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class SaplingManager extends Manager {
|
public class SaplingManager extends Manager {
|
||||||
|
private final Random random;
|
||||||
|
private final Set<Location> protectedSaplings;
|
||||||
|
|
||||||
private Random random;
|
public SaplingManager(UltimateTimber plugin) {
|
||||||
private Set<Location> protectedSaplings;
|
super(plugin);
|
||||||
|
|
||||||
public SaplingManager(UltimateTimber ultimateTimber) {
|
|
||||||
super(ultimateTimber);
|
|
||||||
this.random = new Random();
|
this.random = new Random();
|
||||||
this.protectedSaplings = new HashSet<>();
|
this.protectedSaplings = new HashSet<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void reload() {
|
public void reload() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void disable() {
|
public void disable() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -44,12 +41,14 @@ public class SaplingManager extends Manager {
|
|||||||
* @param treeBlock The ITreeBlock to replant for
|
* @param treeBlock The ITreeBlock to replant for
|
||||||
*/
|
*/
|
||||||
public void replantSapling(TreeDefinition treeDefinition, ITreeBlock treeBlock) {
|
public void replantSapling(TreeDefinition treeDefinition, ITreeBlock treeBlock) {
|
||||||
if (!ConfigurationManager.Setting.REPLANT_SAPLINGS.getBoolean())
|
if (!ConfigurationManager.Setting.REPLANT_SAPLINGS.getBoolean()) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Block block = treeBlock.getLocation().getBlock();
|
Block block = treeBlock.getLocation().getBlock();
|
||||||
if (!block.getType().equals(Material.AIR) || treeBlock.getTreeBlockType().equals(TreeBlockType.LEAF))
|
if (block.getType() != Material.AIR || treeBlock.getTreeBlockType() == TreeBlockType.LEAF) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Bukkit.getScheduler().scheduleSyncDelayedTask(this.plugin, () -> this.internalReplant(treeDefinition, treeBlock), 1L);
|
Bukkit.getScheduler().scheduleSyncDelayedTask(this.plugin, () -> this.internalReplant(treeDefinition, treeBlock), 1L);
|
||||||
}
|
}
|
||||||
@ -62,12 +61,14 @@ public class SaplingManager extends Manager {
|
|||||||
* @param treeBlock The ITreeBlock to replant for
|
* @param treeBlock The ITreeBlock to replant for
|
||||||
*/
|
*/
|
||||||
public void replantSaplingWithChance(TreeDefinition treeDefinition, ITreeBlock treeBlock) {
|
public void replantSaplingWithChance(TreeDefinition treeDefinition, ITreeBlock treeBlock) {
|
||||||
if (!ConfigurationManager.Setting.FALLING_BLOCKS_REPLANT_SAPLINGS.getBoolean() || !treeBlock.getLocation().getBlock().getType().equals(Material.AIR))
|
if (!ConfigurationManager.Setting.FALLING_BLOCKS_REPLANT_SAPLINGS.getBoolean() || !CompatibleMaterial.getMaterial(treeBlock.getLocation().getBlock()).isAir()) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
double chance = ConfigurationManager.Setting.FALLING_BLOCKS_REPLANT_SAPLINGS_CHANCE.getDouble();
|
double chance = ConfigurationManager.Setting.FALLING_BLOCKS_REPLANT_SAPLINGS_CHANCE.getDouble();
|
||||||
if (this.random.nextDouble() > chance / 100)
|
if (this.random.nextDouble() > chance / 100) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Bukkit.getScheduler().scheduleSyncDelayedTask(this.plugin, () -> this.internalReplant(treeDefinition, treeBlock), 1L);
|
Bukkit.getScheduler().scheduleSyncDelayedTask(this.plugin, () -> this.internalReplant(treeDefinition, treeBlock), 1L);
|
||||||
}
|
}
|
||||||
@ -85,14 +86,15 @@ public class SaplingManager extends Manager {
|
|||||||
Block blockBelow = block.getRelative(BlockFace.DOWN);
|
Block blockBelow = block.getRelative(BlockFace.DOWN);
|
||||||
boolean isValidSoil = false;
|
boolean isValidSoil = false;
|
||||||
for (CompatibleMaterial soilMaterial : treeDefinitionManager.getPlantableSoilMaterial(treeDefinition)) {
|
for (CompatibleMaterial soilMaterial : treeDefinitionManager.getPlantableSoilMaterial(treeDefinition)) {
|
||||||
if (soilMaterial.equals(CompatibleMaterial.getMaterial(blockBelow))) {
|
if (soilMaterial == CompatibleMaterial.getMaterial(blockBelow)) {
|
||||||
isValidSoil = true;
|
isValidSoil = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isValidSoil)
|
if (!isValidSoil) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
CompatibleMaterial material = treeDefinition.getSaplingMaterial();
|
CompatibleMaterial material = treeDefinition.getSaplingMaterial();
|
||||||
material.applyToBlock(block);
|
material.applyToBlock(block);
|
||||||
@ -113,5 +115,4 @@ public class SaplingManager extends Manager {
|
|||||||
public boolean isSaplingProtected(Block block) {
|
public boolean isSaplingProtected(Block block) {
|
||||||
return this.protectedSaplings.contains(block.getLocation());
|
return this.protectedSaplings.contains(block.getLocation());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -30,15 +30,14 @@ import java.util.HashSet;
|
|||||||
import java.util.Set;
|
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 final int taskId;
|
private final int taskId;
|
||||||
|
|
||||||
public TreeAnimationManager(UltimateTimber ultimateTimber) {
|
public TreeAnimationManager(UltimateTimber plugin) {
|
||||||
super(ultimateTimber);
|
super(plugin);
|
||||||
this.activeAnimations = new HashSet<>();
|
this.activeAnimations = new HashSet<>();
|
||||||
this.taskId = -1;
|
this.taskId = -1;
|
||||||
Bukkit.getPluginManager().registerEvents(this, ultimateTimber);
|
Bukkit.getPluginManager().registerEvents(this, plugin);
|
||||||
Bukkit.getScheduler().runTaskTimer(this.plugin, this, 0, 1L);
|
Bukkit.getScheduler().runTaskTimer(this.plugin, this, 0, 1L);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,14 +58,16 @@ public class TreeAnimationManager extends Manager implements Listener, Runnable
|
|||||||
Set<ITreeBlock<FallingBlock>> groundedBlocks = new HashSet<>();
|
Set<ITreeBlock<FallingBlock>> groundedBlocks = new HashSet<>();
|
||||||
for (ITreeBlock<FallingBlock> fallingTreeBlock : treeAnimation.getFallingTreeBlocks().getAllTreeBlocks()) {
|
for (ITreeBlock<FallingBlock> fallingTreeBlock : treeAnimation.getFallingTreeBlocks().getAllTreeBlocks()) {
|
||||||
FallingBlock fallingBlock = fallingTreeBlock.getBlock();
|
FallingBlock fallingBlock = fallingTreeBlock.getBlock();
|
||||||
if (fallingBlock.isDead() || ServerVersion.isServerVersionAtLeast(ServerVersion.V1_17) && fallingBlock.isOnGround())
|
if (fallingBlock.isDead() || ServerVersion.isServerVersionAtLeast(ServerVersion.V1_17) && fallingBlock.isOnGround()) {
|
||||||
groundedBlocks.add(fallingTreeBlock);
|
groundedBlocks.add(fallingTreeBlock);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (ITreeBlock<FallingBlock> fallingBlock : groundedBlocks) {
|
for (ITreeBlock<FallingBlock> fallingBlock : groundedBlocks) {
|
||||||
this.runFallingBlockImpact(treeAnimation, fallingBlock);
|
this.runFallingBlockImpact(treeAnimation, fallingBlock);
|
||||||
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_17))
|
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_17)) {
|
||||||
fallingBlock.getBlock().remove();
|
fallingBlock.getBlock().remove();
|
||||||
|
}
|
||||||
treeAnimation.getFallingTreeBlocks().remove(fallingBlock);
|
treeAnimation.getFallingTreeBlocks().remove(fallingBlock);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -101,10 +102,13 @@ public class TreeAnimationManager extends Manager implements Listener, Runnable
|
|||||||
* @param block The block to check
|
* @param block The block to check
|
||||||
*/
|
*/
|
||||||
public boolean isBlockInAnimation(Block block) {
|
public boolean isBlockInAnimation(Block block) {
|
||||||
for (TreeAnimation treeAnimation : this.activeAnimations)
|
for (TreeAnimation treeAnimation : this.activeAnimations) {
|
||||||
for (ITreeBlock<Block> treeBlock : treeAnimation.getDetectedTree().getDetectedTreeBlocks().getAllTreeBlocks())
|
for (ITreeBlock<Block> treeBlock : treeAnimation.getDetectedTree().getDetectedTreeBlocks().getAllTreeBlocks()) {
|
||||||
if (treeBlock.getBlock().equals(block))
|
if (treeBlock.getBlock().equals(block)) {
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -114,10 +118,13 @@ public class TreeAnimationManager extends Manager implements Listener, Runnable
|
|||||||
* @param fallingBlock The falling block to check
|
* @param fallingBlock The falling block to check
|
||||||
*/
|
*/
|
||||||
public boolean isBlockInAnimation(FallingBlock fallingBlock) {
|
public boolean isBlockInAnimation(FallingBlock fallingBlock) {
|
||||||
for (TreeAnimation treeAnimation : this.activeAnimations)
|
for (TreeAnimation treeAnimation : this.activeAnimations) {
|
||||||
for (ITreeBlock<FallingBlock> treeBlock : treeAnimation.getFallingTreeBlocks().getAllTreeBlocks())
|
for (ITreeBlock<FallingBlock> treeBlock : treeAnimation.getFallingTreeBlocks().getAllTreeBlocks()) {
|
||||||
if (treeBlock.getBlock().equals(fallingBlock))
|
if (treeBlock.getBlock().equals(fallingBlock)) {
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -127,10 +134,13 @@ public class TreeAnimationManager extends Manager implements Listener, Runnable
|
|||||||
* @return A TreeAnimation
|
* @return A TreeAnimation
|
||||||
*/
|
*/
|
||||||
private TreeAnimation getAnimationForBlock(FallingBlock fallingBlock) {
|
private TreeAnimation getAnimationForBlock(FallingBlock fallingBlock) {
|
||||||
for (TreeAnimation treeAnimation : this.activeAnimations)
|
for (TreeAnimation treeAnimation : this.activeAnimations) {
|
||||||
for (ITreeBlock<FallingBlock> treeBlock : treeAnimation.getFallingTreeBlocks().getAllTreeBlocks())
|
for (ITreeBlock<FallingBlock> treeBlock : treeAnimation.getFallingTreeBlocks().getAllTreeBlocks()) {
|
||||||
if (treeBlock.getBlock().equals(fallingBlock))
|
if (treeBlock.getBlock().equals(fallingBlock)) {
|
||||||
return treeAnimation;
|
return treeAnimation;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -154,10 +164,12 @@ public class TreeAnimationManager extends Manager implements Listener, Runnable
|
|||||||
boolean useCustomParticles = ConfigurationManager.Setting.USE_CUSTOM_PARTICLES.getBoolean();
|
boolean useCustomParticles = ConfigurationManager.Setting.USE_CUSTOM_PARTICLES.getBoolean();
|
||||||
TreeDefinition treeDefinition = treeAnimation.getDetectedTree().getTreeDefinition();
|
TreeDefinition treeDefinition = treeAnimation.getDetectedTree().getTreeDefinition();
|
||||||
|
|
||||||
if (useCustomParticles)
|
if (useCustomParticles) {
|
||||||
ParticleUtils.playLandingParticles(treeBlock);
|
ParticleUtils.playLandingParticles(treeBlock);
|
||||||
if (useCustomSound)
|
}
|
||||||
|
if (useCustomSound) {
|
||||||
SoundUtils.playLandingSound(treeBlock);
|
SoundUtils.playLandingSound(treeBlock);
|
||||||
|
}
|
||||||
|
|
||||||
Block block = treeBlock.getLocation().subtract(0, 1, 0).getBlock();
|
Block block = treeBlock.getLocation().subtract(0, 1, 0).getBlock();
|
||||||
if (ConfigurationManager.Setting.FRAGILE_BLOCKS.getStringList().contains(block.getType().toString())) {
|
if (ConfigurationManager.Setting.FRAGILE_BLOCKS.getStringList().contains(block.getType().toString())) {
|
||||||
@ -172,17 +184,21 @@ public class TreeAnimationManager extends Manager implements Listener, Runnable
|
|||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGH)
|
@EventHandler(priority = EventPriority.HIGH)
|
||||||
public void onFallingBlockLand(EntityChangeBlockEvent event) {
|
public void onFallingBlockLand(EntityChangeBlockEvent event) {
|
||||||
if (!event.getEntityType().equals(EntityType.FALLING_BLOCK))
|
if (event.getEntityType() != EntityType.FALLING_BLOCK) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
FallingBlock fallingBlock = (FallingBlock) event.getEntity();
|
FallingBlock fallingBlock = (FallingBlock) event.getEntity();
|
||||||
if (!this.isBlockInAnimation(fallingBlock))
|
if (!this.isBlockInAnimation(fallingBlock)) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (ConfigurationManager.Setting.FALLING_BLOCKS_DEAL_DAMAGE.getBoolean()) {
|
if (ConfigurationManager.Setting.FALLING_BLOCKS_DEAL_DAMAGE.getBoolean()) {
|
||||||
int damage = ConfigurationManager.Setting.FALLING_BLOCK_DAMAGE.getInt();
|
int damage = ConfigurationManager.Setting.FALLING_BLOCK_DAMAGE.getInt();
|
||||||
for (Entity entity : fallingBlock.getNearbyEntities(0.5, 0.5, 0.5)) {
|
for (Entity entity : fallingBlock.getNearbyEntities(0.5, 0.5, 0.5)) {
|
||||||
if (!(entity instanceof LivingEntity)) continue;
|
if (!(entity instanceof LivingEntity)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
((LivingEntity) entity).damage(damage, fallingBlock);
|
((LivingEntity) entity).damage(damage, fallingBlock);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,6 @@ import java.util.Set;
|
|||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class TreeDefinitionManager extends Manager {
|
public class TreeDefinitionManager extends Manager {
|
||||||
|
|
||||||
private final Random random;
|
private final Random random;
|
||||||
private final Set<TreeDefinition> treeDefinitions;
|
private final Set<TreeDefinition> treeDefinitions;
|
||||||
private final Set<CompatibleMaterial> globalPlantableSoil;
|
private final Set<CompatibleMaterial> globalPlantableSoil;
|
||||||
@ -42,8 +41,8 @@ public class TreeDefinitionManager extends Manager {
|
|||||||
private ItemStack requiredAxe;
|
private ItemStack requiredAxe;
|
||||||
private String requiredAxeKey;
|
private String requiredAxeKey;
|
||||||
|
|
||||||
public TreeDefinitionManager(UltimateTimber ultimateTimber) {
|
public TreeDefinitionManager(UltimateTimber plugin) {
|
||||||
super(ultimateTimber);
|
super(plugin);
|
||||||
this.random = new Random();
|
this.random = new Random();
|
||||||
this.treeDefinitions = new HashSet<>();
|
this.treeDefinitions = new HashSet<>();
|
||||||
this.globalPlantableSoil = new HashSet<>();
|
this.globalPlantableSoil = new HashSet<>();
|
||||||
@ -88,13 +87,17 @@ public class TreeDefinitionManager extends Manager {
|
|||||||
|
|
||||||
for (String materialString : tree.getStringList("logs")) {
|
for (String materialString : tree.getStringList("logs")) {
|
||||||
CompatibleMaterial material = CompatibleMaterial.getMaterial(materialString);
|
CompatibleMaterial material = CompatibleMaterial.getMaterial(materialString);
|
||||||
if (material == null || material.getMaterial() == null) continue top;
|
if (material == null || material.getMaterial() == null) {
|
||||||
|
continue top;
|
||||||
|
}
|
||||||
logMaterials.add(material);
|
logMaterials.add(material);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (String materialString : tree.getStringList("leaves")) {
|
for (String materialString : tree.getStringList("leaves")) {
|
||||||
CompatibleMaterial material = CompatibleMaterial.getMaterial(materialString);
|
CompatibleMaterial material = CompatibleMaterial.getMaterial(materialString);
|
||||||
if (material == null || material.getMaterial() == null) continue top;
|
if (material == null || material.getMaterial() == null) {
|
||||||
|
continue top;
|
||||||
|
}
|
||||||
leafMaterials.add(material);
|
leafMaterials.add(material);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -102,7 +105,9 @@ public class TreeDefinitionManager extends Manager {
|
|||||||
|
|
||||||
for (String materialString : tree.getStringList("plantable-soil")) {
|
for (String materialString : tree.getStringList("plantable-soil")) {
|
||||||
CompatibleMaterial material = CompatibleMaterial.getMaterial(materialString);
|
CompatibleMaterial material = CompatibleMaterial.getMaterial(materialString);
|
||||||
if (material == null || material.getMaterial() == null) continue top;
|
if (material == null || material.getMaterial() == null) {
|
||||||
|
continue top;
|
||||||
|
}
|
||||||
plantableSoilMaterial.add(material);
|
plantableSoilMaterial.add(material);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -113,23 +118,31 @@ public class TreeDefinitionManager extends Manager {
|
|||||||
dropOriginalLeaf = tree.getBoolean("drop-original-leaf");
|
dropOriginalLeaf = tree.getBoolean("drop-original-leaf");
|
||||||
|
|
||||||
ConfigurationSection logLootSection = tree.getConfigurationSection("log-loot");
|
ConfigurationSection logLootSection = tree.getConfigurationSection("log-loot");
|
||||||
if (logLootSection != null)
|
if (logLootSection != null) {
|
||||||
for (String lootKey : logLootSection.getKeys(false))
|
for (String lootKey : logLootSection.getKeys(false)) {
|
||||||
logLoot.add(this.getTreeLootEntry(TreeBlockType.LOG, logLootSection.getConfigurationSection(lootKey)));
|
logLoot.add(this.getTreeLootEntry(TreeBlockType.LOG, logLootSection.getConfigurationSection(lootKey)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ConfigurationSection leafLootSection = tree.getConfigurationSection("leaf-loot");
|
ConfigurationSection leafLootSection = tree.getConfigurationSection("leaf-loot");
|
||||||
if (leafLootSection != null)
|
if (leafLootSection != null) {
|
||||||
for (String lootKey : leafLootSection.getKeys(false))
|
for (String lootKey : leafLootSection.getKeys(false)) {
|
||||||
leafLoot.add(this.getTreeLootEntry(TreeBlockType.LEAF, leafLootSection.getConfigurationSection(lootKey)));
|
leafLoot.add(this.getTreeLootEntry(TreeBlockType.LEAF, leafLootSection.getConfigurationSection(lootKey)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ConfigurationSection entireTreeLootSection = tree.getConfigurationSection("entire-tree-loot");
|
ConfigurationSection entireTreeLootSection = tree.getConfigurationSection("entire-tree-loot");
|
||||||
if (entireTreeLootSection != null)
|
if (entireTreeLootSection != null) {
|
||||||
for (String lootKey : entireTreeLootSection.getKeys(false))
|
for (String lootKey : entireTreeLootSection.getKeys(false)) {
|
||||||
entireTreeLoot.add(this.getTreeLootEntry(TreeBlockType.LEAF, entireTreeLootSection.getConfigurationSection(lootKey)));
|
entireTreeLoot.add(this.getTreeLootEntry(TreeBlockType.LEAF, entireTreeLootSection.getConfigurationSection(lootKey)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (String itemStackString : tree.getStringList("required-tools")) {
|
for (String itemStackString : tree.getStringList("required-tools")) {
|
||||||
CompatibleMaterial material = CompatibleMaterial.getMaterial(itemStackString);
|
CompatibleMaterial material = CompatibleMaterial.getMaterial(itemStackString);
|
||||||
if (material == null) continue top;
|
if (material == null) {
|
||||||
|
continue top;
|
||||||
|
}
|
||||||
requiredTools.add(material.getItem());
|
requiredTools.add(material.getItem());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -140,43 +153,52 @@ public class TreeDefinitionManager extends Manager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Load global plantable soil
|
// Load global plantable soil
|
||||||
for (String material : config.getStringList("global-plantable-soil"))
|
for (String material : config.getStringList("global-plantable-soil")) {
|
||||||
this.globalPlantableSoil.add(CompatibleMaterial.getMaterial(material));
|
this.globalPlantableSoil.add(CompatibleMaterial.getMaterial(material));
|
||||||
|
}
|
||||||
|
|
||||||
// Load global log drops
|
// Load global log drops
|
||||||
ConfigurationSection logSection = config.getConfigurationSection("global-log-loot");
|
ConfigurationSection logSection = config.getConfigurationSection("global-log-loot");
|
||||||
if (logSection != null)
|
if (logSection != null) {
|
||||||
for (String lootKey : logSection.getKeys(false))
|
for (String lootKey : logSection.getKeys(false)) {
|
||||||
this.globalLogLoot.add(this.getTreeLootEntry(TreeBlockType.LOG, logSection.getConfigurationSection(lootKey)));
|
this.globalLogLoot.add(this.getTreeLootEntry(TreeBlockType.LOG, logSection.getConfigurationSection(lootKey)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Load global leaf drops
|
// Load global leaf drops
|
||||||
ConfigurationSection leafSection = config.getConfigurationSection("global-leaf-loot");
|
ConfigurationSection leafSection = config.getConfigurationSection("global-leaf-loot");
|
||||||
if (leafSection != null)
|
if (leafSection != null) {
|
||||||
for (String lootKey : leafSection.getKeys(false))
|
for (String lootKey : leafSection.getKeys(false)) {
|
||||||
this.globalLeafLoot.add(this.getTreeLootEntry(TreeBlockType.LEAF, leafSection.getConfigurationSection(lootKey)));
|
this.globalLeafLoot.add(this.getTreeLootEntry(TreeBlockType.LEAF, leafSection.getConfigurationSection(lootKey)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Load global entire tree drops
|
// Load global entire tree drops
|
||||||
ConfigurationSection entireTreeSection = config.getConfigurationSection("global-entire-tree-loot");
|
ConfigurationSection entireTreeSection = config.getConfigurationSection("global-entire-tree-loot");
|
||||||
if (entireTreeSection != null)
|
if (entireTreeSection != null) {
|
||||||
for (String lootKey : entireTreeSection.getKeys(false))
|
for (String lootKey : entireTreeSection.getKeys(false)) {
|
||||||
this.globalEntireTreeLoot.add(this.getTreeLootEntry(TreeBlockType.LOG, entireTreeSection.getConfigurationSection(lootKey)));
|
this.globalEntireTreeLoot.add(this.getTreeLootEntry(TreeBlockType.LOG, entireTreeSection.getConfigurationSection(lootKey)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Load global tools
|
// Load global tools
|
||||||
for (String itemStackString : config.getStringList("global-required-tools")) {
|
for (String itemStackString : config.getStringList("global-required-tools")) {
|
||||||
ItemStack tool = CompatibleMaterial.getMaterial(itemStackString).getItem();
|
ItemStack tool = CompatibleMaterial.getMaterial(itemStackString).getItem();
|
||||||
if (tool == null) continue;
|
if (tool == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
this.globalRequiredTools.add(tool);
|
this.globalRequiredTools.add(tool);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.globalAxeRequired = config.getBoolean("global-required-axe", false);
|
this.globalAxeRequired = config.getBoolean("global-required-axe", false);
|
||||||
|
|
||||||
// Load required axe
|
// Load required axe
|
||||||
if (config.contains("required-axe"))
|
if (config.contains("required-axe")) {
|
||||||
loadAxe(config);
|
loadAxe(config);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void loadAxe(YamlConfiguration config) {
|
private void loadAxe(YamlConfiguration config) {
|
||||||
|
|
||||||
// Reset the axe loaded, but load the NBT anyway in case someone wanted to use another plugin to give it.
|
// Reset the axe loaded, but load the NBT anyway in case someone wanted to use another plugin to give it.
|
||||||
this.requiredAxeKey = config.getString("required-axe.nbt");
|
this.requiredAxeKey = config.getString("required-axe.nbt");
|
||||||
this.requiredAxe = null;
|
this.requiredAxe = null;
|
||||||
@ -184,14 +206,14 @@ public class TreeDefinitionManager extends Manager {
|
|||||||
String typeString = config.getString("required-axe.type");
|
String typeString = config.getString("required-axe.type");
|
||||||
|
|
||||||
if (Strings.isNullOrEmpty(typeString)) {
|
if (Strings.isNullOrEmpty(typeString)) {
|
||||||
plugin.getLogger().warning("Required-axe has to have a material set.");
|
this.plugin.getLogger().warning("Required-axe has to have a material set.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
CompatibleMaterial material = CompatibleMaterial.getMaterial(typeString);
|
CompatibleMaterial material = CompatibleMaterial.getMaterial(typeString);
|
||||||
|
|
||||||
if (material == null) {
|
if (material == null) {
|
||||||
plugin.getLogger().warning("Material " + typeString + " is invalid.");
|
this.plugin.getLogger().warning("Material " + typeString + " is invalid.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -219,13 +241,15 @@ public class TreeDefinitionManager extends Manager {
|
|||||||
enchantment = Enchantment.getByKey(key);
|
enchantment = Enchantment.getByKey(key);
|
||||||
|
|
||||||
// Try to fall back to #getByName() if someone uses the old names.
|
// Try to fall back to #getByName() if someone uses the old names.
|
||||||
if (enchantment == null)
|
if (enchantment == null) {
|
||||||
enchantment = Enchantment.getByName(arr[0].trim());
|
enchantment = Enchantment.getByName(arr[0].trim());
|
||||||
} else
|
}
|
||||||
|
} else {
|
||||||
enchantment = Enchantment.getByName(arr[0].trim());
|
enchantment = Enchantment.getByName(arr[0].trim());
|
||||||
|
}
|
||||||
|
|
||||||
if (enchantment == null) {
|
if (enchantment == null) {
|
||||||
plugin.getLogger().warning("Enchantment " + arr[0].trim() + " is invalid.");
|
this.plugin.getLogger().warning("Enchantment " + arr[0].trim() + " is invalid.");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -236,7 +260,7 @@ public class TreeDefinitionManager extends Manager {
|
|||||||
|
|
||||||
// Apply NBT
|
// Apply NBT
|
||||||
NBTItem nbtItem = new NBTItem(item);
|
NBTItem nbtItem = new NBTItem(item);
|
||||||
nbtItem.setBoolean(requiredAxeKey, true);
|
nbtItem.setBoolean(this.requiredAxeKey, true);
|
||||||
item = nbtItem.getItem();
|
item = nbtItem.getItem();
|
||||||
|
|
||||||
this.requiredAxe = item;
|
this.requiredAxe = item;
|
||||||
@ -255,7 +279,7 @@ public class TreeDefinitionManager extends Manager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean isGlobalAxeRequired() {
|
public boolean isGlobalAxeRequired() {
|
||||||
return globalAxeRequired;
|
return this.globalAxeRequired;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -267,7 +291,6 @@ public class TreeDefinitionManager extends Manager {
|
|||||||
* Gets a Set of possible TreeDefinitions that match the given Block
|
* Gets a Set of possible TreeDefinitions that match the given Block
|
||||||
*
|
*
|
||||||
* @param block The Block to check
|
* @param block The Block to check
|
||||||
*
|
|
||||||
* @return A Set of TreeDefinitions for the given Block
|
* @return A Set of TreeDefinitions for the given Block
|
||||||
*/
|
*/
|
||||||
public Set<TreeDefinition> getTreeDefinitionsForLog(Block block) {
|
public Set<TreeDefinition> getTreeDefinitionsForLog(Block block) {
|
||||||
@ -280,7 +303,6 @@ public class TreeDefinitionManager extends Manager {
|
|||||||
* @param possibleTreeDefinitions The possible TreeDefinitions
|
* @param possibleTreeDefinitions The possible TreeDefinitions
|
||||||
* @param block The Block to narrow to
|
* @param block The Block to narrow to
|
||||||
* @param treeBlockType The TreeBlockType of the given Block
|
* @param treeBlockType The TreeBlockType of the given Block
|
||||||
*
|
|
||||||
* @return A Set of TreeDefinitions narrowed down
|
* @return A Set of TreeDefinitions narrowed down
|
||||||
*/
|
*/
|
||||||
public Set<TreeDefinition> narrowTreeDefinition(Set<TreeDefinition> possibleTreeDefinitions, Block block, TreeBlockType treeBlockType) {
|
public Set<TreeDefinition> narrowTreeDefinition(Set<TreeDefinition> possibleTreeDefinitions, Block block, TreeBlockType treeBlockType) {
|
||||||
@ -289,7 +311,7 @@ public class TreeDefinitionManager extends Manager {
|
|||||||
case LOG:
|
case LOG:
|
||||||
for (TreeDefinition treeDefinition : possibleTreeDefinitions) {
|
for (TreeDefinition treeDefinition : possibleTreeDefinitions) {
|
||||||
for (CompatibleMaterial material : treeDefinition.getLogMaterial()) {
|
for (CompatibleMaterial material : treeDefinition.getLogMaterial()) {
|
||||||
if (material.equals(CompatibleMaterial.getMaterial(block))) {
|
if (material == CompatibleMaterial.getMaterial(block)) {
|
||||||
matchingTreeDefinitions.add(treeDefinition);
|
matchingTreeDefinitions.add(treeDefinition);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -299,7 +321,7 @@ public class TreeDefinitionManager extends Manager {
|
|||||||
case LEAF:
|
case LEAF:
|
||||||
for (TreeDefinition treeDefinition : possibleTreeDefinitions) {
|
for (TreeDefinition treeDefinition : possibleTreeDefinitions) {
|
||||||
for (CompatibleMaterial material : treeDefinition.getLeafMaterial()) {
|
for (CompatibleMaterial material : treeDefinition.getLeafMaterial()) {
|
||||||
if (material.equals(CompatibleMaterial.getMaterial(block))) {
|
if (material == CompatibleMaterial.getMaterial(block)) {
|
||||||
matchingTreeDefinitions.add(treeDefinition);
|
matchingTreeDefinitions.add(treeDefinition);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -315,28 +337,34 @@ public class TreeDefinitionManager extends Manager {
|
|||||||
* Checks if a given tool is valid for any tree definitions, also takes into account global tools
|
* Checks if a given tool is valid for any tree definitions, also takes into account global tools
|
||||||
*
|
*
|
||||||
* @param tool The tool to check
|
* @param tool The tool to check
|
||||||
*
|
|
||||||
* @return True if the tool is allowed for toppling any trees
|
* @return True if the tool is allowed for toppling any trees
|
||||||
*/
|
*/
|
||||||
public boolean isToolValidForAnyTreeDefinition(ItemStack tool) {
|
public boolean isToolValidForAnyTreeDefinition(ItemStack tool) {
|
||||||
if (ConfigurationManager.Setting.IGNORE_REQUIRED_TOOLS.getBoolean())
|
if (ConfigurationManager.Setting.IGNORE_REQUIRED_TOOLS.getBoolean()) {
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
for (TreeDefinition treeDefinition : this.treeDefinitions) {
|
for (TreeDefinition treeDefinition : this.treeDefinitions) {
|
||||||
if (treeDefinition.isRequiredAxe() || isGlobalAxeRequired()) {
|
if (treeDefinition.isRequiredAxe() || isGlobalAxeRequired()) {
|
||||||
if (tool != null && !tool.getType().isAir() && new NBTItem(tool).hasKey(requiredAxeKey))
|
if (tool != null && !tool.getType().isAir() && new NBTItem(tool).hasTag(this.requiredAxeKey)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (TreeDefinition treeDefinition : this.treeDefinitions)
|
for (TreeDefinition treeDefinition : this.treeDefinitions) {
|
||||||
for (ItemStack requiredTool : treeDefinition.getRequiredTools())
|
for (ItemStack requiredTool : treeDefinition.getRequiredTools()) {
|
||||||
if (requiredTool.getType().equals(tool.getType()))
|
if (requiredTool.getType() == tool.getType()) {
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (ItemStack requiredTool : this.globalRequiredTools)
|
for (ItemStack requiredTool : this.globalRequiredTools) {
|
||||||
if (requiredTool.getType().equals(tool.getType()))
|
if (requiredTool.getType() == tool.getType()) {
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -346,26 +374,29 @@ public class TreeDefinitionManager extends Manager {
|
|||||||
*
|
*
|
||||||
* @param treeDefinition The TreeDefinition to use
|
* @param treeDefinition The TreeDefinition to use
|
||||||
* @param tool The tool to check
|
* @param tool The tool to check
|
||||||
*
|
|
||||||
* @return True if the tool is allowed for toppling the given TreeDefinition
|
* @return True if the tool is allowed for toppling the given TreeDefinition
|
||||||
*/
|
*/
|
||||||
public boolean isToolValidForTreeDefinition(TreeDefinition treeDefinition, ItemStack tool) {
|
public boolean isToolValidForTreeDefinition(TreeDefinition treeDefinition, ItemStack tool) {
|
||||||
|
if (ConfigurationManager.Setting.IGNORE_REQUIRED_TOOLS.getBoolean()) {
|
||||||
if (ConfigurationManager.Setting.IGNORE_REQUIRED_TOOLS.getBoolean())
|
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
// If the tree definition requires the custom axe, don't allow any other checks to pass.
|
// If the tree definition requires the custom axe, don't allow any other checks to pass.
|
||||||
if (treeDefinition.isRequiredAxe() || isGlobalAxeRequired()) {
|
if (treeDefinition.isRequiredAxe() || isGlobalAxeRequired()) {
|
||||||
return tool != null && !tool.getType().isAir() && new NBTItem(tool).hasKey(requiredAxeKey);
|
return tool != null && !tool.getType().isAir() && new NBTItem(tool).hasTag(this.requiredAxeKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (ItemStack requiredTool : treeDefinition.getRequiredTools())
|
for (ItemStack requiredTool : treeDefinition.getRequiredTools()) {
|
||||||
if (requiredTool.getType().equals(tool.getType()))
|
if (requiredTool.getType() == tool.getType()) {
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (ItemStack requiredTool : this.globalRequiredTools)
|
for (ItemStack requiredTool : this.globalRequiredTools) {
|
||||||
if (requiredTool.getType().equals(tool.getType()))
|
if (requiredTool.getType() == tool.getType()) {
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -391,8 +422,9 @@ public class TreeDefinitionManager extends Manager {
|
|||||||
} else {
|
} else {
|
||||||
if (ConfigurationManager.Setting.APPLY_SILK_TOUCH.getBoolean() && hasSilkTouch) {
|
if (ConfigurationManager.Setting.APPLY_SILK_TOUCH.getBoolean() && hasSilkTouch) {
|
||||||
if (ConfigurationManager.Setting.HOOKS_APPLY_EXTRA_DROPS.getBoolean()
|
if (ConfigurationManager.Setting.HOOKS_APPLY_EXTRA_DROPS.getBoolean()
|
||||||
&& McMMOHook.hasWoodcuttingDoubleDrops(player))
|
&& McMMOHook.hasWoodcuttingDoubleDrops(player)) {
|
||||||
lootedItems.addAll(BlockUtils.getBlockDrops(treeBlock));
|
lootedItems.addAll(BlockUtils.getBlockDrops(treeBlock));
|
||||||
|
}
|
||||||
lootedItems.addAll(BlockUtils.getBlockDrops(treeBlock));
|
lootedItems.addAll(BlockUtils.getBlockDrops(treeBlock));
|
||||||
} else {
|
} else {
|
||||||
switch (treeBlock.getTreeBlockType()) {
|
switch (treeBlock.getTreeBlockType()) {
|
||||||
@ -401,8 +433,9 @@ public class TreeDefinitionManager extends Manager {
|
|||||||
toTry.addAll(this.globalLogLoot);
|
toTry.addAll(this.globalLogLoot);
|
||||||
if (treeDefinition.shouldDropOriginalLog()) {
|
if (treeDefinition.shouldDropOriginalLog()) {
|
||||||
if (ConfigurationManager.Setting.HOOKS_APPLY_EXTRA_DROPS.getBoolean()
|
if (ConfigurationManager.Setting.HOOKS_APPLY_EXTRA_DROPS.getBoolean()
|
||||||
&& McMMOHook.hasWoodcuttingDoubleDrops(player))
|
&& McMMOHook.hasWoodcuttingDoubleDrops(player)) {
|
||||||
lootedItems.addAll(BlockUtils.getBlockDrops(treeBlock));
|
lootedItems.addAll(BlockUtils.getBlockDrops(treeBlock));
|
||||||
|
}
|
||||||
lootedItems.addAll(BlockUtils.getBlockDrops(treeBlock));
|
lootedItems.addAll(BlockUtils.getBlockDrops(treeBlock));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -411,8 +444,9 @@ public class TreeDefinitionManager extends Manager {
|
|||||||
toTry.addAll(this.globalLeafLoot);
|
toTry.addAll(this.globalLeafLoot);
|
||||||
if (treeDefinition.shouldDropOriginalLeaf()) {
|
if (treeDefinition.shouldDropOriginalLeaf()) {
|
||||||
if (ConfigurationManager.Setting.HOOKS_APPLY_EXTRA_DROPS.getBoolean()
|
if (ConfigurationManager.Setting.HOOKS_APPLY_EXTRA_DROPS.getBoolean()
|
||||||
&& McMMOHook.hasWoodcuttingDoubleDrops(player))
|
&& McMMOHook.hasWoodcuttingDoubleDrops(player)) {
|
||||||
lootedItems.addAll(BlockUtils.getBlockDrops(treeBlock));
|
lootedItems.addAll(BlockUtils.getBlockDrops(treeBlock));
|
||||||
|
}
|
||||||
lootedItems.addAll(BlockUtils.getBlockDrops(treeBlock));
|
lootedItems.addAll(BlockUtils.getBlockDrops(treeBlock));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -423,22 +457,27 @@ public class TreeDefinitionManager extends Manager {
|
|||||||
// Roll the dice
|
// Roll the dice
|
||||||
double bonusLootMultiplier = ConfigurationManager.Setting.BONUS_LOOT_MULTIPLIER.getDouble();
|
double bonusLootMultiplier = ConfigurationManager.Setting.BONUS_LOOT_MULTIPLIER.getDouble();
|
||||||
for (TreeLoot treeLoot : toTry) {
|
for (TreeLoot treeLoot : toTry) {
|
||||||
if (treeLoot == null) continue;
|
if (treeLoot == null) {
|
||||||
double chance = hasBonusChance ? treeLoot.getChance() * bonusLootMultiplier : treeLoot.getChance();
|
|
||||||
if (this.random.nextDouble() > chance / 100)
|
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
double chance = hasBonusChance ? treeLoot.getChance() * bonusLootMultiplier : treeLoot.getChance();
|
||||||
|
if (this.random.nextDouble() > chance / 100) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (treeLoot.hasItem()) {
|
if (treeLoot.hasItem()) {
|
||||||
if (ConfigurationManager.Setting.HOOKS_APPLY_EXTRA_DROPS.getBoolean()
|
if (ConfigurationManager.Setting.HOOKS_APPLY_EXTRA_DROPS.getBoolean()
|
||||||
&& McMMOHook.hasWoodcuttingDoubleDrops(player))
|
&& McMMOHook.hasWoodcuttingDoubleDrops(player)) {
|
||||||
lootedItems.add(treeLoot.getItem());
|
lootedItems.add(treeLoot.getItem());
|
||||||
|
}
|
||||||
lootedItems.add(treeLoot.getItem());
|
lootedItems.add(treeLoot.getItem());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (treeLoot.hasCommand()) {
|
if (treeLoot.hasCommand()) {
|
||||||
if (ConfigurationManager.Setting.HOOKS_APPLY_EXTRA_DROPS.getBoolean()
|
if (ConfigurationManager.Setting.HOOKS_APPLY_EXTRA_DROPS.getBoolean()
|
||||||
&& McMMOHook.hasWoodcuttingDoubleDrops(player))
|
&& McMMOHook.hasWoodcuttingDoubleDrops(player)) {
|
||||||
lootedCommands.add(treeLoot.getCommand());
|
lootedCommands.add(treeLoot.getCommand());
|
||||||
|
}
|
||||||
lootedCommands.add(treeLoot.getCommand());
|
lootedCommands.add(treeLoot.getCommand());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -446,32 +485,35 @@ public class TreeDefinitionManager extends Manager {
|
|||||||
// Add to inventory or drop on ground
|
// Add to inventory or drop on ground
|
||||||
if (addToInventory && player.getWorld().equals(treeBlock.getLocation().getWorld())) {
|
if (addToInventory && player.getWorld().equals(treeBlock.getLocation().getWorld())) {
|
||||||
List<ItemStack> extraItems = new ArrayList<>();
|
List<ItemStack> extraItems = new ArrayList<>();
|
||||||
for (ItemStack lootedItem : lootedItems)
|
for (ItemStack lootedItem : lootedItems) {
|
||||||
extraItems.addAll(player.getInventory().addItem(lootedItem).values());
|
extraItems.addAll(player.getInventory().addItem(lootedItem).values());
|
||||||
|
}
|
||||||
Location location = player.getLocation().clone().subtract(0.5, 0, 0.5);
|
Location location = player.getLocation().clone().subtract(0.5, 0, 0.5);
|
||||||
for (ItemStack extraItem : extraItems)
|
for (ItemStack extraItem : extraItems) {
|
||||||
location.getWorld().dropItemNaturally(location, extraItem);
|
location.getWorld().dropItemNaturally(location, extraItem);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
Location location = treeBlock.getLocation().clone().add(0.5, 0.5, 0.5);
|
Location location = treeBlock.getLocation().clone().add(0.5, 0.5, 0.5);
|
||||||
for (ItemStack lootedItem : lootedItems)
|
for (ItemStack lootedItem : lootedItems) {
|
||||||
location.getWorld().dropItemNaturally(location, lootedItem);
|
location.getWorld().dropItemNaturally(location, lootedItem);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Run looted commands
|
// Run looted commands
|
||||||
for (String lootedCommand : lootedCommands)
|
for (String lootedCommand : lootedCommands) {
|
||||||
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(),
|
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(),
|
||||||
lootedCommand.replace("%player%", player.getName())
|
lootedCommand.replace("%player%", player.getName())
|
||||||
.replace("%type%", treeDefinition.getKey())
|
.replace("%type%", treeDefinition.getKey())
|
||||||
.replace("%xPos%", treeBlock.getLocation().getBlockX() + "")
|
.replace("%xPos%", String.valueOf(treeBlock.getLocation().getBlockX()))
|
||||||
.replace("%yPos%", treeBlock.getLocation().getBlockY() + "")
|
.replace("%yPos%", String.valueOf(treeBlock.getLocation().getBlockY()))
|
||||||
.replace("%zPos%", treeBlock.getLocation().getBlockZ() + ""));
|
.replace("%zPos%", String.valueOf(treeBlock.getLocation().getBlockZ())));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets all possible plantable soil blocks for the given tree definition
|
* Gets all possible plantable soil blocks for the given tree definition
|
||||||
*
|
*
|
||||||
* @param treeDefinition The TreeDefinition
|
* @param treeDefinition The TreeDefinition
|
||||||
*
|
|
||||||
* @return A Set of IBlockData of plantable soil
|
* @return A Set of IBlockData of plantable soil
|
||||||
*/
|
*/
|
||||||
public Set<CompatibleMaterial> getPlantableSoilMaterial(TreeDefinition treeDefinition) {
|
public Set<CompatibleMaterial> getPlantableSoilMaterial(TreeDefinition treeDefinition) {
|
||||||
@ -486,7 +528,6 @@ public class TreeDefinitionManager extends Manager {
|
|||||||
*
|
*
|
||||||
* @param treeBlockType The TreeBlockType to use
|
* @param treeBlockType The TreeBlockType to use
|
||||||
* @param configurationSection The ConfigurationSection
|
* @param configurationSection The ConfigurationSection
|
||||||
*
|
|
||||||
* @return A TreeLoot entry from the section
|
* @return A TreeLoot entry from the section
|
||||||
*/
|
*/
|
||||||
private TreeLoot getTreeLootEntry(TreeBlockType treeBlockType, ConfigurationSection configurationSection) {
|
private TreeLoot getTreeLootEntry(TreeBlockType treeBlockType, ConfigurationSection configurationSection) {
|
||||||
|
@ -2,16 +2,24 @@ package com.songoda.ultimatetimber.manager;
|
|||||||
|
|
||||||
import com.songoda.core.compatibility.CompatibleMaterial;
|
import com.songoda.core.compatibility.CompatibleMaterial;
|
||||||
import com.songoda.ultimatetimber.UltimateTimber;
|
import com.songoda.ultimatetimber.UltimateTimber;
|
||||||
import com.songoda.ultimatetimber.tree.*;
|
import com.songoda.ultimatetimber.tree.DetectedTree;
|
||||||
|
import com.songoda.ultimatetimber.tree.ITreeBlock;
|
||||||
|
import com.songoda.ultimatetimber.tree.TreeBlock;
|
||||||
|
import com.songoda.ultimatetimber.tree.TreeBlockSet;
|
||||||
|
import com.songoda.ultimatetimber.tree.TreeBlockType;
|
||||||
|
import com.songoda.ultimatetimber.tree.TreeDefinition;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.BlockFace;
|
import org.bukkit.block.BlockFace;
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public class TreeDetectionManager extends Manager {
|
public class TreeDetectionManager extends Manager {
|
||||||
|
|
||||||
private final Set<Vector> VALID_TRUNK_OFFSETS, VALID_BRANCH_OFFSETS, VALID_LEAF_OFFSETS;
|
private final Set<Vector> VALID_TRUNK_OFFSETS, VALID_BRANCH_OFFSETS, VALID_LEAF_OFFSETS;
|
||||||
|
|
||||||
private TreeDefinitionManager treeDefinitionManager;
|
private TreeDefinitionManager treeDefinitionManager;
|
||||||
@ -19,24 +27,30 @@ public class TreeDetectionManager extends Manager {
|
|||||||
private int numLeavesRequiredForTree;
|
private int numLeavesRequiredForTree;
|
||||||
private boolean onlyBreakLogsUpwards, entireTreeBase, destroyLeaves;
|
private boolean onlyBreakLogsUpwards, entireTreeBase, destroyLeaves;
|
||||||
|
|
||||||
public TreeDetectionManager(UltimateTimber ultimateTimber) {
|
public TreeDetectionManager(UltimateTimber plugin) {
|
||||||
super(ultimateTimber);
|
super(plugin);
|
||||||
|
|
||||||
this.VALID_BRANCH_OFFSETS = new HashSet<>();
|
this.VALID_BRANCH_OFFSETS = new HashSet<>();
|
||||||
this.VALID_TRUNK_OFFSETS = new HashSet<>();
|
this.VALID_TRUNK_OFFSETS = new HashSet<>();
|
||||||
this.VALID_LEAF_OFFSETS = new HashSet<>();
|
this.VALID_LEAF_OFFSETS = new HashSet<>();
|
||||||
|
|
||||||
// 3x2x3 centered around log, excluding -y axis
|
// 3x2x3 centered around log, excluding -y axis
|
||||||
for (int y = 0; y <= 1; y++)
|
for (int y = 0; y <= 1; y++) {
|
||||||
for (int x = -1; x <= 1; x++)
|
for (int x = -1; x <= 1; x++) {
|
||||||
for (int z = -1; z <= 1; z++)
|
for (int z = -1; z <= 1; z++) {
|
||||||
this.VALID_BRANCH_OFFSETS.add(new Vector(x, y, z));
|
this.VALID_BRANCH_OFFSETS.add(new Vector(x, y, z));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 3x3x3 centered around log
|
// 3x3x3 centered around log
|
||||||
for (int y = -1; y <= 1; y++)
|
for (int y = -1; y <= 1; y++) {
|
||||||
for (int x = -1; x <= 1; x++)
|
for (int x = -1; x <= 1; x++) {
|
||||||
for (int z = -1; z <= 1; z++)
|
for (int z = -1; z <= 1; z++) {
|
||||||
this.VALID_TRUNK_OFFSETS.add(new Vector(x, y, z));
|
this.VALID_TRUNK_OFFSETS.add(new Vector(x, y, z));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Adjacent blocks to log
|
// Adjacent blocks to log
|
||||||
for (int i = -1; i <= 1; i += 2) {
|
for (int i = -1; i <= 1; i += 2) {
|
||||||
@ -58,7 +72,6 @@ public class TreeDetectionManager extends Manager {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void disable() {
|
public void disable() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -74,8 +87,9 @@ public class TreeDetectionManager extends Manager {
|
|||||||
TreeBlockSet<Block> detectedTreeBlocks = new TreeBlockSet<>(initialTreeBlock);
|
TreeBlockSet<Block> detectedTreeBlocks = new TreeBlockSet<>(initialTreeBlock);
|
||||||
Set<TreeDefinition> possibleTreeDefinitions = this.treeDefinitionManager.getTreeDefinitionsForLog(initialBlock);
|
Set<TreeDefinition> possibleTreeDefinitions = this.treeDefinitionManager.getTreeDefinitionsForLog(initialBlock);
|
||||||
|
|
||||||
if (possibleTreeDefinitions.isEmpty())
|
if (possibleTreeDefinitions.isEmpty()) {
|
||||||
return null;
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
// Detect tree trunk
|
// Detect tree trunk
|
||||||
List<Block> trunkBlocks = new ArrayList<>();
|
List<Block> trunkBlocks = new ArrayList<>();
|
||||||
@ -98,47 +112,54 @@ public class TreeDetectionManager extends Manager {
|
|||||||
Collections.reverse(trunkBlocks);
|
Collections.reverse(trunkBlocks);
|
||||||
|
|
||||||
// Detect branches off the main trunk
|
// Detect branches off the main trunk
|
||||||
for (Block trunkBlock : trunkBlocks)
|
for (Block trunkBlock : trunkBlocks) {
|
||||||
this.recursiveBranchSearch(possibleTreeDefinitions, trunkBlocks, detectedTreeBlocks, trunkBlock, initialBlock.getLocation().getBlockY());
|
this.recursiveBranchSearch(possibleTreeDefinitions, trunkBlocks, detectedTreeBlocks, trunkBlock, initialBlock.getLocation().getBlockY());
|
||||||
|
}
|
||||||
|
|
||||||
// Detect leaves off the trunk/branches
|
// Detect leaves off the trunk/branches
|
||||||
Set<ITreeBlock<Block>> branchBlocks = new HashSet<>(detectedTreeBlocks.getLogBlocks());
|
Set<ITreeBlock<Block>> branchBlocks = new HashSet<>(detectedTreeBlocks.getLogBlocks());
|
||||||
for (ITreeBlock<Block> branchBlock : branchBlocks)
|
for (ITreeBlock<Block> branchBlock : branchBlocks) {
|
||||||
this.recursiveLeafSearch(possibleTreeDefinitions, detectedTreeBlocks, branchBlock.getBlock(), new HashSet<>());
|
this.recursiveLeafSearch(possibleTreeDefinitions, detectedTreeBlocks, branchBlock.getBlock(), new HashSet<>());
|
||||||
|
}
|
||||||
|
|
||||||
// Use the first tree definition in the set
|
// Use the first tree definition in the set
|
||||||
TreeDefinition actualTreeDefinition = possibleTreeDefinitions.iterator().next();
|
TreeDefinition actualTreeDefinition = possibleTreeDefinitions.iterator().next();
|
||||||
|
|
||||||
// Trees need at least a certain number of leaves
|
// Trees need at least a certain number of leaves
|
||||||
if (detectedTreeBlocks.getLeafBlocks().size() < this.numLeavesRequiredForTree)
|
if (detectedTreeBlocks.getLeafBlocks().size() < this.numLeavesRequiredForTree) {
|
||||||
return null;
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
// Remove leaves if we don't care about the leaves
|
// Remove leaves if we don't care about the leaves
|
||||||
if (!this.destroyLeaves)
|
if (!this.destroyLeaves) {
|
||||||
detectedTreeBlocks.removeAll(TreeBlockType.LEAF);
|
detectedTreeBlocks.removeAll(TreeBlockType.LEAF);
|
||||||
|
}
|
||||||
|
|
||||||
// Check that the tree isn't on the ground if enabled
|
// Check that the tree isn't on the ground if enabled
|
||||||
if (this.entireTreeBase) {
|
if (this.entireTreeBase) {
|
||||||
Set<Block> groundBlocks = new HashSet<>();
|
Set<Block> groundBlocks = new HashSet<>();
|
||||||
for (ITreeBlock<Block> treeBlock : detectedTreeBlocks.getLogBlocks())
|
for (ITreeBlock<Block> treeBlock : detectedTreeBlocks.getLogBlocks()) {
|
||||||
if (treeBlock != detectedTreeBlocks.getInitialLogBlock() && treeBlock.getLocation().getBlockY() == initialBlock.getLocation().getBlockY())
|
if (treeBlock != detectedTreeBlocks.getInitialLogBlock() && treeBlock.getLocation().getBlockY() == initialBlock.getLocation().getBlockY()) {
|
||||||
groundBlocks.add(treeBlock.getBlock());
|
groundBlocks.add(treeBlock.getBlock());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (Block block : groundBlocks) {
|
for (Block block : groundBlocks) {
|
||||||
Block blockBelow = block.getRelative(BlockFace.DOWN);
|
Block blockBelow = block.getRelative(BlockFace.DOWN);
|
||||||
boolean blockBelowIsLog = this.isValidLogType(possibleTreeDefinitions, null, blockBelow);
|
boolean blockBelowIsLog = this.isValidLogType(possibleTreeDefinitions, null, blockBelow);
|
||||||
boolean blockBelowIsSoil = false;
|
boolean blockBelowIsSoil = false;
|
||||||
for (CompatibleMaterial material : treeDefinitionManager.getPlantableSoilMaterial(actualTreeDefinition)) {
|
for (CompatibleMaterial material : treeDefinitionManager.getPlantableSoilMaterial(actualTreeDefinition)) {
|
||||||
if (material.equals(CompatibleMaterial.getMaterial(blockBelow))) {
|
if (material == CompatibleMaterial.getMaterial(blockBelow)) {
|
||||||
blockBelowIsSoil = true;
|
blockBelowIsSoil = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (blockBelowIsLog || blockBelowIsSoil)
|
if (blockBelowIsLog || blockBelowIsSoil) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return new DetectedTree(actualTreeDefinition, detectedTreeBlocks);
|
return new DetectedTree(actualTreeDefinition, detectedTreeBlocks);
|
||||||
}
|
}
|
||||||
@ -159,11 +180,12 @@ public class TreeDetectionManager extends Manager {
|
|||||||
if (this.isValidLogType(treeDefinitions, trunkBlocks, targetBlock) && !treeBlocks.contains(treeBlock)) {
|
if (this.isValidLogType(treeDefinitions, trunkBlocks, targetBlock) && !treeBlocks.contains(treeBlock)) {
|
||||||
treeBlocks.add(treeBlock);
|
treeBlocks.add(treeBlock);
|
||||||
treeDefinitions.retainAll(this.treeDefinitionManager.narrowTreeDefinition(treeDefinitions, targetBlock, TreeBlockType.LOG));
|
treeDefinitions.retainAll(this.treeDefinitionManager.narrowTreeDefinition(treeDefinitions, targetBlock, TreeBlockType.LOG));
|
||||||
if (!this.onlyBreakLogsUpwards || targetBlock.getLocation().getBlockY() > startingBlockY)
|
if (!this.onlyBreakLogsUpwards || targetBlock.getLocation().getBlockY() > startingBlockY) {
|
||||||
this.recursiveBranchSearch(treeDefinitions, trunkBlocks, treeBlocks, targetBlock, startingBlockY);
|
this.recursiveBranchSearch(treeDefinitions, trunkBlocks, treeBlocks, targetBlock, startingBlockY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Recursively searches for leaves that are next to this tree
|
* Recursively searches for leaves that are next to this tree
|
||||||
@ -177,8 +199,9 @@ public class TreeDetectionManager extends Manager {
|
|||||||
|
|
||||||
for (Vector offset : !detectLeavesDiagonally ? this.VALID_LEAF_OFFSETS : this.VALID_TRUNK_OFFSETS) {
|
for (Vector offset : !detectLeavesDiagonally ? this.VALID_LEAF_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());
|
||||||
if (visitedBlocks.contains(targetBlock))
|
if (visitedBlocks.contains(targetBlock)) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
visitedBlocks.add(targetBlock);
|
visitedBlocks.add(targetBlock);
|
||||||
TreeBlock treeBlock = new TreeBlock(targetBlock, TreeBlockType.LEAF);
|
TreeBlock treeBlock = new TreeBlock(targetBlock, TreeBlockType.LEAF);
|
||||||
@ -201,9 +224,10 @@ public class TreeDetectionManager extends Manager {
|
|||||||
private boolean doesLeafBorderInvalidLog(Set<TreeDefinition> treeDefinitions, TreeBlockSet<Block> treeBlocks, Block block) {
|
private boolean doesLeafBorderInvalidLog(Set<TreeDefinition> treeDefinitions, TreeBlockSet<Block> treeBlocks, Block block) {
|
||||||
for (Vector offset : this.VALID_TRUNK_OFFSETS) {
|
for (Vector offset : this.VALID_TRUNK_OFFSETS) {
|
||||||
Block targetBlock = block.getRelative(offset.getBlockX(), offset.getBlockY(), offset.getBlockZ());
|
Block targetBlock = block.getRelative(offset.getBlockX(), offset.getBlockY(), offset.getBlockZ());
|
||||||
if (this.isValidLogType(treeDefinitions, null, targetBlock) && !treeBlocks.contains(new TreeBlock(targetBlock, TreeBlockType.LOG)))
|
if (this.isValidLogType(treeDefinitions, null, targetBlock) && !treeBlocks.contains(new TreeBlock(targetBlock, TreeBlockType.LOG))) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -217,36 +241,43 @@ public class TreeDetectionManager extends Manager {
|
|||||||
*/
|
*/
|
||||||
private boolean isValidLogType(Set<TreeDefinition> treeDefinitions, List<Block> trunkBlocks, Block block) {
|
private boolean isValidLogType(Set<TreeDefinition> treeDefinitions, List<Block> trunkBlocks, Block block) {
|
||||||
// Check if block is placed
|
// Check if block is placed
|
||||||
if (this.placedBlockManager.isBlockPlaced(block))
|
if (this.placedBlockManager.isBlockPlaced(block)) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// Check if it matches the tree definition
|
// Check if it matches the tree definition
|
||||||
boolean isCorrectType = false;
|
boolean isCorrectType = false;
|
||||||
for (TreeDefinition treeDefinition : treeDefinitions) {
|
for (TreeDefinition treeDefinition : treeDefinitions) {
|
||||||
for (CompatibleMaterial material : treeDefinition.getLogMaterial()) {
|
for (CompatibleMaterial material : treeDefinition.getLogMaterial()) {
|
||||||
if (material.equals(CompatibleMaterial.getMaterial(block))) {
|
if (material == CompatibleMaterial.getMaterial(block)) {
|
||||||
isCorrectType = true;
|
isCorrectType = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isCorrectType)
|
if (!isCorrectType) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// Check that it is close enough to the trunk
|
// Check that it is close enough to the trunk
|
||||||
if (trunkBlocks == null || trunkBlocks.isEmpty())
|
if (trunkBlocks == null || trunkBlocks.isEmpty()) {
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
Location location = block.getLocation();
|
Location location = block.getLocation();
|
||||||
for (TreeDefinition treeDefinition : treeDefinitions) {
|
for (TreeDefinition treeDefinition : treeDefinitions) {
|
||||||
double maxDistance = treeDefinition.getMaxLogDistanceFromTrunk() * treeDefinition.getMaxLogDistanceFromTrunk();
|
double maxDistance = treeDefinition.getMaxLogDistanceFromTrunk() * treeDefinition.getMaxLogDistanceFromTrunk();
|
||||||
if (!this.onlyBreakLogsUpwards) // Help detect logs more often if the tree isn't broken at the base
|
if (!this.onlyBreakLogsUpwards) // Help detect logs more often if the tree isn't broken at the base
|
||||||
|
{
|
||||||
maxDistance *= 1.5;
|
maxDistance *= 1.5;
|
||||||
for (Block trunkBlock : trunkBlocks)
|
}
|
||||||
if (location.distanceSquared(trunkBlock.getLocation()) < maxDistance)
|
for (Block trunkBlock : trunkBlocks) {
|
||||||
|
if (location.distanceSquared(trunkBlock.getLocation()) < maxDistance) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -261,29 +292,31 @@ public class TreeDetectionManager extends Manager {
|
|||||||
*/
|
*/
|
||||||
private boolean isValidLeafType(Set<TreeDefinition> treeDefinitions, TreeBlockSet<Block> treeBlocks, Block block) {
|
private boolean isValidLeafType(Set<TreeDefinition> treeDefinitions, TreeBlockSet<Block> treeBlocks, Block block) {
|
||||||
// Check if block is placed
|
// Check if block is placed
|
||||||
if (this.placedBlockManager.isBlockPlaced(block))
|
if (this.placedBlockManager.isBlockPlaced(block)) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// Check if it matches the tree definition
|
// Check if it matches the tree definition
|
||||||
boolean isCorrectType = false;
|
boolean isCorrectType = false;
|
||||||
for (TreeDefinition treeDefinition : treeDefinitions) {
|
for (TreeDefinition treeDefinition : treeDefinitions) {
|
||||||
for (CompatibleMaterial material : treeDefinition.getLeafMaterial()) {
|
for (CompatibleMaterial material : treeDefinition.getLeafMaterial()) {
|
||||||
if (material.equals(CompatibleMaterial.getMaterial(block))) {
|
if (material == CompatibleMaterial.getMaterial(block)) {
|
||||||
isCorrectType = true;
|
isCorrectType = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isCorrectType)
|
if (!isCorrectType) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// Check that it is close enough to a log
|
// Check that it is close enough to a log
|
||||||
if (treeBlocks == null || treeBlocks.isEmpty())
|
if (treeBlocks == null || treeBlocks.isEmpty()) {
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
int maxDistanceFromLog = treeDefinitions.stream().map(TreeDefinition::getMaxLeafDistanceFromLog).max(Integer::compareTo).orElse(0);
|
int maxDistanceFromLog = treeDefinitions.stream().map(TreeDefinition::getMaxLeafDistanceFromLog).max(Integer::compareTo).orElse(0);
|
||||||
return treeBlocks.getLogBlocks().stream().anyMatch(x -> x.getLocation().distanceSquared(block.getLocation()) < maxDistanceFromLog * maxDistanceFromLog);
|
return treeBlocks.getLogBlocks().stream().anyMatch(x -> x.getLocation().distanceSquared(block.getLocation()) < maxDistanceFromLog * maxDistanceFromLog);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -28,12 +28,11 @@ import org.bukkit.inventory.ItemStack;
|
|||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class TreeFallManager extends Manager implements Listener {
|
public class TreeFallManager extends Manager implements Listener {
|
||||||
|
|
||||||
private int maxLogBlocksAllowed;
|
private int maxLogBlocksAllowed;
|
||||||
|
|
||||||
public TreeFallManager(UltimateTimber ultimateTimber) {
|
public TreeFallManager(UltimateTimber plugin) {
|
||||||
super(ultimateTimber);
|
super(plugin);
|
||||||
Bukkit.getPluginManager().registerEvents(this, ultimateTimber);
|
Bukkit.getPluginManager().registerEvents(this, plugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -43,7 +42,6 @@ public class TreeFallManager extends Manager implements Listener {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void disable() {
|
public void disable() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
@ -67,54 +65,65 @@ public class TreeFallManager extends Manager implements Listener {
|
|||||||
// Condition checks
|
// Condition checks
|
||||||
boolean isValid = true;
|
boolean isValid = true;
|
||||||
|
|
||||||
if (ConfigurationManager.Setting.DISABLED_WORLDS.getStringList().contains(player.getWorld().getName()))
|
if (ConfigurationManager.Setting.DISABLED_WORLDS.getStringList().contains(player.getWorld().getName())) {
|
||||||
isValid = false;
|
isValid = false;
|
||||||
|
}
|
||||||
|
|
||||||
if (!ConfigurationManager.Setting.ALLOW_CREATIVE_MODE.getBoolean() && player.getGameMode().equals(GameMode.CREATIVE))
|
if (!ConfigurationManager.Setting.ALLOW_CREATIVE_MODE.getBoolean() && player.getGameMode().equals(GameMode.CREATIVE)) {
|
||||||
isValid = false;
|
isValid = false;
|
||||||
|
}
|
||||||
|
|
||||||
if (!this.checkToppleWhile(player))
|
if (!this.checkToppleWhile(player)) {
|
||||||
isValid = false;
|
isValid = false;
|
||||||
|
}
|
||||||
|
|
||||||
if (ConfigurationManager.Setting.REQUIRE_CHOP_PERMISSION.getBoolean() && !player.hasPermission("ultimatetimber.chop"))
|
if (ConfigurationManager.Setting.REQUIRE_CHOP_PERMISSION.getBoolean() && !player.hasPermission("ultimatetimber.chop")) {
|
||||||
isValid = false;
|
isValid = false;
|
||||||
|
}
|
||||||
|
|
||||||
if (!choppingManager.isChopping(player))
|
if (!choppingManager.isChopping(player)) {
|
||||||
isValid = false;
|
isValid = false;
|
||||||
|
}
|
||||||
|
|
||||||
if (choppingManager.isInCooldown(player))
|
if (choppingManager.isInCooldown(player)) {
|
||||||
isValid = false;
|
isValid = false;
|
||||||
|
}
|
||||||
|
|
||||||
if (treeAnimationManager.isBlockInAnimation(block)) {
|
if (treeAnimationManager.isBlockInAnimation(block)) {
|
||||||
isValid = false;
|
isValid = false;
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!treeDefinitionManager.isToolValidForAnyTreeDefinition(tool))
|
if (!treeDefinitionManager.isToolValidForAnyTreeDefinition(tool)) {
|
||||||
isValid = false;
|
isValid = false;
|
||||||
|
}
|
||||||
|
|
||||||
if (ConfigurationManager.Setting.HOOKS_REQUIRE_ABILITY_ACTIVE.getBoolean()
|
if (ConfigurationManager.Setting.HOOKS_REQUIRE_ABILITY_ACTIVE.getBoolean() && !McMMOHook.isUsingTreeFeller(player)) {
|
||||||
&& !McMMOHook.isUsingTreeFeller(player))
|
|
||||||
isValid = false;
|
isValid = false;
|
||||||
|
}
|
||||||
|
|
||||||
boolean alwaysReplantSapling = ConfigurationManager.Setting.ALWAYS_REPLANT_SAPLING.getBoolean();
|
boolean alwaysReplantSapling = ConfigurationManager.Setting.ALWAYS_REPLANT_SAPLING.getBoolean();
|
||||||
if (!isValid && !alwaysReplantSapling)
|
if (!isValid && !alwaysReplantSapling) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
DetectedTree detectedTree = treeDetectionManager.detectTree(block);
|
DetectedTree detectedTree = treeDetectionManager.detectTree(block);
|
||||||
if (detectedTree == null)
|
if (detectedTree == null) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (alwaysReplantSapling) {
|
if (alwaysReplantSapling) {
|
||||||
Bukkit.getScheduler().scheduleSyncDelayedTask(this.plugin, () ->
|
Bukkit.getScheduler().scheduleSyncDelayedTask(this.plugin, () ->
|
||||||
saplingManager.replantSapling(detectedTree.getTreeDefinition(), detectedTree.getDetectedTreeBlocks().getInitialLogBlock()));
|
saplingManager.replantSapling(detectedTree.getTreeDefinition(), detectedTree.getDetectedTreeBlocks().getInitialLogBlock()));
|
||||||
|
|
||||||
if (!isValid)
|
if (!isValid) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!treeDefinitionManager.isToolValidForTreeDefinition(detectedTree.getTreeDefinition(), tool))
|
if (!treeDefinitionManager.isToolValidForTreeDefinition(detectedTree.getTreeDefinition(), tool)) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
short toolDamage = this.getToolDamage(detectedTree.getDetectedTreeBlocks(), tool.containsEnchantment(Enchantment.SILK_TOUCH));
|
short toolDamage = this.getToolDamage(detectedTree.getDetectedTreeBlocks(), tool.containsEnchantment(Enchantment.SILK_TOUCH));
|
||||||
if (ConfigurationManager.Setting.PROTECT_TOOL.getBoolean() && !ItemUtils.hasEnoughDurability(tool, toolDamage)) {
|
if (ConfigurationManager.Setting.PROTECT_TOOL.getBoolean() && !ItemUtils.hasEnoughDurability(tool, toolDamage)) {
|
||||||
@ -124,13 +133,14 @@ public class TreeFallManager extends Manager implements Listener {
|
|||||||
// Trigger fall event
|
// Trigger fall event
|
||||||
TreeFallEvent treeFallEvent = new TreeFallEvent(player, detectedTree);
|
TreeFallEvent treeFallEvent = new TreeFallEvent(player, detectedTree);
|
||||||
Bukkit.getPluginManager().callEvent(treeFallEvent);
|
Bukkit.getPluginManager().callEvent(treeFallEvent);
|
||||||
if (treeFallEvent.isCancelled())
|
if (treeFallEvent.isCancelled()) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// 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);
|
detectedTree.getDetectedTreeBlocks().sortAndLimit(this.maxLogBlocksAllowed);
|
||||||
|
|
||||||
choppingManager.cooldownPlayer(player);
|
choppingManager.cooldownPlayer(player);
|
||||||
|
|
||||||
@ -140,7 +150,7 @@ public class TreeFallManager extends Manager implements Listener {
|
|||||||
detectedTree.getDetectedTreeBlocks().remove(detectedTree.getDetectedTreeBlocks().getInitialLogBlock());
|
detectedTree.getDetectedTreeBlocks().remove(detectedTree.getDetectedTreeBlocks().getInitialLogBlock());
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isCreative = player.getGameMode().equals(GameMode.CREATIVE);
|
boolean isCreative = player.getGameMode() == GameMode.CREATIVE;
|
||||||
|
|
||||||
if (!isCreative) {
|
if (!isCreative) {
|
||||||
new SItemStack(tool).addDamage(player, toolDamage, true);
|
new SItemStack(tool).addDamage(player, toolDamage, true);
|
||||||
@ -150,13 +160,16 @@ public class TreeFallManager extends Manager implements Listener {
|
|||||||
McMMOHook.addWoodcutting(player, detectedTree.getDetectedTreeBlocks().getAllTreeBlocks().stream()
|
McMMOHook.addWoodcutting(player, detectedTree.getDetectedTreeBlocks().getAllTreeBlocks().stream()
|
||||||
.map(ITreeBlock::getBlock).collect(Collectors.toList()));
|
.map(ITreeBlock::getBlock).collect(Collectors.toList()));
|
||||||
|
|
||||||
if (!isCreative && JobsHook.isEnabled())
|
if (!isCreative && JobsHook.isEnabled()) {
|
||||||
for (ITreeBlock<Block> treeBlock : detectedTree.getDetectedTreeBlocks().getLogBlocks())
|
for (ITreeBlock<Block> treeBlock : detectedTree.getDetectedTreeBlocks().getLogBlocks()) {
|
||||||
JobsHook.breakBlock(player, treeBlock.getBlock());
|
JobsHook.breakBlock(player, treeBlock.getBlock());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (ITreeBlock<Block> treeBlock : detectedTree.getDetectedTreeBlocks().getAllTreeBlocks())
|
for (ITreeBlock<Block> treeBlock : detectedTree.getDetectedTreeBlocks().getAllTreeBlocks()) {
|
||||||
LogManager.logRemoval(player, treeBlock.getBlock());
|
LogManager.logRemoval(player, treeBlock.getBlock());
|
||||||
|
}
|
||||||
|
|
||||||
treeAnimationManager.runAnimation(detectedTree, player);
|
treeAnimationManager.runAnimation(detectedTree, player);
|
||||||
treeDefinitionManager.dropTreeLoot(detectedTree.getTreeDefinition(), detectedTree.getDetectedTreeBlocks().getInitialLogBlock(), player, false, true);
|
treeDefinitionManager.dropTreeLoot(detectedTree.getTreeDefinition(), detectedTree.getDetectedTreeBlocks().getInitialLogBlock(), player, false, true);
|
||||||
@ -170,7 +183,6 @@ public class TreeFallManager extends Manager implements Listener {
|
|||||||
* Checks if a player is doing a certain action required to topple a tree
|
* Checks if a player is doing a certain action required to topple a tree
|
||||||
*
|
*
|
||||||
* @param player The player to check
|
* @param player The player to check
|
||||||
*
|
|
||||||
* @return True if the check passes, otherwise false
|
* @return True if the check passes, otherwise false
|
||||||
*/
|
*/
|
||||||
private boolean checkToppleWhile(Player player) {
|
private boolean checkToppleWhile(Player player) {
|
||||||
@ -185,8 +197,9 @@ public class TreeFallManager extends Manager implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private short getToolDamage(TreeBlockSet<Block> treeBlocks, boolean hasSilkTouch) {
|
private short getToolDamage(TreeBlockSet<Block> treeBlocks, boolean hasSilkTouch) {
|
||||||
if (!ConfigurationManager.Setting.REALISTIC_TOOL_DAMAGE.getBoolean())
|
if (!ConfigurationManager.Setting.REALISTIC_TOOL_DAMAGE.getBoolean()) {
|
||||||
return 1;
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
if (ConfigurationManager.Setting.APPLY_SILK_TOUCH_TOOL_DAMAGE.getBoolean() && hasSilkTouch) {
|
if (ConfigurationManager.Setting.APPLY_SILK_TOUCH_TOOL_DAMAGE.getBoolean() && hasSilkTouch) {
|
||||||
return (short) treeBlocks.size();
|
return (short) treeBlocks.size();
|
||||||
|
@ -1,20 +1,20 @@
|
|||||||
package com.songoda.ultimatetimber.misc;
|
package com.songoda.ultimatetimber.misc;
|
||||||
|
|
||||||
public enum OnlyToppleWhile {
|
public enum OnlyToppleWhile {
|
||||||
SNEAKING,
|
SNEAKING, NOT_SNEAKING, ALWAYS;
|
||||||
NOT_SNEAKING,
|
|
||||||
ALWAYS;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets an OnlyToppleWhile from a given string
|
* Gets an OnlyToppleWhile from a given string
|
||||||
*
|
*
|
||||||
* @param string The string
|
* @return The TreeAnimationType, returns {@link #ALWAYS} if the string is an invalid type
|
||||||
* @return The TreeAnimationType, returns FANCY if the string is an invalid type
|
|
||||||
*/
|
*/
|
||||||
public static OnlyToppleWhile fromString(String string) {
|
public static OnlyToppleWhile fromString(String string) {
|
||||||
for (OnlyToppleWhile value : values())
|
for (OnlyToppleWhile value : values()) {
|
||||||
if (value.name().equalsIgnoreCase(string))
|
if (value.name().equalsIgnoreCase(string)) {
|
||||||
return value;
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return OnlyToppleWhile.ALWAYS;
|
return OnlyToppleWhile.ALWAYS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,9 +3,8 @@ package com.songoda.ultimatetimber.tree;
|
|||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
|
|
||||||
public class DetectedTree {
|
public class DetectedTree {
|
||||||
|
private final TreeDefinition treeDefinition;
|
||||||
private TreeDefinition treeDefinition;
|
private final TreeBlockSet<Block> detectedTreeBlocks;
|
||||||
private TreeBlockSet<Block> detectedTreeBlocks;
|
|
||||||
|
|
||||||
public DetectedTree(TreeDefinition treeDefinition, TreeBlockSet<Block> detectedTreeBlocks) {
|
public DetectedTree(TreeDefinition treeDefinition, TreeBlockSet<Block> detectedTreeBlocks) {
|
||||||
this.treeDefinition = treeDefinition;
|
this.treeDefinition = treeDefinition;
|
||||||
@ -29,5 +28,4 @@ public class DetectedTree {
|
|||||||
public TreeBlockSet<Block> getDetectedTreeBlocks() {
|
public TreeBlockSet<Block> getDetectedTreeBlocks() {
|
||||||
return this.detectedTreeBlocks;
|
return this.detectedTreeBlocks;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,6 @@ import org.bukkit.Location;
|
|||||||
import org.bukkit.entity.FallingBlock;
|
import org.bukkit.entity.FallingBlock;
|
||||||
|
|
||||||
public class FallingTreeBlock implements ITreeBlock<FallingBlock> {
|
public class FallingTreeBlock implements ITreeBlock<FallingBlock> {
|
||||||
|
|
||||||
private final FallingBlock fallingBlock;
|
private final FallingBlock fallingBlock;
|
||||||
private final TreeBlockType treeBlockType;
|
private final TreeBlockType treeBlockType;
|
||||||
|
|
||||||
@ -27,5 +26,4 @@ public class FallingTreeBlock implements ITreeBlock<FallingBlock> {
|
|||||||
public TreeBlockType getTreeBlockType() {
|
public TreeBlockType getTreeBlockType() {
|
||||||
return this.treeBlockType;
|
return this.treeBlockType;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,6 @@ package com.songoda.ultimatetimber.tree;
|
|||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
|
|
||||||
public interface ITreeBlock<BlockType> {
|
public interface ITreeBlock<BlockType> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the block this TreeBlock represents
|
* Gets the block this TreeBlock represents
|
||||||
*
|
*
|
||||||
@ -24,5 +23,4 @@ public interface ITreeBlock<BlockType> {
|
|||||||
* @return The TreeBlockType
|
* @return The TreeBlockType
|
||||||
*/
|
*/
|
||||||
TreeBlockType getTreeBlockType();
|
TreeBlockType getTreeBlockType();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,6 @@ import org.bukkit.block.Block;
|
|||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
public class TreeBlock implements ITreeBlock<Block> {
|
public class TreeBlock implements ITreeBlock<Block> {
|
||||||
|
|
||||||
private final Block block;
|
private final Block block;
|
||||||
private final TreeBlockType treeBlockType;
|
private final TreeBlockType treeBlockType;
|
||||||
|
|
||||||
@ -36,11 +35,15 @@ public class TreeBlock implements ITreeBlock<Block> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object obj) {
|
||||||
if (!(o instanceof TreeBlock)) return false;
|
if (!(obj instanceof TreeBlock)) {
|
||||||
if (o == this) return true;
|
return false;
|
||||||
TreeBlock oTreeBlock = (TreeBlock)o;
|
}
|
||||||
return oTreeBlock.block.equals(this.block) && oTreeBlock.treeBlockType.equals(this.treeBlockType);
|
if (obj == this) {
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TreeBlock oTreeBlock = (TreeBlock) obj;
|
||||||
|
return oTreeBlock.block.equals(this.block) && oTreeBlock.treeBlockType == this.treeBlockType;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
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.Comparator;
|
||||||
@ -13,7 +11,6 @@ import java.util.Set;
|
|||||||
import java.util.stream.Collectors;
|
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 List<ITreeBlock<BlockType>> logBlocks;
|
private List<ITreeBlock<BlockType>> logBlocks;
|
||||||
private final List<ITreeBlock<BlockType>> leafBlocks;
|
private final List<ITreeBlock<BlockType>> leafBlocks;
|
||||||
@ -29,9 +26,10 @@ public class TreeBlockSet<BlockType> implements Collection {
|
|||||||
this.logBlocks = new LinkedList<>();
|
this.logBlocks = new LinkedList<>();
|
||||||
this.leafBlocks = new LinkedList<>();
|
this.leafBlocks = new LinkedList<>();
|
||||||
|
|
||||||
if (initialLogBlock != null)
|
if (initialLogBlock != null) {
|
||||||
this.logBlocks.add(initialLogBlock);
|
this.logBlocks.add(initialLogBlock);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the TreeBlock that initiated the tree topple
|
* Gets the TreeBlock that initiated the tree topple
|
||||||
@ -100,7 +98,9 @@ public class TreeBlockSet<BlockType> implements Collection {
|
|||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public boolean add(Object o) {
|
public boolean add(Object o) {
|
||||||
if (!(o instanceof ITreeBlock)) return false;
|
if (!(o instanceof ITreeBlock)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
ITreeBlock treeBlock = (ITreeBlock) o;
|
ITreeBlock treeBlock = (ITreeBlock) o;
|
||||||
switch (treeBlock.getTreeBlockType()) {
|
switch (treeBlock.getTreeBlockType()) {
|
||||||
case LOG:
|
case LOG:
|
||||||
@ -113,7 +113,9 @@ public class TreeBlockSet<BlockType> implements Collection {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean remove(Object o) {
|
public boolean remove(Object o) {
|
||||||
if (!(o instanceof ITreeBlock)) return false;
|
if (!(o instanceof ITreeBlock)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
ITreeBlock treeBlock = (ITreeBlock) o;
|
ITreeBlock treeBlock = (ITreeBlock) o;
|
||||||
switch (treeBlock.getTreeBlockType()) {
|
switch (treeBlock.getTreeBlockType()) {
|
||||||
case LOG:
|
case LOG:
|
||||||
@ -168,18 +170,22 @@ public class TreeBlockSet<BlockType> implements Collection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void sortAndLimit(int max) {
|
public void sortAndLimit(int max) {
|
||||||
if (logBlocks.size() < max)
|
if (this.logBlocks.size() < max) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
logBlocks = logBlocks.stream().sorted(Comparator.comparingInt(b -> b.getLocation().getBlockY()))
|
this.logBlocks = this.logBlocks.stream().sorted(Comparator.comparingInt(b -> b.getLocation().getBlockY()))
|
||||||
.limit(max).collect(Collectors.toList());
|
.limit(max).collect(Collectors.toList());
|
||||||
|
|
||||||
int highest = logBlocks.get(logBlocks.size() - 1).getLocation().getBlockY();
|
int highest = this.logBlocks.get(this.logBlocks.size() - 1).getLocation().getBlockY();
|
||||||
|
|
||||||
if (logBlocks.size() >= max)
|
if (this.logBlocks.size() >= max) {
|
||||||
for (ITreeBlock<BlockType> leafBlock : new LinkedList<>(leafBlocks))
|
for (ITreeBlock<BlockType> leafBlock : new LinkedList<>(this.leafBlocks)) {
|
||||||
if (leafBlock.getLocation().getY() > highest)
|
if (leafBlock.getLocation().getY() > highest) {
|
||||||
leafBlocks.remove(leafBlock);
|
this.leafBlocks.remove(leafBlock);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -189,11 +195,12 @@ public class TreeBlockSet<BlockType> implements Collection {
|
|||||||
* @return If any blocks were removed
|
* @return If any blocks were removed
|
||||||
*/
|
*/
|
||||||
public boolean removeAll(TreeBlockType treeBlockType) {
|
public boolean removeAll(TreeBlockType treeBlockType) {
|
||||||
if (treeBlockType.equals(TreeBlockType.LOG)) {
|
if (treeBlockType == TreeBlockType.LOG) {
|
||||||
boolean removedAny = !this.logBlocks.isEmpty();
|
boolean removedAny = !this.logBlocks.isEmpty();
|
||||||
this.logBlocks.clear();
|
this.logBlocks.clear();
|
||||||
return removedAny;
|
return removedAny;
|
||||||
} else if (treeBlockType.equals(TreeBlockType.LEAF)) {
|
}
|
||||||
|
if (treeBlockType == TreeBlockType.LEAF) {
|
||||||
boolean removedAny = !this.leafBlocks.isEmpty();
|
boolean removedAny = !this.leafBlocks.isEmpty();
|
||||||
this.leafBlocks.clear();
|
this.leafBlocks.clear();
|
||||||
return removedAny;
|
return removedAny;
|
||||||
@ -203,9 +210,11 @@ public class TreeBlockSet<BlockType> implements Collection {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean containsAll(Collection c) {
|
public boolean containsAll(Collection c) {
|
||||||
for (Object o : c)
|
for (Object o : c) {
|
||||||
if (!this.contains(o))
|
if (!this.contains(o)) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -213,10 +222,12 @@ public class TreeBlockSet<BlockType> implements Collection {
|
|||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public Object[] toArray(Object[] a) {
|
public Object[] toArray(Object[] a) {
|
||||||
Set<ITreeBlock<BlockType>> treeBlocks = new HashSet<>();
|
Set<ITreeBlock<BlockType>> treeBlocks = new HashSet<>();
|
||||||
for (Object o : a)
|
for (Object o : a) {
|
||||||
if (o instanceof ITreeBlock)
|
if (o instanceof ITreeBlock) {
|
||||||
treeBlocks.add((ITreeBlock<BlockType>) o);
|
treeBlocks.add((ITreeBlock<BlockType>) o);
|
||||||
return treeBlocks.toArray();
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return treeBlocks.toArray();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,5 @@
|
|||||||
package com.songoda.ultimatetimber.tree;
|
package com.songoda.ultimatetimber.tree;
|
||||||
|
|
||||||
/**
|
|
||||||
* Represents a tree block type and whether it is a log or a leaf block
|
|
||||||
*/
|
|
||||||
public enum TreeBlockType {
|
public enum TreeBlockType {
|
||||||
LOG,
|
LOG, LEAF
|
||||||
LEAF
|
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,6 @@ import java.util.Collections;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class TreeDefinition {
|
public class TreeDefinition {
|
||||||
|
|
||||||
private final String key;
|
private final String key;
|
||||||
private final Set<CompatibleMaterial> logMaterial, leafMaterial, plantableSoilMaterial;
|
private final Set<CompatibleMaterial> logMaterial, leafMaterial, plantableSoilMaterial;
|
||||||
private final CompatibleMaterial saplingMaterial;
|
private final CompatibleMaterial saplingMaterial;
|
||||||
@ -167,11 +166,11 @@ public class TreeDefinition {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns whether or not does this TreeDefinition require a custom axe.
|
* Returns whether this TreeDefinition requires a custom axe.
|
||||||
*
|
*
|
||||||
* @return True if the TreeDefinition requires a custom axe
|
* @return True if the TreeDefinition requires a custom axe
|
||||||
*/
|
*/
|
||||||
public boolean isRequiredAxe() {
|
public boolean isRequiredAxe() {
|
||||||
return requiredAxe;
|
return this.requiredAxe;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,6 @@ package com.songoda.ultimatetimber.tree;
|
|||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
public class TreeLoot {
|
public class TreeLoot {
|
||||||
|
|
||||||
private final TreeBlockType treeBlockType;
|
private final TreeBlockType treeBlockType;
|
||||||
private final ItemStack item;
|
private final ItemStack item;
|
||||||
private final String command;
|
private final String command;
|
||||||
@ -73,10 +72,10 @@ public class TreeLoot {
|
|||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "TreeLoot{" +
|
return "TreeLoot{" +
|
||||||
"treeBlockType=" + treeBlockType +
|
"treeBlockType=" + this.treeBlockType +
|
||||||
", item=" + item +
|
", item=" + this.item +
|
||||||
", command='" + command + '\'' +
|
", command='" + this.command + '\'' +
|
||||||
", chance=" + chance +
|
", chance=" + this.chance +
|
||||||
'}';
|
'}';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,6 @@ import java.util.HashSet;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class BlockUtils {
|
public class BlockUtils {
|
||||||
|
|
||||||
public static Collection<ItemStack> getBlockDrops(ITreeBlock treeBlock) {
|
public static Collection<ItemStack> getBlockDrops(ITreeBlock treeBlock) {
|
||||||
Set<ItemStack> drops = new HashSet<>();
|
Set<ItemStack> drops = new HashSet<>();
|
||||||
if (treeBlock.getBlock() instanceof Block) {
|
if (treeBlock.getBlock() instanceof Block) {
|
||||||
@ -45,5 +44,4 @@ public class BlockUtils {
|
|||||||
fallingBlock.setDropItem(false);
|
fallingBlock.setDropItem(false);
|
||||||
fallingBlock.setHurtEntities(false);
|
fallingBlock.setHurtEntities(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,6 @@ package com.songoda.ultimatetimber.utils;
|
|||||||
|
|
||||||
import com.songoda.core.compatibility.ServerVersion;
|
import com.songoda.core.compatibility.ServerVersion;
|
||||||
import com.songoda.ultimatetimber.tree.ITreeBlock;
|
import com.songoda.ultimatetimber.tree.ITreeBlock;
|
||||||
import com.songoda.ultimatetimber.tree.TreeDefinition;
|
|
||||||
import org.bukkit.Effect;
|
import org.bukkit.Effect;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Particle;
|
import org.bukkit.Particle;
|
||||||
@ -14,7 +13,6 @@ import org.bukkit.inventory.ItemStack;
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
public class ParticleUtils {
|
public class ParticleUtils {
|
||||||
|
|
||||||
public static void playFallingParticles(ITreeBlock treeBlock) {
|
public static void playFallingParticles(ITreeBlock treeBlock) {
|
||||||
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13)) {
|
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13)) {
|
||||||
BlockData blockData;
|
BlockData blockData;
|
||||||
@ -22,15 +20,20 @@ public class ParticleUtils {
|
|||||||
blockData = ((Block) treeBlock.getBlock()).getBlockData();
|
blockData = ((Block) treeBlock.getBlock()).getBlockData();
|
||||||
} else if (treeBlock.getBlock() instanceof FallingBlock) {
|
} else if (treeBlock.getBlock() instanceof FallingBlock) {
|
||||||
blockData = ((FallingBlock) treeBlock.getBlock()).getBlockData();
|
blockData = ((FallingBlock) treeBlock.getBlock()).getBlockData();
|
||||||
} else return;
|
} else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Location location = treeBlock.getLocation().clone().add(0.5, 0.5, 0.5);
|
Location location = treeBlock.getLocation().clone().add(0.5, 0.5, 0.5);
|
||||||
location.getWorld().spawnParticle(Particle.BLOCK_DUST, location, 10, blockData);
|
location.getWorld().spawnParticle(Particle.BLOCK_DUST, location, 10, blockData);
|
||||||
} else {
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Collection<ItemStack> blockDrops = BlockUtils.getBlockDrops(treeBlock);
|
Collection<ItemStack> blockDrops = BlockUtils.getBlockDrops(treeBlock);
|
||||||
if (!blockDrops.iterator().hasNext())
|
if (!blockDrops.iterator().hasNext()) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Location location = treeBlock.getLocation().clone().add(0.5, 0.5, 0.5);
|
Location location = treeBlock.getLocation().clone().add(0.5, 0.5, 0.5);
|
||||||
if (ServerVersion.isServerVersion(ServerVersion.V1_8)) {
|
if (ServerVersion.isServerVersion(ServerVersion.V1_8)) {
|
||||||
@ -39,7 +42,6 @@ public class ParticleUtils {
|
|||||||
location.getWorld().spawnParticle(Particle.BLOCK_DUST, location, 10, blockDrops.iterator().next().getData());
|
location.getWorld().spawnParticle(Particle.BLOCK_DUST, location, 10, blockDrops.iterator().next().getData());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public static void playLandingParticles(ITreeBlock treeBlock) {
|
public static void playLandingParticles(ITreeBlock treeBlock) {
|
||||||
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13)) {
|
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13)) {
|
||||||
@ -48,14 +50,20 @@ public class ParticleUtils {
|
|||||||
blockData = ((Block) treeBlock.getBlock()).getBlockData();
|
blockData = ((Block) treeBlock.getBlock()).getBlockData();
|
||||||
} else if (treeBlock.getBlock() instanceof FallingBlock) {
|
} else if (treeBlock.getBlock() instanceof FallingBlock) {
|
||||||
blockData = ((FallingBlock) treeBlock.getBlock()).getBlockData();
|
blockData = ((FallingBlock) treeBlock.getBlock()).getBlockData();
|
||||||
} else return;
|
} else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Location location = treeBlock.getLocation().clone().add(0.5, 0.5, 0.5);
|
Location location = treeBlock.getLocation().clone().add(0.5, 0.5, 0.5);
|
||||||
location.getWorld().spawnParticle(Particle.BLOCK_CRACK, location, 10, blockData);
|
location.getWorld().spawnParticle(Particle.BLOCK_CRACK, location, 10, blockData);
|
||||||
} else {
|
|
||||||
Collection<ItemStack> blockDrops = BlockUtils.getBlockDrops(treeBlock);
|
|
||||||
if (!blockDrops.iterator().hasNext())
|
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Collection<ItemStack> blockDrops = BlockUtils.getBlockDrops(treeBlock);
|
||||||
|
if (!blockDrops.iterator().hasNext()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Location location = treeBlock.getLocation().clone().add(0.5, 0.5, 0.5);
|
Location location = treeBlock.getLocation().clone().add(0.5, 0.5, 0.5);
|
||||||
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_9)) {
|
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_9)) {
|
||||||
@ -65,4 +73,3 @@ public class ParticleUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
@ -6,22 +6,24 @@ import com.songoda.ultimatetimber.tree.TreeBlockType;
|
|||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
|
|
||||||
public class SoundUtils {
|
public class SoundUtils {
|
||||||
|
|
||||||
public static void playFallingSound(ITreeBlock block) {
|
public static void playFallingSound(ITreeBlock block) {
|
||||||
Location location = block.getLocation();
|
Location location = block.getLocation();
|
||||||
if (location.getWorld() == null) return;
|
if (location.getWorld() == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
CompatibleSound.BLOCK_CHEST_OPEN.play(location.getWorld(), location, 2F, 0.1F);
|
CompatibleSound.BLOCK_CHEST_OPEN.play(location.getWorld(), location, 2F, 0.1F);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void playLandingSound(ITreeBlock block) {
|
public static void playLandingSound(ITreeBlock block) {
|
||||||
Location location = block.getLocation();
|
Location location = block.getLocation();
|
||||||
if (location.getWorld() == null) return;
|
if (location.getWorld() == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (block.getTreeBlockType().equals(TreeBlockType.LOG)) {
|
if (block.getTreeBlockType() == TreeBlockType.LOG) {
|
||||||
CompatibleSound.BLOCK_WOOD_FALL.play(location.getWorld(), location, 2F, 0.1F);
|
CompatibleSound.BLOCK_WOOD_FALL.play(location.getWorld(), location, 2F, 0.1F);
|
||||||
} else {
|
} else {
|
||||||
CompatibleSound.BLOCK_GRASS_BREAK.play(location.getWorld(), location, 0.5F, 0.75F);
|
CompatibleSound.BLOCK_GRASS_BREAK.play(location.getWorld(), location, 0.5F, 0.75F);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user