Infinity loop or something ?

Discussion in 'Plugin Development' started by Zen3515, Nov 17, 2013.

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

    Zen3515

    Code:java
    1. @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = false)
    2. public void onPlayerToggleSprintEvent(PlayerToggleSprintEvent event)
    3. {
    4. Player player = event.getPlayer();
    5. while (player.isSprinting() == true)
    6. {
    7. if (player.hasPotionEffect(PotionEffectType.SPEED) == false)
    8. {
    9. player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 10000, 10));
    10. if (player.hasPotionEffect(PotionEffectType.SPEED) == false)
    11. {
    12. player.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, 10000, 10));
    13. }
    14. };
    15. }
    16. player.removePotionEffect(PotionEffectType.SPEED);
    17. player.removePotionEffect(PotionEffectType.JUMP);
    18. }

    after I sprint 1 time my server will not responding.
    Please help me I'm really newbie.
     
  2. Offline

    1Rogue

    Why not just use if() instead of while(), and then have an else() that would remove the effects? The way you have it, the while()'s statement will never be false.
     
Thread Status:
Not open for further replies.

Share This Page