SteamWar/BungeeCore
Archiviert
13
2

Commits vergleichen

...
Dieses Repository wurde am 2024-08-05 archiviert. Du kannst Dateien ansehen und es klonen, aber nicht pushen oder Issues/Pull-Requests öffnen.

4 Commits

Autor SHA1 Nachricht Datum
yoyosource
c7937847bc Update TeamCommand
Einige Prüfungen sind fehlgeschlagen
SteamWarCI Build failed
2022-09-22 21:30:32 +02:00
yoyosource
18a16e91b0 Update TeamCommand
Einige Prüfungen sind fehlgeschlagen
SteamWarCI Build failed
2022-09-22 17:16:37 +02:00
yoyosource
9628ff8ac7 Update TeamCommand
Einige Prüfungen sind fehlgeschlagen
SteamWarCI Build failed
2022-09-22 17:03:26 +02:00
yoyosource
e1a713d52f Initial TeamCommand rework
Einige Prüfungen sind fehlgeschlagen
SteamWarCI Build failed
2022-09-22 16:51:24 +02:00
2 geänderte Dateien mit 325 neuen und 260 gelöschten Zeilen

Datei anzeigen

@ -24,6 +24,9 @@ import de.steamwar.bungeecore.Storage;
import de.steamwar.bungeecore.inventory.SWItem; import de.steamwar.bungeecore.inventory.SWItem;
import de.steamwar.bungeecore.inventory.SWListInv; import de.steamwar.bungeecore.inventory.SWListInv;
import de.steamwar.bungeecore.sql.*; 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 de.steamwar.messages.ChatSender;
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;
@ -41,15 +44,12 @@ import net.md_5.bungee.api.event.ServerConnectEvent;
import java.net.*; import java.net.*;
import java.time.Instant; import java.time.Instant;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.ArrayList; import java.util.*;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static de.steamwar.bungeecore.Storage.teamInvitations; 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<>(); private static final List<SWListInv.SWListEntry<String>> COLOR_CODES = new ArrayList<>();
@ -80,37 +80,223 @@ public class TeamCommand extends BasicCommand {
super("team", ""); super("team", "");
} }
private void help(CommandSender sender){ @Register(help = true)
Message.send("TEAM_HELP_HEADER", sender); public void help(ProxiedPlayer player, String... args) {
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;
SteamwarUser user = SteamwarUser.get(player.getUniqueId()); 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) { if (user.getTeam() == 0) {
Message.send("TEAM_HELP_CREATE", sender); Message.send("TEAM_HELP_CREATE", player);
Message.send("TEAM_HELP_JOIN", sender); Message.send("TEAM_HELP_JOIN", player);
} else { } else {
Message.send("TEAM_HELP_CHAT", sender); Message.send("TEAM_HELP_CHAT", player);
Message.send("TEAM_HELP_EVENT", sender); Message.send("TEAM_HELP_EVENT", player);
Message.send("TEAM_HELP_LEAVE", sender); Message.send("TEAM_HELP_LEAVE", player);
if (user.isLeader()) { if (user.isLeader()) {
Message.send("TEAM_HELP_INVITE", sender); Message.send("TEAM_HELP_INVITE", player);
Message.send("TEAM_HELP_REMOVE", sender); Message.send("TEAM_HELP_REMOVE", player);
Message.send("TEAM_HELP_KUERZEL", sender); Message.send("TEAM_HELP_KUERZEL", player);
Message.send("TEAM_HELP_NAME", sender); Message.send("TEAM_HELP_NAME", player);
Message.send("TEAM_HELP_COLOR", sender); Message.send("TEAM_HELP_COLOR", player);
Message.send("TEAM_HELP_LEADER", sender); Message.send("TEAM_HELP_LEADER", player);
Message.send("TEAM_HELP_STEP_BACK", sender); Message.send("TEAM_HELP_STEP_BACK", player);
Message.send("TEAM_HELP_SERVER", sender); 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());
}
@Register("stepback")
public void stepBack(@Validator("isLeader") ProxiedPlayer player) {
SteamwarUser user = SteamwarUser.get(player);
Team team = Team.get(user.getTeam());
if (team.size() > 1 && team.getMembers().stream().map(SteamwarUser::get).filter(member -> user != member).noneMatch(SteamwarUser::isLeader)) {
Message.send("TEAM_OTHER_LEADER_REQUIRED", player);
return;
}
user.setLeader(false);
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(value = "noTeam", local = true)
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(value = "inTeam", local = true)
private TypeValidator<ProxiedPlayer> inTeamValidator() {
return (sender, value, messageSender) -> {
if (SteamwarUser.get(value).getTeam() != 0) {
return true;
} else {
messageSender.send("TEAM_NOT_IN_TEAM");
return false;
}
};
}
@Validator(value = "isLeader", local = true)
private TypeValidator<ProxiedPlayer> isLeaderValidator() {
TypeValidator<ProxiedPlayer> inTeam = inTeamValidator();
return (sender, value, messageSender) -> {
if (!inTeam.validate(sender, value, messageSender)) return false;
SteamwarUser steamwarUser = SteamwarUser.get(value);
if (!steamwarUser.isLeader()) {
messageSender.send("TEAM_NOT_LEADER");
return false;
}
return true;
};
}
@Validator(value = "notDuringEvent", local = true)
private TypeValidator<ProxiedPlayer> notDuringEventValidator() {
return (sender, value, messageSender) -> {
if (Event.get() == null) {
return true;
} else {
messageSender.send("TEAM_NOT_IN_EVENT");
return false;
}
};
}
@Validator(value = "teamJoin", local = true)
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(value = "teamJoinTypeMapper", local = true)
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) {
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 true;
}
@Override
public Collection<String> tabCompletes(CommandSender sender, String[] previousArguments, String s) {
SteamwarUser user = SteamwarUser.get((ProxiedPlayer) sender);
return teamInvitations.get(user.getId()).stream().map(Team::get).map(Team::getTeamName).collect(Collectors.toList());
}
};
}
@Validator(value = "unusedKuerzel", local = true)
private TypeValidator<String> unusedTeamKuerzel() {
return (sender, value, messageSender) -> {
if (value.length() < 2 || value.length() > 4) {
messageSender.send("TEAM_KUERZEL_LENGHT");
return false;
}
Team team = Team.get(SteamwarUser.get((ProxiedPlayer) sender).getTeam());
Team t = Team.get(value);
if (t != null && (team == null || t.getTeamId() != team.getTeamId())) {
messageSender.send("TEAM_KUERZEL_TAKEN");
return false;
}
return true;
};
}
@Validator(value = "unusedName", local = true)
private TypeValidator<String> unusedTeamName() {
return (sender, value, messageSender) -> {
if (value.length() < 4 || value.length() > 15) {
messageSender.send("TEAM_NAME_LENGHT");
return false;
}
Team team = Team.get(SteamwarUser.get((ProxiedPlayer) sender).getTeam());
Team t = Team.get(value);
if (t != null && t.getTeamId() != team.getTeamId()) {
messageSender.send("TEAM_NAME_TAKEN");
return false;
}
return true;
};
}
@Override @Override
public void execute(CommandSender sender, String[] args) { public void execute(CommandSender sender, String[] args) {
if (args.length < 1) { if (args.length < 1) {
@ -126,18 +312,6 @@ public class TeamCommand extends BasicCommand {
Team team = Team.get(user.getTeam()); Team team = Team.get(user.getTeam());
switch (args[0].toLowerCase()) { 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;
case "leave":
leave(player, user, team);
break;
case "invite": case "invite":
invite(player, user, team, args); invite(player, user, team, args);
break; break;
@ -176,107 +350,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;
if(team.size() > 1 && team.getMembers().stream().map(SteamwarUser::get).filter(member -> user != member).noneMatch(SteamwarUser::isLeader)){
Message.send("TEAM_OTHER_LEADER_REQUIRED", player);
return;
}
user.setLeader(false);
Message.send("TEAM_STEP_BACK", player);
}
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))
@ -675,7 +748,8 @@ public class TeamCommand extends BasicCommand {
colors.add(new SWListInv.SWListEntry<>(item, stringSWListEntry.getObject())); colors.add(new SWListInv.SWListEntry<>(item, stringSWListEntry.getObject()));
}); });
SWListInv<String> inv = new SWListInv<>(player, Message.parse("TEAM_COLOR_TITLE", player), colors, (click, element) -> {}); SWListInv<String> inv = new SWListInv<>(player, Message.parse("TEAM_COLOR_TITLE", player), colors, (click, element) -> {
});
inv.setCallback((click, element) -> { inv.setCallback((click, element) -> {
inv.close(); inv.close();
team.setTeamColor(element); team.setTeamColor(element);
@ -711,14 +785,6 @@ public class TeamCommand extends BasicCommand {
return false; return false;
} }
private boolean unwantedInTeam(ProxiedPlayer player, SteamwarUser user){
if(user.getTeam() != 0){
Message.send("TEAM_IN_TEAM", player);
return true;
}
return false;
}
private boolean notInTeam(ProxiedPlayer player, SteamwarUser user) { private boolean notInTeam(ProxiedPlayer player, SteamwarUser user) {
if (user.getTeam() == 0) { if (user.getTeam() == 0) {
Message.send("TEAM_NOT_IN_TEAM", player); Message.send("TEAM_NOT_IN_TEAM", player);

Datei anzeigen

@ -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!