Solved How to pause before executing code

Discussion in 'Spigot Plugin Development' started by SpiroMarshes, May 29, 2016.

  1. Hi,

    I'm trying to pause for about 1000ms before executing a line of code. I've tried the generic Java sleep/pause but it doesn't seem to work.

    Here is my code:

    Code (Text):
    public class joinListener implements Listener{
        public void onPlayerJoin(PlayerJoinEvent playerJoin) throws InterruptedException{
            Player player = playerJoin.getPlayer();
            Player spiro = Bukkit.getServer().getPlayer("SpiroMarshes");
            if(player.hasPlayedBefore() == false)
                // DELAY HERE
      "Welcome " + player + "!");
            if(player.hasPlayedBefore() == true)      
                // DELAY HERE  
      "wb :)");          
  2. Schedule a delayed task.
  3. How exactly would that look? Trying to learn the Spigot API which is why I'm tinkering around with this. Help is appreciated. :)
  4. Code (Text):
                Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable(){
                    public void run(){
                     //Do your magic stuff here. and then close it and set a task timer
    • Friendly Friendly x 1
  5. Mark as solved :3
  6. Sorry :p
  7. I prefer to use the bukkit runnable:

    Code (Text):
    new BukkitRunnable() {
        public void run() {
            //Do STUFF
    }.runTaskLater(plugin, ticks);
    Or any other run task method from it.