Opening iron door by right click?

Discussion in 'Plugin Development' started by dekrosik, May 27, 2017.

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

    dekrosik

    Hello i try to open iron door by right click, in my InteractEvent
    if (e.getClickedBlock().getType() != Material.IRON_DOOR_BLOCK) {
    return;
    }
    Bukkit.broadcastMessage("v1");
    // if (e.getClickedBlock().getState() instanceof Door) {
    Door door = (Door) e.getClickedBlock().getType().getNewData((e.getClickedBlock().getData()));
    Bukkit.broadcastMessage("v2");
    // Door door = (Door) e.getClickedBlock().getState();
    door.setOpen(true);
    e.getClickedBlock().getState().update();
    e.getClickedBlock().getWorld().playEffect(e.getClickedBlock().getLocation(), Effect.DOOR_TOGGLE, 0);
    // }
    and when i click on door i see on chat "V1" and "v2" but door still stay closed;/ what i can change?
     
  2. Online

    timtower Administrator Administrator Moderator

    @dekrosik Door door = e.getClickedBlock().getState()
    Then use setOpen, and update the state.
    Do keep the instanceof checks though.
     
  3. Offline

    dekrosik

    @timtower as you can see i comment this line
    // Door door = (Door) e.getClickedBlock().getState();
    because i have error like " cannot cast..." but i check
    e.getClickedBlock().getState() instanceOf Door
     
  4. Online

    timtower Administrator Administrator Moderator

    @dekrosik Apparently it is not in the state but in the Data.
    Use getData
     
  5. Offline

    dekrosik

    @timtower where i should use getData, can you write some example code?
     
  6. Online

    timtower Administrator Administrator Moderator

    @dekrosik I don't spoonfeed.
    Go to http://jd.bukkit.org
    Find the Door class.
    See what it extends.
    Cast the getData() to that.
    switch the open state of the door.
     
Thread Status:
Not open for further replies.

Share This Page