下面列出了org.bukkit.event.block.LeavesDecayEvent#getBlock ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@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);
}
}
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));
}
});
}