Development Assistance Click on Door Event

Discussion in 'Plugin Help/Development/Requests' started by bas_3008, Feb 17, 2015.

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

    bas_3008

    Hello,

    I'm currently trying to solve an error in one of my plugins, that occured since Bukkit 1.7.9 R0.2 (I think), though I noticed it just recently (haven't used that plugin for a while).
    My plugin should detect when a player right-clicks an IRON DOOR and I try to achieve that with the following code:
    Code:
    public void onPlayerInteract(PlayerInteractEvent event) {
        if(event.getAction() != Action.RIGHT_CLICK_BLOCK && event.getAction() != Action.LEFT_CLICK_BLOCK)
            return;
        Block block = event.getClickedBlock();
        [...]
    So far, so good. Now, when I right-click an iron door, the action seems to be Action.RIGHT_CLICK_AIR instead of BLOCK, hence it returns. But even if I change BLOCK to AIR, event.getClickedBlock() returns null.

    Anyone also noticed this? Maybe I'm doing something wrong?
    Any help is appreciated. Thanks.

    Greetings,
    Bas3008
     
  2. Offline

    BurnerDiamond

    Instead of != why don't you just do

    If(event.getAction() == Action.RIGHT_CLICK_AIR)
     
  3. Offline

    bas_3008

    Line 2 and 3 are to filter out any actions that don't involve clicking on a block (e.g. clicking in air). If the Action isn't RIGHT_CLICK_BLOCK or LEFT_CLICK_BLOCK it justn returns. If it is, the clicked block should be written into the variable block
     
  4. Offline

    bas_3008

    *bump*
     
  5. Offline

    _Filip

    if (get clicked block's type == iron door material) {
    do stuff;
    }
     
  6. Offline

    bas_3008

    @_Filip what is that kinda pseudo code supposed to mean?
    Anyway, thanks for your effort, I got it working again. Still don't know where the error was, I updated my server to 1.8 today and it works. Very weird.
     
  7. Offline

    timtower Administrator Administrator Moderator

    Moved to Bukkit alternatives
     
Thread Status:
Not open for further replies.

Share This Page