Per Player Cooldown

Discussion in 'Spigot Plugin Help' started by RayoxHD, Apr 29, 2017.

  1. Hello,

    I'm on this problem for 8h+ and i cant figure it out. For example Sunflower A was harvested by Player A so Player A has a 10m Cooldown Player B can still harvest the Sunflower but will receive also a cooldown after he harvested it. After the Cooldown runs out the Players can harvest it again. How would i make such a per Player Cooldown system? Would be very thankful im at the end and cant think of any Solutions.

    Thanks in Advcance
     
  2. This should be in "Spigot Plugin Development", not here...

    When the player harvests a sunflower, put him in a Map (HashMap): the key is the player ('s uuid for example), the value is the cooldown in some form (example: timestamp when he can harvest again). When a player harvests a sunflower, you check the map.
     
  3. When player A harvest a sunflower, save the moment in his metadata (Use system.currenttimemillis() i think). When he will harvest a flower again, check if he has the metadata, get the time from it and finally compare the time
     
  4. But this makes a Global cooldowen on All Sunflowers i need a why to make it Per player per Flower so i need to save the Location of Sunflower Cooldown and Player.
     
  5. Make a map where the key is the player's UUID and the value is another map: Location key, long value (timestamp). (Remove the entry from the inner map, if the timestamp specified in the entry's value has passed)
    Alternatively, you can use a map where the key is the player's UUID and the value is a Set<Location>, but you have to use BukkitRunnables or other timers in addition if you choose this method. (Remove the location from the set after X seconds)