WEIRD ERROR Kicked for Internal Server Error

Discussion in 'Plugin Development' started by Bigrat123, Feb 5, 2014.

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

    Bigrat123

    I am getting a pretty weird error. I've tried removing bits and pieces of the code, can't find anything that does it. Any ideas? Here's the error log and below that's the code.




    [​IMG]








    Code:java
    1. @SuppressWarnings("deprecation")
    2. @EventHandler(priority = EventPriority.MONITOR)
    3. public void damageEvent(EntityDamageEvent hurt){
    4.  
    5. Entity damaged = hurt.getEntity();
    6. if(damaged instanceof Player){
    7.  
    8. if(withers.containsKey(damaged)){
    9. if(hurt.getCause() == DamageCause.WITHER){
    10.  
    11.  
    12. if(((Player) damaged).getHealth() < 5){
    13.  
    14. damaged.teleport(loc.get(damaged));
    15. ((Player) damaged).setHealth(20);
    16. withers.remove(damaged);
    17. ((Player) damaged).removePotionEffect(PotionEffectType.WITHER);
    18. ((Player) damaged).removePotionEffect(PotionEffectType.SPEED);
    19. ((Player) damaged).removePotionEffect(PotionEffectType.INVISIBILITY);
    20.  
    21. ((HumanEntity) damaged).getInventory().setHelmet(null);
    22. ((HumanEntity) damaged).getInventory().setChestplate(null);
    23.  
    24.  
    25. game.remove(damaged);
    26. ((Player) damaged).sendMessage(label + ChatColor.GRAY + "You died as a wither! You have lost!");
    27.  
    28.  
    29. ItemStack[] inventory2 = inv.get(damaged);
    30. ((Player) damaged).getInventory().setContents(inventory2);
    31.  
    32.  
    33.  
    34. for(Player s1 : game.keySet()) {
    35.  
    36. s1.sendMessage(label + ChatColor.GRAY + "The wither has died!");
    37. }
    38.  
    39. Object[] playas = game.keySet().toArray();
    40.  
    41. String tk = lobby.get(damaged);
    42.  
    43.  
    44. Player wither = (Player) playas[(int) (Math.random() * playas.length)];
    45.  
    46. int ws = withers.size();
    47. if(playas.length > 1)
    48. {
    49. if(ws == 0){
    50. withers.put(wither, tk);
    51. chased.remove(wither);
    52. wither.sendMessage(label + ChatColor.GRAY + "You are the wither! Tag the other players to stop from dieing!");
    53. wither.addPotionEffect(new PotionEffect(PotionEffectType.WITHER, 18000, 1));
    54. wither.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 18000, 1));
    55. ((Player) wither).addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY,18000,1));
    56. ((HumanEntity) wither).getInventory().setHelmet(new ItemStack(Material.getMaterial(397),1,(short) 1));
    57. ((HumanEntity) wither).getInventory().setChestplate(chestPlate());
    58.  
    59. }
    60.  
    61.  
    62.  
    63.  
    64.  
    65.  
    66.  
    67.  
    68.  
    69.  
    70.  
    71.  
    72. }
    73. else{
    74. wither.sendMessage(label + ChatColor.DARK_GRAY + "============================");
    75. wither.sendMessage(label + ChatColor.GRAY + "==========You Won!==========");
    76. wither.sendMessage(label + ChatColor.DARK_GRAY + "============================");
    77.  
    78. ItemStack[] inventory = inv.get(wither);
    79. wither.getInventory().setContents(inventory);
    80. inProgress.put(game.get(wither), false);
    81. game.remove(wither);
    82. withers.remove(wither);
    83.  
    84.  
    85.  
    86.  
    87. }
    88.  
    89.  
    90.  
    91.  
    92. }
    93.  
    94.  
    95.  
    96. }
    97.  
    98.  
    99.  
    100.  
    101. }
    102. if(hurt.getCause() != DamageCause.WITHER | hurt.getCause() != DamageCause.ENTITY_ATTACK){
    103.  
    104.  
    105. if(game.containsKey(damaged)){
    106.  
    107. if(hurt.getCause() != DamageCause.WITHER){
    108. hurt.setCancelled(true);
    109.  
    110. }
    111.  
    112. if(hurt.getCause() != DamageCause.ENTITY_ATTACK){
    113.  
    114. hurt.setDamage(.25);
    115. }
    116. }
    117.  
    118.  
    119.  
    120. }
    121.  
    122.  
    123.  
    124.  
    125.  
    126. }
    127.  
    128.  
    129.  
    130.  
    131.  
    132.  
    133.  
    134. }
    135.  



    Been working on this for hours.. Any help greatly appreciated!

    Tried removing all the code in the section and it works... but I tried removing different sections of the code to narrow it down, and each time I got the error.. Ugh

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

    Weasel_Squeezer

    It is a ConcurrentModificationException which means you are concurrently modifying the state of an object when it cannot be modified. You are most likely modifying a collection while iterating it. And so it is probably at
    Code:
    game.remove(wither);
    while iterating the keyset of the game Map. You cannot remove a value from a collection (and in this case, removing a mapping will remove the value in the key set) while iterating it. However, you can avoid this by not using a for each loop. A foreach loop works with classes that implement Iteratable, and so it will use that Iteratable object, whereas if you just used a standard for loop, you are just iterating over the size of the collection.
    EDIT: or you can create a list to add values that should be removed while iterating the keyset, and then loop through that list afterwards to modify the state of the map. Example:
    Code:java
    1. List<player> toRemove = new ArrayList<player>();
    2. for(Player s1 : game.keySet()) {
    3. //do stuff
    4.  
    5. toRemove.add(player);
    6. }
    7. for (player removedPlayer : toRemove) {
    8. game.remove(removedPlayer);
    9. }
     
  3. Offline

    Bigrat123

    Well, worked on it some more and the remove potion effect method is what is causing the error..
     
  4. Offline

    Weasel_Squeezer

    oh well after digging through that unformatted code example, I noticed I missed the closing brace for the for loop... lol so it looked like there was a lot more code in that loop that I thought...
     
  5. Offline

    Bigrat123

    Though I am getting the error only while this is in there
    ((Player) damaged).removePotionEffect(PotionEffectType.TYPE)
    is that causing the same problem with iteration? Because the potion effect is causing the damage, the potion effect cannot be removed?


    Potion effects are removed in other parts of the plugin too in situations that are similar. Though only this one is giving errors. I tried creating a custom method for the removal, that still gave an error and disconnected the player.


    Thanks for the reply, I appreciate the suggestion.
     
Thread Status:
Not open for further replies.

Share This Page