Cooldown class causing console crash (without message) and player kick

Discussion in 'Plugin Development' started by Pezah, Mar 24, 2014.

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

    Pezah

    I've been trying to create a cooldown class and it makes me lag for a bit then crashes the console (stops responding, no warnings or anything), it kicks me with: Internal Exception: io.netty.handler.timeout.ReadTimeoutException

    Here's an example (when player talks, cant talk for 60 secs);

    Code:java
    1. @EventHandler
    2. public void onTalk(AsyncPlayerChatEvent e)
    3. {
    4. Player p = e.getPlayer();
    5.  
    6. if (Cooldown.isCooling(p, "talk"))
    7. {
    8. p.sendMessage(F.M("Skill", "Seconds: " + F.PINK + Cooldown.getCooltime(p, "talk")));
    9. }
    10. else
    11. {
    12. Cooldown.setCooling(p, 60, "talk");
    13. }
    14. }


    The Cooldown class:
    Code:java
    1. ublic class Cooldown
    2. {
    3. public static void setCooling(Player player, final int secs, final String coolerName)
    4. {
    5. Core.getPlugin().getConfig().set(player.getName() + coolerName + ".secs", Integer.valueOf(secs));
    6. int i = Core.getPlugin().getConfig().getInt(player.getName() + coolerName + ".secs");
    7.  
    8. while (i > 0)
    9. {
    10. BukkitScheduler scheduler = Bukkit.getServer().getScheduler();
    11. scheduler.scheduleSyncRepeatingTask(Core.plugin, new Runnable()
    12. {
    13. public void run()
    14. {
    15. Core.getPlugin().getConfig().set(Cooldown.this.getName() + coolerName + ".secs",
    16. Integer.valueOf(Core.getPlugin().getConfig().getInt(Cooldown.this.getName() + coolerName + ".secs") - 1));
    17. Cooldown.this.sendMessage(F.M("Skill", "You used " + F.GREEN + coolerName + F.YELLOW + " COOLDOWN: " + F.PINK + secs));
    18. }
    19. }
    20. , 0L, 20L);
    21. }
    22. }
    23.  
    24. public static boolean isCooling(Player player, String string)
    25. {
    26. if (Core.getPlugin().getConfig().getInt(player.getName() + string + ".secs") >= 0)
    27. {
    28. return false;
    29. }
    30.  
    31. return true;
    32. }
    33.  
    34. public static int getCooltime(Player player, String string)
    35. {
    36. return Core.getPlugin().getConfig().getInt(player.getName() + string + ".secs");
    37. }
     
  2. Offline

    RawCode

    scheduleSyncRepeatingTask every zero tick...

    try adding some debug messages to make things clear.
     
  3. Offline

    L33m4n123

    You're locking up the main thread with that while loop
     
Thread Status:
Not open for further replies.

Share This Page