How to make pause?

Discussion in 'Plugin Development' started by Tezlastorme, Dec 15, 2011.

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

    Tezlastorme

    Hey I was wondering how to make a pause/delay in the code so it waits a certain amount of time before going to the next line.
     
  2. Offline

    Monstertke

  3. Offline

    Tezlastorme

  4. Offline

    polaris120990

    @Monstertke @Tezlastorme Speaking from experience using sleep will make the entire server freeze while sleeping. You should use the bukkit scheduler to delay or repeat tasks.
     
    TheHandfish likes this.
  5. Offline

    Tezlastorme

    How?
     
  6. Offline

    polaris120990

  7. Offline

    Blop

    Use a code like:
    server.getScheduler().scheduleSyncRepeatingTask(plugin, runnableObject, firstDelay, repeatPeriod);

    with runnableObject implementing a method like:
    void run()
    {
    <repeating task code>
    }
     
  8. Offline

    desht

  9. Offline

    Tezlastorme


    Okay, I'll try that. Thanks. :)

    Btw reason I'm asking this is because I'm trying to make the server broadcast a player's gamemode when they login and it always returns null. It also appears in the log before it says the player has logged in. I'm not actually certain that a delay would solve it :/

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

    Don Redhorse

    post your code (via pastie or similar) or give us the link to your hopefully github or similar repository
     
  11. Offline

    desht

    What event handler are you using? onPlayerJoin() ?
     
  12. Offline

    Tezlastorme

    Here is the source for the player listener:
    Code:
    package me.tezlastorme.GamemodeDetector;
    
    import org.bukkit.GameMode;
    import org.bukkit.Server;
    import org.bukkit.entity.Player;
    import org.bukkit.event.player.PlayerListener;
    import org.bukkit.event.player.PlayerLoginEvent;
    
    public class gdplayerlistener extends PlayerListener{
        public void onPlayerLogin(PlayerLoginEvent event) {
            Player player = event.getPlayer();
            Server server = player.getServer();
            GameMode gamemode = player.getGameMode();
            server.broadcastMessage("GameMode: " + gamemode);
        }
    }
    
     
  13. Offline

    desht

    Yeah, try it in onPlayerJoin(), not onPlayerLogin(). onPlayerLogin() is called when the player initially connects to the server, before they've actually appeared in the world.
     
  14. Offline

    Tezlastorme

    Thanks loads! Working fine now :)
     
  15. Offline

    Monstertke

    Meh, I just googled java pause and pasted the first oracle link.
     
  16. Offline

    Waterflames

    You can use sleep if you do it in a seperate thread.
     
    audhen likes this.
Thread Status:
Not open for further replies.

Share This Page