How would I code a plugin that continuously rewards a player after an interval of ontime?

Discussion in 'Plugin Development' started by Milese3, Aug 29, 2015.

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

    Milese3

    Hey, I'm developing a plugin which rewards a player after they have been online for 10 minutes. Every 10 minutes they are online- during which they must be online continuously, they receive a reward. However, I have no idea how to begin to program this.

    Thank you, Milese.
     
  2. Moved to Plugin Development.
     
  3. Offline

    mythbusterma

    @Milese3

    1. Create a repeating task that runs every 10 minutes
    2. ???
    3. PROFIT!!
     
    Konato_K likes this.
  4. Offline

    Konato_K

  5. Offline

    Milese3

    I tried this, but I don't know how to stop a task when a user logs out.
     
  6. Offline

    mythbusterma

    @Milese3

    If the player isn't online, cancel the Runnable.
     
  7. Online

    timtower Administrator Administrator Moderator

    @Milese3 Why not make 1 runnable that runs for all players then?
     
    Konato_K and TheGamesHawk2001 like this.
  8. You're going to have to store the join time some where. Why not just store it in a configuration file and constantly check if they're online in one runnable etc.

    @See toMinutes(long duration)
    @See currentTimeMillis()
     
  9. Offline

    caderape

    @Milese3

    1. You should add players in an arraylist when you start your runnable of 10 minuts.
    2. Check playerQuitEvent and remove from the arraylist if a player leave.
    3. After 10 minuts, check if the player is in the arraylist and give him a reward.
    4. Do it again
     
  10. Offline

    Xerox262

    1. Make a map of UUID and Long
    2. Make a runnable to get all online players and check their Long in the Map to see if it is due for rewarding
    3. Set the player's long in the map to the current time
    4. When the player joins add them to the Map
    5. When the player leaves remove them from the Map
     
Thread Status:
Not open for further replies.

Share This Page