Create countdown for teleport

Discussion in 'Plugin Development' started by mateuszhp, Sep 10, 2013.

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

    mateuszhp

    Hi!

    I wanted to write a plugin that after 120 seconds teleports players to a different arena (from the lobby to spawn team).

    Currently the code I have:
    Code:java
    1.  
    2. Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
    3. public void run() {
    4. p.sendMessage(ChatColor.GREEN + "* Teleport to team SPAWN : " + api.getTeam(p.getName()));
    5. p.teleport(loc1);
    6. }
    7. }, 2400L);


    I do not know how to make a plugin to notify the players how many seconds to teleport. Please help me.
     
  2. Offline

    ShredNyx

    Create a timer
    And send the player the seconds like 30..29...28..27
    p.sendmessage(ChatColor.GREEN + "10".......
     
  3. Offline

    mateuszhp

    So I don't know how to do :/ Can you help me?
     
  4. Offline

    The_Doctor_123

    mateuszhp

    Look into repeating tasks rather than delayed.
     
  5. Offline

    MrTwiggy

    Code:
    new BukkitRunnable()
    {
            int seconds = 5;
            public void run()
            {
                    player.sendMessage(seconds + " seconds until teleport...");
                    seconds--;
     
                    if (seconds <= 0)
                    {
                            player.teleport(destination);
                            player.sendMessage("You have been teleported!");
                            cancel();
                    }
            }
    }.runTaskTimer(plugin, 0, 20);
    
     
  6. Offline

    Deleted user

    I'd personally send that message a little different...

    Code:
    player.sendMessage(String.valueOf(seconds) + (seconds != 1 ? " seconds " : " second ") + "until teleport.");
    
    Sorry for any mistakes, programming from mobile.
     
  7. Offline

    MrTwiggy


    Code:
    String.valueOf(seconds) = seconds.toString() = seconds + "string"
    
     
Thread Status:
Not open for further replies.

Share This Page