LockPicking

Discussion in 'Plugin Development' started by LegoPal92, Aug 6, 2012.

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

    LegoPal92

    I am trying to make a lockpicking plugin, but i cannot for the life of me get this delay to work, it should be a two second delay, but the delay effect never happens!!!!! GRRRR, i am so frustrated, can you please help me?
    Code:
    if (id == -1) {
                        if (rand < 44) {
     
                            if (door.isTopHalf()) {
                                block = block.getRelative(BlockFace.DOWN);
                            }
                            door.setOpen(true);
                            p.giveExp(1);
                            //if (door.isOpen()) e.setCancelled(true);
                           
                            this.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
     
                                @Override
                                public void run() {
                                    if (door.isOpen()) e.setCancelled(true);
                                }
                            }, 40L);
     
                        } else if (rand > 44) {
                            e.setCancelled(true);
     
                            if (h >= 3.5) {
                                p.setHealth(h - 3);
                            } else {
                                p.setHealth(h - 3);
                                p.sendMessage("Well, it appears that while trying to break the lock, you died, there must have been a sniper somewhere.");
                                Bukkit.broadcastMessage(p.getName() + "died of mysterious reasons.");
     
                            }
                        }
     
  2. Offline

    ZeusAllMighty11 Retired Staff

    Did you set up the scheduler part for the onEnable method?
     
  3. Offline

    LegoPal92

    no, how do i do that?
     
  4. Offline

    ZeusAllMighty11 Retired Staff

    Do you even know how to use a scheduler?... lol
     
  5. Offline

    LegoPal92

    I am learning, will you please help me figure out a scheduler? I am just trying to elarn something new

    ZeusAllMighty11 will you please help me with this? I don't know what to put in the onEnable() I dont know what is wrong with this, this is my first scheduler. here is the full code http://pastie.org/4389500

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 27, 2016
  6. Offline

    pzxc

    You can't do e.setCancelled inside a delayed task, because by the time the task fires (2 seconds later), the event has already occurred and is in the past.
     
  7. Offline

    LegoPal92

    what could i do instead? i just want to close the door after two seconds, is it really that hard?
     
Thread Status:
Not open for further replies.

Share This Page