Search in sources :

Example 6 with BlockBreakEvent

use of org.bukkit.event.block.BlockBreakEvent in project Essentials by drtshock.

the class Commandbreak method run.

//TODO: Switch to use util class
@Override
public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception {
    final Block block = user.getBase().getTargetBlock((HashSet<Byte>) null, 20);
    if (block == null) {
        throw new NoChargeException();
    }
    if (block.getType() == Material.AIR) {
        throw new NoChargeException();
    }
    if (block.getType() == Material.BEDROCK && !user.isAuthorized("essentials.break.bedrock")) {
        throw new Exception(tl("noBreakBedrock"));
    }
    //final List<ItemStack> list = (List<ItemStack>)block.getDrops();
    //final BlockBreakEvent event = new BlockBreakEvent(block, user.getBase(), list);
    final BlockBreakEvent event = new BlockBreakEvent(block, user.getBase());
    server.getPluginManager().callEvent(event);
    if (event.isCancelled()) {
        throw new NoChargeException();
    } else {
        block.setType(Material.AIR);
    }
}
Also used : Block(org.bukkit.block.Block) BlockBreakEvent(org.bukkit.event.block.BlockBreakEvent)

Aggregations

BlockBreakEvent (org.bukkit.event.block.BlockBreakEvent)6 Player (org.bukkit.entity.Player)3 Test (org.junit.Test)3 Block (org.bukkit.block.Block)2 Listener (org.bukkit.event.Listener)2 PlayerInteractEvent (org.bukkit.event.player.PlayerInteractEvent)2 ItemStack (org.bukkit.inventory.ItemStack)2 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 List (java.util.List)1 GlowWorld (net.glowstone.GlowWorld)1 GlowBlock (net.glowstone.block.GlowBlock)1 GlowBlockState (net.glowstone.block.GlowBlockState)1 BlockContainer (net.glowstone.block.blocktype.BlockContainer)1 BlockType (net.glowstone.block.blocktype.BlockType)1 ItemTimedUsage (net.glowstone.block.itemtype.ItemTimedUsage)1 ItemType (net.glowstone.block.itemtype.ItemType)1 GlowPlayer (net.glowstone.entity.GlowPlayer)1 GlowItem (net.glowstone.entity.objects.GlowItem)1 TeamManager (net.warvale.core.game.logic.TeamManager)1