How to put a player in a task then do something else?

Discussion in 'Plugin Development' started by xxmobkiller, May 12, 2014.

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

    xxmobkiller

    Hi, i am trying to create a Plugin that tp a player to a location only for 1 hour then tp them back to there last location before they tp to the warp location. How would i go about puting them in a task then broadcast them a msg every 3 minutes then before they get tp back the get a msg saying that they are geting tp back Remember this will have to pull the time they get for each Warp so each warp has its own timer how would i go about doing this?

    Can anyone help me?

    I am really needing some help> :)

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

    thecrystalflame

    make a runnable class that has a map like this.
    Code:java
    1.  
    2. private Map<String, Integer> playerWarpTimes = new HashMap<String, Integer>();
    3.  

    use the integer as minutes remaining.
    in the run method you can loop through this and check/modifer the integer value per player. like this.
    Code:java
    1.  
    2. @Override
    3. public void run() {
    4. for (Map.Entry<String, Integer> current : playerWarpTimes.entrySet()) {
    5. Player player = bukkit.getPlayer("String");
    6. if (current.getValue >= 1) {
    7. current.setValue(current.getValue()-1);
    8. } else {
    9. player.teleport(whateverLocation);
    10. playerWarpTimes.remove(current.getKey);
    11. }
    12. }
    13. }
    14.  

    it wont be bang on accurate but have this runnable set with Bukkit.getServer().getSchedular().runTaskTimer(plugin, new RunnableClassYouMade(), 1200L, 1200L);
    this will run this method every 1 minute.
    i dont want to get into to much detail but im sure you can figure things out from here.
     
    xxmobkiller likes this.
  3. Offline

    xxmobkiller

    Thank You. :)
     
Thread Status:
Not open for further replies.

Share This Page