Tasks Crashing The Server?

Discussion in 'Plugin Development' started by TehVoyager, Feb 1, 2014.

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

    TehVoyager

    I am Making a MiniGame Plugin and the Countdown is crashing the server?
    Code :
    Code:java
    1. public void startCountDown(){
    2. gamestate = TagGameState.COUNTDOWN;
    3. countdown = 60;
    4. while(countdown >= 0){
    5. Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){
    6.  
    7. @Override
    8. public void run() {
    9. broadcastCount(countdown);
    10. countdown--;
    11. if(countdown == 0){
    12. startGame();
    13. gamestate = TagGameState.GAME;
    14. }
    15. }
    16.  
    17. }, 20);
    18.  
    19. }
    20. }
     
  2. I had the same with a previous plugin I was trying to make work which I eventually gave up on. I remember the problem being with a while loop. Something about stopping the stream of the server or something.
     
  3. Offline

    TehVoyager

  4. Offline

    ZeusAllMighty11

    You're scheduling a load of tasks inside your while loop.
    In addition, your schedulers will constantly start the game
     
  5. Offline

    TehVoyager

    ZeusAllMighty11
    I only want to schedule one task a second and No, They will not constantly start the game.
     
  6. Offline

    Iaccidentally

    You don't want to schedule one task a second, it can all be done in a single task.
     
  7. Offline

    SuperOmegaCow

    Iaccidentally try a repeating task and cancel it when the game starts.
     
  8. Offline

    Iaccidentally

    I'm not the one asking about it, I know how lol.
     
    ZeusAllMighty11 likes this.
  9. Offline

    zeeveener

    Code:java
    1. int count
    2. BukkitTask task = runtasktimer(plugin, runnable{
    3. if (count == 0) {
    4. startGame()
    5. return
    6. }
    7. print "Countdown: " + count
    8. count--
    9. }, 1 second, 1 second)
    10.  
    11. startGame(){
    12. task.cancel()
    13. }
     
Thread Status:
Not open for further replies.

Share This Page