CoolDowns for non-commands

Discussion in 'Plugin Development' started by ProMCKingz, Jul 13, 2014.

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

    RawCode

  2. Offline

    ProMCKingz

    I get error on UUID
     
  3. Offline

    jacklin213

    ProMCKingz sorry replace getUUID() with getUniqueId()
     
  4. Offline

    ProMCKingz

    Hi,
    I tried this
    Code:java
    1. package me.ProMCKingz.VIP;
    2.  
    3. import java.util.ArrayList;
    4.  
    5. import org.bukkit.ChatColor;
    6. import org.bukkit.Effect;
    7. import org.bukkit.Material;
    8. import org.bukkit.entity.Player;
    9. import org.bukkit.event.EventHandler;
    10. import org.bukkit.event.Listener;
    11. import org.bukkit.event.block.Action;
    12. import org.bukkit.event.player.PlayerInteractEvent;
    13. import org.bukkit.inventory.ItemStack;
    14.  
    15. public class Method2Return implements Listener{
    16.  
    17. public class MyListener implements Listener {
    18. private Main plugin;
    19. private ArrayList<String> cooldowns = new ArrayList<String>();
    20. public MyListener(Main instance) {
    21. plugin = instance;
    22. }
    23.  
    24. @EventHandler
    25. public void onPlayerInteract(final PlayerInteractEvent e){
    26. ItemStack is = e.getItem();
    27. Player player = e.getPlayer();
    28. if (e.getPlayer().getItemInHand().getType() == Material.PISTON_STICKY_BASE &&
    29. e.getAction() == Action.LEFT_CLICK_AIR){
    30. is.setType(Material.PISTON_BASE);
    31. player.sendMessage(ChatColor.RED + "[PLugin] " + ChatColor.DARK_RED + "De-Activated");
    32. e.getPlayer().playEffect(e.getPlayer().getLocation(), Effect.SMOKE, 5);
    33. cooldowns.add(e.getPlayer().getUniqueId().toString());
    34. plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
    35. public void run() {
    36. cooldowns.remove(e.getPlayer().getUniqueId().toString());
    37. }
    38. }, 100); //Cooldown in ticks. 20 ticks per sec. 100 ticks for 5 sec
    39. }
    40.  
    41. }
    42. }
    43. }
    44. [/syntax]
    45.  
    46. However this just seems to stop the process that used to happen before in my class.
    47. And does not have a cooldown. How may I fix it?[/PLugin]
     
  5. Offline

    xTigerRebornx

    ProMCKingz First, read the link RawCode posted on a better way of doing cooldowns.
    Next, just look at your code. You are doing no checks for the cooldown at all, you are just adding the Player to a list then removing him.
     
Thread Status:
Not open for further replies.

Share This Page