diff --git a/src/main/java/com/songoda/ultimatetimber/adapter/VersionAdapter.java b/src/main/java/com/songoda/ultimatetimber/adapter/VersionAdapter.java index 681faf9..4d20456 100644 --- a/src/main/java/com/songoda/ultimatetimber/adapter/VersionAdapter.java +++ b/src/main/java/com/songoda/ultimatetimber/adapter/VersionAdapter.java @@ -6,6 +6,7 @@ import com.songoda.ultimatetimber.tree.TreeBlockSet; import com.songoda.ultimatetimber.tree.TreeDefinition; import org.bukkit.block.Block; import org.bukkit.block.BlockState; +import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import java.util.Set; @@ -47,6 +48,14 @@ public interface VersionAdapter { */ void applyToolDurability(TreeBlockSet treeBlocks, ItemStack tool); + /** + * Gets the item in the player's main hand + * + * @param player The Player to get the item from + * @return The ItemStack in the Player's main hand + */ + ItemStack getItemInHand(Player player); + /** * Plays particles to indicate a tree has started falling */ diff --git a/src/main/java/com/songoda/ultimatetimber/adapter/current/CurrentAdapter.java b/src/main/java/com/songoda/ultimatetimber/adapter/current/CurrentAdapter.java index c6dd98e..bdda521 100644 --- a/src/main/java/com/songoda/ultimatetimber/adapter/current/CurrentAdapter.java +++ b/src/main/java/com/songoda/ultimatetimber/adapter/current/CurrentAdapter.java @@ -8,6 +8,7 @@ import com.songoda.ultimatetimber.tree.TreeBlockSet; import com.songoda.ultimatetimber.tree.TreeDefinition; import org.bukkit.block.Block; import org.bukkit.block.BlockState; +import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import java.util.Set; @@ -39,6 +40,11 @@ public class CurrentAdapter implements VersionAdapter { } + @Override + public ItemStack getItemInHand(Player player) { + return null; + } + @Override public void playFallingParticles(TreeBlockSet treeBlocks) { diff --git a/src/main/java/com/songoda/ultimatetimber/adapter/legacy/LegacyAdapter.java b/src/main/java/com/songoda/ultimatetimber/adapter/legacy/LegacyAdapter.java index d8e7f47..ca24403 100644 --- a/src/main/java/com/songoda/ultimatetimber/adapter/legacy/LegacyAdapter.java +++ b/src/main/java/com/songoda/ultimatetimber/adapter/legacy/LegacyAdapter.java @@ -8,6 +8,7 @@ import com.songoda.ultimatetimber.tree.TreeBlockSet; import com.songoda.ultimatetimber.tree.TreeDefinition; import org.bukkit.block.Block; import org.bukkit.block.BlockState; +import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import java.util.Set; @@ -39,6 +40,11 @@ public class LegacyAdapter implements VersionAdapter { } + @Override + public ItemStack getItemInHand(Player player) { + return null; + } + @Override public void playFallingParticles(TreeBlockSet treeBlocks) { diff --git a/src/main/java/com/songoda/ultimatetimber/events/TreeEvent.java b/src/main/java/com/songoda/ultimatetimber/events/TreeEvent.java index cd9757f..295ebfe 100644 --- a/src/main/java/com/songoda/ultimatetimber/events/TreeEvent.java +++ b/src/main/java/com/songoda/ultimatetimber/events/TreeEvent.java @@ -1,41 +1,29 @@ package com.songoda.ultimatetimber.events; +import com.songoda.ultimatetimber.tree.TreeBlockSet; import org.bukkit.block.Block; import org.bukkit.entity.Player; import org.bukkit.event.player.PlayerEvent; -import com.songoda.ultimatetimber.old_code.TreeChecker; - /** * Abstract tree event containing tree's blocks and broke block */ public abstract class TreeEvent extends PlayerEvent { - protected final TreeChecker treeChecker; - protected final Block broke; - - public TreeEvent(Player who, TreeChecker treeChecker, Block broke) { - super(who); - this.treeChecker = treeChecker; - this.broke = broke; + protected final TreeBlockSet treeBlocks; + + public TreeEvent(Player player, TreeBlockSet treeBlocks) { + super(player); + this.treeBlocks = treeBlocks; } /** - * Get the tree checker + * Get the tree blocks * * @return tree checker for the tree */ - public TreeChecker getTreeChecker() { - return treeChecker; - } - - /** - * Get the initial block broke by player - * - * @return block broke by player - */ - public Block getBroke() { - return broke; + public TreeBlockSet getTreeBlocks() { + return this.treeBlocks; } } diff --git a/src/main/java/com/songoda/ultimatetimber/events/TreeFallEvent.java b/src/main/java/com/songoda/ultimatetimber/events/TreeFallEvent.java index 0c1550c..9e7d9d5 100644 --- a/src/main/java/com/songoda/ultimatetimber/events/TreeFallEvent.java +++ b/src/main/java/com/songoda/ultimatetimber/events/TreeFallEvent.java @@ -1,12 +1,11 @@ package com.songoda.ultimatetimber.events; +import com.songoda.ultimatetimber.tree.TreeBlockSet; import org.bukkit.block.Block; import org.bukkit.entity.Player; import org.bukkit.event.Cancellable; import org.bukkit.event.HandlerList; -import com.songoda.ultimatetimber.old_code.TreeChecker; - /** * Called when a tree will fall */ @@ -14,8 +13,8 @@ public class TreeFallEvent extends TreeEvent implements Cancellable { private boolean cancelled = false; - public TreeFallEvent(Player player, TreeChecker treeChecker, Block broke) { - super(player, treeChecker, broke); + public TreeFallEvent(Player player, TreeBlockSet treeBlocks) { + super(player, treeBlocks); } private static final HandlerList handlers = new HandlerList(); diff --git a/src/main/java/com/songoda/ultimatetimber/events/TreeFellEvent.java b/src/main/java/com/songoda/ultimatetimber/events/TreeFellEvent.java index 21ba1e1..7abdf39 100644 --- a/src/main/java/com/songoda/ultimatetimber/events/TreeFellEvent.java +++ b/src/main/java/com/songoda/ultimatetimber/events/TreeFellEvent.java @@ -1,18 +1,17 @@ package com.songoda.ultimatetimber.events; +import com.songoda.ultimatetimber.tree.TreeBlockSet; import org.bukkit.block.Block; import org.bukkit.entity.Player; import org.bukkit.event.HandlerList; -import com.songoda.ultimatetimber.old_code.TreeChecker; - /** * Called when a tree fell */ public class TreeFellEvent extends TreeEvent { - public TreeFellEvent(Player player, TreeChecker treeChecker, Block broke) { - super(player, treeChecker, broke); + public TreeFellEvent(Player player, TreeBlockSet treeBlocks) { + super(player, treeBlocks); } private static final HandlerList handlers = new HandlerList(); @@ -25,6 +24,5 @@ public class TreeFellEvent extends TreeEvent { public static HandlerList getHandlerList() { return handlers; } - } diff --git a/src/main/java/com/songoda/ultimatetimber/hooks/TimberHook.java b/src/main/java/com/songoda/ultimatetimber/hooks/TimberHook.java index 5d02b2b..8b3c0c9 100644 --- a/src/main/java/com/songoda/ultimatetimber/hooks/TimberHook.java +++ b/src/main/java/com/songoda/ultimatetimber/hooks/TimberHook.java @@ -1,12 +1,9 @@ package com.songoda.ultimatetimber.hooks; -import com.songoda.ultimatetimber.tree.TreeBlock; import com.songoda.ultimatetimber.tree.TreeBlockSet; import org.bukkit.block.Block; import org.bukkit.entity.Player; -import java.util.Set; - public interface TimberHook { /** diff --git a/src/main/java/com/songoda/ultimatetimber/manager/HookManager.java b/src/main/java/com/songoda/ultimatetimber/manager/HookManager.java index cc3d756..9deac3f 100644 --- a/src/main/java/com/songoda/ultimatetimber/manager/HookManager.java +++ b/src/main/java/com/songoda/ultimatetimber/manager/HookManager.java @@ -1,17 +1,16 @@ package com.songoda.ultimatetimber.manager; -import java.util.HashSet; -import java.util.Set; - import com.songoda.ultimatetimber.UltimateTimber; import com.songoda.ultimatetimber.hooks.JobsHook; import com.songoda.ultimatetimber.hooks.McMMOHook; import com.songoda.ultimatetimber.hooks.TimberHook; import com.songoda.ultimatetimber.tree.TreeBlockSet; import org.bukkit.Bukkit; -import org.bukkit.block.Block; import org.bukkit.entity.Player; +import java.util.HashSet; +import java.util.Set; + public class HookManager extends Manager { private Set hooks; diff --git a/src/main/java/com/songoda/ultimatetimber/manager/TreeDefinitionManager.java b/src/main/java/com/songoda/ultimatetimber/manager/TreeDefinitionManager.java index 0188303..1a6a3a6 100644 --- a/src/main/java/com/songoda/ultimatetimber/manager/TreeDefinitionManager.java +++ b/src/main/java/com/songoda/ultimatetimber/manager/TreeDefinitionManager.java @@ -1,26 +1,105 @@ package com.songoda.ultimatetimber.manager; import com.songoda.ultimatetimber.UltimateTimber; +import com.songoda.ultimatetimber.adapter.VersionAdapter; +import com.songoda.ultimatetimber.tree.ITreeBlock; +import com.songoda.ultimatetimber.tree.TreeBlockType; import com.songoda.ultimatetimber.tree.TreeDefinition; +import com.songoda.ultimatetimber.tree.TreeLoot; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.block.Block; +import org.bukkit.block.BlockState; +import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; import java.util.HashSet; +import java.util.Random; import java.util.Set; public class TreeDefinitionManager extends Manager { - private UltimateTimber ultimateTimber; + private final Random random; private Set treeDefinitions; + private Set globalLogLoot, globalLeafLoot; + private Set globalRequiredTools; public TreeDefinitionManager(UltimateTimber ultimateTimber) { super(ultimateTimber); + this.random = new Random(); this.treeDefinitions = new HashSet<>(); + this.globalLogLoot = new HashSet<>(); + this.globalLeafLoot = new HashSet<>(); + this.globalRequiredTools = new HashSet<>(); } @Override public void reload() { this.treeDefinitions.clear(); + this.globalLogLoot.clear(); + this.globalLeafLoot.clear(); + this.globalRequiredTools.clear(); - ConfigurationManager configurationManager = ultimateTimber.getConfigurationManager(); + VersionAdapter versionAdapter = this.ultimateTimber.getVersionAdapter(); + ConfigurationManager configurationManager = this.ultimateTimber.getConfigurationManager(); + YamlConfiguration config = configurationManager.getConfig(); + + // Load tree settings + ConfigurationSection treeSection = config.getConfigurationSection("trees"); + for (String key : treeSection.getKeys(false)) { + ConfigurationSection tree = treeSection.getConfigurationSection(key); + + Set logBlockStates = new HashSet<>(); + Set leafBlockStates = new HashSet<>(); + BlockState saplingBlockState; + int maxLeafDistanceFromLog; + boolean dropOriginalLog; + boolean dropOriginalLeaf; + Set logLoot = new HashSet<>(); + Set leafLoot = new HashSet<>(); + Set requiredTools = new HashSet<>(); + + for (String blockStateString : tree.getStringList("logs")) + logBlockStates.add(versionAdapter.parseBlockStateFromString(blockStateString)); + + for (String blockStateString : tree.getStringList("leaves")) + leafBlockStates.add(versionAdapter.parseBlockStateFromString(blockStateString)); + + saplingBlockState = versionAdapter.parseBlockStateFromString(tree.getString("sapling")); + maxLeafDistanceFromLog = tree.getInt("max-leaf-distance-from-log"); + dropOriginalLog = tree.getBoolean("drop-original-log"); + dropOriginalLeaf = tree.getBoolean("drop-original-leaf"); + + ConfigurationSection logLootSection = tree.getConfigurationSection("log-loot"); + for (String lootKey : logLootSection.getKeys(false)) + logLoot.add(this.getTreeLootEntry(versionAdapter, TreeBlockType.LOG, logLootSection.getConfigurationSection(lootKey))); + + ConfigurationSection leafLootSection = tree.getConfigurationSection("leaf-loot"); + for (String lootKey : leafLootSection.getKeys(false)) + leafLoot.add(this.getTreeLootEntry(versionAdapter, TreeBlockType.LEAF, leafLootSection.getConfigurationSection(lootKey))); + + for (String itemStackString : tree.getStringList("required-tools")) + requiredTools.add(versionAdapter.parseItemStackFromString(itemStackString)); + + this.treeDefinitions.add(new TreeDefinition(key, logBlockStates, leafBlockStates, saplingBlockState, maxLeafDistanceFromLog, dropOriginalLog, dropOriginalLeaf, logLoot, leafLoot, requiredTools)); + } + + // Load global log drops + ConfigurationSection logSection = config.getConfigurationSection("global-log-loot"); + for (String lootKey : logSection.getKeys(false)) + this.globalLogLoot.add(this.getTreeLootEntry(versionAdapter, TreeBlockType.LOG, logSection.getConfigurationSection(lootKey))); + + // Load global leaf drops + ConfigurationSection leafSection = config.getConfigurationSection("global-leaf-loot"); + for (String lootKey : leafSection.getKeys(false)) + this.globalLeafLoot.add(this.getTreeLootEntry(versionAdapter, TreeBlockType.LEAF, leafSection.getConfigurationSection(lootKey))); + + // Load global tools + for (String itemStackString : config.getStringList("global-required-tools")) + this.globalRequiredTools.add(versionAdapter.parseItemStackFromString(itemStackString)); } @Override @@ -28,4 +107,95 @@ public class TreeDefinitionManager extends Manager { this.treeDefinitions.clear(); } + /** + * Checks if a given tool is valid for a given tree definition, also takes into account global tools + * + * @param treeDefinition The TreeDefinition to use + * @param tool The tool to check + * @return True if the tool is allowed for toppling the given TreeDefinition + */ + public boolean isToolValidForTreeDefinition(TreeDefinition treeDefinition, ItemStack tool) { + for (ItemStack requiredTool : treeDefinition.getRequiredTools()) + if (requiredTool.isSimilar(tool)) + return true; + for (ItemStack requiredTool : this.globalRequiredTools) + if (requiredTool.isSimilar(tool)) + return true; + return false; + } + + /** + * Tries to spawn loot for a given TreeBlock with the given TreeDefinition for a given player + * + * @param treeDefinition The TreeDefinition to use + * @param treeBlock The TreeBlock to drop for + * @param player The Player to drop for + */ + @SuppressWarnings("unchecked") + public void dropTreeLoot(TreeDefinition treeDefinition, ITreeBlock treeBlock, Player player) { + boolean addToInventory = ConfigurationManager.Setting.ADD_ITEMS_TO_INVENTORY.getBoolean(); + ItemStack itemInHand = this.ultimateTimber.getVersionAdapter().getItemInHand(player); + boolean hasSilkTouch = itemInHand != null && itemInHand.hasItemMeta() && itemInHand.getItemMeta().hasEnchant(Enchantment.SILK_TOUCH); + boolean hasBonusChance = player.hasPermission("ultimatetimber.bonusloot"); + Set lootedItems = new HashSet<>(); + Set lootedCommands = new HashSet<>(); + + // Get the loot that we should try to drop + Set toTry = new HashSet<>(); + switch (treeBlock.getTreeBlockType()) { + case LOG: + toTry.addAll(treeDefinition.getLogLoot()); + toTry.addAll(this.globalLogLoot); + if (treeDefinition.shouldDropOriginalLog() || hasSilkTouch) + lootedItems.addAll(treeBlock.getDrops()); + break; + case LEAF: + toTry.addAll(treeDefinition.getLeafLoot()); + toTry.addAll(this.globalLeafLoot); + if (treeDefinition.shouldDropOriginalLeaf() || hasSilkTouch) + lootedItems.addAll(treeBlock.getDrops()); + break; + } + + // Roll the dice + for (TreeLoot treeLoot : toTry) { + double chance = hasBonusChance ? treeLoot.getChance() * 2 : treeLoot.getChance(); + if (this.random.nextDouble() > chance) + continue; + if (treeLoot.hasItem()) + lootedItems.add(treeLoot.getItem()); + if (treeLoot.hasCommand()) + lootedCommands.add(treeLoot.getCommand()); + } + + // Add to inventory or drop on ground + if (addToInventory) { + for (ItemStack lootedItem : lootedItems) + player.getInventory().addItem(lootedItem); + } else { + Location location = treeBlock.getLocation().clone().add(0.5, 0.5, 0.5); + for (ItemStack lootedItem : lootedItems) + location.getWorld().dropItemNaturally(location, lootedItem); + } + + // Run looted commands + for (String lootedCommand : lootedCommands) + Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), lootedCommand.replace("%player", player.getName()).replace("%type", treeDefinition.getKey())); + } + + /** + * Gets a TreeLoot entry from a ConfigurationSection + * + * @param versionAdapter The VersionAdapter to use + * @param treeBlockType The TreeBlockType to use + * @param configurationSection The ConfigurationSection + * @return A TreeLoot entry from the section + */ + private TreeLoot getTreeLootEntry(VersionAdapter versionAdapter, TreeBlockType treeBlockType, ConfigurationSection configurationSection) { + ItemStack item = versionAdapter.parseItemStackFromString(configurationSection.getString("material")); + String command = configurationSection.getString("command"); + double chance = configurationSection.getDouble("chance"); + return new TreeLoot(treeBlockType, item, command, chance); + } + } diff --git a/src/main/java/com/songoda/ultimatetimber/old_code/AxeDurability.java b/src/main/java/com/songoda/ultimatetimber/old_code/AxeDurability.java index 1d81a55..f2ec201 100644 --- a/src/main/java/com/songoda/ultimatetimber/old_code/AxeDurability.java +++ b/src/main/java/com/songoda/ultimatetimber/old_code/AxeDurability.java @@ -1,8 +1,6 @@ package com.songoda.ultimatetimber.old_code; -import java.util.HashSet; -import java.util.Random; - +import com.songoda.ultimatetimber.utils.WoodToLogConverter; import org.bukkit.GameMode; import org.bukkit.Material; import org.bukkit.block.Block; @@ -12,7 +10,8 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.Damageable; import org.bukkit.inventory.meta.ItemMeta; -import com.songoda.ultimatetimber.utils.WoodToLogConverter; +import java.util.HashSet; +import java.util.Random; public class AxeDurability { diff --git a/src/main/java/com/songoda/ultimatetimber/old_code/NoAnimationTreeDestroyer.java b/src/main/java/com/songoda/ultimatetimber/old_code/NoAnimationTreeDestroyer.java index 86e83f8..e3837c7 100644 --- a/src/main/java/com/songoda/ultimatetimber/old_code/NoAnimationTreeDestroyer.java +++ b/src/main/java/com/songoda/ultimatetimber/old_code/NoAnimationTreeDestroyer.java @@ -1,9 +1,9 @@ package com.songoda.ultimatetimber.old_code; -import java.util.HashSet; - import org.bukkit.block.Block; +import java.util.HashSet; + class NoAnimationTreeDestroyer { /* diff --git a/src/main/java/com/songoda/ultimatetimber/old_code/TreeChecker.java b/src/main/java/com/songoda/ultimatetimber/old_code/TreeChecker.java index 7d24bfc..513891f 100644 --- a/src/main/java/com/songoda/ultimatetimber/old_code/TreeChecker.java +++ b/src/main/java/com/songoda/ultimatetimber/old_code/TreeChecker.java @@ -1,18 +1,17 @@ package com.songoda.ultimatetimber.old_code; -import java.util.Arrays; -import java.util.Comparator; -import java.util.HashSet; -import java.util.Set; - +import com.songoda.ultimatetimber.UltimateTimber; +import com.songoda.ultimatetimber.utils.LogToLeafConverter; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.util.Vector; -import com.songoda.ultimatetimber.UltimateTimber; -import com.songoda.ultimatetimber.utils.LogToLeafConverter; +import java.util.Arrays; +import java.util.Comparator; +import java.util.HashSet; +import java.util.Set; public class TreeChecker { diff --git a/src/main/java/com/songoda/ultimatetimber/old_code/TreeFallAnimation.java b/src/main/java/com/songoda/ultimatetimber/old_code/TreeFallAnimation.java index 909d6de..fb20cbe 100644 --- a/src/main/java/com/songoda/ultimatetimber/old_code/TreeFallAnimation.java +++ b/src/main/java/com/songoda/ultimatetimber/old_code/TreeFallAnimation.java @@ -1,10 +1,6 @@ package com.songoda.ultimatetimber.old_code; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.Random; -import java.util.Set; - +import com.songoda.ultimatetimber.UltimateTimber; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.Particle; @@ -19,7 +15,10 @@ import org.bukkit.event.entity.EntityChangeBlockEvent; import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.util.Vector; -import com.songoda.ultimatetimber.UltimateTimber; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.Random; +import java.util.Set; public class TreeFallAnimation implements Listener, Runnable { diff --git a/src/main/java/com/songoda/ultimatetimber/old_code/TreeFallListener.java b/src/main/java/com/songoda/ultimatetimber/old_code/TreeFallListener.java index 92215ab..f9eb38e 100644 --- a/src/main/java/com/songoda/ultimatetimber/old_code/TreeFallListener.java +++ b/src/main/java/com/songoda/ultimatetimber/old_code/TreeFallListener.java @@ -1,7 +1,9 @@ package com.songoda.ultimatetimber.old_code; -import java.util.HashSet; - +import com.songoda.ultimatetimber.UltimateTimber; +import com.songoda.ultimatetimber.events.TreeFallEvent; +import com.songoda.ultimatetimber.events.TreeFellEvent; +import com.songoda.ultimatetimber.manager.HookManager; import org.bukkit.Bukkit; import org.bukkit.block.Block; import org.bukkit.configuration.file.FileConfiguration; @@ -11,10 +13,7 @@ import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.block.BlockBreakEvent; -import com.songoda.ultimatetimber.UltimateTimber; -import com.songoda.ultimatetimber.events.TreeFallEvent; -import com.songoda.ultimatetimber.events.TreeFellEvent; -import com.songoda.ultimatetimber.manager.HookManager; +import java.util.HashSet; public class TreeFallListener implements Listener { diff --git a/src/main/java/com/songoda/ultimatetimber/old_code/TreeLoot.java b/src/main/java/com/songoda/ultimatetimber/old_code/TreeLoot.java index 372f109..67ae728 100644 --- a/src/main/java/com/songoda/ultimatetimber/old_code/TreeLoot.java +++ b/src/main/java/com/songoda/ultimatetimber/old_code/TreeLoot.java @@ -1,15 +1,14 @@ package com.songoda.ultimatetimber.old_code; -import java.util.Random; - +import com.songoda.ultimatetimber.utils.LeafToSaplingConverter; +import com.songoda.ultimatetimber.utils.WoodToLogConverter; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.World; import org.bukkit.block.data.BlockData; import org.bukkit.inventory.ItemStack; -import com.songoda.ultimatetimber.utils.LeafToSaplingConverter; -import com.songoda.ultimatetimber.utils.WoodToLogConverter; +import java.util.Random; class TreeLoot { diff --git a/src/main/java/com/songoda/ultimatetimber/old_code/TreeReplant.java b/src/main/java/com/songoda/ultimatetimber/old_code/TreeReplant.java index 6631e1b..b04d7ce 100644 --- a/src/main/java/com/songoda/ultimatetimber/old_code/TreeReplant.java +++ b/src/main/java/com/songoda/ultimatetimber/old_code/TreeReplant.java @@ -1,9 +1,7 @@ package com.songoda.ultimatetimber.old_code; -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.ThreadLocalRandom; - +import com.songoda.ultimatetimber.UltimateTimber; +import com.songoda.ultimatetimber.utils.WoodToLogConverter; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; @@ -12,8 +10,9 @@ import org.bukkit.block.BlockFace; import org.bukkit.entity.FallingBlock; import org.bukkit.util.Vector; -import com.songoda.ultimatetimber.UltimateTimber; -import com.songoda.ultimatetimber.utils.WoodToLogConverter; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.ThreadLocalRandom; class TreeReplant { diff --git a/src/main/java/com/songoda/ultimatetimber/tree/FallingTreeBlock.java b/src/main/java/com/songoda/ultimatetimber/tree/FallingTreeBlock.java index f023bf4..2d3d983 100644 --- a/src/main/java/com/songoda/ultimatetimber/tree/FallingTreeBlock.java +++ b/src/main/java/com/songoda/ultimatetimber/tree/FallingTreeBlock.java @@ -1,15 +1,21 @@ package com.songoda.ultimatetimber.tree; +import org.bukkit.Location; import org.bukkit.entity.FallingBlock; +import org.bukkit.inventory.ItemStack; + +import java.util.Collection; public class FallingTreeBlock implements ITreeBlock { private final FallingBlock fallingBlock; private final TreeBlockType treeBlockType; + private final Collection drops; - public FallingTreeBlock(FallingBlock fallingBlock, TreeBlockType treeBlockType) { + public FallingTreeBlock(TreeBlock originalTreeBlock, FallingBlock fallingBlock, TreeBlockType treeBlockType) { this.fallingBlock = fallingBlock; this.treeBlockType = treeBlockType; + this.drops = originalTreeBlock.getDrops(); } @Override @@ -17,6 +23,16 @@ public class FallingTreeBlock implements ITreeBlock { return this.fallingBlock; } + @Override + public Location getLocation() { + return this.fallingBlock.getLocation(); + } + + @Override + public Collection getDrops() { + return this.drops; + } + @Override public TreeBlockType getTreeBlockType() { return this.treeBlockType; diff --git a/src/main/java/com/songoda/ultimatetimber/tree/ITreeBlock.java b/src/main/java/com/songoda/ultimatetimber/tree/ITreeBlock.java index be455d6..63c98f9 100644 --- a/src/main/java/com/songoda/ultimatetimber/tree/ITreeBlock.java +++ b/src/main/java/com/songoda/ultimatetimber/tree/ITreeBlock.java @@ -1,5 +1,10 @@ package com.songoda.ultimatetimber.tree; +import org.bukkit.Location; +import org.bukkit.inventory.ItemStack; + +import java.util.Collection; + public interface ITreeBlock { /** @@ -9,6 +14,20 @@ public interface ITreeBlock { */ BlockType getBlock(); + /** + * Gets the location of this TreeBlock + * + * @return The Location of this TreeBlock + */ + Location getLocation(); + + /** + * Gets the items this TreeBlock naturally drops + * + * @return The ItemStack this TreeBlock naturally drops + */ + Collection getDrops(); + /** * Gets what type of TreeBlock this is * diff --git a/src/main/java/com/songoda/ultimatetimber/tree/TreeBlock.java b/src/main/java/com/songoda/ultimatetimber/tree/TreeBlock.java index e07237a..fc4be40 100644 --- a/src/main/java/com/songoda/ultimatetimber/tree/TreeBlock.java +++ b/src/main/java/com/songoda/ultimatetimber/tree/TreeBlock.java @@ -1,6 +1,11 @@ package com.songoda.ultimatetimber.tree; +import org.bukkit.Location; import org.bukkit.block.Block; +import org.bukkit.inventory.ItemStack; + +import java.util.Collection; +import java.util.Set; public class TreeBlock implements ITreeBlock { @@ -17,6 +22,16 @@ public class TreeBlock implements ITreeBlock { return this.block; } + @Override + public Location getLocation() { + return this.block.getLocation(); + } + + @Override + public Collection getDrops() { + return this.block.getDrops(); + } + @Override public TreeBlockType getTreeBlockType() { return this.treeBlockType; diff --git a/src/main/java/com/songoda/ultimatetimber/tree/TreeDefinition.java b/src/main/java/com/songoda/ultimatetimber/tree/TreeDefinition.java index 241ee78..9b2c42d 100644 --- a/src/main/java/com/songoda/ultimatetimber/tree/TreeDefinition.java +++ b/src/main/java/com/songoda/ultimatetimber/tree/TreeDefinition.java @@ -13,12 +13,12 @@ public class TreeDefinition { private final BlockState saplingBlockState; private final int maxLeafDistanceFromLog; private final boolean dropOriginalLog, dropOriginalLeaf; - private final Set customLogLoot, customLeafLoot; + private final Set logLoot, leafLoot; private final Set requiredTools; public TreeDefinition(String key, Set logBlocks, Set leafBlocks, BlockState saplingBlockState, int maxLeafDistanceFromLog, boolean dropOriginalLog, boolean dropOriginalLeaf, - Set customLogLoot, Set customLeafLoot, Set requiredTools) { + Set logLoot, Set leafLoot, Set requiredTools) { this.key = key; this.logBlockStates = logBlocks; this.leafBlockStates = leafBlocks; @@ -26,8 +26,8 @@ public class TreeDefinition { this.maxLeafDistanceFromLog = maxLeafDistanceFromLog; this.dropOriginalLog = dropOriginalLog; this.dropOriginalLeaf = dropOriginalLeaf; - this.customLogLoot = customLogLoot; - this.customLeafLoot = customLeafLoot; + this.logLoot = logLoot; + this.leafLoot = leafLoot; this.requiredTools = requiredTools; } @@ -95,21 +95,21 @@ public class TreeDefinition { } /** - * Gets the custom log loot for this TreeDefinition + * Gets the log loot for this TreeDefinition * * @return A Set of TreeLoot */ - public Set getCustomLogLoot() { - return Collections.unmodifiableSet(this.customLogLoot); + public Set getLogLoot() { + return Collections.unmodifiableSet(this.logLoot); } /** - * Gets the custom leaf loot for this TreeDefinition + * Gets the leaf loot for this TreeDefinition * * @return A Set of TreeLoot */ - public Set getCustomLeafLoot() { - return Collections.unmodifiableSet(this.customLeafLoot); + public Set getLeafLoot() { + return Collections.unmodifiableSet(this.leafLoot); } /** diff --git a/src/main/java/com/songoda/ultimatetimber/tree/TreeLoot.java b/src/main/java/com/songoda/ultimatetimber/tree/TreeLoot.java index 50c28d3..de8818c 100644 --- a/src/main/java/com/songoda/ultimatetimber/tree/TreeLoot.java +++ b/src/main/java/com/songoda/ultimatetimber/tree/TreeLoot.java @@ -16,8 +16,58 @@ public class TreeLoot { this.chance = chance; } - public void tryDropLoot(ITreeBlock treeBlock) { + /** + * Gets the tree block type this loot is for + * + * @return The tree block type this loot is for + */ + public TreeBlockType getTreeBlockType() { + return this.treeBlockType; + } + /** + * Checks if this TreeLoot has an item to drop + * + * @return True if an item exists, otherwise false + */ + public boolean hasItem() { + return this.item != null; + } + + /** + * Gets the item that this tree loot can drop + * + * @return An ItemStack this tree loot can drop + */ + public ItemStack getItem() { + return this.item; + } + + /** + * Checks if this TreeLoot has a command to run + * + * @return True if a command exists, otherwise false + */ + public boolean hasCommand() { + return this.command != null; + } + + /** + * Gets the command that this tree loot can run + * + * @return The command that this tree loot can run + */ + public String getCommand() { + return command; + } + + /** + * Gets the percent chance this tree loot will drop + * + * @return The percent chance this tree loot can drop + */ + public double getChance() { + return this.chance; } } diff --git a/src/main/resources/config-current.yml b/src/main/resources/config-current.yml index 16b61b5..1e34551 100644 --- a/src/main/resources/config-current.yml +++ b/src/main/resources/config-current.yml @@ -91,6 +91,10 @@ add-items-to-inventory: false # Default: true use-custom-sounds: true +# Use custom particles when toppling trees +# Default: true +use-custom-particles: true + # The type of animation to use for tree toppling # Types: FANCY, DISINTEGRATE, CHAOS, NONE tree-animation-type: FANCY @@ -109,7 +113,6 @@ mix-all-tree-types: false # Tree configuration # Allows for extreme fine-tuning of tree detection and what are considered trees # Multiple log and leaf types are allowed, only one sapling type is allowed -# For custom-tool and required-tools use the same format as the global settings below the trees section # You can add your own custom tree types here, just add a new section trees: oak: @@ -124,8 +127,8 @@ trees: max-leaf-distance-from-log: 6 drop-original-log: true drop-original-leaf: false - custom-log-loot: [] - custom-leaf-loot: + log-loot: [] + leaf-loot: 0: material: OAK_SAPLING chance: 5 @@ -145,8 +148,8 @@ trees: max-leaf-distance-from-log: 6 drop-original-log: true drop-original-leaf: false - custom-log-loot: [] - custom-leaf-loot: + log-loot: [] + leaf-loot: 0: material: SPRUCE_SAPLING chance: 5 @@ -163,8 +166,8 @@ trees: max-leaf-distance-from-log: 4 drop-original-log: true drop-original-leaf: false - custom-log-loot: [] - custom-leaf-loot: + log-loot: [] + leaf-loot: 0: material: BIRCH_SAPLING chance: 5 @@ -181,8 +184,8 @@ trees: max-leaf-distance-from-log: 5 drop-original-log: true drop-original-leaf: false - custom-log-loot: [] - custom-leaf-loot: + log-loot: [] + leaf-loot: 0: material: JUNGLE_SAPLING chance: 2.5 @@ -199,8 +202,8 @@ trees: max-leaf-distance-from-log: 5 drop-original-log: true drop-original-leaf: false - custom-log-loot: [] - custom-leaf-loot: + log-loot: [] + leaf-loot: 0: material: ACACIA_SAPLING chance: 5 @@ -217,8 +220,8 @@ trees: max-leaf-distance-from-log: 5 drop-original-log: true drop-original-leaf: false - custom-log-loot: [] - custom-leaf-loot: + log-loot: [] + leaf-loot: 0: material: DARK_OAK_SAPLING chance: 5 @@ -235,8 +238,8 @@ trees: max-leaf-distance-from-log: 4 drop-original-log: false drop-original-leaf: false - custom-log-loot: [] - custom-leaf-loot: + log-loot: [] + leaf-loot: 0: material: BROWN_MUSHROOM chance: 25 @@ -250,8 +253,8 @@ trees: max-leaf-distance-from-log: 4 drop-original-log: false drop-original-leaf: false - custom-log-loot: [] - custom-leaf-loot: + log-loot: [] + leaf-loot: 0: material: RED_MUSHROOM chance: 25 @@ -262,23 +265,23 @@ trees: # To add more, increment the number by 1 # The chance is out of 100 and can contain decimals # The default examples here are to show what you can do with custom loot -global-custom-log-loot: +global-log-loot: 0: material: DIAMOND chance: 0 1: - command: 'eco give %player% 5' + command: 'eco give %player 5' chance: 0 2: material: GOLDEN_APPLE - command: 'broadcast %player% found a golden apple in a %type% tree!' + command: 'broadcast %player found a golden apple in a %type tree!' chance: 0 # Custom loot that is available for all tree types # The loot applies to each leaf broken in the tree # To add more, increment the number by 1 # The chance is out of 100 and can contain decimals -global-custom-leaf-loot: +global-leaf-loot: 0: material: GOLDEN_APPLE chance: 0.5 diff --git a/src/main/resources/config-legacy.yml b/src/main/resources/config-legacy.yml index 7d20ff9..00e1fea 100644 --- a/src/main/resources/config-legacy.yml +++ b/src/main/resources/config-legacy.yml @@ -92,6 +92,10 @@ add-items-to-inventory: false # Default: true use-custom-sounds: true +# Use custom particles when toppling trees +# Default: true +use-custom-particles: true + # The type of animation to use for tree toppling # Types: FANCY, DISINTEGRATE, CHAOS, NONE tree-animation-type: FANCY @@ -109,7 +113,6 @@ mix-all-tree-types: false # Tree configuration # Allows for extreme fine-tuning of tree detection and what are considered trees # Multiple log and leaf types are allowed, only one sapling type is allowed -# For custom-tool and required-tools use the same format as the global settings below the trees section # You can add your own custom tree types here, just add a new section trees: oak: @@ -127,8 +130,8 @@ trees: max-leaf-distance-from-log: 6 drop-original-log: true drop-original-leaf: false - custom-log-loot: [] - custom-leaf-loot: + log-loot: [] + leaf-loot: 0: material: SAPLING:0 chance: 5 @@ -151,8 +154,8 @@ trees: max-leaf-distance-from-log: 6 drop-original-log: true drop-original-leaf: false - custom-log-loot: [] - custom-leaf-loot: + log-loot: [] + leaf-loot: 0: material: SAPLING:1 chance: 5 @@ -172,8 +175,8 @@ trees: max-leaf-distance-from-log: 4 drop-original-log: true drop-original-leaf: false - custom-log-loot: [] - custom-leaf-loot: + log-loot: [] + leaf-loot: 0: material: SAPLING:2 chance: 5 @@ -193,8 +196,8 @@ trees: max-leaf-distance-from-log: 5 drop-original-log: true drop-original-leaf: false - custom-log-loot: [] - custom-leaf-loot: + log-loot: [] + leaf-loot: 0: material: SAPLING:3 chance: 2.5 @@ -214,8 +217,8 @@ trees: max-leaf-distance-from-log: 5 drop-original-log: true drop-original-leaf: false - custom-log-loot: [] - custom-leaf-loot: + log-loot: [] + leaf-loot: 0: material: SAPLING:4 chance: 5 @@ -235,8 +238,8 @@ trees: max-leaf-distance-from-log: 5 drop-original-log: true drop-original-leaf: false - custom-log-loot: [] - custom-leaf-loot: + log-loot: [] + leaf-loot: 0: material: SAPLING:5 chance: 5 @@ -264,8 +267,8 @@ trees: max-leaf-distance-from-log: 4 drop-original-log: false drop-original-leaf: false - custom-log-loot: [] - custom-leaf-loot: + log-loot: [] + leaf-loot: 0: material: BROWN_MUSHROOM chance: 25 @@ -290,8 +293,8 @@ trees: max-leaf-distance-from-log: 4 drop-original-log: false drop-original-leaf: false - custom-log-loot: [] - custom-leaf-loot: + log-loot: [] + leaf-loot: 0: material: RED_MUSHROOM chance: 25 @@ -302,7 +305,7 @@ trees: # To add more, increment the number by 1 # The chance is out of 100 and can contain decimals # The default examples here are to show what you can do with custom loot -global-custom-log-loot: +global-log-loot: 0: material: DIAMOND chance: 0 @@ -311,14 +314,14 @@ global-custom-log-loot: chance: 0 2: material: GOLDEN_APPLE - command: 'broadcast %player% found a golden apple in a %type tree!' + command: 'broadcast %player found a golden apple in a %type tree!' chance: 0 # Custom loot that is available for all tree types # The loot applies to each leaf broken in the tree # To add more, increment the number by 1 # The chance is out of 100 and can contain decimals -global-custom-leaf-loot: +global-leaf-loot: 0: material: GOLDEN_APPLE chance: 0.5 diff --git a/src/main/resources/messages.yml b/src/main/resources/messages.yml deleted file mode 100644 index e69de29..0000000