Solved How can I do a timer on a plugin?

Discussion in 'Plugin Development' started by ZygoZ, Feb 19, 2015.

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

    ZygoZ

    I have a plugin just like tpa thingy.. Where you have to request another player to get teleported, to him.. I just wanted something like a request timeout.

    Anybody know how to do that?
    - Thanks.
     
  2. Offline

    q8minecraft

    Try doing a repeating task, then create a countdown method. Not sure, correct me if I'm wrong.. Never worked with countdowns :p
     
  3. Offline

    ProMCKingz

    @ZygoZ
    It's called a cooldown. Make an array, and add the player to the array if you want him to have the cooldown. Then, make a runnable which only counts down for players in the array.
    Watch this:
     
  4. Offline

    ZygoZ

    Thread.sleep is not a proper way to do it, I wanted to know if there was some other way.
     
  5. Offline

    ProMCKingz

    @ZygoZ
    There's a search engine called "google". There are lots of other videos/posts on this.
     
  6. Offline

    ZygoZ

    @ProMCKingz Google? :confused:

    @ProMCKingz Well.. Now I have a cooldown for the command.. Now I just want a timeout.. I'm a newb. :'(

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 13, 2016
  7. Offline

    Avygeil

    @ProMCKingz Both videos are bad practices. Protip : exclude YT from searches related to programming by appending "-site:youtube.com".

    Now that you're not distracted by bad results, here is a good post, except you would use UUID's @ZygoZ (I actually had a player rename during a 4 hours long countdown with a very outdated plugin :()
     
  8. Offline

    candyfloss20

    @ZygoZ
    Some code taken from my UHC plugin,
    Code:
        public static void startBorder() {
            border = 5000;
            blocksLostPerSecond = 1;
            new BukkitRunnable() {
                @Override
                public void run() {
    
                    if (border != 250) {
                        border = border - blocksLostPerSecond;
                    }
                    else {
                        for (Player p : GameManager.getOnlinePlayers()) {
                            p.playSound(p.getLocation(), Sound.NOTE_BASS_GUITAR,10,10);
                        }
                        Bukkit.broadcastMessage("§6§l>> §5The border has been frozen at §d§l250§5!");
                        this.cancel();
                    }
    
                }
            }.runTaskTimer(Main.getInstance(), 20L, 20L);
        }
     
  9. Offline

    Funergy

    @ProMCKingz Why use video tutorials?
    @mythbusterma has told us enough times why video tutorials are bad xD

    @ZygoZ
    Code:
    new BukkitRunnable(){
    @Override
    public void run(){
    
    }
    }.runTaskLater(<instance of main class>,<time before the timer starts>,<delay>)
     
  10. Offline

    ZygoZ

    I think I got something going for me.. Thank you for helping guys! :)
     
    Funergy likes this.
Thread Status:
Not open for further replies.

Share This Page