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."); } }
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.
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.