MultiArena: a countdown for every arena

Discussion in 'Spigot Plugin Development' started by Alex0589, Feb 9, 2018.

  1. As you can read from the title, I want to create aacountdown for every arena. I have already tryed to use a single Bukkit Runnable but it will set the same time for every arena so that different arenas cannot have 2 different number of seconds left and I do not wont that. How can I resolve my problem?
     
  2. Create multiple runnables if you want different timers per arena?
     
  3. Can you give me a pratic example because I wasn't able to(I could look like a noob but I am stuck)
     
  4. The same way you create one runnable to create a second one? Can you show some of your current code that doesn't work?
     
  5. Make a class implements BukkitRunnable

    And use this;

    public void startCount() {
    new ClassHere().runTaskTimer(plugin, 0, 20);
    }
     
  6. Sorry but now I cannot use my PC. Anyway I have a Player Teleport Event who checks some things than if the number of players is the number of players in that arena is the minNumber of players than it starts a bukkitRunnable
     
  7. What would change from what I am doing?
     
  8. Well this is a counter for MultiArena
     
  9. Ok but could you explain what's the difference between my method and yours? If I do something I want also to understand it
     
  10. We don't have your method so we can't compare them.
     
  11. Code (Text):
    package me.auties.SkyWarsLocaut.countdowns;

    import java.util.ArrayList;
    import java.util.HashMap;

    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.scheduler.BukkitRunnable;
    import org.bukkit.scheduler.BukkitScheduler;
    import org.bukkit.scheduler.BukkitTask;

    import me.auties.SkyWarsLocaut.main.Main;
    import me.auties.SkyWarsLocaut.scoreboard.InGame;
    import me.auties.SkyWarsLocaut.scoreboard.Lobby;

    public class countdown  {
        static int time = 30;
        static BukkitTask scheduler;
        @SuppressWarnings("deprecation")
         public void lobby(Player p) {
            scheduler = Bukkit.getServer().getScheduler().runTaskTimer(Main.p, new BukkitRunnable(){
                @Override
                public void run() {
                 
                    if(time != 0) {
                            time--;
                       
                         for (Player player : Bukkit.getOnlinePlayers()){
                             player.sendTitle(ChatColor.RED + "Waiting", ChatColor.GREEN + "The game starts in " + time);
                             player.sendMessage(ChatColor.AQUA + "[CakeWars]" + ChatColor.RED + "This game starts in " + ChatColor.GREEN + time + ChatColor.RED + " seconds");
                         }
                     
                    }else if(time == 0) {
                        InGame.scoreGame(p);
                        cancelTask();
                     
                     
                    }
                 
                }

         
             
            }, 0L, 20L);
         
        }
     
        public static void cancelTask() {
            scheduler.cancel();
        }


         
           
         
        }
     
  12. Ai, the statics are causing your problem. Create a new class called "Countdown" and make it extend BukkitRunnable. Your IDE will complain that you need to implement run(), do this. Then you can place your code in there like you currently have. Then, whenever you need a new countdown, you can simply create a new instance of your Countdown object. Make sure you do pass in some logic to actually execute after the countdown expires. E.G. Pass in the ID of an arena to execute something on.
     
    • Like Like x 1
  13. Ok I think I got it
     
  14. Ok here in my country is late so I'm going to sleep but I will let you know. Anyway I think I got it!
     
  15. if you can't already do this for your arenas, then your entire design for your arena system isn't right. i suggest learning more java
     

Share This Page