Pass right click to plugin & interact after destroying a block

Discussion in 'Plugin Development' started by MrRump, Jun 4, 2011.

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

    MrRump

    Hey :)

    A few days ago I started development with plugins. I've already developed with Java, so my problem isn't the language Java, my problem is, I don't know the functions, and classes of Bukkit yet.

    A lot of plugins use a player's right click to do something. Now my first question: How can do an action after a player has right-clicked on a particular block type, for example wood?

    Second question. If I destroy a block of a particular block type, for example the wood block, I want to do something. How can I do it? I don't exactly know if i have to check this in the PlayerListener (because the Player creates the signal) or in the BlockListener (because I do something with blocks ;D)

    :) Thanks.
     
  2. Look at my tutorial on the wiki, link's in my signature. There's also links to source code of some of my plugins which should also help you.
     
  3. Offline

    Sethcran

    For right clicks, take a look at the PlayerListener class, and register the onPlayerInteract event.
    http://javadoc.lukegb.com/Bukkit/d0/df0/classorg_1_1bukkit_1_1event_1_1player_1_1PlayerListener.html

    Then in the function
    Code:
    @Override
    public void onPlayerInteract(PlayerInteractEvent event) {
        if(event.getAction() == Action.RIGHT_CLICK_BLOCK) {
            // Do stuff.
        }
    }
    As for the second, you want to use the BlockListener class, particularly the onBlockBreak event.
    http://javadoc.lukegb.com/Bukkit/de/df8/classorg_1_1bukkit_1_1event_1_1block_1_1BlockListener.html
    Code:
    @Override
    public void onBlockBreak(BlockBreakEvent event) {
        if(event.getBlock().getType() == Material.WOOD) {
            // Do stuff
        }
    }
    As for registering events and how to use the listener classes, see adam's tutorial above me, it really is great.
     
Thread Status:
Not open for further replies.

Share This Page