下面列出了怎么用org.bukkit.event.block.LeavesDecayEvent的API类实例代码及写法,或者点击链接到github查看源代码。
@EventHandler(priority = EventPriority.LOWEST)
public void onBlockDecay(LeavesDecayEvent event) {
if (!GDFlags.LEAF_DECAY) {
return;
}
final World world = event.getBlock().getWorld();
if (!GriefDefenderPlugin.getInstance().claimsEnabledForWorld(world.getUID())) {
return;
}
Location location = event.getBlock().getLocation();
GDClaim targetClaim = this.storage.getClaimAt(location);
// check overrides
final Tristate result = GDPermissionManager.getInstance().getFinalPermission(event, location, targetClaim, Flags.LEAF_DECAY, event.getBlock().getWorld(), event.getBlock(), (GDPermissionUser) null);
if (result == Tristate.FALSE) {
event.setCancelled(true);
}
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onDecay(LeavesDecayEvent e) {
if (!SlimefunPlugin.getWorldSettingsService().isWorldEnabled(e.getBlock().getWorld())) {
return;
}
String id = BlockStorage.checkID(e.getBlock());
if (id != null) {
for (Berry berry : ExoticGarden.getBerries()) {
if (id.equalsIgnoreCase(berry.getID())) {
e.setCancelled(true);
return;
}
}
}
dropFruitFromTree(e.getBlock());
ItemStack item = BlockStorage.retrieve(e.getBlock());
if (item != null) {
e.setCancelled(true);
e.getBlock().setType(Material.AIR);
e.getBlock().getWorld().dropItemNaturally(e.getBlock().getLocation(), item);
}
}
@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);
}
}
@EventHandler
public void onLeaveDecay(LeavesDecayEvent e){
int random = RandomUtils.randomInteger(0, 200);
if (random > 1){
return;
}
// add gapple
e.getBlock().getWorld().dropItem(e.getBlock().getLocation().add(.5,0,.5),new ItemStack(Material.GOLDEN_APPLE));
}
private void onBlockBreak(Block block){
for (BlockFace face : NEIGHBOURS) {
final Block relative = block.getRelative(face);
if (!UniversalMaterial.isLeaves(relative.getType())){
continue; // Not a leave so don't fast decay
}
if (findLog(relative, DECAY_RANGE)){
continue; // A log is too close so don't fast decay
}
Bukkit.getScheduler().runTaskLater(UhcCore.getPlugin(), new Runnable() {
@Override
public void run() {
if (!UniversalMaterial.isLeaves(relative.getType())){
return; // Double check to make sure the block hasn't changed since
}
LeavesDecayEvent event = new LeavesDecayEvent(relative);
Bukkit.getPluginManager().callEvent(event);
if (!event.isCancelled()) {
relative.breakNaturally();
relative.getWorld().playSound(relative.getLocation(), UniversalSound.BLOCK_GRASS_BREAK.getSound(), 1, 1);
}
}
}, 5);
}
}
private void handleShearedLeaves(BlockBreakEvent e){
MainConfiguration cfg = GameManager.getGameManager().getConfiguration();
if (!cfg.getAppleDropsFromShearing()){
return;
}
if (!UniversalMaterial.isLeaves(e.getBlock().getType())){
return;
}
if (e.getPlayer().getItemInHand().getType() == Material.SHEARS){
Bukkit.getPluginManager().callEvent(new LeavesDecayEvent(e.getBlock()));
}
}
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));
}
});
}
@EventHandler(priority = EventPriority.HIGH)
public void noBucket(final LeavesDecayEvent event) {
event.setCancelled(true);
}
@EventHandler
public void onLeaveDecay(LeavesDecayEvent e){
onBlockBreak(e.getBlock());
}
@EventHandler
public void onLeavesDecay(LeavesDecayEvent event){
handleAppleDrops(event);
}
@EventHandler(priority = EventPriority.MONITOR)
public void blockChanged(LeavesDecayEvent e){
if(e.isCancelled())return;
logBlockDestoryed(e.getBlock());
i.put("LDECAY", i.get("LDECAY")+1);
// System.out.println(9);
}