BlockBreakEvent help

Discussion in 'Plugin Development' started by shoetechnews, Aug 7, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    shoetechnews

    I am new to plugin development, not really looking to LEARN, but just basic things, I tried to google around to find how to make it so when I break a block, it drops another, rather than the one it is suppose to drop.

    (Break a snow block, drop a snow block)

    Here is the code I have now:
    Code:java
    1. @EventHandler
    2. public void onBlockBreak(BlockBreakEvent event) {
    3. final Block origin = event.getBlock();
    4. final int type = origin.getTypeId();
    5. if (type == 80) {
    6. Block block = event.getBlock();
    7. World world = block.getWorld();
    8. Location playerLocation = event.getPlayer().getLocation();
    9. world.dropItem(playerLocation, SNOW_BLOCK);
    10. }
    11. }


    Thanks for the help :).
     
  2. Offline

    LinearLogic

    Cancel the BlockBreakEvent, set the block to air, and call world.dropItem(...) (use the location of the block, not that of the player).
     
  3. Offline

    shoetechnews


    Ok I changed it to this, and it still doesn't work, as I said I am not very experienced.

    Code:java
    1. @EventHandler
    2. public void onBlockBreak(BlockBreakEvent event) {
    3. final Block origin = event.getBlock();
    4. final int type = origin.getTypeId();
    5. if (type == 80) {
    6. Block block = event.getBlock();
    7. World world = block.getWorld();
    8. event.setCancelled(true);
    9. block.setType(Material.AIR);
    10. Location blockLocation = event.getBlock().getLocation();
    11. world.dropItem(blockLocation, SNOW_BLOCK);
     
  4. Offline

    Bammerbom

    shoetechnews
    Change this:
    Code:java
    1. final Block origin = event.getBlock();
    2. final int type = origin.getTypeId();
    3. if (type == 80) {

    To this:
    Code:java
    1. if(event.getBlock().getType().equals(Material.SNOW_BLOCK){
    (Snow_Block import from org.bukkit)

    If not works: Send the error. (No error = not registered events)
     
  5. Offline

    LinearLogic

    The world.dropItem(...) method takes an ItemStack object as its second paramater, not a Material enum value. Use:
    Code:java
    1. world.dropItem(blockLocation, new ItemStack(Material.SNOW_BLOCK));
     
Thread Status:
Not open for further replies.

Share This Page