Cooldowns.... Not working.

Discussion in 'Plugin Development' started by SenseTheGod, Feb 12, 2014.

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

    SenseTheGod

    Okay, so i dont know what ive done wrong ive spent hours and hours googled and looking on bukkit for fixes... Nothing.. So what happens is when you hit a player with the stick it all works.. then if you try to hit him or another player it tells you that you are still on a cooldown. which is good. but you never get off the cooldown?
    Code:java
    1.  
    2. @EventHandler
    3. public void onDowny(EntityDamageByEntityEvent e) {
    4. if ((e.getDamager() instanceof Player && (e.getEntity() instanceof Player))) {
    5. Player hit = (Player)e.getEntity();
    6. final Player hitter = (Player)e.getDamager();
    7. if(hitter.getItemInHand().getType() == Material.STICK){
    8. if (Main.cooldown.contains(hitter.getName())) {
    9. hitter.sendMessage(ChatColor.RED + "You are still on a cooldown!");
    10. return;
    11. }
    12. if (!Main.cooldown.contains(hitter.getName())) {
    13. if (Main.downy.contains(hitter.getName())) {
    14. hit.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 120, 0));
    15. hit.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 120, 0));
    16. hit.addPotionEffect(new PotionEffect(PotionEffectType.WEAKNESS, 120, 0));
    17. hit.addPotionEffect(new PotionEffect(PotionEffectType.POISON, 120, 0));
    18. hitter.sendMessage(ChatColor.GRAY + "You gave " + ChatColor.AQUA + hit.getName() + ChatColor.GRAY + " down syndrome!" );
    19. hit.sendMessage(ChatColor.GRAY + "You got down syndrome from " + ChatColor.AQUA + hitter.getName() + ChatColor.GRAY + "!");
    20. Main.cooldown.add(hitter.getName());
    21. Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
    22. public void run() {
    23. Main.cooldown.remove(hitter.getName());
    24. }
    25. }, 300L);
    26. }
    27.  
    28. }
    29.  
    30. }
    31.  
    32. }
    33.  
    34. }
    35.  


    Anyone help me please.. I would really need it and appreciate it! Please <3

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 6, 2016
  2. Offline

    Gater12

  3. Offline

    SenseTheGod

    Yes it is. Gater12
    In case you wanna see the main class..
    Code:java
    1.  
    2. package me.sensethegod.main;
    3.  
    4. import java.util.ArrayList;
    5. import java.util.List;
    6.  
    7. import me.sensethegod.kits.downy;
    8. import me.sensethegod.kits.switcher;
    9. import me.sensethegod.kits.fisherman;
    10. import me.sensethegod.kits.archer;
    11. import me.sensethegod.kits.pvp;
    12.  
    13. import org.bukkit.entity.Player;
    14. import org.bukkit.event.EventHandler;
    15. import org.bukkit.event.Listener;
    16. import org.bukkit.event.entity.PlayerDeathEvent;
    17. import org.bukkit.plugin.PluginManager;
    18. import org.bukkit.plugin.java.JavaPlugin;
    19.  
    20. public class Main extends JavaPlugin implements Listener{
    21.  
    22. public void onEnable() {
    23. PluginManager pm = getServer().getPluginManager();
    24. getServer().getPluginManager().registerEvents((Listener) this, this);
    25. pm.registerEvents((Listener) new pvp(), this);
    26. pm.registerEvents((Listener) new archer(), this);
    27. pm.registerEvents((Listener) new fisherman(), this);
    28. pm.registerEvents((Listener) new switcher(), this);
    29. pm.registerEvents((Listener) new downy(), this);
    30. getLogger().info("dKits Enabled!");
    31. getCommands();
    32. }
    33.  
    34. public void onDisable() {
    35. getLogger().info("dKits Disabled! Please fix!");
    36. }
    37.  
    38. private void getCommands() {
    39. getCommand("pvp").setExecutor(new pvp());
    40. getCommand("archer").setExecutor(new archer());
    41. getCommand("fisherman").setExecutor(new fisherman());
    42. getCommand("switcher").setExecutor(new switcher());
    43. getCommand("downy").setExecutor(new downy());
    44. }
    45.  
    46. public static List<String> used = new ArrayList<String>();
    47. public static List<String> cooldown = new ArrayList<String>();
    48. public static List<String> downy = new ArrayList<String>();
    49. @EventHandler
    50. public void playerDeath(PlayerDeathEvent e) {
    51. Player p = e.getEntity().getPlayer();
    52. used.remove(p.getName());
    53. downy.remove(p.getName());
    54. cooldown.remove(p.getName());
    55. }
    56. }
    57.  
     
  4. Offline

    Gater12

    SenseTheGod The scheduler first parameter takes in the the main class instance. So replace this with Main.
     
  5. Offline

    SenseTheGod

    What do you mean? I don't follow, also do you have skype?

    Gater12 Can you help me please? Anyone please help me?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 6, 2016
  6. Offline

    Wizehh

    The bukkit schedule method takes plugin as its first parameter, so you can't use the "this" keyword if you're not in your main class.
    Put "public static <Main class name> plugin" in your main class; then, to initialize the variable, put "plugin = this" in your onEnable() method. This isn't the ideal way to accomplish this, but it works.
    Why do you make a joke out of down syndrome?
     
Thread Status:
Not open for further replies.

Share This Page