Skip to content

Commit

Permalink
Fixed a bug about the names of the players not being colorized after …
Browse files Browse the repository at this point in the history
…the user logs off and in.
  • Loading branch information
AmauryCarrade committed Jul 19, 2014
1 parent 689c748 commit ce4bcd7
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
4 changes: 4 additions & 0 deletions src/main/java/me/azenet/UHPlugin/UHPluginListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,12 @@ public void onPlayerJoin(final PlayerJoinEvent ev) {
p.getGameManager().getScoreboardManager().updateHealthScore(ev.getPlayer());
}

// Mainly useful on the first join.
p.getGameManager().getScoreboardManager().setScoreboardForPlayer(ev.getPlayer());

// The display name is reset when the player log off.
p.getTeamManager().colorizePlayer(ev.getPlayer());

// A warning to the administrators if WorldBorder is not present.
if(ev.getPlayer().hasPermission("uh.*") && !p.getWorldBorderIntegration().isWBIntegrationEnabled()) {
ev.getPlayer().sendMessage(ChatColor.RED + "WorldBorder is not installed, you should use it with the Ultra Hardcore plugin.");
Expand Down
8 changes: 2 additions & 6 deletions src/main/java/me/azenet/UHPlugin/UHTeam.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,15 @@ public void addPlayer(Player player) {
players.add(player);
plugin.getGameManager().getScoreboardManager().getScoreboard().getTeam(this.name).addPlayer(player);

if(plugin.getConfig().getBoolean("colorizeChat")) {
player.setDisplayName(this.color + player.getName() + ChatColor.RESET);
}
plugin.getTeamManager().colorizePlayer(player);
}

public void removePlayer(Player player) {
updatePlayerObjects();
players.remove(player);
plugin.getGameManager().getScoreboardManager().getScoreboard().getTeam(this.name).removePlayer(player);

if(plugin.getConfig().getBoolean("colorizeChat")) {
player.setDisplayName(ChatColor.WHITE + player.getName() + ChatColor.RESET);
}
plugin.getTeamManager().colorizePlayer(player);
}

public void deleteTeam() {
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/me/azenet/UHPlugin/UHTeamManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,26 @@ public void reset() {
teams = new ArrayList<UHTeam>();
}

/**
* Sets the correct display name of a player, according to his team.
*
* @param player
*/
public void colorizePlayer(Player player) {
if(!p.getConfig().getBoolean("colorizeChat")) {
return;
}

UHTeam team = getTeamForPlayer(player);

if(team == null) {
player.setDisplayName(ChatColor.WHITE + player.getName() + ChatColor.RESET);
}
else {
player.setDisplayName(team.getChatColor() + player.getName() + ChatColor.RESET);
}
}

/**
* Returns all the teams.
*
Expand Down

0 comments on commit ce4bcd7

Please sign in to comment.