Created
February 28, 2012 14:43
-
-
Save NeatMonster/1932908 to your computer and use it in GitHub Desktop.
AmaTree
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.first4ever.amatree; | |
import org.bukkit.Bukkit; | |
import org.bukkit.Material; | |
import org.bukkit.block.Block; | |
import org.bukkit.block.BlockFace; | |
import org.bukkit.entity.Player; | |
import org.bukkit.event.EventHandler; | |
import org.bukkit.event.Listener; | |
import org.bukkit.event.block.BlockBreakEvent; | |
import org.bukkit.plugin.java.JavaPlugin; | |
public class AmaTree extends JavaPlugin implements Listener { | |
@EventHandler | |
public void onBlockBreak(final BlockBreakEvent event) { | |
if (event.isCancelled() || event.getBlock().getType() != Material.LOG) | |
return; | |
final Player player = event.getPlayer(); | |
if (player.hasPermission("amatree.entiretree")) { | |
Block block = event.getBlock(); | |
while (block.getType() == Material.LOG) { | |
block.breakNaturally(); | |
block = block.getRelative(BlockFace.UP); | |
} | |
} | |
if (player.hasPermission("amatree.replanting") | |
&& (event.getBlock().getRelative(BlockFace.DOWN).getType() == Material.DIRT || event.getBlock() | |
.getRelative(BlockFace.DOWN).getType() == Material.GRASS)) { | |
final Block block = event.getBlock(); | |
final byte data = block.getData(); | |
getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() { | |
@Override | |
public void run() { | |
if (block.getType() == Material.AIR) | |
block.setTypeIdAndData(Material.SAPLING.getId(), data, false); | |
} | |
}, 10L); | |
} | |
} | |
@Override | |
public void onEnable() { | |
super.onEnable(); | |
Bukkit.getPluginManager().registerEvents(this, this); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment