Dieser Commit ist enthalten in:
Ursprung
9628ff8ac7
Commit
18a16e91b0
@ -28,7 +28,6 @@ import de.steamwar.command.SWCommand;
|
|||||||
import de.steamwar.command.TypeMapper;
|
import de.steamwar.command.TypeMapper;
|
||||||
import de.steamwar.command.TypeValidator;
|
import de.steamwar.command.TypeValidator;
|
||||||
import de.steamwar.messages.ChatSender;
|
import de.steamwar.messages.ChatSender;
|
||||||
import jdk.nashorn.internal.codegen.TypeMap;
|
|
||||||
import net.md_5.bungee.BungeeCord;
|
import net.md_5.bungee.BungeeCord;
|
||||||
import net.md_5.bungee.api.ChatColor;
|
import net.md_5.bungee.api.ChatColor;
|
||||||
import net.md_5.bungee.api.CommandSender;
|
import net.md_5.bungee.api.CommandSender;
|
||||||
@ -48,7 +47,6 @@ import java.time.format.DateTimeFormatter;
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static de.steamwar.bungeecore.Storage.fabricCheckedPlayers;
|
|
||||||
import static de.steamwar.bungeecore.Storage.teamInvitations;
|
import static de.steamwar.bungeecore.Storage.teamInvitations;
|
||||||
|
|
||||||
public class TeamCommand extends SWCommand {
|
public class TeamCommand extends SWCommand {
|
||||||
@ -143,6 +141,22 @@ public class TeamCommand extends SWCommand {
|
|||||||
Message.send("TEAM_STEP_BACK", player);
|
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")
|
@Validator("noTeam")
|
||||||
private TypeValidator<ProxiedPlayer> noTeamValidator() {
|
private TypeValidator<ProxiedPlayer> noTeamValidator() {
|
||||||
return (sender, value, messageSender) -> {
|
return (sender, value, messageSender) -> {
|
||||||
@ -155,8 +169,8 @@ public class TeamCommand extends SWCommand {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Validator("notInTeam")
|
@Validator("inTeam")
|
||||||
private TypeValidator<ProxiedPlayer> notInTeamValidator() {
|
private TypeValidator<ProxiedPlayer> inTeamValidator() {
|
||||||
return (sender, value, messageSender) -> {
|
return (sender, value, messageSender) -> {
|
||||||
if (SteamwarUser.get(value).getTeam() != 0) {
|
if (SteamwarUser.get(value).getTeam() != 0) {
|
||||||
return true;
|
return true;
|
||||||
@ -169,9 +183,9 @@ public class TeamCommand extends SWCommand {
|
|||||||
|
|
||||||
@Validator("notLeader")
|
@Validator("notLeader")
|
||||||
private TypeValidator<ProxiedPlayer> notLeaderValidator() {
|
private TypeValidator<ProxiedPlayer> notLeaderValidator() {
|
||||||
TypeValidator<ProxiedPlayer> notInTeam = notInTeamValidator();
|
TypeValidator<ProxiedPlayer> inTeam = inTeamValidator();
|
||||||
return (sender, value, messageSender) -> {
|
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);
|
SteamwarUser steamwarUser = SteamwarUser.get(value);
|
||||||
if (!steamwarUser.isLeader()) {
|
if (!steamwarUser.isLeader()) {
|
||||||
messageSender.send("TEAM_NOT_LEADER");
|
messageSender.send("TEAM_NOT_LEADER");
|
||||||
@ -229,7 +243,13 @@ public class TeamCommand extends SWCommand {
|
|||||||
@Override
|
@Override
|
||||||
public boolean validate(CommandSender sender, Team value, MessageSender messageSender) {
|
public boolean validate(CommandSender sender, Team value, MessageSender messageSender) {
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
messageSender.send("TEAM_JOIN_NOT_BY_TEAM");
|
SteamwarUser user = SteamwarUser.get((ProxiedPlayer) sender);
|
||||||
|
List<Integer> 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 false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@ -237,7 +257,7 @@ public class TeamCommand extends SWCommand {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<String> tabCompletes(CommandSender sender, String[] previousArguments, String s) {
|
public Collection<String> 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());
|
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());
|
Team team = Team.get(user.getTeam());
|
||||||
|
|
||||||
switch (args[0].toLowerCase()) {
|
switch (args[0].toLowerCase()) {
|
||||||
case "leave":
|
|
||||||
leave(player, user, team);
|
|
||||||
break;
|
|
||||||
case "invite":
|
case "invite":
|
||||||
invite(player, user, team, args);
|
invite(player, user, team, args);
|
||||||
break;
|
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) {
|
private void invite(ProxiedPlayer player, SteamwarUser user, Team team, String[] args) {
|
||||||
if (notLeader(player, user, team))
|
if (notLeader(player, user, team))
|
||||||
|
@ -412,7 +412,6 @@ TEAM_CREATE_CREATED=§7You have created the team §e{0}§7!
|
|||||||
#Team Join
|
#Team Join
|
||||||
TEAM_JOIN_NO_INVITE=§7You have no pending invitation.
|
TEAM_JOIN_NO_INVITE=§7You have no pending invitation.
|
||||||
TEAM_JOIN_USAGE=§8/§7team join §8[§eteam§8]
|
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_NOT_BY_TEAM=§cYou have no pending invitation from this team.
|
||||||
TEAM_JOIN_JOINED=§7You joined the team §e{0}§7!
|
TEAM_JOIN_JOINED=§7You joined the team §e{0}§7!
|
||||||
|
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren