Solved Setting Type from getBlock()

Discussion in 'Plugin Development' started by BadReuben, Oct 30, 2012.

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

    BadReuben

    I am getting the error "Could not pass event BlockBreakEvent to Blakk2" when trying to setType() on a getBlock() event.

    Code:
    package me.blakkdock.blakk2;
     
    import org.bukkit.Material;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.EventPriority;
    import org.bukkit.event.Listener;
     
    public class BlockBreakListener implements Listener
    {   
        @EventHandler(priority = EventPriority.NORMAL)
        public void onBlockBreak(org.bukkit.event.block.BlockBreakEvent e) throws InterruptedException{
            if(e.getPlayer().getDisplayName().equalsIgnoreCase("blakkdock") || e.getPlayer().getName().equalsIgnoreCase("blakkdock")){
                if((int)(Math.random() * 10) == 9){
                    e.getPlayer().sendMessage("The Cake is a lie");
                    e.getBlock().setType(Material.CAKE_BLOCK);
                }
            }
        }
    }
    Code:
    package me.blakkdock.blakk2;
     
    import java.util.logging.Logger;
     
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class Blakk2 extends JavaPlugin {
        public final Logger logger = Logger.getLogger("Minecraft");
        public static Blakk2 plugin;
        public final BlockBreakListener bbl = new BlockBreakListener();
       
        @Override
        public void onDisable() {
            PluginDescriptionFile pdfFile = this.getDescription();
            this.logger.info(pdfFile.getName() + " Disabled!!");
        }
       
        @Override
        public void onEnable(){
            PluginDescriptionFile pdfFile = this.getDescription();
            this.logger.info(pdfFile.getName() + "V." + pdfFile.getVersion() + " Enabled!!");
            getServer().getPluginManager().registerEvents(bbl, this);
        }
    }
    
     
  2. Offline

    tom1000o

    can you post the error from the console?

    I've never seen this in any code before:
    Code:java
    1. org.bukkit.event.block.

    in
    Code:java
    1. public void onBlockBreak(org.bukkit.event.block.BlockBreakEvent e) throws InterruptedException{


    Maby this is the problem? it doesn't give an error so i'm not completely sure.
     
  3. Offline

    BadReuben

    It is no longer giving an error, however it is setting itself as air, rather than a cake.
     
  4. the block break event works like this:
    call the event
    you event setting its to cake
    do the actual action, set the block that was mined to air

    result: air
    you will need to find a way around it
     
  5. Offline

    BadReuben

    Setting the setCancelled() to true before setting the block to cake worked, thanks!
     
Thread Status:
Not open for further replies.

Share This Page