Can't get my onBlockDamage function to work.

Discussion in 'Plugin Development' started by wabsta, Feb 7, 2011.

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

    wabsta

    So, I'm trying to learn bukkit. But, I have 1 problem.
    I can't get my function to work..
    Code:
    public void onBlockDamaged(BlockDamageEvent event) {
              System.out.println("DERP DOE T NOU");
              Player player = event.getPlayer();
              Block block = event.getBlock();
                if (event.getDamageLevel() == BlockDamageLevel.BROKEN && WabXPPlayerListener.plugin.enabled(player)) {
                    player.sendMessage("It's broken now");
                }
            }
          public void onBlockDamage(BlockDamageEvent event) {
              System.out.println("DERP DOE T NOU 2");
              Player player = event.getPlayer();
                if (event.getDamageLevel() == BlockDamageLevel.BROKEN && WabXPPlayerListener.plugin.enabled(player)) {
                    player.sendMessage("It's broken now");
                }
          }
    
    Those are my functions, as I have no idea which on to use, I keep on reading a different one all over the internet.
    But it doesn't seem to even reach those 2 functions, as it also doesn't just print the system print.
    Also, I have another function in the same file, onBlockPlace(), that one works fine.
    This are my imports:
    Code:
    import com.bukkit.wabsta.WabXP.WabXPPlayerListener;
    import org.bukkit.Material;
    import org.bukkit.event.block.BlockDamageEvent;
    import org.bukkit.event.block.BlockPlaceEvent;
    import org.bukkit.event.block.BlockListener;
    import org.bukkit.block.Block;
    import org.bukkit.block.BlockDamageLevel;
    import org.bukkit.entity.Player;
    
    I feel like I've tried everything. Also, with @overrides before the functions, but also didn't work.
    I also checked another, open source project, Big Brother, and their function also doesn't have that so..

    Could anyone tell me wth I'm doing wrong?
     
  2. Offline

    Samkio

    When your plugin starts you need to register the events.
    Here is the BLOCK_DAMAGE event.
    Code:
     PluginManager pm = getServer().getPluginManager();
             pm.registerEvent(Event.Type.BLOCK_DAMAGED, blockListener, Event.Priority.Normal, this);
    Also make sure they are accosiated with the blocklistener class.
    Code:
        private final PluginBlockListener blockListener = new PluginBlockListener(this);
    And finally maintain the listener extends BlockListener
    Code:
    public class PluginBlockListener extends BlockListener {
     
  3. Offline

    wabsta

    Aaaaaah, that is exactly what I needed!
    I didn't know that, could have guessed if I took a better look at my current code though.

    Thank you :)
     
  4. Offline

    Samkio

    Your welcome :)
     
Thread Status:
Not open for further replies.

Share This Page