Error

Discussion in 'Plugin Development' started by A4Papers, Jun 9, 2014.

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

    A4Papers

    I coded this up todo what I needed -

    for (String s : Attacker) {
    if (Attacker.equals(killer)) {
    s = killer;

    }
    else if (Attacker.equals(killed)){
    s = killed;
    }


    However it is giving a error: http://pastebin.com/8x0f2uq7

    Posted from my phone.
     
  2. Offline

    Robin Bi

    A4Papers We need more code. In line 162 of your Main class, there's the mistake.
     
  3. Offline

    A4Papers

    Robin Bi Line 162 is "for (String s : Attacker) {". I apologise for not having the full code with me at the moment
     
  4. Offline

    MrSnare

    You cannot modify an ArrayList as you cycle through it. Post more code so we can provide a solution
     
    Robin Bi likes this.
  5. Offline

    Robin Bi

    A4Papers It would be great to know what type of variable "Attacker" is.
     
  6. Offline

    Deleted user

    Robin Bi
    Probably something extending Iterable, hence the for-each loop

    A4Papers

    However, why is the if statement checking if Attacker, which is what you're looping through, is equal to something from Attacker?

    Also, you're setting the temporary variable 's' to a different value
     
    MrSnare likes this.
  7. Offline

    A4Papers

    MrSnare Robin Bi
    Code:java
    1.  
    2.  
    3. ArrayList<String> Attacker = new ArrayList<String>();
    4.  
    5.  
    6.  
    7.  
    8.  
    9. @EventHandler
    10.  
    11. public void onEntityDeath(EntityDamageByEntityEvent e) {
    12.  
    13. if (e.getDamager() instanceof Player) {
    14.  
    15. Player target = (Player) e.getEntity();
    16.  
    17. Player Attack = (Player) e.getDamager();
    18.  
    19. String Attack2 = Attack.getName();
    20.  
    21.  
    22.  
    23. if (!(target.equals(Attack)) || (!(Attacker.contains(Attack2)))) {
    24.  
    25.  
    26.  
    27. Attacker.add(Attack2);
    28.  
    29.  
    30.  
    31. }
    32.  
    33. }
    34.  
    35. }
    36.  
    37.  
    38.  
    39. // For death messages
    40.  
    41. @EventHandler
    42.  
    43. public void onKill(PlayerDeathEvent e) {
    44.  
    45.  
    46.  
    47. String killed = e.getEntity().getName();
    48.  
    49.  
    50.  
    51. if (e.getEntity().getKiller() != null)
    52.  
    53.  
    54.  
    55. {
    56.  
    57. String killer = e.getEntity().getKiller().getName();
    58.  
    59. String PColour = getConfig().getString("Prefix.Colour");
    60.  
    61. String PText = getConfig().getString("Prefix.Text");
    62.  
    63. String KilledColour = getConfig().getString("Colour.Killed");
    64.  
    65. String ByColour = getConfig().getString("Colour.By");
    66.  
    67. String KillerColour = getConfig().getString("Colour.Killer");
    68.  
    69. Location loc = e.getEntity().getKiller().getLocation();
    70.  
    71.  
    72.  
    73. e.getEntity().sendMessage(
    74.  
    75. "§" + PColour + PText + " " + "§" + KilledColour + killed
    76.  
    77. + "§" + ByColour + " " + "was killed by" + " "
    78.  
    79. + "§" + KillerColour + killer);
    80.  
    81. e.getEntity()
    82.  
    83. .getKiller()
    84.  
    85. .sendMessage(
    86.  
    87. "§" + PColour + PText + " " + "§" + KilledColour
    88.  
    89. + killed + "§" + ByColour + " "
    90.  
    91. + "was killed by" + " " + "§"
    92.  
    93. + KillerColour + killer);
    94.  
    95. for (String s : Attacker) {
    96.  
    97. if (Attacker.equals(killer)) {
    98.  
    99. s = killer;
    100.  
    101. } else if (Attacker.equals(killed)) {
    102.  
    103. s = killed;
    104.  
    105. }
    106.  
    107. for (Player player : getServer().getOnlinePlayers()) {
    108.  
    109. if (((player.hasPermission("pdm.toggle")))
    110.  
    111. && (!this.pdmtoggle.contains(player.getName()))) {
    112.  
    113. if ((!player.equals(e.getEntity()))
    114.  
    115. && (!player.equals(e.getEntity().getKiller()))) {
    116.  
    117.  
    118.  
    119. player.sendMessage("§" + PColour + PText + " "
    120.  
    121. + "§" + KilledColour + killed + "§"
    122.  
    123. + ByColour + " " + "was killed by" + " "
    124.  
    125. + "§" + KillerColour + killer
    126.  
    127. + ChatColor.AQUA + " at the location of"
    128.  
    129. + ChatColor.WHITE + ": " + ChatColor.YELLOW
    130.  
    131. + loc.getBlockX() + ", " + loc.getBlockY()
    132.  
    133. + ", " + loc.getBlockZ() + ChatColor.AQUA
    134.  
    135. + "" + " after " + ChatColor.RED + s
    136.  
    137. + ChatColor.AQUA + " started the fight.");
    138.  
    139. }
    140.  
    141. //test stuff
    142.  
    143.  
    144.  
    145. String kl = killer;
    146.  
    147. String kd = killed;
    148.  
    149. Attacker.remove(kd);
    150.  
    151. Attacker.remove(kl);
    152.  
    153. Attacker.remove(s);
    154.  
    155. Attacked.remove(s);
    156.  
    157. Attacked.remove(kl);
    158.  
    159. Attacked.remove(kd);
    160.  
    161. cmdblock.add(kl);
    162.  
    163. Attacked.clear();
    164.  
    165. }


    Bump :(

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

    MrSnare

    This is very messy code. you are going to need to explain what you are trying to do because I can't understand your end goal from this.

    Also for the love of notch will you change your variable names to lower case?
     
  9. Offline

    A4Papers

    MrSnare My end goal is this - '<Player1> was killed by <Player2> after <Player1> started the fight.'[​IMG]
    it is displaying the message that i want fine, However it is giving this error http://pastebin.com/8x0f2uq7 (line 162 is "for (String s : Attacker){")

    Sorry about the messy code :p
     
  10. Offline

    MrSnare

    Why are you doing: if(Attacker.equals(killer))

    How can killer(a string) be equal to Attacker(A list of strings)?

    Also, remove all of the test stuff at the bottom, that is what is causing the concurrent modification error

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

Share This Page