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


    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. Offline

    Forge_User_45064837 Retired Staff

    Moved to Plugin Development.
  3. Offline



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


  5. Offline


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



    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



    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


    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