Repeating Task

Discussion in 'Plugin Development' started by Fhbgsdhkfbl, Jun 8, 2016.

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

    Fhbgsdhkfbl

    I'm coding a tutorial plugin for my server, and I need a task to teleport players around the server, every 15 seconds, I'm not sure whether to do one runnable, or multiple. I'd appreciate the help.
    Thanks!
     
  2. Offline

    timtower Administrator Administrator Moderator

  3. Offline

    Fhbgsdhkfbl

    @timtower How would I make it teleport someone to a new spot after 15 seconds?? I'm new to runnables so...
     
  4. Offline

    timtower Administrator Administrator Moderator

    @Fhbgsdhkfbl You store the UUID, time and location somewhere.
    Time will be in seconds from start of the tutorial.
    Runnable will move the player when time%15 == 0
     
  5. Offline

    Fhbgsdhkfbl

    @timtower Show me an example please.. I'm confusing myself so much..
     
  6. Offline

    timtower Administrator Administrator Moderator

    @Fhbgsdhkfbl I don't spoonfeed.
    Get the teleporting working first, make a method that will teleport a player by UUID to the next teleport location.
     
  7. Offline

    Fhbgsdhkfbl

    I have the player in an ArrayList, I'm trying to figure out how to the runnable part and teleporting them to multiple locations after a certain amount of time.
     
  8. Offline

    timtower Administrator Administrator Moderator

    @Fhbgsdhkfbl You also need to store the current location index and time for this to work. Get around that first as this needs to work for multiple players.
     
  9. Offline

    Fhbgsdhkfbl

    @timtower
    HashMap<String, Long> time = new HashMap<String, Long>();
    HashMap<String, Location> location = new HashMap<String, Location>();
    Would this be the proper way to store those two?
     
  10. Offline

    timtower Administrator Administrator Moderator

    @Fhbgsdhkfbl I would use UUID's instead.
    Now write a method that takes an UUID and teleports that person to the next location.
     
  11. Offline

    Fhbgsdhkfbl

    @timtower
    but after that one location, how would I make it teleport them to the next location after 15 seconds with the runnable? Thats the part I don't understand.
     
  12. Offline

    timtower Administrator Administrator Moderator

    @Fhbgsdhkfbl Don't look at the timer yet.
    You need to know the current and the next location of the tutorial.
    That is why I would use a counter instead of a location.
    The counter would just point to a list of locations
     
  13. Offline

    Fhbgsdhkfbl

    @timtower Would it be possible to have a list of coords and world names to teleport them to? And what exactly do you mean by "a counter" ?
     
  14. Offline

    timtower Administrator Administrator Moderator

    @Fhbgsdhkfbl List<Location>
    Currently at index 0,
    teleport
    currently at index 1
     
  15. Offline

    Fhbgsdhkfbl

    @timtower
    So lets say
    I have this location "Location l = new Location(Bukkit.getWorld("world"), 120, 100, -65);"
    and I make another one "Location a = new Location etc"
    Could I do it that way?
     
  16. Offline

    timtower Administrator Administrator Moderator

    @Fhbgsdhkfbl I suggest that you put them in a list instead.
    And make sure to do that in the onEnable so the world is loaded.
     
  17. Offline

    Fhbgsdhkfbl

    @timtower
    Would you suggest a repeating task or a delayed to do this? if repeating, I would have to cancel it right? And I still can't figure out how to do multiple locations in that list. I made a List like you said
    ArrayList<Location> location = new ArrayList<Location>();
     
  18. Offline

    timtower Administrator Administrator Moderator

    @Fhbgsdhkfbl You are jumping ahead of things. Timer is not important yet, and yes: I do know that this is for timers.
    No need to cancel anything before the plugin gets disabled.
    You should know the current location and the next one.
     
Thread Status:
Not open for further replies.

Share This Page