Skip to content

Commit

Permalink
Fix exception changing player role
Browse files Browse the repository at this point in the history
  • Loading branch information
Redned235 committed Jul 16, 2024
1 parent fd14873 commit bf86774
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,23 @@ public final void leave(ArenaPlayer player, ArenaLeaveEvent.Cause cause) {
player.remove();
}

/**
* Changes the role of the player to the specified role.
*
* @param player the player to change the role of
* @param role the new role of the player
*/
public final void changeRole(ArenaPlayer player, PlayerRole role) {
if (role == player.getRole()) {
return;
}

this.playersByRole.get(player.getRole()).remove(player);
this.playersByRole.computeIfAbsent(role, e -> new HashSet<>()).add(player);

player.setRole(role);
}

/**
* Gets all the {@link ArenaPlayer players} in the competition.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public ChangeRoleAction(Map<String, String> params) {
public void call(ArenaPlayer arenaPlayer, Resolvable resolvable) {
PlayerRole role = PlayerRole.valueOf(this.get(ROLE_KEY).toUpperCase(Locale.ROOT));
boolean changedRole = arenaPlayer.getRole() != role;
arenaPlayer.setRole(role);
arenaPlayer.getCompetition().changeRole(arenaPlayer, role);

if (changedRole && role == PlayerRole.SPECTATING) {
arenaPlayer.getCompetition().getTeamManager().leaveTeam(arenaPlayer);
Expand Down

0 comments on commit bf86774

Please sign in to comment.