Solved Internal Server Error

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

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

    JoshArgent

    Hi,

    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.
    Code:java
    1.  
    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. }
    21.  


    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:
    Code:
    [WARNING] Failed to handle packet for Daffy22/127.0.0.1: 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(EntityPlayer.java:269)
    at net.minecraft.server.v1_6_R2.PlayerConnection.a(PlayerConnection.java:345)
    at net.minecraft.server.v1_6_R2.Packet10Flying.handle(SourceFile:136)
    at net.minecraft.server.v1_6_R2.NetworkManager.b(NetworkManager.java:296)
    at net.minecraft.server.v1_6_R2.PlayerConnection.e(PlayerConnection.java:118)
    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(MinecraftServer.java:590)
    at net.minecraft.server.v1_6_R2.DedicatedServer.t(DedicatedServer.java:226)
    at net.minecraft.server.v1_6_R2.MinecraftServer.s(MinecraftServer.java:486)
    at net.minecraft.server.v1_6_R2.MinecraftServer.run(MinecraftServer.java:419)
    at net.minecraft.server.v1_6_R2.ThreadServerApplication.run(SourceFile:582)
    Caused by: java.util.ConcurrentModificationException
    at java.util.HashMap$HashIterator.nextEntry(Unknown Source)
    at java.util.HashMap$KeyIterator.next(Unknown Source)
    at net.minecraft.server.v1_6_R2.EntityLiving.aI(EntityLiving.java:419)
    at net.minecraft.server.v1_6_R2.EntityLiving.x(EntityLiving.java:217)
    at net.minecraft.server.v1_6_R2.Entity.l_(Entity.java:230)
    at net.minecraft.server.v1_6_R2.EntityLiving.l_(EntityLiving.java:1220)
    at net.minecraft.server.v1_6_R2.EntityHuman.l_(EntityHuman.java:157)
    at net.minecraft.server.v1_6_R2.EntityPlayer.h(EntityPlayer.java:221)
    ... 11 more
    
    I'd really appreciate some help with this one.

    Thanks,
    Josh.
     
  2. Offline

    Omerrg

     
  3. Offline

    JoshArgent

    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

    Blir

    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

    JoshArgent

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

    Blir

    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

    JoshArgent

    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

    Blir

    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

    JoshArgent

    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:
    Code:java
    1.  
    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. }
    45.  


    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