Solved Help, Multiple Instances of One BukkitTask?

Discussion in 'Plugin Development' started by SuperOriginal, Mar 1, 2014.

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

    SuperOriginal

    So i'm making a custom mute plugin, and my tempmute function is a bit jacked up. So I can only have one person muted at a time or else the timers interfere and everything gets messed up. Here's a part of my code:
    Code:java
    1. if(!muted.contains(target.getName())){
    2. muted.add(p.getName());
    3. int num = Integer.parseInt(args[1]);
    4. p.sendMessage(ChatColor.GREEN + "You have muted " + target.getName() + " for " + num + " Seconds.");
    5. target.sendMessage(ChatColor.GOLD + "You have been Softmuted for " + num + " Seconds.");
    6. Bukkit.getServer().getScheduler().runTaskLater(this, new BukkitRunnable(){
    7. public void run(){
    8. if(muted.contains(target.getName())){
    9. muted.remove(target.getName());
    10. target.sendMessage(ChatColor.GOLD + " You are no longer Softmuted.");
    11. }
    12.  
    13.  
    14.  
    15. }
    16. }, num*20);
    17.  
    18. return true;


    How could I set it up so everyone has an individual timer counting down their on mute times?
     
  2. Offline

    Ironraptor3

    just when an op/admin etc types that command in, do:
    Code:java
    1.  
    2.  
    3. //under the command checks
    4. new Mute(target, num);
    5.  
    6. //then make a new class, so when this fires, it makes a new instance
    7.  
    8. public Mute(Player target, int num) {
    9. //put your runnable here
    10. }
    11.  


    This should work, i use similar things in my listener class
     
  3. Offline

    SuperOriginal

    Could you put that into context with my example? Sorry, i'm new to this realm of coding.
     
  4. Offline

    SuperOriginal

  5. 1: Make a global timer that runs every x seconds. (recommend every 60 seconds)
    2: Use a hashmap to store <String, Date>
    3: In the global timer, check if the player's name is in the hashmap.
    4: If it is, then check if the current date is equal to the date in the hashmap.
    5: When you do a mute command, add the mute time to the current date, and store it to the hashmap.
    6: If the date is equal to the current date, then remove his name from the hashmap.
    7: Monitor chat events, and cancel it if their name is in the hashmap.
    supercube101
     
  6. Offline

    SuperOriginal

    Im_Zeus I used your concept of Hashmaps and Dates and now I have it working! Thanks a bunch!
     
Thread Status:
Not open for further replies.

Share This Page