Solved Internal Server Error

Discussion in 'Plugin Development' started by JoshArgent, Jul 30, 2013.

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



    I'm making a custom plugin for my server but for some reason this little code snippet is causing players to be kicked with the "Internal Server Error" message. This code is inside the EntityDamageEvent and has been checked that the entity is a Player.
    2. if(event.getCause().equals(DamageCause.POISON))
    3. {
    4. if(Perks.playerHasPerk((Player) event.getEntity(), Perk.TacticalMask))
    5. {
    6. event.setCancelled(true);
    7. if(((Player) event.getEntity()).hasPotionEffect(PotionEffectType.POISON))
    8. {
    9. ((Player) event.getEntity()).removePotionEffect(PotionEffectType.POISON);
    10. }
    11. if(((Player) event.getEntity()).hasPotionEffect(PotionEffectType.CONFUSION))
    12. {
    13. ((Player) event.getEntity()).removePotionEffect(PotionEffectType.CONFUSION);
    14. }
    15. if(((Player) event.getEntity()).hasPotionEffect(PotionEffectType.SLOW))
    16. {
    17. ((Player) event.getEntity()).removePotionEffect(PotionEffectType.SLOW);
    18. }
    19. }
    20. }

    If I comment out all of the potion related stuff I don't get any errors. The error occurs when essentially another plugin gives the Player potion of slowness, confusion and poison.

    The error in the console isn't much to go off either:
    [WARNING] Failed to handle packet for Daffy22/ net.minecraft.server.v1_6_R2.ReportedException: Ticking player
    net.minecraft.server.v1_6_R2.ReportedException: Ticking player
    at net.minecraft.server.v1_6_R2.EntityPlayer.h(
    at net.minecraft.server.v1_6_R2.PlayerConnection.a(
    at net.minecraft.server.v1_6_R2.Packet10Flying.handle(SourceFile:136)
    at net.minecraft.server.v1_6_R2.NetworkManager.b(
    at net.minecraft.server.v1_6_R2.PlayerConnection.e(
    at net.minecraft.server.v1_6_R2.ServerConnection.b(SourceFile:37)
    at net.minecraft.server.v1_6_R2.DedicatedServerConnection.b(SourceFile:30)
    at net.minecraft.server.v1_6_R2.MinecraftServer.t(
    at net.minecraft.server.v1_6_R2.DedicatedServer.t(
    at net.minecraft.server.v1_6_R2.MinecraftServer.s(
    Caused by: java.util.ConcurrentModificationException
    at java.util.HashMap$HashIterator.nextEntry(Unknown Source)
    at java.util.HashMap$ Source)
    at net.minecraft.server.v1_6_R2.EntityLiving.aI(
    at net.minecraft.server.v1_6_R2.EntityLiving.x(
    at net.minecraft.server.v1_6_R2.Entity.l_(
    at net.minecraft.server.v1_6_R2.EntityLiving.l_(
    at net.minecraft.server.v1_6_R2.EntityHuman.l_(
    at net.minecraft.server.v1_6_R2.EntityPlayer.h(
    ... 11 more
    I'd really appreciate some help with this one.

  2. Offline


  3. Offline


    That bit isn't the problem. It's only the code in the final if statement because it works fine when I comment that out.
  4. Offline


    The stack trace doesn't reference your source code anywhere in it. I don't think your code is the problem. You may be triggering an already existing bug in Bukkit. What version of Bukkit are you using?
  5. Offline


    I suppose that could be the case. I'm using 1.6.2 R0.1 b2815
  6. Offline


    Since that's a development build, I would recommend trying an earlier recommended build without changing your code, and see if it still happens.
  7. Offline


    Still getting the error in the 1.5.2 recommended and the latest 1.6.2 dev build (2823). Maybe as a work around I could make the player drink milk to remove potion effects?
  8. Offline


    Weird. I have always found ConcurrentModificationExceptions to be rather nasty... but yeah, I think milk sounds like a plausible idea. You could also try removing the if statements testing if the player has those potion effects (trying to remove a potion effect that the entity doesn't have wouldn't really affect anything), and I wouldn't be surprised if that was somehow causing the exception.
  9. Offline


    I think I may of fixed it by completely by-passing the Bukkit API and sending the packets manually. It's no biggie for me because it's for my own server and I already have some CB code. I will post my code once I've checked it works. :)
    Thanks for you help though.

    The final code I used, just for anyone who stumbles upon this thread:
    2. if(Perks.playerHasPerk((Player) event.getEntity(), Perk.TacticalMask))
    3. {
    4. event.setCancelled(true);
    5. if(((Player) event.getEntity()).hasPotionEffect(PotionEffectType.POISON))
    6. {
    7. if(Bukkit.getOnlinePlayers().length > 0)
    8. {
    9. MobEffect effect = new MobEffect(PotionEffectType.POISON.getId(), 500);
    10. Packet42RemoveMobEffect packet = new Packet42RemoveMobEffect(event.getEntity().getEntityId(), effect);
    11. for(Player p : Bukkit.getOnlinePlayers())
    12. {
    13. CraftPlayer cp = (CraftPlayer) p;
    14. cp.getHandle().playerConnection.sendPacket(packet);
    15. }
    16. }
    17. }
    18. if(((Player) event.getEntity()).hasPotionEffect(PotionEffectType.CONFUSION))
    19. {
    20. if(Bukkit.getOnlinePlayers().length > 0)
    21. {
    22. MobEffect effect = new MobEffect(PotionEffectType.CONFUSION.getId(), 500);
    23. Packet42RemoveMobEffect packet = new Packet42RemoveMobEffect(event.getEntity().getEntityId(), effect);
    24. for(Player p : Bukkit.getOnlinePlayers())
    25. {
    26. CraftPlayer cp = (CraftPlayer) p;
    27. cp.getHandle().playerConnection.sendPacket(packet);
    28. }
    29. }
    30. }
    31. if(((Player) event.getEntity()).hasPotionEffect(PotionEffectType.SLOW))
    32. {
    33. if(Bukkit.getOnlinePlayers().length > 0)
    34. {
    35. MobEffect effect = new MobEffect(PotionEffectType.SLOW.getId(), 500);
    36. Packet42RemoveMobEffect packet = new Packet42RemoveMobEffect(event.getEntity().getEntityId(), effect);
    37. for(Player p : Bukkit.getOnlinePlayers())
    38. {
    39. CraftPlayer cp = (CraftPlayer) p;
    40. cp.getHandle().playerConnection.sendPacket(packet);
    41. }
    42. }
    43. }
    44. }

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: Jun 3, 2016
Thread Status:
Not open for further replies.

Share This Page