Add tree events

This commit is contained in:
electro2560 2019-01-19 01:35:05 -05:00 committed by Brianna O'Keefe
parent 041c265024
commit 407fbdccc0
6 changed files with 92 additions and 8 deletions

View File

@ -4,7 +4,7 @@ import com.songoda.ultimatetimber.commands.CommandHandler;
import com.songoda.ultimatetimber.configurations.DefaultConfig;
import com.songoda.ultimatetimber.treefall.CustomLoot;
import com.songoda.ultimatetimber.treefall.TreeFallAnimation;
import com.songoda.ultimatetimber.treefall.TreeFallEvent;
import com.songoda.ultimatetimber.treefall.TreeFallListener;
import com.songoda.ultimatetimber.utils.Methods;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
@ -48,7 +48,7 @@ public class UltimateTimber extends JavaPlugin {
/*
Register the main event that handles toppling down trees
*/
Bukkit.getServer().getPluginManager().registerEvents(new TreeFallEvent(), this);
Bukkit.getServer().getPluginManager().registerEvents(new TreeFallListener(), this);
/*
Prevent falling blocks from forming new blocks on the floor

View File

@ -0,0 +1,41 @@
package com.songoda.ultimatetimber.api.events;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerEvent;
import com.songoda.ultimatetimber.treefall.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;
}
/**
* Get the tree checker
*
* @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;
}
}

View File

@ -0,0 +1,30 @@
package com.songoda.ultimatetimber.api.events;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList;
import com.songoda.ultimatetimber.treefall.TreeChecker;
/**
* Called when a tree will fall
*/
public class TreeFallEvent extends TreeEvent {
public TreeFallEvent(Player player, TreeChecker treeChecker, Block broke) {
super(player, treeChecker, broke);
}
private static final HandlerList handlers = new HandlerList();
@Override
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
}

View File

@ -81,8 +81,7 @@ class NoAnimationTreeDestroyer {
}
}
}
static ItemStack getItem(Material material) {

View File

@ -8,7 +8,7 @@ import org.bukkit.util.Vector;
import java.util.*;
class TreeChecker {
public class TreeChecker {
/*
Used to check if a tree is a tree
@ -112,12 +112,19 @@ class TreeChecker {
return blocks;
}
/*
Returns all of the blocks in this tree
*/
public HashSet<Block> getAllBlocks(){
return allBlocks;
}
/**
* This parses a tree; returns a hashset if it is a valid tree, or returns null if it isn't
*
* @param block block the player originally destroys
* @return returns null if the tree isn't valid or all blocks in the tree if it isn't
* @return returns all blocks in the tree if it is valid or null if the tree isn't
*/
private HashSet<Block> parseTree(Block block) {

View File

@ -1,7 +1,10 @@
package com.songoda.ultimatetimber.treefall;
import com.songoda.ultimatetimber.UltimateTimber;
import com.songoda.ultimatetimber.api.events.TreeFallEvent;
import com.songoda.ultimatetimber.configurations.DefaultConfig;
import org.bukkit.Bukkit;
import org.bukkit.block.Block;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.enchantments.Enchantment;
@ -12,7 +15,7 @@ import org.bukkit.event.block.BlockBreakEvent;
import java.util.HashSet;
public class TreeFallEvent implements Listener {
public class TreeFallListener implements Listener {
/*
This is the starting point for the whole effect
@ -49,6 +52,10 @@ public class TreeFallEvent implements Listener {
if (fileConfiguration.getBoolean(DefaultConfig.CUSTOM_AUDIO))
TreeSounds.tipOverNoise(event.getBlock().getLocation());
//Call event that tree will fall
TreeFallEvent tfe = new TreeFallEvent(event.getPlayer(), treeChecker, event.getBlock());
Bukkit.getPluginManager().callEvent(tfe);
if (fileConfiguration.getBoolean(DefaultConfig.SHOW_ANIMATION)) {
TreeFallAnimation treeFallAnimation = new TreeFallAnimation();
treeFallAnimation.startAnimation(event.getBlock(), blocks, event.getPlayer());
@ -56,7 +63,7 @@ public class TreeFallEvent implements Listener {
NoAnimationTreeDestroyer.destroyTree(blocks, event.getPlayer().hasPermission("ultimatetimber.bonusloot"),
event.getPlayer().getInventory().getItemInMainHand().containsEnchantment(Enchantment.SILK_TOUCH));
}
}
}