Event Cooldown Help!

Discussion in 'Plugin Development' started by FirecatHD, Dec 5, 2013.

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

    FirecatHD

    I am trying to make the event have a cooldown of 10 seconds, but i have tried everything i can think of...
    I know the guys here dont like n00b questions like this, but i really dont have a choise :oops:

    Here is the code:
    Code:java
    1. package me.FirecatHD.TBS_PvP;
    2.  
    3. import java.util.ArrayList;
    4. import java.util.List;
    5.  
    6. import org.bukkit.Material;
    7. import org.bukkit.entity.LivingEntity;
    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. import org.bukkit.plugin.Plugin;
    15. import org.bukkit.potion.PotionEffect;
    16. import org.bukkit.potion.PotionEffectType;
    17.  
    18. public class SakuraListener implements Listener {
    19.  
    20. public static ArrayList<String> healkit = new ArrayList<String>();
    21.  
    22. public static List<String> getFraggerKit() {
    23. return healkit;
    24. }
    25.  
    26.  
    27. public static ArrayList<Player> healcooldown = new ArrayList<Player>();
    28.  
    29. public static ArrayList<Player> getGetHealCooldown() {
    30. return healcooldown;
    31. }
    32.  
    33. @EventHandler
    34. public void onPlayerInteract (PlayerInteractEvent e){
    35.  
    36. final Player p = e.getPlayer();
    37. ItemStack h = p.getItemInHand();
    38.  
    39. //if(!p.getWorld().getName().equals("Arenas")) return;
    40.  
    41. if (e.getAction() == Action.LEFT_CLICK_AIR) return;
    42.  
    43. if (!h.hasItemMeta()) return;
    44. //if (!(h.getItemMeta().getDisplayName() == "The Stick")) return; {
    45. if (e.getAction() == Action.RIGHT_CLICK_AIR); {
    46. if (e.getPlayer().getItemInHand().getType() == Material.DIAMOND_SWORD) {
    47.  
    48. List<org.bukkit.entity.Entity> nearbyEntities = p.getNearbyEntities(3, 3, 3);
    49. for (int i = 0; i < nearbyEntities.size(); i++) {
    50. if (nearbyEntities.get(i) instanceof LivingEntity) {
    51. LivingEntity t = (LivingEntity) nearbyEntities.get(i);
    52.  
    53. t.addPotionEffect(new PotionEffect(
    54. PotionEffectType.HEAL, 1, 0));
    55.  
    56. healcooldown.add(p);
    57. public void removePlayerCooldown(final Player p) {
    58. final int taskID = p.getServer().getScheduler().scheduleSyncRepeatingTask((Plugin) this, new Runnable(){
    59.  
    60. @Override
    61. public void run() {
    62. healcooldown.remove(p.getName());
    63. p.getServer().getScheduler().cancelTask(taskID);
    64. }
    65.  
    66. }, 100,100);
    67. }
    68. }
    69. }
    70. }
    71. }
    72. }
    73. }
    74.  
    75.  


    You can also see i am trying to check the displayname, so if someone know, i need help with that too.

    Thanks!

    Tags: sgavster SkillSam L33m4n123 Chinwe
     
  2. Offline

    RainoBoy97

    You cannot have a method inside a method.
     
  3. Offline

    Wolfey

    It should actually be like this:

    Code:
    
    private ArrayList<String> cooldown = new ArrayList<String>();
    
    @EventHandler
    public void onInteract(final PlayerInteractEvent e) {
    // check if player is in cooldown
    if(cooldown.contains(e.getPlayer().getName()) { e.setCancelled(true); }
    
    // if the player does not have a cooldown, do your stuff here
    
    // then add player to cooldown
    cooldown.add(e.getPlayer().getName());
    // Then remove it in 10 seconds
    Bukkit.getScheduler().scheduleSyncDelayedTask(Bukkit.getPluginManager().getPlugin(yourPluginName), new Runnable() {
    cooldown.remove(e.getPlayer().getName());
    }, 10 * 20);
    }
    
    I did this all on here, so if there is any mistake, feel free to correct me.
     
Thread Status:
Not open for further replies.

Share This Page