anyone knows a way that can delay a command for a bit before it runs in bukkit? you cant use thread.sleep since i think it blocks the whole server and the server needs to keep running in that time i want to delay for a second because of a login event i want mine to be displayed AFTER the you joined a game message and AFTER all the other plugins welcome you??
new BukkitRunable() { public void run() { YOUR CODE HERE } }.runTaskLater(Some things here) Sorry, i am on mobile so i dont know the exact code... Auto correct will do I hope
where is the bit i would put how long i want the code delayed for for me it would be about half a second or a second depending on what works best
@gaberilde Code: BukkitScheduler scheduler = getServer().getScheduler(); scheduler.scheduleSyncDelayedTask(this, new Runnable() { @Override public void run() { // Do something } }, 20L); } } 20L = 20 ticks = 1 second.
Here is an example. To make it more clear. Code: public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) { if (cmd.getName().equalsIgnoreCase("spawn"))) { final Player player = (Player)sender; player.sendMessage(ChatColor.GRAY + "You will be teleported to §aSpawn §7in §a3 §7Seconds."); Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() { public void run() { player.teleport(new Location(Bukkit.getWorld("world"), 255.412, 64, 56)); player.sendMessage(ChatColor.RED + "Woosh!"); } }, 3 * 20L); }