How to open and close door?

Hello,

I didnt find a class for doors and any method to open/close doors or gates using my code.

On bukkit:

if (isDoor(block)){ byte data = block.getData(); if ((data & 0x8) == 0x8 && !isTrapDoor(block)) { block = block.getRelative(BlockFace.DOWN); data = block.getData(); } if (isDoorClosed(block) && !isTrapDoor(block)) { data = (byte) (data | 0x4); } block.setData(data, true); }

How to do this on Sponge, if possible?
Thanks!

You need to use the Data API, specifically OpenData or the OPEN key.

import org.spongepowered.api.data.key.Keys;

public boolean isOpen(Location<World> blockLoc) {
    return blockLoc.get(Keys.OPEN).orElse(false);
}

Ohh, fine, and one more think. Using this only code:

static void changeDoorState(BlockSnapshot b) {
      b.getLocation().get().offer(Keys.OPEN, !getDoorState(b));
}

The door will close/open or i need more other code to update the door the player is interacting?