Countdown Help

Discussion in 'Plugin Development' started by Minibros, Jul 8, 2015.

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

    Minibros

    Hello.
    My Countdown Dont work.
    Can someone optimize my code?
    Thank you!


    Code:
    package Puncher;
    
    import org.bukkit.Bukkit;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.scheduler.BukkitScheduler;
    public final class Countdown extends JavaPlugin {
      public void onEnable() {
         int Countdown = 20;
      BukkitScheduler scheduler = Bukkit.getServer().getScheduler();
      scheduler.scheduleSyncRepeatingTask(this, new Runnable() {
        
        
      @Override
      public void run() {
      
         if(Countdown == 10) {
           Bukkit.broadcastMessage("The match is starting in" + Countdown + "Seconds");
         }
         if(Countdown == 9) {
           Bukkit.broadcastMessage("The match is starting in" + Countdown + "Seconds");
         }
         if(Countdown == 8) {
           Bukkit.broadcastMessage("The match is starting in" + Countdown + "Seconds");
         }
         if(Countdown == 7) {
           Bukkit.broadcastMessage("The match is starting in" + Countdown + "Seconds");
         }
         if(Countdown == 6) {
           Bukkit.broadcastMessage("The match is starting in" + Countdown + "Seconds");
         }
         if(Countdown == 5) {
           Bukkit.broadcastMessage("The match is starting in" + Countdown + "Seconds");
         }
         if(Countdown == 4) {
           Bukkit.broadcastMessage("The match is starting in" + Countdown + "Seconds");
         }
         if(Countdown == 3) {
           Bukkit.broadcastMessage("The match is starting in" + Countdown + "Seconds");
         }
         if(Countdown == 2) {
           Bukkit.broadcastMessage("The match is starting in" + Countdown + "Seconds");
         }
         if(Countdown == 1) {
           Bukkit.broadcastMessage("The match is starting in" + Countdown + "Second");
         }
         if(Countdown == 0) {
           Bukkit.broadcastMessage("The match is now starting.");
         }
        
      }
      
      
      }, 0L, 20L);
      }
    }
     
  2. Online

    timtower Administrator Administrator Moderator

    @Minibros if countdown > 0 match is starting in ...
    else: starting
     
  3. Offline

    Minibros

    @timtower
    output: The Match is now starting...


    Code:
    package Puncher;
    
    import org.bukkit.Bukkit;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.scheduler.BukkitScheduler;
    public final class Countdown extends JavaPlugin {
      public void onEnable() {
         int Countdown = 20;
      BukkitScheduler scheduler = Bukkit.getServer().getScheduler();
      scheduler.scheduleSyncRepeatingTask(this, new Runnable() {
        
        
      @Override
      public void run() {
      
         if(Countdown == 10) {
           Bukkit.broadcastMessage("The match is starting in" + Countdown + "Seconds");
         }
         if(Countdown == 9) {
           Bukkit.broadcastMessage("The match is starting in" + Countdown + "Seconds");
         }
         if(Countdown == 8) {
           Bukkit.broadcastMessage("The match is starting in" + Countdown + "Seconds");
         }
         if(Countdown == 7) {
           Bukkit.broadcastMessage("The match is starting in" + Countdown + "Seconds");
         }
         if(Countdown == 6) {
           Bukkit.broadcastMessage("The match is starting in" + Countdown + "Seconds");
         }
         if(Countdown == 5) {
           Bukkit.broadcastMessage("The match is starting in" + Countdown + "Seconds");
         }
         if(Countdown == 4) {
           Bukkit.broadcastMessage("The match is starting in" + Countdown + "Seconds");
         }
         if(Countdown == 3) {
           Bukkit.broadcastMessage("The match is starting in" + Countdown + "Seconds");
         }
         if(Countdown == 2) {
           Bukkit.broadcastMessage("The match is starting in" + Countdown + "Seconds");
         }
         if(Countdown == 1) {
           Bukkit.broadcastMessage("The match is starting in" + Countdown + "Second");
         }
         if(Countdown > 0) {
           Bukkit.broadcastMessage("The match is now starting.");
         }
        
      }
      
      
      }, 0L, 20L);
      }
    }
     
  4. Online

    timtower Administrator Administrator Moderator

    @Minibros Check my comment, then check your code again.
    You are doing something else then what I said
     
  5. Offline

    Lolmewn

    You're never decreasing countdown.
     
    CodePlaysMinecraft likes this.
  6. Offline

    Minibros

    @timtower
    OUTPUT: The Match is starting
    Without stopping

    CODE
    package Puncher;

    import org.bukkit.Bukkit;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.scheduler.BukkitScheduler;
    public final class Countdown extends JavaPlugin {
    public void onEnable() {
    int Countdown = 20;
    BukkitScheduler scheduler = Bukkit.getServer().getScheduler();
    scheduler.scheduleSyncRepeatingTask(this, new Runnable() {


    @Override
    public void run() {

    if(Countdown == 10) {
    Bukkit.broadcastMessage("The match is starting in" + 10 + "Seconds");
    }

    if(Countdown > 0) {
    Bukkit.broadcastMessage("The match is now starting.");
    }
    }


    }, 0L, 20L);
    }
    }
     
  7. Online

    timtower Administrator Administrator Moderator

    @Minibros Again:
    Code:
    if countdown > 0 : match is starting in
    else
    match is starting
     
  8. Offline

    Minibros

    @timtower
    it isnt working
    Can you just add your method in my code
    And then send it to me?
     
  9. Online

    timtower Administrator Administrator Moderator

    @Minibros
    Code:
    public void run() {
      
         if(Countdown >0) {
           Bukkit.broadcastMessage("The match is starting in" + Countdown + "Seconds");
         }
        
         if(Countdown == 0) {
           Bukkit.broadcastMessage("The match is now starting.");
         }
      }
    Not much difference.
     
    Sulphate likes this.
  10. You should use Bukkit.getScheduler().cancelTask().
     
  11. Offline

    poepdrolify

Thread Status:
Not open for further replies.

Share This Page