Even more boilerplate code

This commit is contained in:
Esophose 2019-03-27 22:22:13 -06:00
parent 665ece06da
commit 4192e5ba74
41 changed files with 534 additions and 99 deletions

View File

@ -4,7 +4,7 @@ stages:
variables: variables:
name: "UltimateTimber" name: "UltimateTimber"
path: "/builds/$CI_PROJECT_PATH" path: "/builds/$CI_PROJECT_PATH"
version: "1.0.14" version: "2.0.0"
build: build:
stage: build stage: build

View File

@ -11,11 +11,16 @@ import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import java.util.HashSet;
import java.util.Set;
public class UltimateTimber extends JavaPlugin { public class UltimateTimber extends JavaPlugin {
private static final CommandSender console = Bukkit.getConsoleSender(); private static final CommandSender console = Bukkit.getConsoleSender();
private static UltimateTimber INSTANCE; private static UltimateTimber INSTANCE;
private Set<Manager> managers;
private VersionAdapter versionAdapter; private VersionAdapter versionAdapter;
private ConfigurationManager configurationManager; private ConfigurationManager configurationManager;
private DisabledWorldManager disabledWorldManager; private DisabledWorldManager disabledWorldManager;
@ -24,6 +29,7 @@ public class UltimateTimber extends JavaPlugin {
private SettingsManager settingsManager; private SettingsManager settingsManager;
private TreeAnimationManager treeAnimationManager; private TreeAnimationManager treeAnimationManager;
private TreeDefinitionManager treeDefinitionManager; private TreeDefinitionManager treeDefinitionManager;
private TreeDetectionManager treeDetectionManager;
private TreeFallManager treeFallManager; private TreeFallManager treeFallManager;
public static UltimateTimber getInstance() { public static UltimateTimber getInstance() {
@ -38,14 +44,16 @@ public class UltimateTimber extends JavaPlugin {
console.sendMessage(Methods.formatText("&7" + this.getDescription().getName() + " " + this.getDescription().getVersion() + " by &5Songoda <3&7!")); console.sendMessage(Methods.formatText("&7" + this.getDescription().getName() + " " + this.getDescription().getVersion() + " by &5Songoda <3&7!"));
console.sendMessage(Methods.formatText("&7Action: &aEnabling&7...")); console.sendMessage(Methods.formatText("&7Action: &aEnabling&7..."));
this.configurationManager = new ConfigurationManager(this); this.managers = new HashSet<>();
this.disabledWorldManager = new DisabledWorldManager(this); this.configurationManager = this.registerManager(ConfigurationManager.class);
this.hookManager = new HookManager(this); this.disabledWorldManager = this.registerManager(DisabledWorldManager.class);
this.messageManager = new MessageManager(this); this.hookManager = this.registerManager(HookManager.class);
this.settingsManager = new SettingsManager(this); this.messageManager = this.registerManager(MessageManager.class);
this.treeAnimationManager = new TreeAnimationManager(this); this.settingsManager = this.registerManager(SettingsManager.class);
this.treeDefinitionManager = new TreeDefinitionManager(this); this.treeAnimationManager = this.registerManager(TreeAnimationManager.class);
this.treeFallManager = new TreeFallManager(this); this.treeDefinitionManager = this.registerManager(TreeDefinitionManager.class);
this.treeDetectionManager = this.registerManager(TreeDetectionManager.class);
this.treeFallManager = this.registerManager(TreeFallManager.class);
this.setupVersionAdapter(); this.setupVersionAdapter();
this.reload(); this.reload();
@ -61,7 +69,7 @@ public class UltimateTimber extends JavaPlugin {
console.sendMessage(Methods.formatText("&7" + this.getDescription().getName() + " " + this.getDescription().getVersion() + " by &5Songoda <3&7!")); console.sendMessage(Methods.formatText("&7" + this.getDescription().getName() + " " + this.getDescription().getVersion() + " by &5Songoda <3&7!"));
console.sendMessage(Methods.formatText("&7Action: &cDisabling&7...")); console.sendMessage(Methods.formatText("&7Action: &cDisabling&7..."));
this.disable();
console.sendMessage(Methods.formatText("&a=============================")); console.sendMessage(Methods.formatText("&a============================="));
} }
@ -70,7 +78,14 @@ public class UltimateTimber extends JavaPlugin {
* Reloads the plugin's settings * Reloads the plugin's settings
*/ */
public void reload() { public void reload() {
this.managers.forEach(Manager::reload);
}
/**
* Disables most of the plugin
*/
public void disable() {
this.managers.forEach(Manager::disable);
} }
/** /**
@ -84,6 +99,28 @@ public class UltimateTimber extends JavaPlugin {
} }
} }
/**
* Registers a manager
*
* @param managerClass The class of the manager to create a new instance of
* @param <T> extends Manager
* @return A new instance of the given manager class
*/
private <T extends Manager> T registerManager(Class<T> managerClass) {
try {
T newManager = managerClass.getConstructor(UltimateTimber.class).newInstance(this);
this.managers.add(newManager);
return newManager;
} catch (Exception ignored) {
return null;
}
}
/**
* Gets the active version adapter being used
*
* @return The VersionAdapter being used for the plugin
*/
public VersionAdapter getVersionAdapter() { public VersionAdapter getVersionAdapter() {
return this.versionAdapter; return this.versionAdapter;
} }
@ -151,6 +188,15 @@ public class UltimateTimber extends JavaPlugin {
return treeDefinitionManager; return treeDefinitionManager;
} }
/**
* Gets the tree detection manager
*
* @return The TreeDetectionManager instance
*/
public TreeDetectionManager getTreeDetectionManager() {
return treeDetectionManager;
}
/** /**
* Gets the tree fall manager * Gets the tree fall manager
* *

View File

@ -1,8 +1,10 @@
package com.songoda.ultimatetimber.adapter; package com.songoda.ultimatetimber.adapter;
import com.songoda.ultimatetimber.tree.FallingTreeBlock;
import com.songoda.ultimatetimber.tree.TreeBlock; import com.songoda.ultimatetimber.tree.TreeBlock;
import com.songoda.ultimatetimber.tree.TreeBlockSet;
import com.songoda.ultimatetimber.tree.TreeDefinition; import com.songoda.ultimatetimber.tree.TreeDefinition;
import jdk.nashorn.internal.ir.Block; import org.bukkit.block.Block;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import java.util.Set; import java.util.Set;
@ -33,6 +35,30 @@ public interface VersionAdapter {
* @param treeBlocks The Set of tree blocks that are being broken * @param treeBlocks The Set of tree blocks that are being broken
* @param tool The tool to apply damage to * @param tool The tool to apply damage to
*/ */
void applyToolDurability(Set<TreeBlock> treeBlocks, ItemStack tool); void applyToolDurability(TreeBlockSet<Block> treeBlocks, ItemStack tool);
/**
* Plays particles to indicate a tree has started falling
*/
void playFallingParticles(TreeBlockSet<Block> treeBlocks);
/**
* Plays particles to indicate a tree block has hit the ground
*/
void playLandingParticles(FallingTreeBlock treeBlock);
/**
* Plays a sound to indicate a tree block has started falling
*
* @param treeBlocks The TreeBlocks to play the sound for
*/
void playFallingSound(TreeBlockSet<Block> treeBlocks);
/**
* Plays a sound to indicate a tree block has hit the ground
*
* @param treeBlock The FallingTreeBlock to play the sound for
*/
void playLandingSound(FallingTreeBlock treeBlock);
} }

View File

@ -2,8 +2,11 @@ package com.songoda.ultimatetimber.adapter.current;
import com.songoda.ultimatetimber.adapter.VersionAdapter; import com.songoda.ultimatetimber.adapter.VersionAdapter;
import com.songoda.ultimatetimber.adapter.VersionAdapterType; import com.songoda.ultimatetimber.adapter.VersionAdapterType;
import com.songoda.ultimatetimber.tree.FallingTreeBlock;
import com.songoda.ultimatetimber.tree.TreeBlock; import com.songoda.ultimatetimber.tree.TreeBlock;
import com.songoda.ultimatetimber.tree.TreeBlockSet;
import com.songoda.ultimatetimber.tree.TreeDefinition; import com.songoda.ultimatetimber.tree.TreeDefinition;
import org.bukkit.block.Block;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import java.util.Set; import java.util.Set;
@ -26,7 +29,27 @@ public class CurrentAdapter implements VersionAdapter {
} }
@Override @Override
public void applyToolDurability(Set<TreeBlock> blocks, ItemStack tool) { public void applyToolDurability(TreeBlockSet<Block> treeBlocks, ItemStack tool) {
}
@Override
public void playFallingParticles(TreeBlockSet<Block> treeBlocks) {
}
@Override
public void playLandingParticles(FallingTreeBlock treeBlock) {
}
@Override
public void playFallingSound(TreeBlockSet<Block> treeBlocks) {
}
@Override
public void playLandingSound(FallingTreeBlock treeBlock) {
} }

View File

@ -2,8 +2,11 @@ package com.songoda.ultimatetimber.adapter.legacy;
import com.songoda.ultimatetimber.adapter.VersionAdapter; import com.songoda.ultimatetimber.adapter.VersionAdapter;
import com.songoda.ultimatetimber.adapter.VersionAdapterType; import com.songoda.ultimatetimber.adapter.VersionAdapterType;
import com.songoda.ultimatetimber.tree.FallingTreeBlock;
import com.songoda.ultimatetimber.tree.TreeBlock; import com.songoda.ultimatetimber.tree.TreeBlock;
import com.songoda.ultimatetimber.tree.TreeBlockSet;
import com.songoda.ultimatetimber.tree.TreeDefinition; import com.songoda.ultimatetimber.tree.TreeDefinition;
import org.bukkit.block.Block;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import java.util.Set; import java.util.Set;
@ -26,7 +29,27 @@ public class LegacyAdapter implements VersionAdapter {
} }
@Override @Override
public void applyToolDurability(Set<TreeBlock> blocks, ItemStack tool) { public void applyToolDurability(TreeBlockSet<Block> treeBlocks, ItemStack tool) {
}
@Override
public void playFallingParticles(TreeBlockSet<Block> treeBlocks) {
}
@Override
public void playLandingParticles(FallingTreeBlock treeBlock) {
}
@Override
public void playFallingSound(TreeBlockSet<Block> treeBlocks) {
}
@Override
public void playLandingSound(FallingTreeBlock treeBlock) {
} }

View File

@ -3,7 +3,7 @@ package com.songoda.ultimatetimber.commands;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import com.songoda.ultimatetimber.UltimateTimber; import com.songoda.ultimatetimber.UltimateTimber;
import com.songoda.ultimatetimber.treefall.CustomLoot; import com.songoda.ultimatetimber.old_code.CustomLoot;
import com.songoda.ultimatetimber.utils.Methods; import com.songoda.ultimatetimber.utils.Methods;
class ReloadCommand { class ReloadCommand {

View File

@ -4,7 +4,7 @@ import org.bukkit.block.Block;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerEvent; import org.bukkit.event.player.PlayerEvent;
import com.songoda.ultimatetimber.treefall.TreeChecker; import com.songoda.ultimatetimber.old_code.TreeChecker;
/** /**
* Abstract tree event containing tree's blocks and broke block * Abstract tree event containing tree's blocks and broke block

View File

@ -5,7 +5,7 @@ import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable; import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
import com.songoda.ultimatetimber.treefall.TreeChecker; import com.songoda.ultimatetimber.old_code.TreeChecker;
/** /**
* Called when a tree will fall * Called when a tree will fall

View File

@ -4,7 +4,7 @@ import org.bukkit.block.Block;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
import com.songoda.ultimatetimber.treefall.TreeChecker; import com.songoda.ultimatetimber.old_code.TreeChecker;
/** /**
* Called when a tree fell * Called when a tree fell

View File

@ -1,23 +1,19 @@
package com.songoda.ultimatetimber.hooks; package com.songoda.ultimatetimber.hooks;
import java.util.HashSet;
import java.util.Set;
import java.util.stream.Collectors;
import org.bukkit.GameMode;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.Jobs;
import com.gamingmesh.jobs.actions.BlockActionInfo; import com.gamingmesh.jobs.actions.BlockActionInfo;
import com.gamingmesh.jobs.container.ActionType; import com.gamingmesh.jobs.container.ActionType;
import com.gamingmesh.jobs.container.JobsPlayer; import com.gamingmesh.jobs.container.JobsPlayer;
import com.songoda.ultimatetimber.utils.WoodToLogConverter; import com.songoda.ultimatetimber.tree.ITreeBlock;
import com.songoda.ultimatetimber.tree.TreeBlockSet;
import org.bukkit.GameMode;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
public class JobsHook implements TimberHook { public class JobsHook implements TimberHook {
@Override @Override
public void apply(Player player, HashSet<Block> treeBlocks) throws Exception { public void apply(Player player, TreeBlockSet<Block> treeBlocks) throws Exception {
if (player.getGameMode().equals(GameMode.CREATIVE)) if (player.getGameMode().equals(GameMode.CREATIVE))
return; return;
@ -26,10 +22,10 @@ public class JobsHook implements TimberHook {
if (jPlayer == null) if (jPlayer == null)
return; return;
Set<Block> logs = treeBlocks.stream().filter(x -> WoodToLogConverter.convert(x.getType()).name().endsWith("LOG")).collect(Collectors.toSet()); for (ITreeBlock<Block> treeBlock : treeBlocks.getLogBlocks()) {
for (Block log : logs) { Block block = treeBlock.getBlock();
BlockActionInfo bInfo = new BlockActionInfo(log, ActionType.BREAK); BlockActionInfo bInfo = new BlockActionInfo(block, ActionType.BREAK);
Jobs.action(jPlayer, bInfo, log); Jobs.action(jPlayer, bInfo, block);
} }
} }

View File

@ -1,16 +1,15 @@
package com.songoda.ultimatetimber.hooks; package com.songoda.ultimatetimber.hooks;
import java.lang.reflect.Method; import com.gmail.nossr50.api.ExperienceAPI;
import java.util.Set; import com.gmail.nossr50.config.experience.ExperienceConfig;
import com.songoda.ultimatetimber.tree.ITreeBlock;
import com.songoda.ultimatetimber.tree.TreeBlock; import com.songoda.ultimatetimber.tree.TreeBlockSet;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.gmail.nossr50.api.ExperienceAPI; import java.lang.reflect.Method;
import com.gmail.nossr50.config.experience.ExperienceConfig;
public class McMMOHook implements TimberHook { public class McMMOHook implements TimberHook {
@ -42,13 +41,14 @@ public class McMMOHook implements TimberHook {
} }
@Override @Override
public void apply(Player player, Set<TreeBlock> treeBlocks) throws Exception { public void apply(Player player, TreeBlockSet<Block> treeBlocks) throws Exception {
if (player.getGameMode().equals(GameMode.CREATIVE)) if (player.getGameMode().equals(GameMode.CREATIVE))
return; return;
int xp = 0; int xp = 0;
for (Block block : treeBlocks) { for (ITreeBlock<Block> treeBlock : treeBlocks.getLogBlocks()) {
Material material = WoodToLogConverter.convert(block.getType()); Block block = treeBlock.getBlock();
Material material = block.getType();
if (!material.name().endsWith("LOG")) continue; if (!material.name().endsWith("LOG")) continue;
xp += (int) getXpMethod.invoke(ExperienceConfig.getInstance(), woodcuttingEnum, material); xp += (int) getXpMethod.invoke(ExperienceConfig.getInstance(), woodcuttingEnum, material);
} }

View File

@ -1,6 +1,8 @@
package com.songoda.ultimatetimber.hooks; package com.songoda.ultimatetimber.hooks;
import com.songoda.ultimatetimber.tree.TreeBlock; import com.songoda.ultimatetimber.tree.TreeBlock;
import com.songoda.ultimatetimber.tree.TreeBlockSet;
import org.bukkit.block.Block;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.Set; import java.util.Set;
@ -10,6 +12,6 @@ public interface TimberHook {
/** /**
* Applies the hook * Applies the hook
*/ */
void apply(Player player, Set<TreeBlock> treeBlocks) throws Exception; void apply(Player player, TreeBlockSet<Block> treeBlocks) throws Exception;
} }

View File

@ -7,6 +7,7 @@ import com.songoda.ultimatetimber.UltimateTimber;
import com.songoda.ultimatetimber.hooks.JobsHook; import com.songoda.ultimatetimber.hooks.JobsHook;
import com.songoda.ultimatetimber.hooks.McMMOHook; import com.songoda.ultimatetimber.hooks.McMMOHook;
import com.songoda.ultimatetimber.hooks.TimberHook; import com.songoda.ultimatetimber.hooks.TimberHook;
import com.songoda.ultimatetimber.tree.TreeBlockSet;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -21,20 +22,15 @@ public class HookManager extends Manager {
@Override @Override
public void reload() { public void reload() {
this.hooks.clear();
this.tryHook("mcMMO", McMMOHook.class);
this.tryHook("Jobs", JobsHook.class);
} }
@Override @Override
public void disable() { public void disable() {
this.hooks.clear();
}
/**
* Hooks into compatible plugins
*/
public void hook() {
this.tryHook("mcMMO", McMMOHook.class);
this.tryHook("Jobs", JobsHook.class);
} }
/** /**
@ -61,7 +57,7 @@ public class HookManager extends Manager {
* @param player The player to apply the hook for * @param player The player to apply the hook for
* @param treeBlocks The blocks of the tree that were broken * @param treeBlocks The blocks of the tree that were broken
*/ */
public void applyHooks(Player player, HashSet<Block> treeBlocks) { public void applyHooks(Player player, TreeBlockSet treeBlocks) {
Set<TimberHook> invalidHooks = new HashSet<>(); Set<TimberHook> invalidHooks = new HashSet<>();
for (TimberHook hook : this.hooks) { for (TimberHook hook : this.hooks) {
try { try {

View File

@ -2,7 +2,7 @@ package com.songoda.ultimatetimber.manager;
import com.songoda.ultimatetimber.UltimateTimber; import com.songoda.ultimatetimber.UltimateTimber;
abstract class Manager { public abstract class Manager {
protected UltimateTimber ultimateTimber; protected UltimateTimber ultimateTimber;
@ -13,11 +13,11 @@ abstract class Manager {
/** /**
* Reloads the Manager's settings * Reloads the Manager's settings
*/ */
abstract void reload(); public abstract void reload();
/** /**
* Cleans up the Manager's resources * Cleans up the Manager's resources
*/ */
abstract void disable(); public abstract void disable();
} }

View File

@ -0,0 +1,23 @@
package com.songoda.ultimatetimber.manager;
import com.songoda.ultimatetimber.UltimateTimber;
public class TreeDetectionManager extends Manager {
private UltimateTimber ultimateTimber;
public TreeDetectionManager(UltimateTimber ultimateTimber) {
super(ultimateTimber);
}
@Override
public void reload() {
}
@Override
public void disable() {
}
}

View File

@ -1,4 +1,4 @@
package com.songoda.ultimatetimber.treefall; package com.songoda.ultimatetimber.old_code;
import java.util.HashSet; import java.util.HashSet;
import java.util.Random; import java.util.Random;
@ -49,7 +49,7 @@ public class AxeDurability {
item.setItemMeta((ItemMeta) damageableMeta); item.setItemMeta((ItemMeta) damageableMeta);
if (item.getDurability() >= item.getType().getMaxDurability()) if (damageableMeta.getDamage() >= item.getType().getMaxDurability())
player.getInventory().setItemInMainHand(new ItemStack(Material.AIR)); player.getInventory().setItemInMainHand(new ItemStack(Material.AIR));
} }

View File

@ -1,4 +1,4 @@
package com.songoda.ultimatetimber.treefall; package com.songoda.ultimatetimber.old_code;
import com.songoda.ultimatetimber.UltimateTimber; import com.songoda.ultimatetimber.UltimateTimber;
import com.songoda.ultimatetimber.configurations.DefaultConfig; import com.songoda.ultimatetimber.configurations.DefaultConfig;

View File

@ -1,4 +1,4 @@
package com.songoda.ultimatetimber.treefall; package com.songoda.ultimatetimber.old_code;
import com.songoda.ultimatetimber.UltimateTimber; import com.songoda.ultimatetimber.UltimateTimber;
import com.songoda.ultimatetimber.configurations.DefaultConfig; import com.songoda.ultimatetimber.configurations.DefaultConfig;

View File

@ -1,4 +1,4 @@
package com.songoda.ultimatetimber.treefall; package com.songoda.ultimatetimber.old_code;
import java.util.HashSet; import java.util.HashSet;

View File

@ -1,4 +1,4 @@
package com.songoda.ultimatetimber.treefall; package com.songoda.ultimatetimber.old_code;
import java.util.Arrays; import java.util.Arrays;
import java.util.Comparator; import java.util.Comparator;

View File

@ -1,4 +1,4 @@
package com.songoda.ultimatetimber.treefall; package com.songoda.ultimatetimber.old_code;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.FallingBlock; import org.bukkit.entity.FallingBlock;

View File

@ -1,4 +1,4 @@
package com.songoda.ultimatetimber.treefall; package com.songoda.ultimatetimber.old_code;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;

View File

@ -1,4 +1,4 @@
package com.songoda.ultimatetimber.treefall; package com.songoda.ultimatetimber.old_code;
import java.util.HashSet; import java.util.HashSet;

View File

@ -1,4 +1,4 @@
package com.songoda.ultimatetimber.treefall; package com.songoda.ultimatetimber.old_code;
import java.util.Random; import java.util.Random;

View File

@ -1,4 +1,4 @@
package com.songoda.ultimatetimber.treefall; package com.songoda.ultimatetimber.old_code;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;

View File

@ -1,4 +1,4 @@
package com.songoda.ultimatetimber.treefall; package com.songoda.ultimatetimber.old_code;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;

View File

@ -0,0 +1,25 @@
package com.songoda.ultimatetimber.tree;
import org.bukkit.entity.FallingBlock;
public class FallingTreeBlock implements ITreeBlock<FallingBlock> {
private final FallingBlock fallingBlock;
private final TreeBlockType treeBlockType;
public FallingTreeBlock(FallingBlock fallingBlock, TreeBlockType treeBlockType) {
this.fallingBlock = fallingBlock;
this.treeBlockType = treeBlockType;
}
@Override
public FallingBlock getBlock() {
return this.fallingBlock;
}
@Override
public TreeBlockType getTreeBlockType() {
return this.treeBlockType;
}
}

View File

@ -0,0 +1,19 @@
package com.songoda.ultimatetimber.tree;
public interface ITreeBlock<BlockType> {
/**
* Gets the block this TreeBlock represents
*
* @return The Block for this TreeBlock
*/
BlockType getBlock();
/**
* Gets what type of TreeBlock this is
*
* @return The TreeBlockType
*/
TreeBlockType getTreeBlockType();
}

View File

@ -1,8 +0,0 @@
package com.songoda.ultimatetimber.tree;
public enum TreeAnimationType {
FANCY,
DISENTIGRATE,
CHAOS,
NONE
}

View File

@ -2,7 +2,7 @@ package com.songoda.ultimatetimber.tree;
import org.bukkit.block.Block; import org.bukkit.block.Block;
public class TreeBlock { public class TreeBlock implements ITreeBlock<Block> {
private final Block block; private final Block block;
private final TreeBlockType treeBlockType; private final TreeBlockType treeBlockType;
@ -12,10 +12,12 @@ public class TreeBlock {
this.treeBlockType = treeBlockType; this.treeBlockType = treeBlockType;
} }
@Override
public Block getBlock() { public Block getBlock() {
return this.block; return this.block;
} }
@Override
public TreeBlockType getTreeBlockType() { public TreeBlockType getTreeBlockType() {
return this.treeBlockType; return this.treeBlockType;
} }

View File

@ -2,14 +2,27 @@ package com.songoda.ultimatetimber.tree;
import java.util.*; import java.util.*;
public class TreeBlockSet implements Collection { public class TreeBlockSet<BlockType> implements Collection {
private Set<TreeBlock> logBlocks; private final ITreeBlock<BlockType> initialLogBlock;
private Set<TreeBlock> leafBlocks; private final Set<ITreeBlock<BlockType>> logBlocks;
private final Set<ITreeBlock<BlockType>> leafBlocks;
public TreeBlockSet() { public TreeBlockSet(ITreeBlock<BlockType> initialLogBlock) {
this.initialLogBlock = initialLogBlock;
this.logBlocks = new HashSet<>(); this.logBlocks = new HashSet<>();
this.leafBlocks = new HashSet<>(); this.leafBlocks = new HashSet<>();
this.logBlocks.add(initialLogBlock);
}
/**
* Gets the TreeBlock that initiated the tree topple
*
* @return The TreeBlock of the initial topple point
*/
public ITreeBlock<BlockType> getInitialLogBlock() {
return this.initialLogBlock;
} }
/** /**
@ -17,7 +30,7 @@ public class TreeBlockSet implements Collection {
* *
* @return A Set of TreeBlocks * @return A Set of TreeBlocks
*/ */
public Set<TreeBlock> getLogBlocks() { public Set<ITreeBlock<BlockType>> getLogBlocks() {
return Collections.unmodifiableSet(this.logBlocks); return Collections.unmodifiableSet(this.logBlocks);
} }
@ -26,7 +39,7 @@ public class TreeBlockSet implements Collection {
* *
* @return A Set of TreeBlocks * @return A Set of TreeBlocks
*/ */
public Set<TreeBlock> getLeafBlocks() { public Set<ITreeBlock<BlockType>> getLeafBlocks() {
return Collections.unmodifiableSet(this.leafBlocks); return Collections.unmodifiableSet(this.leafBlocks);
} }
@ -35,8 +48,8 @@ public class TreeBlockSet implements Collection {
* *
* @return A Set of all TreeBlocks * @return A Set of all TreeBlocks
*/ */
public Set<TreeBlock> getAllTreeBlocks() { public Set<ITreeBlock<BlockType>> getAllTreeBlocks() {
Set<TreeBlock> treeBlocks = new HashSet<>(); Set<ITreeBlock<BlockType>> treeBlocks = new HashSet<>();
treeBlocks.addAll(this.logBlocks); treeBlocks.addAll(this.logBlocks);
treeBlocks.addAll(this.leafBlocks); treeBlocks.addAll(this.leafBlocks);
return treeBlocks; return treeBlocks;
@ -69,8 +82,7 @@ public class TreeBlockSet implements Collection {
@Override @Override
public boolean add(Object o) { public boolean add(Object o) {
if (!(o instanceof TreeBlock)) return false; ITreeBlock<BlockType> treeBlock = (ITreeBlock<BlockType>) o;
TreeBlock treeBlock = (TreeBlock) o;
switch (treeBlock.getTreeBlockType()) { switch (treeBlock.getTreeBlockType()) {
case LOG: case LOG:
return this.logBlocks.add(treeBlock); return this.logBlocks.add(treeBlock);
@ -82,8 +94,7 @@ public class TreeBlockSet implements Collection {
@Override @Override
public boolean remove(Object o) { public boolean remove(Object o) {
if (!(o instanceof TreeBlock)) return false; ITreeBlock<BlockType> treeBlock = (ITreeBlock<BlockType>) o;
TreeBlock treeBlock = (TreeBlock) o;
switch (treeBlock.getTreeBlockType()) { switch (treeBlock.getTreeBlockType()) {
case LOG: case LOG:
return this.logBlocks.remove(treeBlock); return this.logBlocks.remove(treeBlock);
@ -146,10 +157,10 @@ public class TreeBlockSet implements Collection {
@Override @Override
public Object[] toArray(Object[] a) { public Object[] toArray(Object[] a) {
Set<TreeBlock> treeBlocks = new HashSet<>(); Set<ITreeBlock<BlockType>> treeBlocks = new HashSet<>();
for (Object o : a) for (Object o : a)
if (o instanceof TreeBlock) if (o instanceof ITreeBlock)
treeBlocks.add((TreeBlock)o); treeBlocks.add((ITreeBlock<BlockType>)o);
return treeBlocks.toArray(); return treeBlocks.toArray();
} }

View File

@ -1,9 +1,124 @@
package com.songoda.ultimatetimber.tree; package com.songoda.ultimatetimber.tree;
import org.bukkit.block.BlockState;
import org.bukkit.inventory.ItemStack;
import java.util.Collections;
import java.util.Set;
public class TreeDefinition { public class TreeDefinition {
public TreeDefinition() { private final String key;
private final Set<BlockState> logBlockStates, leafBlockStates;
private final BlockState saplingBlockState;
private final int maxLeafDistanceFromLog;
private final boolean dropOriginalLog, dropOriginalLeaf;
private final Set<TreeLoot> customLogLoot, customLeafLoot;
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) {
this.key = key;
this.logBlockStates = logBlocks;
this.leafBlockStates = leafBlocks;
this.saplingBlockState = saplingBlockState;
this.maxLeafDistanceFromLog = maxLeafDistanceFromLog;
this.dropOriginalLog = dropOriginalLog;
this.dropOriginalLeaf = dropOriginalLeaf;
this.customLogLoot = customLogLoot;
this.customLeafLoot = customLeafLoot;
this.requiredTools = requiredTools;
}
/**
* Gets the key of this TreeDefinition in the config
*
* @return The key
*/
public String getKey() {
return this.key;
}
/**
* Gets a set of valid log block states for this TreeDefinition
*
* @return A Set of BlockStates
*/
public Set<BlockState> getLogBlockStates() {
return Collections.unmodifiableSet(this.logBlockStates);
}
/**
* Gets a set of valid leaf block states for this TreeDefinition
*
* @return A Set of BlockStates
*/
public Set<BlockState> getLeafBlockStates() {
return Collections.unmodifiableSet(this.leafBlockStates);
}
/**
* Gets the sapling block state of this TreeDefinition
*
* @return A BlockState for the sapling
*/
public BlockState getSaplingBlockState() {
return this.saplingBlockState;
}
/**
* Gets the max distance away a leaf can be from a log in order to be part of the tree
*
* @return The max distance a leaf can be from a log
*/
public int getMaxLeafDistanceFromLog() {
return this.maxLeafDistanceFromLog;
}
/**
* Gets if the logs of this tree should drop their original block
*
* @return True if the original log block should be dropped, otherwise false
*/
public boolean shouldDropOriginalLog() {
return this.dropOriginalLog;
}
/**
* Gets if the leaves of this tree should drop their original block
*
* @return True if the original leaf block should be dropped, otherwise false
*/
public boolean shouldDropOriginalLeaf() {
return this.dropOriginalLeaf;
}
/**
* Gets the custom log loot for this TreeDefinition
*
* @return A Set of TreeLoot
*/
public Set<TreeLoot> getCustomLogLoot() {
return Collections.unmodifiableSet(this.customLogLoot);
}
/**
* Gets the custom leaf loot for this TreeDefinition
*
* @return A Set of TreeLoot
*/
public Set<TreeLoot> getCustomLeafLoot() {
return Collections.unmodifiableSet(this.customLeafLoot);
}
/**
* Gets the tools that can be used to activate this tree topple
*
* @return A Set of ItemStacks
*/
public Set<ItemStack> getRequiredTools() {
return Collections.unmodifiableSet(this.requiredTools);
} }
} }

View File

@ -0,0 +1,23 @@
package com.songoda.ultimatetimber.tree;
import org.bukkit.inventory.ItemStack;
public class TreeLoot {
private final TreeBlockType treeBlockType;
private final ItemStack item;
private final String command;
private final double chance;
public TreeLoot(TreeBlockType treeBlockType, ItemStack item, String command, double chance) {
this.treeBlockType = treeBlockType;
this.item = item;
this.command = command;
this.chance = chance;
}
public void tryDropLoot(ITreeBlock treeBlock) {
}
}

View File

@ -0,0 +1,21 @@
package com.songoda.ultimatetimber.tree.animation;
import com.songoda.ultimatetimber.tree.TreeBlockSet;
import com.songoda.ultimatetimber.tree.TreeDefinition;
import org.bukkit.block.Block;
public abstract class TreeAnimation {
protected final TreeAnimationType treeAnimationType;
protected final TreeBlockSet<Block> treeBlocks;
protected final TreeDefinition treeDefinition;
TreeAnimation(TreeAnimationType treeAnimationType, TreeBlockSet<Block> treeBlocks, TreeDefinition treeDefinition) {
this.treeAnimationType = treeAnimationType;
this.treeBlocks = treeBlocks;
this.treeDefinition = treeDefinition;
}
abstract void playAnimation();
}

View File

@ -0,0 +1,18 @@
package com.songoda.ultimatetimber.tree.animation;
import com.songoda.ultimatetimber.tree.TreeBlock;
import com.songoda.ultimatetimber.tree.TreeBlockSet;
import com.songoda.ultimatetimber.tree.TreeDefinition;
public class TreeAnimationChaos extends TreeAnimation {
public TreeAnimationChaos(TreeBlockSet<TreeBlock> treeBlocks, TreeDefinition treeDefinition) {
super(TreeAnimationType.CHAOS, treeBlocks, treeDefinition);
}
@Override
public void playAnimation() {
}
}

View File

@ -0,0 +1,18 @@
package com.songoda.ultimatetimber.tree.animation;
import com.songoda.ultimatetimber.tree.TreeBlock;
import com.songoda.ultimatetimber.tree.TreeBlockSet;
import com.songoda.ultimatetimber.tree.TreeDefinition;
public class TreeAnimationDisintegrate extends TreeAnimation {
public TreeAnimationDisintegrate(TreeBlockSet<TreeBlock> treeBlocks, TreeDefinition treeDefinition) {
super(TreeAnimationType.DISINTIGRATE, treeBlocks, treeDefinition);
}
@Override
public void playAnimation() {
}
}

View File

@ -0,0 +1,18 @@
package com.songoda.ultimatetimber.tree.animation;
import com.songoda.ultimatetimber.tree.TreeBlock;
import com.songoda.ultimatetimber.tree.TreeBlockSet;
import com.songoda.ultimatetimber.tree.TreeDefinition;
public class TreeAnimationFancy extends TreeAnimation {
public TreeAnimationFancy(TreeBlockSet<TreeBlock> treeBlocks, TreeDefinition treeDefinition) {
super(TreeAnimationType.FANCY, treeBlocks, treeDefinition);
}
@Override
public void playAnimation() {
}
}

View File

@ -0,0 +1,18 @@
package com.songoda.ultimatetimber.tree.animation;
import com.songoda.ultimatetimber.tree.TreeBlock;
import com.songoda.ultimatetimber.tree.TreeBlockSet;
import com.songoda.ultimatetimber.tree.TreeDefinition;
public class TreeAnimationNone extends TreeAnimation {
public TreeAnimationNone(TreeBlockSet<TreeBlock> treeBlocks, TreeDefinition treeDefinition) {
super(TreeAnimationType.NONE, treeBlocks, treeDefinition);
}
@Override
public void playAnimation() {
}
}

View File

@ -0,0 +1,11 @@
package com.songoda.ultimatetimber.tree.animation;
/**
* The types of tree animations that are available
*/
public enum TreeAnimationType {
FANCY,
DISINTIGRATE,
CHAOS,
NONE
}

View File

@ -11,7 +11,7 @@ server-type: CURRENT
# A list of worlds that the plugin is disabled in # A list of worlds that the plugin is disabled in
# Default: # Default:
# - 'disabled_world_name' # - disabled_world_name
disabled-worlds: disabled-worlds:
- disabled_world_name - disabled_world_name
@ -51,6 +51,10 @@ allow-creative-mode: true
# Default: true # Default: true
require-chop-permission: true require-chop-permission: true
# Allow players to topple trees regardless of what they are holding in their hand
# Default: false
ignore-required-tools: false
# Automatically replant saplings when a tree is toppled # Automatically replant saplings when a tree is toppled
# Default: true # Default: true
replant-saplings: true replant-saplings: true
@ -98,6 +102,7 @@ scatter-tree-blocks-on-ground: false
# Mix all the tree types below and consider all of them as a single tree type # Mix all the tree types below and consider all of them as a single tree type
# Useful for EpicWorldGenerator and similar plugins that make custom trees # Useful for EpicWorldGenerator and similar plugins that make custom trees
# Warning: Custom loot can get messy with this enabled
# Default: false # Default: false
mix-all-tree-types: false mix-all-tree-types: false
@ -266,7 +271,7 @@ global-custom-log-loot:
chance: 0 chance: 0
2: 2:
material: GOLDEN_APPLE material: GOLDEN_APPLE
command: 'broadcast %player% found a golden apple in a tree!' command: 'broadcast %player% found a golden apple in a %type% tree!'
chance: 0 chance: 0
# Custom loot that is available for all tree types # Custom loot that is available for all tree types

View File

@ -12,7 +12,7 @@ server-type: LEGACY
# A list of worlds that the plugin is disabled in # A list of worlds that the plugin is disabled in
# Default: # Default:
# - 'disabled_world_name' # - disabled_world_name
disabled-worlds: disabled-worlds:
- disabled_world_name - disabled_world_name
@ -52,6 +52,10 @@ allow-creative-mode: true
# Default: true # Default: true
require-chop-permission: true require-chop-permission: true
# Allow players to topple trees regardless of what they are holding in their hand
# Default: false
ignore-required-tools: false
# Automatically replant saplings when a tree is toppled # Automatically replant saplings when a tree is toppled
# Default: true # Default: true
replant-saplings: true replant-saplings: true
@ -92,13 +96,13 @@ use-custom-sounds: true
# Types: FANCY, DISINTEGRATE, CHAOS, NONE # Types: FANCY, DISINTEGRATE, CHAOS, NONE
tree-animation-type: FANCY tree-animation-type: FANCY
# If the tree-animation-type is FANCY, make the blocks stick to the ground # If the tree-animation-type uses falling block entities, make the falling blocks stick to the ground
# Does nothing if tree-animation-type is not FANCY
# Default: false # Default: false
scatter-tree-blocks-on-ground: false scatter-tree-blocks-on-ground: false
# Mix all the tree types below and consider all of them as a single tree type # Mix all the tree types below and consider all of them as a single tree type
# Useful for EpicWorldGenerator and similar plugins that make custom trees # Useful for EpicWorldGenerator and similar plugins that make custom trees
# Warning: Custom loot can get messy with this enabled
# Default: false # Default: false
mix-all-tree-types: false mix-all-tree-types: false
@ -303,11 +307,11 @@ global-custom-log-loot:
material: DIAMOND material: DIAMOND
chance: 0 chance: 0
1: 1:
command: 'eco give %player% 5' command: 'eco give %player 5'
chance: 0 chance: 0
2: 2:
material: GOLDEN_APPLE material: GOLDEN_APPLE
command: 'broadcast %player% found a golden apple in a tree!' command: 'broadcast %player% found a golden apple in a %type tree!'
chance: 0 chance: 0
# Custom loot that is available for all tree types # Custom loot that is available for all tree types