mirror of
https://github.com/songoda/UltimateTimber.git
synced 2024-12-02 23:03:37 +01:00
Tree definition loading & some other methods
This commit is contained in:
parent
a267bd745c
commit
671236f57d
@ -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<Block> 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
|
||||
*/
|
||||
|
@ -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<Block> treeBlocks) {
|
||||
|
||||
|
@ -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<Block> treeBlocks) {
|
||||
|
||||
|
@ -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;
|
||||
protected final TreeBlockSet<Block> treeBlocks;
|
||||
|
||||
public TreeEvent(Player who, TreeChecker treeChecker, Block broke) {
|
||||
super(who);
|
||||
this.treeChecker = treeChecker;
|
||||
this.broke = broke;
|
||||
public TreeEvent(Player player, TreeBlockSet<Block> 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<Block> getTreeBlocks() {
|
||||
return this.treeBlocks;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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<Block> treeBlocks) {
|
||||
super(player, treeBlocks);
|
||||
}
|
||||
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
@ -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<Block> treeBlocks) {
|
||||
super(player, treeBlocks);
|
||||
}
|
||||
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
@ -26,5 +25,4 @@ public class TreeFellEvent extends TreeEvent {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -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 {
|
||||
|
||||
/**
|
||||
|
@ -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<TimberHook> hooks;
|
||||
|
@ -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<TreeDefinition> treeDefinitions;
|
||||
private Set<TreeLoot> globalLogLoot, globalLeafLoot;
|
||||
private Set<ItemStack> 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<BlockState> logBlockStates = new HashSet<>();
|
||||
Set<BlockState> leafBlockStates = new HashSet<>();
|
||||
BlockState saplingBlockState;
|
||||
int maxLeafDistanceFromLog;
|
||||
boolean dropOriginalLog;
|
||||
boolean dropOriginalLeaf;
|
||||
Set<TreeLoot> logLoot = new HashSet<>();
|
||||
Set<TreeLoot> leafLoot = new HashSet<>();
|
||||
Set<ItemStack> 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<ItemStack> lootedItems = new HashSet<>();
|
||||
Set<String> lootedCommands = new HashSet<>();
|
||||
|
||||
// Get the loot that we should try to drop
|
||||
Set<TreeLoot> 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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 {
|
||||
|
||||
|
@ -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 {
|
||||
|
||||
/*
|
||||
|
@ -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 {
|
||||
|
||||
|
@ -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 {
|
||||
|
||||
|
@ -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 {
|
||||
|
||||
|
@ -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 {
|
||||
|
||||
|
@ -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 {
|
||||
|
||||
|
@ -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<FallingBlock> {
|
||||
|
||||
private final FallingBlock fallingBlock;
|
||||
private final TreeBlockType treeBlockType;
|
||||
private final Collection<ItemStack> 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<FallingBlock> {
|
||||
return this.fallingBlock;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Location getLocation() {
|
||||
return this.fallingBlock.getLocation();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ItemStack> getDrops() {
|
||||
return this.drops;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TreeBlockType getTreeBlockType() {
|
||||
return this.treeBlockType;
|
||||
|
@ -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<BlockType> {
|
||||
|
||||
/**
|
||||
@ -9,6 +14,20 @@ public interface ITreeBlock<BlockType> {
|
||||
*/
|
||||
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<ItemStack> getDrops();
|
||||
|
||||
/**
|
||||
* Gets what type of TreeBlock this is
|
||||
*
|
||||
|
@ -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<Block> {
|
||||
|
||||
@ -17,6 +22,16 @@ public class TreeBlock implements ITreeBlock<Block> {
|
||||
return this.block;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Location getLocation() {
|
||||
return this.block.getLocation();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ItemStack> getDrops() {
|
||||
return this.block.getDrops();
|
||||
}
|
||||
|
||||
@Override
|
||||
public TreeBlockType getTreeBlockType() {
|
||||
return this.treeBlockType;
|
||||
|
@ -13,12 +13,12 @@ public class TreeDefinition {
|
||||
private final BlockState saplingBlockState;
|
||||
private final int maxLeafDistanceFromLog;
|
||||
private final boolean dropOriginalLog, dropOriginalLeaf;
|
||||
private final Set<TreeLoot> customLogLoot, customLeafLoot;
|
||||
private final Set<TreeLoot> logLoot, leafLoot;
|
||||
private final Set<ItemStack> requiredTools;
|
||||
|
||||
public TreeDefinition(String key, Set<BlockState> logBlocks, Set<BlockState> leafBlocks, BlockState saplingBlockState,
|
||||
int maxLeafDistanceFromLog, boolean dropOriginalLog, boolean dropOriginalLeaf,
|
||||
Set<TreeLoot> customLogLoot, Set<TreeLoot> customLeafLoot, Set<ItemStack> requiredTools) {
|
||||
Set<TreeLoot> logLoot, Set<TreeLoot> leafLoot, Set<ItemStack> 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<TreeLoot> getCustomLogLoot() {
|
||||
return Collections.unmodifiableSet(this.customLogLoot);
|
||||
public Set<TreeLoot> 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<TreeLoot> getCustomLeafLoot() {
|
||||
return Collections.unmodifiableSet(this.customLeafLoot);
|
||||
public Set<TreeLoot> getLeafLoot() {
|
||||
return Collections.unmodifiableSet(this.leafLoot);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user