BlockInteract Event isn't raised when a door is toggled

Discussion in 'Plugin Development' started by madjam002, Mar 12, 2011.

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

    madjam002

    Hi all,
    I'm in the process of building a plugin which requires a door to be locked, however I can't seem to get this working.

    To lock the door I'm using setCancelled(true); on the EventHandler on the BlockInteract event, however it's not being raised when I punch or right-click a door.

    My code is simply:
    Code:
    @Override
    public void onBlockInteract(BlockInteractEvent event) {
        event.setCancelled(true);
    }
    and to register the event it's:
    Code:
    pm.registerEvent(Event.Type.BLOCK_INTERACT, blockListener, Priority.Normal, this);
    This code manages to block me from opening chest/dispenser inventories and probably other things too, but it won't work with doors. I have also tried adding logging methods to the Interact Event, and sending player messages to confirm that the event is being called, but nothing happens.
    It's probably just me, and to lock a door I need to be using some other event or something, but this is what I have seen other people use but I can't get it working.
    I'm running CraftBukkit 541 and the Bukkit API version is dated 2nd March (updated from the wiki download link today)
    I also have iConomy and sqlitejdbc-v056 added as external JAR's on my project.

    Thanks! :)
     
  2. Offline

    Raphfrk

    From reading the CraftBukkit code, interact only triggers on:

    Code:
    BlockBed
    BlockButton
    BlockChest
    BlockDispenser
    BlockFurnace
    BlockJukeBox
    BlockLever
    BlockPressurePlate
    BlockWorkbench
    
     
  3. Offline

    madjam002

    Ahh right, so what event can I use which is raised when a door is toggled?
    There must be one because plugins like LWC manage to stop someone opening a door.

    Thanks
     
  4. Offline

    PurelySatanic

    It's possible the person is checking for onRightClick, and then checking to see if the object right clicked is a door.

    If you can't trigger it any other way, that one I know for sure will work. (Disclaimer: I never mean "for sure" literally ;) )
     
  5. Offline

    madjam002

    Okay I'm gonna try onRightClick, check if door, do stuff, then close/open the door.
    And also onBlockDamage for the left click event and do exactly the same stuff.

    Thanks!
    [MERGETIME="1300014829"][/MERGETIME]
    I am now confused, I am looking at the source of LWC on github, and it uses onBlockInteract for doors as well.

    @Override
    public void onBlockInteract(BlockInteractEvent event) {



    So how does LWC and other plugins such as SelfClosingDoors manage to get BlockInteract working with Doors?
     
  6. Offline

    Raphfrk

    Hmm, it might be worth trying something like

    event.getPlayer().sendMessage("Block interact: " + event.getBlock().getType);

    in the interact event. It is possible that they trigger interact for doors somewhere else (or there was a change with a version update)
    [MERGETIME="1300023074"][/MERGETIME]
    Actually, it looks like this commit removed the interact functionality.

    It might be worth submitting a bug report.
     
  7. Offline

    madjam002

    Okay thanks I will submit a bug report later.
    For now I am using the Right Click and Damage event handlers and then using setData to open and close the doors
     
  8. Offline

    Raphfrk

    It might be worth testing it first with an older version of bukkit :)
     
  9. Offline

    madjam002

    So what should I change then, should I change the Bukkit API in my project to an older version, or CraftBukkit running on my server to an older version?

    LWC uses the Interact event fine on my server with a new version of CraftBukkit, but the Interact event isn't called on the same server on my plugin, so maybe it's the Bukkit API.

    I'll try downgrading my Bukkit API version then
    [MERGETIME="1300037659"][/MERGETIME]
    Sorry I'm talking jibberish in my last post.
    LWC is running on a server with CraftBukkit 522 on which still supports the BlockInteract for doors event.
    I'm going to be using my plugin on that server so it should be fine, however the new bukkit versions have ditched the interact event and the source for LWC still uses the Interact event, so I'm guessing LWC won't work on new servers with doors either.

    I hope removing the interact event on doors wasn't intentional, it's a fundamental part. CraftBukkit 522 seems to work with the Interact event so I will use that on my servers now.
     
Thread Status:
Not open for further replies.

Share This Page