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.
Robin Bi Line 162 is "for (String s : Attacker) {". I apologise for not having the full code with me at the moment
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 Robin Bi Code:java ArrayList<String> Attacker = new ArrayList<String>(); @EventHandler public void onEntityDeath(EntityDamageByEntityEvent e) { if (e.getDamager() instanceof Player) { Player target = (Player) e.getEntity(); Player Attack = (Player) e.getDamager(); String Attack2 = Attack.getName(); if (!(target.equals(Attack)) || (!(Attacker.contains(Attack2)))) { Attacker.add(Attack2); } } } // For death messages @EventHandler public void onKill(PlayerDeathEvent e) { String killed = e.getEntity().getName(); if (e.getEntity().getKiller() != null) { String killer = e.getEntity().getKiller().getName(); String PColour = getConfig().getString("Prefix.Colour"); String PText = getConfig().getString("Prefix.Text"); String KilledColour = getConfig().getString("Colour.Killed"); String ByColour = getConfig().getString("Colour.By"); String KillerColour = getConfig().getString("Colour.Killer"); Location loc = e.getEntity().getKiller().getLocation(); e.getEntity().sendMessage( "§" + PColour + PText + " " + "§" + KilledColour + killed + "§" + ByColour + " " + "was killed by" + " " + "§" + KillerColour + killer); e.getEntity() .getKiller() .sendMessage( "§" + PColour + PText + " " + "§" + KilledColour + killed + "§" + ByColour + " " + "was killed by" + " " + "§" + KillerColour + killer); for (String s : Attacker) { if (Attacker.equals(killer)) { s = killer; } else if (Attacker.equals(killed)) { s = killed; } for (Player player : getServer().getOnlinePlayers()) { if (((player.hasPermission("pdm.toggle"))) && (!this.pdmtoggle.contains(player.getName()))) { if ((!player.equals(e.getEntity())) && (!player.equals(e.getEntity().getKiller()))) { player.sendMessage("§" + PColour + PText + " " + "§" + KilledColour + killed + "§" + ByColour + " " + "was killed by" + " " + "§" + KillerColour + killer + ChatColor.AQUA + " at the location of" + ChatColor.WHITE + ": " + ChatColor.YELLOW + loc.getBlockX() + ", " + loc.getBlockY() + ", " + loc.getBlockZ() + ChatColor.AQUA + "" + " after " + ChatColor.RED + s + ChatColor.AQUA + " started the fight."); } //test stuff String kl = killer; String kd = killed; Attacker.remove(kd); Attacker.remove(kl); Attacker.remove(s); Attacked.remove(s); Attacked.remove(kl); Attacked.remove(kd); cmdblock.add(kl); Attacked.clear(); } Bump EDIT by Moderator: merged posts, please use the edit button instead of double posting.
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?
MrSnare My end goal is this - '<Player1> was killed by <Player2> after <Player1> started the fight.' 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
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.