Skip to content

Commit

Permalink
Fixed three old bugs and a translation one.
Browse files Browse the repository at this point in the history
1. Bad number of alive teams (previously, an alive team = a team with a player online...).
2. ConcurrentModificationException when deleting a team.
3. Teams added on-the-fly for the players without team in a game with teams where not deleted in case of aborted start.

4. Fixed non-reset color in fr_FR translation.
  • Loading branch information
AmauryCarrade committed Aug 28, 2014
1 parent bb76d5e commit 8133a40
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 10 deletions.
14 changes: 12 additions & 2 deletions src/main/java/me/azenet/UHPlugin/UHGameManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,9 @@ public void start(CommandSender sender, Boolean slow) throws IllegalStateExcepti
this.players.add(p.getServer().getPlayer(id).getName());
}

// This is used to be able to delete the teams created on-the-fly
ArrayList<String> onTheFlyTeams = new ArrayList<String>();


// No team? We creates a team per player.
if(tm.getTeams().isEmpty()) {
Expand Down Expand Up @@ -266,6 +269,8 @@ public void start(CommandSender sender, Boolean slow) throws IllegalStateExcepti
team.addPlayer(player);

tm.addTeam(team);

onTheFlyTeams.add(teamName);
}
}
}
Expand All @@ -280,7 +285,12 @@ public void start(CommandSender sender, Boolean slow) throws IllegalStateExcepti
if(!this.gameWithTeams) {
tm.reset();
}

// We removes the teams automatically added, to avoid a bad team count.
else {
for(String teamName : onTheFlyTeams) {
tm.removeTeam(teamName);
}
}
return;
}

Expand Down Expand Up @@ -849,7 +859,7 @@ public ArrayList<UHTeam> getAliveTeams() {
ArrayList<UHTeam> aliveTeams = new ArrayList<UHTeam>();
for (UHTeam t : tm.getTeams()) {
for (Player p : t.getPlayers()) {
if (p.isOnline() && !aliveTeams.contains(t)) aliveTeams.add(t);
if (!this.isPlayerDead(p) && !aliveTeams.contains(t)) aliveTeams.add(t);
}
}
return aliveTeams;
Expand Down
28 changes: 21 additions & 7 deletions src/main/java/me/azenet/UHPlugin/UHTeam.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,36 +126,50 @@ public void addPlayer(Player player) {

/**
* Removes a player from this team.
*
*
* Nothing is done if the player wasn't in this team.
*
*
* @param player The player to remove.
*/
public void removePlayer(Player player) {
Validate.notNull(player, "The player cannot be null.");

players.remove(player.getUniqueId());
unregisterPlayer(player);
}

/**
* Unregisters a player from the scoreboard and uncolorizes the pseudo.
*
* Internal use, avoids a ConcurrentModificationException in this.deleteTeam()
* (this.players is listed and emptied simultaneously, else).
*
* @param player
*/
private void unregisterPlayer(Player player) {
plugin.getGameManager().getScoreboardManager().getScoreboard().getTeam(this.name).removePlayer(player);

plugin.getTeamManager().colorizePlayer(player);
}


/**
* Deletes this team.
*
* The players inside the team are left without any team.
*
* The players inside the team are left without any team.
*/
public void deleteTeam() {
// We removes the players from the team (scoreboard team too)
for(UUID id : players) {
removePlayer(plugin.getServer().getPlayer(id));
unregisterPlayer(plugin.getServer().getPlayer(id));
}

this.players.clear();

// Then the scoreboard team is deleted.
plugin.getGameManager().getScoreboardManager().getScoreboard().getTeam(this.name).unregister();

}


/**
* Returns true if the given player is in this team.
*
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/i18n/fr_FR.yml
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ keys:

addplayer:
disconnected: "{ce}Impossible d'ajouter le joueur {0} dans l'équipe {1}. Le joueur doit être connecté."
success: "{cs}Le joueur {0} a été ajouté à l'équipe {1} avec succès."
success: "{cs}Le joueur {0} a été ajouté à l'équipe {1}{cs} avec succès."
doesNotExists: "{ce}Cette équipe n'existe pas."

removeplayer:
Expand Down

0 comments on commit 8133a40

Please sign in to comment.