Solved Per player runnable

Discussion in 'Plugin Development' started by HeavyMine13, Sep 23, 2014.

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

    HeavyMine13

    Hey! I want to create a NEW runnable for a player on a trigger. The problem is, i don't know how i can do that. Note I need an different ID for each runnable so I can cancel it alone. Thanks!
     
  2. HeavyMine13 Use a Map.
    Code:
    Map<UUID, Integer> runnableMap = new HashMap<UUID, Integer>();
     
    public void YOUR_METHOD(Player player) {
        int taskID = [YOUR_RUNNABLE].getTaskID();
        runnableMap.put(player.getUniqueId(), taskID);
    }
    
     
  3. Offline

    HeavyMine13

    That is just making a new runnable. I need a unique id for the runnable too; Note: Im using:

    taskID = 0;

    taskID = Bukkit.get.........getTaskID();
     
  4. Offline

    FabeGabeMC

    HeavyMine13
    Code:java
    1. // CONCEPT
    2. private Map<UUID, Integer> count
    3. = new HashMap<UUID, Integer>();
    4. private int countid = 0;
    5.  
    6. //start runnable void
    7. {
    8. if(count.containsKey(p.getUniqueId())
    9. || count.get(p.getUniqueId()) == 0)
    10. return;
    11. countid++;
    12. countid = // Schedule your task here.
    13. count.put(p.getUniqueId(), countid);
    14. }

    Probably something like that?
     
  5. Offline

    Gnat008

  6. HeavyMine13 The answer has essentially been fed to you already, what are you still confused about?
     
  7. Offline

    FabeGabeMC

    AdamQpzm
    If you are meaning I did that, I just gave him a basic idea of how the actual code would look like.
     
  8. HeavyMine13
    Code:java
    1. Map<UUID, Integer> runnableMap = new HashMap<UUID, Integer>();
    2.  
    3. public void whatever(Plugin plugin, Player player) {
    4. if(!runnableMap.containsKey(player.getUniqueId())) {
    5. int taskID = Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
    6.  
    7. @Override
    8. public void run() {
    9. /* Do whatever you want here */
    10. }
    11.  
    12. });
    13. runnableMap.put(player.getUniqueId(), taskID);
    14. }
    15. }
    16.  
    17. public void cancelRunnable(Player player) {
    18. if(runnableMap.containsKey(player.getUniqueId())) {
    19. Bukkit.getScheduler().cancelTask(runnableMap.get(player.getUniqueId()));
    20. }
    21. }
     
    HeavyMine13 likes this.
  9. FabeGabeMC Well you did feed answer, but it was wrong anyway. DJSkepter is by far the worse offender.
     
  10. Offline

    HeavyMine13

    Hey first of all, thanks. It didn't have to be fed. I could have understood. But thanks anyway.

    Nothing, I was sleepy and didn't logically see that you are having unique ID using getTaskID() and add it to a map sorry it was 1 am ;-; I don't like code feeding

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 14, 2016
Thread Status:
Not open for further replies.

Share This Page