team.addPlayer((Player) sender);
addedPlayers.add(sender.getName());
} else {
for (int i = 3; i < args.length; i++) {
String playerName = args[i];
OfflinePlayer offlinePlayer;
Player player = Bukkit.getPlayerExact(playerName);
if (player != null) {
offlinePlayer = player;
} else {
offlinePlayer = Bukkit.getOfflinePlayer(playerName);
}
team.addPlayer(offlinePlayer);
addedPlayers.add(offlinePlayer.getName());
}
}
sender.sendMessage("Added " + addedPlayers.size() + " player(s) to team " + team.getName() + ": " + stringCollectionToString(addedPlayers));
}
} else if (args[1].equalsIgnoreCase("leave")) {
if (!(sender instanceof Player) && args.length < 3) {
sender.sendMessage(ChatColor.RED + "/scoreboard teams leave [player...]");
return false;
}
Set<String> left = new HashSet<String>();
Set<String> noTeam = new HashSet<String>();
if ((sender instanceof Player) && args.length == 2) {
Team team = mainScoreboard.getPlayerTeam((Player) sender);
if (team != null) {
team.removePlayer((Player) sender);
left.add(sender.getName());
} else {
noTeam.add(sender.getName());
}
} else {
for (int i = 2; i < args.length; i++) {
String playerName = args[i];
OfflinePlayer offlinePlayer;
Player player = Bukkit.getPlayerExact(playerName);
if (player != null) {
offlinePlayer = player;
} else {
offlinePlayer = Bukkit.getOfflinePlayer(playerName);
}
Team team = mainScoreboard.getPlayerTeam(offlinePlayer);
if (team != null) {
team.removePlayer(offlinePlayer);
left.add(offlinePlayer.getName());
} else {
noTeam.add(offlinePlayer.getName());
}
}
}
if (!left.isEmpty()) {
sender.sendMessage("Removed " + left.size() + " player(s) from their teams: " + stringCollectionToString(left));