Get Door Status

Discussion in 'Plugin Development' started by Daniel Few, May 21, 2011.

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

    Daniel Few

    Hey guys,
    I'm going to be making a plugin that involves doors.
    Was wondering if there's a way to get whether a door is open or close and how to switch a door to open or close position.
    -DanJames
     
  2. Offline

    marinating

    Door d = (Door)block.getState().getData();
    if (d.isOpen()){
     
  3. Offline

    DreadKyller

    that answers one of his questions, but how do you open or close the door?
     
  4. Offline

    Daniel Few

    Thanks for that marinating, but how do i close the door once i know its open? Or open it when its closed.
    -DanJames
     
  5. Offline

    marinating

    You should be able to setData() it but I don't know what the data would be ever since the bukkit api updated and removed the extremely helpful .java source files.

    I implore somebody who has the power to change the javadocs back to the way it was before, with a search bar and source code.
     
  6. Offline

    Daniel Few

    That would be very useful :)
     
  7. Offline

    DreadKyller

    havn't had time to test it but this might work

    PHP:
    Door door = (Door)event.getBlock().getState();
    byte state=door.getData();
    byte nstate=(byte) (1-state);
    door.setData(nstate);
    because I belive a byte of 1 is open and 0 is closed, I may be wrong
     
  8. Offline

    Shamebot

    Door isn't a BlockState, it's a MaterialData
    Code:
    Door door = (Door)block.getState().getData();
    block.setData(door.getData() ^ 4);
    Should reverse the state, if it's open it will close, if it's shut it will open,
    didn't test this either.
     
  9. Offline

    DreadKyller

    @Shamebot : I forgot about "^", that helps a bit, also oops, I must have deleted that somehow, cause I had getData() before when I posted it...
     
  10. Offline

    Daniel Few

    Well i want it so if its open, it closes and if its closed it stays close. So i guess id do a if else statement.

    Eg if door open
    close
    else
    stay closed
     
  11. Offline

    DreadKyller

    ok then :
    PHP:
    Door door = (Door)block.getState().getData();
    if(
    d.isOpen()){
        
    block.setData(door.getData() ^ 4);
    }
     
  12. Offline

    Shamebot

    Or:
    Code:
    Door door = (Door)block.getState().getData();
    block.setData(door.getData() | 4);
    If you're not familiar with binary operations | means, OR for example:
    1001 (example door data)
    0100 (=4)
    ------
    1101
    btw doors can have different hinges, so a closed door in a wall might look open.
    http://www.minecraftwiki.net/wiki/Data_values#Doors
     
  13. Offline

    DreadKyller

    witha little more math you could get the hinge, and work with that.
     
  14. Offline

    Shamebot

    Yeah, but it's a lot easier to read the code if you use Door.getHingeCorner() and use some Ifs
     
  15. Offline

    DreadKyller

    @Shamebot : that's exactly what I was meaning
     
  16. Offline

    Daniel Few

    Thanks i'll have a look at that :)
     
Thread Status:
Not open for further replies.

Share This Page