SteamWar/BungeeCore
Archiviert
13
2

Initial TeamCommand rework
Einige Prüfungen sind fehlgeschlagen
SteamWarCI Build failed

Dieser Commit ist enthalten in:
yoyosource 2022-09-22 16:51:24 +02:00
Ursprung 4205bce893
Commit e1a713d52f

Datei anzeigen

@ -24,7 +24,11 @@ import de.steamwar.bungeecore.Storage;
import de.steamwar.bungeecore.inventory.SWItem;
import de.steamwar.bungeecore.inventory.SWListInv;
import de.steamwar.bungeecore.sql.*;
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;
@ -41,15 +45,13 @@ import net.md_5.bungee.api.event.ServerConnectEvent;
import java.net.*;
import java.time.Instant;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
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 BasicCommand {
public class TeamCommand extends SWCommand {
private static final List<SWListInv.SWListEntry<String>> COLOR_CODES = new ArrayList<>();
@ -80,37 +82,138 @@ public class TeamCommand extends BasicCommand {
super("team", "");
}
private void help(CommandSender sender){
Message.send("TEAM_HELP_HEADER", sender);
Message.send("TEAM_HELP_LIST", sender);
Message.send("TEAM_HELP_INFO", sender);
Message.send("TEAM_HELP_TP", sender);
if(!(sender instanceof ProxiedPlayer))
return;
ProxiedPlayer player = (ProxiedPlayer) sender;
@Register(help = true)
public void help(ProxiedPlayer player, String... args) {
SteamwarUser user = SteamwarUser.get(player.getUniqueId());
Message.send("TEAM_HELP_HEADER", player);
Message.send("TEAM_HELP_LIST", player);
Message.send("TEAM_HELP_INFO", player);
Message.send("TEAM_HELP_TP", player);
if(user.getTeam() == 0) {
Message.send("TEAM_HELP_CREATE", sender);
Message.send("TEAM_HELP_JOIN", sender);
}else{
Message.send("TEAM_HELP_CHAT", sender);
Message.send("TEAM_HELP_EVENT", sender);
Message.send("TEAM_HELP_LEAVE", sender);
Message.send("TEAM_HELP_CREATE", player);
Message.send("TEAM_HELP_JOIN", player);
} else {
Message.send("TEAM_HELP_CHAT", player);
Message.send("TEAM_HELP_EVENT", player);
Message.send("TEAM_HELP_LEAVE", player);
if(user.isLeader()){
Message.send("TEAM_HELP_INVITE", sender);
Message.send("TEAM_HELP_REMOVE", sender);
Message.send("TEAM_HELP_KUERZEL", sender);
Message.send("TEAM_HELP_NAME", sender);
Message.send("TEAM_HELP_COLOR", sender);
Message.send("TEAM_HELP_LEADER", sender);
Message.send("TEAM_HELP_STEP_BACK", sender);
Message.send("TEAM_HELP_SERVER", sender);
Message.send("TEAM_HELP_INVITE", player);
Message.send("TEAM_HELP_REMOVE", player);
Message.send("TEAM_HELP_KUERZEL", player);
Message.send("TEAM_HELP_NAME", player);
Message.send("TEAM_HELP_COLOR", player);
Message.send("TEAM_HELP_LEADER", player);
Message.send("TEAM_HELP_STEP_BACK", player);
Message.send("TEAM_HELP_SERVER", player);
}
}
}
@Register(value = "create", description = "TEAM_CREATE_USAGE")
public void createTeam(@Validator("noTeam") ProxiedPlayer player, @Validator("unusedKuerzel") String kuerzel, @Validator("unusedName") String name) {
SteamwarUser user = SteamwarUser.get(player);
Team.create(kuerzel, name);
user.setTeam(Team.get(kuerzel).getTeamId());
user.setLeader(true);
Message.send("TEAM_CREATE_CREATED", player, name);
}
@Register(value = "join", description = "TEAM_JOIN_USAGE")
public void joinTeam(@Validator("teamJoin") ProxiedPlayer player, @Mapper("teamJoinTypeMapper") Team toJoin) {
SteamwarUser user = SteamwarUser.get(player);
user.setTeam(toJoin.getTeamId());
teamInvitations.remove(user.getId());
Message.send("TEAM_JOIN_JOINED", player, toJoin.getTeamName());
}
@Validator("noTeam")
private TypeValidator<ProxiedPlayer> noTeamValidator() {
return (sender, value, messageSender) -> {
if (SteamwarUser.get(value).getTeam() == 0) {
return true;
} else {
messageSender.send("TEAM_IN_TEAM");
return false;
}
};
}
@Validator("notDuringEvent")
private TypeValidator<ProxiedPlayer> notDuringEventValidator() {
return (sender, value, messageSender) -> {
return !notDuringEvent(value);
};
}
@Validator("teamJoin")
private TypeValidator<ProxiedPlayer> teamJoinValidator() {
TypeValidator<ProxiedPlayer> noTeam = noTeamValidator();
TypeValidator<ProxiedPlayer> notDuringEvent = notDuringEventValidator();
return (sender, value, messageSender) -> {
if (!noTeam.validate(sender, value, messageSender)) return false;
if (!notDuringEvent.validate(sender, value, messageSender)) return false;
if (!teamInvitations.containsKey(SteamwarUser.get(value).getId())){
messageSender.send("TEAM_JOIN_NO_INVITATION");
return false;
}
return true;
};
}
@Mapper("teamJoinTypeMapper")
private TypeMapper<Team> teamJoinTypeMapper() {
return new TypeMapper<Team>() {
@Override
public Team map(CommandSender commandSender, String[] previousArguments, String s) {
SteamwarUser user = SteamwarUser.get((ProxiedPlayer) commandSender);
List<Integer> invs = teamInvitations.get(user.getId());
if (invs.isEmpty()) return null;
if (s.equals("") && invs.size() == 1) {
return Team.get(invs.get(0));
}
for (int i : invs) {
Team team = Team.get(i);
if (team.getTeamName().equals(s)) return team;
}
return null;
}
@Override
public boolean validate(CommandSender sender, Team value, MessageSender messageSender) {
if (value == null) {
messageSender.send("TEAM_JOIN_NOT_BY_TEAM");
return false;
}
return true;
}
@Override
public Collection<String> tabCompletes(CommandSender sender, String[] previousArguments, String s) {
SteamwarUser user = SteamwarUser.get((ProxiedPlayer) commandSender);
return teamInvitations.get(user.getId()).stream().map(Team::get).map(Team::getTeamName).collect(Collectors.toList());
}
};
}
@Validator("unusedKuerzel")
private TypeValidator<String> unusedTeamKuerzel() {
return (sender, value, messageSender) -> {
Team team = Team.get(SteamwarUser.get((ProxiedPlayer) sender).getTeam());
return !checkTeamKuerzel((ProxiedPlayer) sender, team, value);
};
}
@Validator("unusedName")
private TypeValidator<String> unusedTeamName() {
return (sender, value, messageSender) -> {
Team team = Team.get(SteamwarUser.get((ProxiedPlayer) sender).getTeam());
return !checkTeamName((ProxiedPlayer) sender, team, value);
};
}
@Override
public void execute(CommandSender sender, String[] args){
if(args.length < 1){
@ -126,12 +229,6 @@ public class TeamCommand extends BasicCommand {
Team team = Team.get(user.getTeam());
switch(args[0].toLowerCase()){
case "create":
create(player, user, team, args);
break;
case "join":
join(player, user, args);
break;
case "stepback":
stepBack(player,user,team);
break;
@ -176,75 +273,6 @@ public class TeamCommand extends BasicCommand {
}
}
private void create(ProxiedPlayer player, SteamwarUser user, Team team, String[] args){
if(unwantedInTeam(player, user))
return;
if(args.length < 3){
Message.send("TEAM_CREATE_USAGE", player);
return;
}
if(checkTeamKuerzel(player, team, args[1]))
return;
if(checkTeamName(player, team, args[2]))
return;
Team.create(args[1], args[2]);
user.setTeam(Team.get(args[1]).getTeamId());
user.setLeader(true);
Message.send("TEAM_CREATE_CREATED", player, args[2]);
}
private void join(ProxiedPlayer player, SteamwarUser user, String[] args){
if(unwantedInTeam(player, user))
return;
if(notDuringEvent(player))
return;
if(!teamInvitations.containsKey(user.getId())){
Message.send("TEAM_JOIN_NO_INVITE", player);
return;
}
List<Integer> invs = teamInvitations.get(user.getId());
Integer t = null;
if(invs.size() == 1){
t = invs.get(0);
}else{
if(args.length != 2){
Message.send("TEAM_JOIN_USAGE", player);
StringBuilder sb = new StringBuilder();
for(int inv : invs){
Team team = Team.get(inv);
sb.append(team.getTeamName()).append(" ");
}
Message.send("TEAM_JOIN_INVITED", player, sb.toString());
return;
}
for(int inv : invs){
Team team = Team.get(inv);
if(team.getTeamName().equals(args[1])){
t = inv;
break;
}
}
if(t == null){
Message.send("TEAM_JOIN_NOT_BY_TEAM", player);
return;
}
}
user.setTeam(t);
teamInvitations.remove(user.getId());
Message.send("TEAM_JOIN_JOINED", player, Team.get(t).getTeamName());
}
private void stepBack(ProxiedPlayer player, SteamwarUser user, Team team) {
if(notLeader(player, user, team))
return;