mirror of
https://github.com/songoda/UltimateTimber.git
synced 2024-12-01 22:33:23 +01:00
Add tree events
This commit is contained in:
parent
041c265024
commit
407fbdccc0
@ -4,7 +4,7 @@ import com.songoda.ultimatetimber.commands.CommandHandler;
|
|||||||
import com.songoda.ultimatetimber.configurations.DefaultConfig;
|
import com.songoda.ultimatetimber.configurations.DefaultConfig;
|
||||||
import com.songoda.ultimatetimber.treefall.CustomLoot;
|
import com.songoda.ultimatetimber.treefall.CustomLoot;
|
||||||
import com.songoda.ultimatetimber.treefall.TreeFallAnimation;
|
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 com.songoda.ultimatetimber.utils.Methods;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
@ -48,7 +48,7 @@ public class UltimateTimber extends JavaPlugin {
|
|||||||
/*
|
/*
|
||||||
Register the main event that handles toppling down trees
|
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
|
Prevent falling blocks from forming new blocks on the floor
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -82,7 +82,6 @@ class NoAnimationTreeDestroyer {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static ItemStack getItem(Material material) {
|
static ItemStack getItem(Material material) {
|
||||||
|
@ -8,7 +8,7 @@ import org.bukkit.util.Vector;
|
|||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
class TreeChecker {
|
public class TreeChecker {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Used to check if a tree is a tree
|
Used to check if a tree is a tree
|
||||||
@ -113,11 +113,18 @@ class TreeChecker {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
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
|
* 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
|
* @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) {
|
private HashSet<Block> parseTree(Block block) {
|
||||||
|
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
package com.songoda.ultimatetimber.treefall;
|
package com.songoda.ultimatetimber.treefall;
|
||||||
|
|
||||||
import com.songoda.ultimatetimber.UltimateTimber;
|
import com.songoda.ultimatetimber.UltimateTimber;
|
||||||
|
import com.songoda.ultimatetimber.api.events.TreeFallEvent;
|
||||||
import com.songoda.ultimatetimber.configurations.DefaultConfig;
|
import com.songoda.ultimatetimber.configurations.DefaultConfig;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
import org.bukkit.enchantments.Enchantment;
|
import org.bukkit.enchantments.Enchantment;
|
||||||
@ -12,7 +15,7 @@ import org.bukkit.event.block.BlockBreakEvent;
|
|||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
|
||||||
public class TreeFallEvent implements Listener {
|
public class TreeFallListener implements Listener {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
This is the starting point for the whole effect
|
This is the starting point for the whole effect
|
||||||
@ -49,6 +52,10 @@ public class TreeFallEvent implements Listener {
|
|||||||
if (fileConfiguration.getBoolean(DefaultConfig.CUSTOM_AUDIO))
|
if (fileConfiguration.getBoolean(DefaultConfig.CUSTOM_AUDIO))
|
||||||
TreeSounds.tipOverNoise(event.getBlock().getLocation());
|
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)) {
|
if (fileConfiguration.getBoolean(DefaultConfig.SHOW_ANIMATION)) {
|
||||||
TreeFallAnimation treeFallAnimation = new TreeFallAnimation();
|
TreeFallAnimation treeFallAnimation = new TreeFallAnimation();
|
||||||
treeFallAnimation.startAnimation(event.getBlock(), blocks, event.getPlayer());
|
treeFallAnimation.startAnimation(event.getBlock(), blocks, event.getPlayer());
|
Loading…
Reference in New Issue
Block a user