Make a correct cooldown time?

Discussion in 'Plugin Development' started by Shzylo, Jul 29, 2013.

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

    Shzylo

    I was doing thread searching for how to make a cooldown with right-clicking with a specific item, and once you right-click with the item I cannot remove a player from the list, so I cannot use it anymore. Here is some lines of code:

    Code:java
    1. @EventHandler
    2. public void onBlockInteract(final PlayerInteractEvent e) {
    3. Action act = e.getAction();
    4. final Player p = e.getPlayer();
    5. Block b = e.getClickedBlock();
    6.  
    7. if (b != null) {
    8. Material hand = p.getItemInHand().getType();
    9. World w = p.getWorld();
    10.  
    11. boolean enabled = plugin.getConfig().getBoolean("sulphur-explosive", true);
    12. int explosionSize = plugin.getConfig().getInt("explosion-size", 1);
    13.  
    14. if (p.hasPermission("mobmeat.sulphur")) {
    15. if (hand.equals(Material.SULPHUR)) {
    16. if (act == Action.RIGHT_CLICK_BLOCK) {
    17. hash.put(p.getName(), delay);
    18. task = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
    19.  
    20. @Override
    21. public void run() {
    22. if (!cooldown.containsKey(p.getName())) {
    23. cooldown.put(p.getName(), delay);
    24. }
    25. cooldown.put(p.getName(), delay - 1);
    26. if (cooldown.get(p.getName()) <= 0) {
    27. Bukkit.getScheduler().cancelTask(cooldown.get(p.getName()));
    28. cooldown.remove(p.getName());
    29. }
    30. }
    31. }, 0L, 20L);
    32.  
    33. if (!cooldown.containsKey(p.getName())) {
    34. if (!p.getGameMode().equals(GameMode.CREATIVE))
    35. p.getInventory().removeItem(new ItemStack(Material.SULPHUR, 1));
    36. else
    37. hash.remove(p.getName());
    38.  
    39. if (explosionSize == 1) {
    40. ...
    41. if (explosionSize == 2) {
    42. ...
    43. }
    44. } else {
    45. ...
    46. }
    47. } else
    48. ...
    49. }
    50. }
    51. }
    52. }
    53. }
     
  2. Offline

    soulofw0lf

    ok so no reason what so ever to make the event final, or the player, act == should be act.equals( pass a final string to the runnable that is the players name instead of making the player final also you should really move the check to see if they have a cooldown to the top of them method, cause right now your runnable is adding them to the cooldown map even if they are already in it
     
  3. Offline

    Shzylo

    I changed that but I still have a problem of it not working correctly
     
  4. Offline

    soulofw0lf

    updated code and what's not working please?
     
Thread Status:
Not open for further replies.

Share This Page