From 18a16e91b07076a7b5fd3f37c796b088e7ca64c5 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Thu, 22 Sep 2022 17:16:37 +0200 Subject: [PATCH] Update TeamCommand --- .../bungeecore/commands/TeamCommand.java | 58 +++++++++---------- .../steamwar/messages/BungeeCore.properties | 1 - 2 files changed, 28 insertions(+), 31 deletions(-) diff --git a/src/de/steamwar/bungeecore/commands/TeamCommand.java b/src/de/steamwar/bungeecore/commands/TeamCommand.java index 65436b7c..843aed0d 100644 --- a/src/de/steamwar/bungeecore/commands/TeamCommand.java +++ b/src/de/steamwar/bungeecore/commands/TeamCommand.java @@ -28,7 +28,6 @@ import de.steamwar.command.SWCommand; import de.steamwar.command.TypeMapper; import de.steamwar.command.TypeValidator; import de.steamwar.messages.ChatSender; -import jdk.nashorn.internal.codegen.TypeMap; import net.md_5.bungee.BungeeCord; import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.CommandSender; @@ -48,7 +47,6 @@ import java.time.format.DateTimeFormatter; import java.util.*; import java.util.stream.Collectors; -import static de.steamwar.bungeecore.Storage.fabricCheckedPlayers; import static de.steamwar.bungeecore.Storage.teamInvitations; public class TeamCommand extends SWCommand { @@ -143,6 +141,22 @@ public class TeamCommand extends SWCommand { Message.send("TEAM_STEP_BACK", player); } + @Register("leave") + public void leave(@Validator("inTeam") ProxiedPlayer player) { + SteamwarUser user = SteamwarUser.get(player); + Team team = Team.get(user.getTeam()); + + int teamSize = team.size(); + if (teamSize > 1 && user.isLeader() && team.getMembers().stream().map(SteamwarUser::get).filter(member -> user != member).noneMatch(SteamwarUser::isLeader)) { + Message.send("TEAM_OTHER_LEADER_REQUIRED", player); + return; + } + + user.setTeam(0); + if (teamSize == 1) team.disband(user); + Message.send("TEAM_LEAVE_LEFT", player); + } + @Validator("noTeam") private TypeValidator noTeamValidator() { return (sender, value, messageSender) -> { @@ -155,8 +169,8 @@ public class TeamCommand extends SWCommand { }; } - @Validator("notInTeam") - private TypeValidator notInTeamValidator() { + @Validator("inTeam") + private TypeValidator inTeamValidator() { return (sender, value, messageSender) -> { if (SteamwarUser.get(value).getTeam() != 0) { return true; @@ -169,9 +183,9 @@ public class TeamCommand extends SWCommand { @Validator("notLeader") private TypeValidator notLeaderValidator() { - TypeValidator notInTeam = notInTeamValidator(); + TypeValidator inTeam = inTeamValidator(); return (sender, value, messageSender) -> { - if (!notInTeam.validate(sender, value, messageSender)) return false; + if (!inTeam.validate(sender, value, messageSender)) return false; SteamwarUser steamwarUser = SteamwarUser.get(value); if (!steamwarUser.isLeader()) { messageSender.send("TEAM_NOT_LEADER"); @@ -229,7 +243,13 @@ public class TeamCommand extends SWCommand { @Override public boolean validate(CommandSender sender, Team value, MessageSender messageSender) { if (value == null) { - messageSender.send("TEAM_JOIN_NOT_BY_TEAM"); + SteamwarUser user = SteamwarUser.get((ProxiedPlayer) sender); + List invs = teamInvitations.get(user.getId()); + if (invs.isEmpty()) { + messageSender.send("TEAM_JOIN_NO_INVITE"); + } else { + messageSender.send("TEAM_JOIN_NOT_BY_TEAM"); + } return false; } return true; @@ -237,7 +257,7 @@ public class TeamCommand extends SWCommand { @Override public Collection tabCompletes(CommandSender sender, String[] previousArguments, String s) { - SteamwarUser user = SteamwarUser.get((ProxiedPlayer) commandSender); + SteamwarUser user = SteamwarUser.get((ProxiedPlayer) sender); return teamInvitations.get(user.getId()).stream().map(Team::get).map(Team::getTeamName).collect(Collectors.toList()); } }; @@ -292,9 +312,6 @@ public class TeamCommand extends SWCommand { Team team = Team.get(user.getTeam()); switch (args[0].toLowerCase()) { - case "leave": - leave(player, user, team); - break; case "invite": invite(player, user, team, args); break; @@ -333,25 +350,6 @@ public class TeamCommand extends SWCommand { } } - private void leave(ProxiedPlayer player, SteamwarUser user, Team team) { - if (notInTeam(player, user)) - return; - - int teamSize = team.size(); - if (teamSize > 1 && user.isLeader() && team.getMembers().stream().map(SteamwarUser::get).filter(member -> user != member).noneMatch(SteamwarUser::isLeader)) { - Message.send("TEAM_OTHER_LEADER_REQUIRED", player); - return; - } - - user.setTeam(0); - - if (teamSize == 1) { - team.disband(user); - } - - Message.send("TEAM_LEAVE_LEFT", player); - } - private void invite(ProxiedPlayer player, SteamwarUser user, Team team, String[] args) { if (notLeader(player, user, team)) diff --git a/src/de/steamwar/messages/BungeeCore.properties b/src/de/steamwar/messages/BungeeCore.properties index 878ede19..e1ea3fa8 100644 --- a/src/de/steamwar/messages/BungeeCore.properties +++ b/src/de/steamwar/messages/BungeeCore.properties @@ -412,7 +412,6 @@ TEAM_CREATE_CREATED=§7You have created the team §e{0}§7! #Team Join TEAM_JOIN_NO_INVITE=§7You have no pending invitation. TEAM_JOIN_USAGE=§8/§7team join §8[§eteam§8] -TEAM_JOIN_INVITED=§7You were invited by the following teams§8: §e{0} TEAM_JOIN_NOT_BY_TEAM=§cYou have no pending invitation from this team. TEAM_JOIN_JOINED=§7You joined the team §e{0}§7!