From b35d5e214a4199d214083bfc8dc7061122b2caa2 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Fri, 25 Aug 2023 15:15:53 +0200 Subject: [PATCH] Fix team leader stepdown and leaving Signed-off-by: Lixfel --- src/de/steamwar/bungeecore/commands/TeamCommand.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/de/steamwar/bungeecore/commands/TeamCommand.java b/src/de/steamwar/bungeecore/commands/TeamCommand.java index 58273bd..6795ec6 100644 --- a/src/de/steamwar/bungeecore/commands/TeamCommand.java +++ b/src/de/steamwar/bungeecore/commands/TeamCommand.java @@ -188,7 +188,7 @@ public class TeamCommand extends SWCommand { if(notLeader(player, user)) return; - if(team.size() > 1 && team.getMembers().stream().map(SteamwarUser::get).filter(member -> user != member).noneMatch(SteamwarUser::isLeader)){ + if(noRemainingLeaders(team, user)){ Message.send("TEAM_OTHER_LEADER_REQUIRED", player); return; } @@ -205,7 +205,7 @@ public class TeamCommand extends SWCommand { return; int teamSize = team.size(); - if(teamSize > 1 && user.isLeader() && team.getMembers().stream().map(SteamwarUser::get).filter(member -> user != member).noneMatch(SteamwarUser::isLeader)){ + if(teamSize > 1 && user.isLeader() && noRemainingLeaders(team, user)) { Message.send("TEAM_OTHER_LEADER_REQUIRED", player); return; } @@ -219,6 +219,10 @@ public class TeamCommand extends SWCommand { Message.send("TEAM_LEAVE_LEFT", player); } + private boolean noRemainingLeaders(Team team, SteamwarUser except) { + return SteamwarUser.getTeam(team.getTeamId()).stream().filter(member -> except.getId() != member.getId()).noneMatch(SteamwarUser::isLeader); + } + @Register(value = "invite", description = "TEAM_INVITE_USAGE") public void invite(ProxiedPlayer player, String toInvite){ -- 2.39.2