Created
June 17, 2013 03:52
-
-
Save tmathmeyer/5794570 to your computer and use it in GitHub Desktop.
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 edu.wpi.tmathmeyer.hungry.pumpkins; | |
import java.util.Collection; | |
import org.bukkit.Location; | |
import org.bukkit.Material; | |
import org.bukkit.block.Block; | |
import org.bukkit.block.BlockFace; | |
import org.bukkit.event.EventHandler; | |
import org.bukkit.event.Listener; | |
import org.bukkit.event.block.BlockRedstoneEvent; | |
import org.bukkit.inventory.ItemStack; | |
import org.bukkit.material.Pumpkin; | |
import org.bukkit.plugin.java.JavaPlugin; | |
public class HungryPumpkin extends JavaPlugin implements Listener { | |
@Override | |
public void onEnable() { | |
getLogger().info("Hungry pumpkins enabled!"); | |
getServer().getPluginManager().registerEvents(this, this); | |
} | |
@Override | |
public void onDisable() { | |
getLogger().info("Hungry pumpkins disabled"); | |
} | |
@EventHandler | |
public void onRedstoneTick(BlockRedstoneEvent bre) | |
{ | |
Block b = bre.getBlock(); | |
if (b.getType().equals(Material.PUMPKIN) && b.getBlockPower() > 0) | |
{ | |
BlockFace bf = ((Pumpkin)b).getFacing(); | |
Block target = b.getRelative(bf); | |
if (target.breakNaturally()) | |
{ | |
Collection<ItemStack> drops = b.getDrops(new ItemStack(Material.DIAMOND_PICKAXE)); | |
BlockFace bf2 = bf==BlockFace.NORTH ? BlockFace.SOUTH : | |
bf==BlockFace.SOUTH ? BlockFace.NORTH : | |
bf==BlockFace.EAST ? BlockFace.WEST : | |
bf==BlockFace.WEST ? BlockFace.EAST : | |
BlockFace.UP; | |
if (b.getRelative(bf2).getType().isSolid()) | |
{ | |
bf2 = BlockFace.UP; | |
} | |
Location drop = b.getRelative(bf2).getLocation(); | |
for (ItemStack i : drops) | |
{ | |
drop.getWorld().dropItem(drop, i); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment