delay command

Discussion in 'Plugin Development' started by gaberilde, Apr 15, 2017.

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

    gaberilde

    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??
     
  2. 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 ;)
     
  3. Offline

    MCMastery

  4. Offline

    gaberilde

    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
     
  5. Offline

    yPedx

    @gaberilde
    Code:
            BukkitScheduler scheduler = getServer().getScheduler();
            scheduler.scheduleSyncDelayedTask(this, new Runnable() {
                @Override
                public void run() {
                    // Do something
                }
            }, 20L);
        }
    }
    20L = 20 ticks = 1 second.
     
  6. Offline

    MrPowWow

    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);
                
     
            }
     
Thread Status:
Not open for further replies.

Share This Page