Solved How to close opened door(all the types)

Discussion in 'Plugin Development' started by NukerFall, Apr 1, 2020.

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

    NukerFall

    I have a runnable in my plugin, which i want to use to close the door five seconds after i opened it. Door can use any material, which represent door (ACACIA, BIRCH, etc), because i use 1.15 api. This is my code:
    Code:
    public void onInteract(PlayerInteractEvent e) {
        if (Tag.DOORS.isTagged(e.getClickedBlock().getType())) {
            BukkitRunnable b = new BukkitRunnable() {
                @Override
                public void run() {
                    //close the door
                }
            };
            b.runTaskLater(main, 100L);
        }
    }
    
    Okay, found a solution myself.

    Code:
    BlockData s = e.getClickedBlock().getBlockData();
    Door d = (Door) s;
    d.setOpen(true);
    e.getClickedBlock().setBlockData(d);
    BukkitRunnable b = new BukkitRunnable() {
        @Override
        public void run() {
            BlockData s = e.getClickedBlock().getBlockData();
            Door d = (Door) s;
            d.setOpen(false);
            e.getClickedBlock().setBlockData(d);
        }
    };
    b.runTaskLater(main, 100L);
    
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Apr 1, 2020
Thread Status:
Not open for further replies.

Share This Page