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

The following examples show how to use org.bukkit.event.block.LeavesDecayEvent#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: LeafDecayListener.java    From IridiumSkyblock with GNU General Public License v2.0 5 votes vote down vote up
@EventHandler
public void onLeafDecay(LeavesDecayEvent event) {
    try {
        final Block block = event.getBlock();
        final Location location = block.getLocation();
        final IslandManager islandManager = IridiumSkyblock.getIslandManager();
        if (!islandManager.isIslandWorld(location)) return;

        if (!IridiumSkyblock.getConfiguration().disableLeafDecay) return;

        event.setCancelled(true);
    } catch (Exception e) {
        IridiumSkyblock.getInstance().sendErrorMessage(e);
    }
}
 
Example 2
Source File: BlockListener.java    From UhcCore with GNU General Public License v3.0 5 votes vote down vote up
private void handleAppleDrops(LeavesDecayEvent e){
	MainConfiguration cfg = GameManager.getGameManager().getConfiguration();
	Block block = e.getBlock();
	Material type = block.getType();
	boolean isOak;

	if (cfg.getAppleDropsFromAllTrees()){
		if (type != UniversalMaterial.OAK_LEAVES.getType()) {
			e.getBlock().setType(UniversalMaterial.OAK_LEAVES.getType());
		}
		isOak = true;
	}else {
		isOak = type == UniversalMaterial.OAK_LEAVES.getType() || type == UniversalMaterial.DARK_OAK_LEAVES.getType();
	}

	if (!isOak){
		return; // Will never drop apples so drops don't need to increase
	}

	double percentage = cfg.getAppleDropPercentage()-0.5;

	if (percentage <= 0){
		return; // No added drops
	}

	// Number 0-100
	double random = RandomUtils.randomInteger(0, 200)/2D;

	if (random > percentage){
		return; // Number above percentage so no extra apples.
	}

	// Add apple to drops
	Bukkit.getScheduler().runTask(UhcCore.getPlugin(), new Runnable() {
		@Override
		public void run() {
			block.getWorld().dropItem(block.getLocation().add(.5, .5, .5), new ItemStack(Material.APPLE));
		}
	});
}