Java Code Examples for org.bukkit.event.block.BlockBreakEvent#getBlock()

The following examples show how to use org.bukkit.event.block.BlockBreakEvent#getBlock() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GlobalProtectionListener.java    From DungeonsXL with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onBlockBreakWithSignOnIt(BlockBreakEvent event) {
    Block block = event.getBlock();
    Player player = event.getPlayer();

    Block blockAbove = block.getRelative(BlockFace.UP);
    //get the above block and return if there is nothing
    if (blockAbove == null) {
        return;
    }

    //return if above block is not a sign
    if (!Category.SIGNS.containsBlock(blockAbove)) {
        return;
    }

    //let onBreak() method to handle the sign
    BlockBreakEvent bbe = new BlockBreakEvent(blockAbove, player);
    onBlockBreak(bbe);

    //follow the onBreak()
    event.setCancelled(bbe.isCancelled());
}
 
Example 2
Source File: DoubleGoldListener.java    From UhcCore with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onBlockBreak(BlockBreakEvent e) {

    if (isActivated(Scenario.CUTCLEAN) || isActivated(Scenario.TRIPLEORES) || isActivated(Scenario.VEINMINER)){
        return;
    }

    Block block = e.getBlock();
    Location loc = e.getBlock().getLocation().add(0.5, 0, 0.5);

    if (block.getType() == Material.GOLD_ORE){
        block.setType(Material.AIR);
        loc.getWorld().dropItem(loc,new ItemStack(Material.GOLD_INGOT, 2));
        UhcItems.spawnExtraXp(loc,6);
    }
}
 
Example 3
Source File: RemoveShopOnChestBreakListener.java    From Shopkeepers with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
void onBlockBreak(BlockBreakEvent event) {
	Block block = event.getBlock();
	if (Utils.isChest(block.getType())) {
		List<PlayerShopkeeper> shopkeepers = plugin.getProtectedChests().getShopkeeperOwnersOfChest(block);
		if (shopkeepers.size() > 0) {
			for (PlayerShopkeeper shopkeeper : shopkeepers) {
				// return creation item for player shopkeepers:
				if (Settings.deletingPlayerShopReturnsCreationItem) {
					ItemStack shopCreationItem = Settings.createShopCreationItem();
					block.getWorld().dropItemNaturally(block.getLocation(), shopCreationItem);
				}
				plugin.deleteShopkeeper(shopkeeper);
			}
			plugin.save();
		}
	}
}
 
Example 4
Source File: SignEvents.java    From uSkyBlock with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR)
public void onSignOrChestBreak(BlockBreakEvent e) {
    if (e.isCancelled()
            || e.getBlock() == null
            || (e.getBlock().getType() != SkyBlockMenu.WALL_SIGN_MATERIAL && !(e.getBlock().getType() == Material.CHEST || e.getBlock().getType() == Material.TRAPPED_CHEST))
            || e.getBlock().getLocation() == null
            || !plugin.getWorldManager().isSkyAssociatedWorld(e.getBlock().getLocation().getWorld())
            ) {
        return;
    }
    if (e.getBlock().getType() == SkyBlockMenu.WALL_SIGN_MATERIAL) {
        logic.removeSign(e.getBlock().getLocation());
    } else {
        logic.removeChest(e.getBlock().getLocation());
    }
}
 
Example 5
Source File: TripleOresListener.java    From UhcCore with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onBlockBreak(BlockBreakEvent e) {

    if (isActivated(Scenario.VEINMINER)) {
        return;
    }

    Block block = e.getBlock();
    Location loc = e.getBlock().getLocation().add(0.5, 0, 0.5);

    switch (block.getType()) {
        case IRON_ORE:
            block.setType(Material.AIR);
            loc.getWorld().dropItem(loc, new ItemStack(Material.IRON_INGOT,3));
            UhcItems.spawnExtraXp(loc,2);
            break;
        case GOLD_ORE:
            block.setType(Material.AIR);
            loc.getWorld().dropItem(loc, new ItemStack(Material.GOLD_INGOT,3));
            if (isActivated(Scenario.DOUBLEGOLD)){
                loc.getWorld().dropItem(loc, new ItemStack(Material.GOLD_INGOT,3));
            }
            UhcItems.spawnExtraXp(loc,3);
            break;
        case DIAMOND_ORE:
            block.setType(Material.AIR);
            loc.getWorld().dropItem(loc, new ItemStack(Material.DIAMOND,3));
            UhcItems.spawnExtraXp(loc,4);
            break;
        case SAND:
            block.setType(Material.AIR);
            loc.getWorld().dropItem(loc, new ItemStack(Material.GLASS));
            break;
        case GRAVEL:
            block.setType(Material.AIR);
            loc.getWorld().dropItem(loc,new ItemStack(Material.FLINT));
            break;
    }

}
 
Example 6
Source File: GameMap.java    From AnnihilationPro with MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.LOW,ignoreCancelled = true)
public void signBreakCheck(BlockBreakEvent event)
{
	if(event.getBlock() != null && event.getPlayer().getGameMode() != GameMode.CREATIVE)
	{
		if(event.getBlock().getType() == Material.FURNACE || event.getBlock().getType() == Material.BURNING_FURNACE)
		{
			MapKey key = MapKey.getKey(event.getBlock().getLocation());
			if(this.enderFurnaces.containsKey(key))
				event.setCancelled(true);
		}
	}
}
 
Example 7
Source File: SignShopListener.java    From Shopkeepers with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
void onBlockBreak(BlockBreakEvent event) {
	Block block = event.getBlock();
	if (Utils.isSign(block.getType())) {
		if (plugin.getShopkeeperByBlock(block) != null) {
			event.setCancelled(true);
		}
	}
}
 
Example 8
Source File: BlockBreak.java    From StaffPlus with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onBreak(BlockBreakEvent event)
{
	Player player = event.getPlayer();
	UUID uuid = player.getUniqueId();
	
	if(freezeHandler.isFrozen(uuid))
	{
		event.setCancelled(true);
		return;
	}
	
	if(options.modeBlockManipulation || !modeCoordinator.isInMode(player.getUniqueId()))
	{
		Block block = event.getBlock();
		
		if(options.alertsXrayBlocks.contains(block.getType()))
		{
			int start = alertCoordinator.getNotifiedAmount();
			int amount = 0;
			
			alertCoordinator.addNotified(block.getLocation());
			calculateVein(block.getType(), block, false);
			amount = alertCoordinator.getNotifiedAmount() - start;
			
			if(amount > 0)
			{
				int lightLevel = player.getLocation().getBlock().getLightLevel();
				
				alertCoordinator.onXray(player.getName(), amount, block.getType(), lightLevel);
			}
		}
		
		return;
	}
	
	event.setCancelled(true);
}
 
Example 9
Source File: PickaxeOfContainment.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public BlockBreakHandler getItemHandler() {
    return new BlockBreakHandler() {

        @Override
        public boolean isPrivate() {
            return false;
        }

        @Override
        public boolean onBlockBreak(BlockBreakEvent e, ItemStack item, int fortune, List<ItemStack> drops) {
            if (isItem(item)) {
                if (!Slimefun.hasUnlocked(e.getPlayer(), PickaxeOfContainment.this, true)) {
                    return true;
                }

                Block b = e.getBlock();

                if (b.getType() != Material.SPAWNER) {
                    return true;
                }

                ItemStack spawner = breakSpawner(b);
                b.getLocation().getWorld().dropItemNaturally(b.getLocation(), spawner);

                e.setExpToDrop(0);
                e.setDropItems(false);
                return true;
            }
            else {
                if (e.getBlock().getType() == Material.SPAWNER) e.setDropItems(false);
                return false;
            }
        }
    };
}
 
Example 10
Source File: MonstersIncListener.java    From UhcCore with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler (ignoreCancelled = true)
public void onBlockBreak(BlockBreakEvent e) {
    Block block = e.getBlock();

    if(isDoor(block)) {
        e.getPlayer().sendMessage(Lang.SCENARIO_MONSTERSINC_ERROR);
        e.setCancelled(true);
    }
}
 
Example 11
Source File: ChestProtectListener.java    From ShopChest with MIT License 5 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onBlockBreak(BlockBreakEvent e) {
    final Block b = e.getBlock();

    if (shopUtils.isShop(b.getLocation())) {
        final Shop shop = shopUtils.getShop(e.getBlock().getLocation());
        Player p = e.getPlayer();

        if (p.isSneaking() && Utils.hasAxeInHand(p)) {
            plugin.debug(String.format("%s tries to break %s's shop (#%d)", p.getName(), shop.getVendor().getName(), shop.getID()));

            if (shop.getShopType() == Shop.ShopType.ADMIN) {
                if (p.hasPermission(Permissions.REMOVE_ADMIN)) {
                    remove(shop, b, p);
                    return;
                }
            } else {
                if (shop.getVendor().getUniqueId().equals(p.getUniqueId()) || p.hasPermission(Permissions.REMOVE_OTHER)) {
                    remove(shop, b, p);
                    return;
                }
            }
        }

        if (shop.getItem() != null) {
            shop.getItem().resetForPlayer(p);
        }

        e.setCancelled(true);
        e.getPlayer().sendMessage(LanguageUtils.getMessage(Message.CANNOT_BREAK_SHOP));
    }
}
 
Example 12
Source File: DoubleOresListener.java    From UhcCore with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onBlockBreak(BlockBreakEvent e) {

    if (isActivated(Scenario.VEINMINER)) {
        return;
    }

    Block block = e.getBlock();
    Location loc = e.getBlock().getLocation().add(0.5, 0, 0.5);

    switch (block.getType()) {
        case IRON_ORE:
            block.setType(Material.AIR);
            loc.getWorld().dropItem(loc, new ItemStack(Material.IRON_INGOT,2));
            UhcItems.spawnExtraXp(loc,2);
            break;
        case GOLD_ORE:
            block.setType(Material.AIR);
            loc.getWorld().dropItem(loc, new ItemStack(Material.GOLD_INGOT,2));
            if (isActivated(Scenario.DOUBLEGOLD)){
                loc.getWorld().dropItem(loc, new ItemStack(Material.GOLD_INGOT,2));
            }
            UhcItems.spawnExtraXp(loc,3);
            break;
        case DIAMOND_ORE:
            block.setType(Material.AIR);
            loc.getWorld().dropItem(loc, new ItemStack(Material.DIAMOND,2));
            UhcItems.spawnExtraXp(loc,4);
            break;
        case SAND:
            block.setType(Material.AIR);
            loc.getWorld().dropItem(loc, new ItemStack(Material.GLASS));
            break;
        case GRAVEL:
            block.setType(Material.AIR);
            loc.getWorld().dropItem(loc,new ItemStack(Material.FLINT));
            break;
    }

}
 
Example 13
Source File: Game.java    From HeavySpleef with GNU General Public License v3.0 5 votes vote down vote up
public void onPlayerBreakBlock(BlockBreakEvent event, SpleefPlayer player) {
	if (gameState != GameState.INGAME) {
		event.setCancelled(true);
		return;
	}
	
	Block block = event.getBlock();
	
	boolean onFloor = false;
	for (Floor floor : floors.values()) {
		if (floor.contains(block)) {
			onFloor = true;
			break;
		}
	}
	
	boolean disableBuild = getPropertyValue(GameProperty.DISABLE_BUILD);
	boolean disableFloorBreak = getPropertyValue(GameProperty.DISABLE_FLOOR_BREAK);
	
	if ((!onFloor && disableBuild) || disableFloorBreak) {
		event.setCancelled(true);
	} else {
		PlayerBlockBreakEvent spleefEvent = new PlayerBlockBreakEvent(this, player, event.getBlock());
		eventBus.callEvent(spleefEvent);
		
		
		if (spleefEvent.isCancelled()) {
			event.setCancelled(true);
			return;
		}
		
		addBlockBroken(player, block);
		//Prevent drops
		block.setType(Material.AIR);
	}
}
 
Example 14
Source File: Signs.java    From AnnihilationPro with MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.LOW,ignoreCancelled = true)
public void signBreakCheck(BlockBreakEvent event)
{
	if(event.getBlock() != null && event.getPlayer().getGameMode() != GameMode.CREATIVE)
	{
		if(event.getBlock().getType() == Material.WALL_SIGN || event.getBlock().getType() == Material.SIGN_POST)
		{
			MapKey key = MapKey.getKey(event.getBlock().getLocation());
			if(this.signs.containsKey(key))
				event.setCancelled(true);
		}
	}
}
 
Example 15
Source File: NetherTerraFormEvents.java    From uSkyBlock with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onBlockBreak(BlockBreakEvent event) {
    if (event == null || !terraformEnabled) {
        return;
    }
    Block block = event.getBlock();
    Player player = event.getPlayer();
    if (!plugin.getWorldManager().isSkyNether(block.getWorld()) || !plugin.getWorldManager().isSkyNether(player.getWorld())) {
        return; // Bail out, not our problem
    }
    if (player.getGameMode() != GameMode.SURVIVAL) {
        return;
    }
    if (!plugin.playerIsOnIsland(player)) {
        return;
    }
    if (!terraFormMap.containsKey(block.getType())) {
        return; // Not a block we terra-form on.
    }
    // TODO: 10/07/2016 - R4zorax: Handle dual-wielding (would break 1.8 compatibility)
    ItemStack tool = event.getPlayer().getItemInHand();
    if (event.getBlock().getDrops(tool).isEmpty()) {
        return; // Only terra-form when stuff is mined correctly
    }
    double toolWeight = getToolWeight(tool);
    Location playerLocation = player.getEyeLocation();
    Location blockLocation = LocationUtil.centerInBlock(block.getLocation());
    Vector v = new Vector(blockLocation.getX(), blockLocation.getY(), blockLocation.getZ());
    v.subtract(new Vector(playerLocation.getX(), playerLocation.getY(), playerLocation.getZ()));
    v.normalize();
    // Disable spawning above the player... enabling the player to clear a region
    if (playerLocation.getPitch() >= minPitch && playerLocation.getPitch() <= maxPitch) {
        ProtectedCuboidRegion islandRegion = WorldGuardHandler.getIslandRegion(playerLocation);
        List<Material> yield = getYield(block.getType(), toolWeight);
        for (Material mat : yield) {
            spawnBlock(mat, blockLocation, v, islandRegion);
        }
    }
}
 
Example 16
Source File: MainListener.java    From ArmorStandTools with MIT License 5 votes vote down vote up
@EventHandler
public void onBlockBreak(BlockBreakEvent event) {
    Block b = event.getBlock();
    if((b.getType() == Material.PLAYER_HEAD && b.hasMetadata("protected")) || (b.getType() == Material.SIGN && b.hasMetadata("armorStand"))) {
        event.setCancelled(true);
    }
}
 
Example 17
Source File: GlobalProtectionListener.java    From DungeonsXL with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onBlockBreak(BlockBreakEvent event) {
    Block block = event.getBlock();
    Player player = event.getPlayer();
    DGlobalPlayer dGlobalPlayer = (DGlobalPlayer) plugin.getPlayerCache().get(player);

    GlobalProtection protection = plugin.getGlobalProtectionCache().getByBlock(block);
    if (protection != null) {
        if (protection.onBreak(dGlobalPlayer)) {
            event.setCancelled(true);
        }
    }
}
 
Example 18
Source File: BlocksBrokenListener.java    From Statz with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBlockBreak(final BlockBreakEvent event) {

    final PlayerStat stat = PlayerStat.BLOCKS_BROKEN;

    // Get player
    final Player player = event.getPlayer();

    // Do general check
    if (!plugin.doGeneralCheck(player, stat))
        return;

    Block blockBroken = event.getBlock();

    final String worldName = blockBroken.getWorld().getName();

    PlayerStatSpecification specification = new BlocksBrokenSpecification(player.getUniqueId(), 1,
            worldName, blockBroken.getType());

    // Update value to new stat.
    plugin.getDataManager().setPlayerInfo(player.getUniqueId(), stat, specification.constructQuery());

}
 
Example 19
Source File: VeinMinerListener.java    From UhcCore with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler
public void onBlockBreak(BlockBreakEvent e){
    Player player = e.getPlayer();

    if (!player.isSneaking()){
        return;
    }

    Block block = e.getBlock();
    ItemStack tool = player.getItemInHand();

    if (block.getType() == UniversalMaterial.GLOWING_REDSTONE_ORE.getType()){
        block.setType(Material.REDSTONE_ORE);
    }

    if (!UniversalMaterial.isCorrectTool(block.getType(), player.getItemInHand().getType())){
        return;
    }

    // find all surrounding blocks
    Vein vein = new Vein(block);
    vein.process();

    player.getWorld().dropItem(player.getLocation().getBlock().getLocation().add(.5,.5,.5), vein.getDrops(getVeinMultiplier(vein.getDropType())));

    if (vein.getTotalXp() != 0){
        UhcItems.spawnExtraXp(player.getLocation(), vein.getTotalXp());
    }

    // Process blood diamonds.
    if (isActivated(Scenario.BLOODDIAMONDS) && vein.getDropType() == Material.DIAMOND){
        player.getWorld().playSound(player.getLocation(), UniversalSound.PLAYER_HURT.getSound(), 1, 1);

        if (player.getHealth() < vein.getOres()){
            player.setHealth(0);
        }else {
            player.setHealth(player.getHealth() - vein.getOres());
        }
    }

    int newDurability = tool.getDurability()-vein.getOres();
    if (newDurability<1) newDurability = 1;

    tool.setDurability((short) newDurability);
    player.setItemInHand(tool);
}
 
Example 20
Source File: BlockBreakListener.java    From IridiumSkyblock with GNU General Public License v2.0 4 votes vote down vote up
@EventHandler
public void onBlockBreak(BlockBreakEvent event) {
    try {
        if (event.isCancelled()) return;
        final Block block = event.getBlock();
        final Location location = block.getLocation();
        final IslandManager islandManager = IridiumSkyblock.getIslandManager();
        final Island island = islandManager.getIslandViaLocation(location);
        if (island == null) return;

        final Player player = event.getPlayer();
        final User user = User.getUser(player);

        if (user.islandID == island.getId()) {
            for (Missions.Mission mission : IridiumSkyblock.getMissions().missions) {
                final int key = island.getMissionLevels().computeIfAbsent(mission.name, (name) -> 1);
                final Map<Integer, Missions.MissionData> levels = mission.levels;
                final Missions.MissionData level = levels.get(key);

                if (level == null) continue;
                if (level.type != MissionType.BLOCK_BREAK) continue;

                final List<String> conditions = level.conditions;

                if (
                        conditions.isEmpty()
                                ||
                                conditions.contains(XMaterial.matchXMaterial(block.getType()).name())
                                ||
                                (
                                        block.getState().getData() instanceof Crops
                                                &&
                                                conditions.contains(((Crops) block.getState().getData()).getState().toString())
                                )
                )
                    island.addMission(mission.name, 1);
            }
        }

        if (!island.getPermissions(user).breakBlocks || (!island.getPermissions(user).breakSpawners && XMaterial.matchXMaterial(block.getType()).equals(XMaterial.SPAWNER))) {
            if (XMaterial.matchXMaterial(block.getType()).equals(XMaterial.SPAWNER)) {
                player.sendMessage(Utils.color(IridiumSkyblock.getMessages().noPermissionBreakSpawners.replace("%prefix%", IridiumSkyblock.getConfiguration().prefix)));
            } else {
                player.sendMessage(Utils.color(IridiumSkyblock.getMessages().noPermissionBuild.replace("%prefix%", IridiumSkyblock.getConfiguration().prefix)));
            }
            event.setCancelled(true);
        }
    } catch (Exception e) {
        IridiumSkyblock.getInstance().sendErrorMessage(e);
    }
}