Archiviert
1
0

Update TeamCommand

Dieser Commit ist enthalten in:
yoyosource 2022-09-22 17:03:26 +02:00
Ursprung e1a713d52f
Commit 9628ff8ac7

Datei anzeigen

@ -91,7 +91,7 @@ public class TeamCommand extends SWCommand {
Message.send("TEAM_HELP_INFO", player); Message.send("TEAM_HELP_INFO", player);
Message.send("TEAM_HELP_TP", player); Message.send("TEAM_HELP_TP", player);
if(user.getTeam() == 0) { if (user.getTeam() == 0) {
Message.send("TEAM_HELP_CREATE", player); Message.send("TEAM_HELP_CREATE", player);
Message.send("TEAM_HELP_JOIN", player); Message.send("TEAM_HELP_JOIN", player);
} else { } else {
@ -99,7 +99,7 @@ public class TeamCommand extends SWCommand {
Message.send("TEAM_HELP_EVENT", player); Message.send("TEAM_HELP_EVENT", player);
Message.send("TEAM_HELP_LEAVE", player); Message.send("TEAM_HELP_LEAVE", player);
if(user.isLeader()){ if (user.isLeader()) {
Message.send("TEAM_HELP_INVITE", player); Message.send("TEAM_HELP_INVITE", player);
Message.send("TEAM_HELP_REMOVE", player); Message.send("TEAM_HELP_REMOVE", player);
Message.send("TEAM_HELP_KUERZEL", player); Message.send("TEAM_HELP_KUERZEL", player);
@ -129,6 +129,20 @@ public class TeamCommand extends SWCommand {
Message.send("TEAM_JOIN_JOINED", player, toJoin.getTeamName()); Message.send("TEAM_JOIN_JOINED", player, toJoin.getTeamName());
} }
@Register("stepback")
public void stepBack(@Validator("notLeader") 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);
}
@Validator("noTeam") @Validator("noTeam")
private TypeValidator<ProxiedPlayer> noTeamValidator() { private TypeValidator<ProxiedPlayer> noTeamValidator() {
return (sender, value, messageSender) -> { return (sender, value, messageSender) -> {
@ -141,10 +155,41 @@ public class TeamCommand extends SWCommand {
}; };
} }
@Validator("notInTeam")
private TypeValidator<ProxiedPlayer> notInTeamValidator() {
return (sender, value, messageSender) -> {
if (SteamwarUser.get(value).getTeam() != 0) {
return true;
} else {
messageSender.send("TEAM_NOT_IN_TEAM");
return false;
}
};
}
@Validator("notLeader")
private TypeValidator<ProxiedPlayer> notLeaderValidator() {
TypeValidator<ProxiedPlayer> notInTeam = notInTeamValidator();
return (sender, value, messageSender) -> {
if (!notInTeam.validate(sender, value, messageSender)) return false;
SteamwarUser steamwarUser = SteamwarUser.get(value);
if (!steamwarUser.isLeader()) {
messageSender.send("TEAM_NOT_LEADER");
return false;
}
return true;
};
}
@Validator("notDuringEvent") @Validator("notDuringEvent")
private TypeValidator<ProxiedPlayer> notDuringEventValidator() { private TypeValidator<ProxiedPlayer> notDuringEventValidator() {
return (sender, value, messageSender) -> { return (sender, value, messageSender) -> {
return !notDuringEvent(value); if (Event.get() == null) {
return true;
} else {
messageSender.send("TEAM_NOT_IN_EVENT");
return false;
}
}; };
} }
@ -155,7 +200,7 @@ public class TeamCommand extends SWCommand {
return (sender, value, messageSender) -> { return (sender, value, messageSender) -> {
if (!noTeam.validate(sender, value, messageSender)) return false; if (!noTeam.validate(sender, value, messageSender)) return false;
if (!notDuringEvent.validate(sender, value, messageSender)) return false; if (!notDuringEvent.validate(sender, value, messageSender)) return false;
if (!teamInvitations.containsKey(SteamwarUser.get(value).getId())){ if (!teamInvitations.containsKey(SteamwarUser.get(value).getId())) {
messageSender.send("TEAM_JOIN_NO_INVITATION"); messageSender.send("TEAM_JOIN_NO_INVITATION");
return false; return false;
} }
@ -201,37 +246,52 @@ public class TeamCommand extends SWCommand {
@Validator("unusedKuerzel") @Validator("unusedKuerzel")
private TypeValidator<String> unusedTeamKuerzel() { private TypeValidator<String> unusedTeamKuerzel() {
return (sender, value, messageSender) -> { 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 team = Team.get(SteamwarUser.get((ProxiedPlayer) sender).getTeam());
return !checkTeamKuerzel((ProxiedPlayer) sender, team, value); Team t = Team.get(value);
if (t != null && (team == null || t.getTeamId() != team.getTeamId())) {
messageSender.send("TEAM_KUERZEL_TAKEN");
return false;
}
return true;
}; };
} }
@Validator("unusedName") @Validator("unusedName")
private TypeValidator<String> unusedTeamName() { private TypeValidator<String> unusedTeamName() {
return (sender, value, messageSender) -> { 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 team = Team.get(SteamwarUser.get((ProxiedPlayer) sender).getTeam());
return !checkTeamName((ProxiedPlayer) sender, team, value); 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) {
help(sender); help(sender);
return; return;
} }
if(!(sender instanceof ProxiedPlayer)) if (!(sender instanceof ProxiedPlayer))
return; return;
ProxiedPlayer player = (ProxiedPlayer) sender; ProxiedPlayer player = (ProxiedPlayer) sender;
SteamwarUser user = SteamwarUser.get(player.getUniqueId()); SteamwarUser user = SteamwarUser.get(player.getUniqueId());
Team team = Team.get(user.getTeam()); Team team = Team.get(user.getTeam());
switch(args[0].toLowerCase()){ switch (args[0].toLowerCase()) {
case "stepback":
stepBack(player,user,team);
break;
case "leave": case "leave":
leave(player, user, team); leave(player, user, team);
break; break;
@ -273,32 +333,19 @@ public class TeamCommand extends SWCommand {
} }
} }
private void stepBack(ProxiedPlayer player, SteamwarUser user, Team team) { private void leave(ProxiedPlayer player, SteamwarUser user, Team team) {
if(notLeader(player, user, team)) if (notInTeam(player, user))
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; return;
int teamSize = team.size(); 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() && team.getMembers().stream().map(SteamwarUser::get).filter(member -> user != member).noneMatch(SteamwarUser::isLeader)) {
Message.send("TEAM_OTHER_LEADER_REQUIRED", player); Message.send("TEAM_OTHER_LEADER_REQUIRED", player);
return; return;
} }
user.setTeam(0); user.setTeam(0);
if(teamSize == 1){ if (teamSize == 1) {
team.disband(user); team.disband(user);
} }
@ -306,31 +353,31 @@ public class TeamCommand extends SWCommand {
} }
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))
return; return;
if(notDuringEvent(player)) if (notDuringEvent(player))
return; return;
if(args.length != 2){ if (args.length != 2) {
Message.send("TEAM_INVITE_USAGE", player); Message.send("TEAM_INVITE_USAGE", player);
return; return;
} }
SteamwarUser target = SteamwarUser.get(args[1]); SteamwarUser target = SteamwarUser.get(args[1]);
if(target == null){ if (target == null) {
Message.send("TEAM_INVITE_NO_PLAYER", player); Message.send("TEAM_INVITE_NO_PLAYER", player);
return; return;
}else if(target.getTeam() != 0){ } else if (target.getTeam() != 0) {
Message.send("TEAM_INVITE_IN_TEAM", player); Message.send("TEAM_INVITE_IN_TEAM", player);
return; return;
} }
if(!teamInvitations.containsKey(target.getId())) if (!teamInvitations.containsKey(target.getId()))
teamInvitations.put(target.getId(), new LinkedList<>()); teamInvitations.put(target.getId(), new LinkedList<>());
if(teamInvitations.get(target.getId()).contains(team.getTeamId())){ if (teamInvitations.get(target.getId()).contains(team.getTeamId())) {
Message.send("TEAM_INVITE_ALREADY_INVITED", player); Message.send("TEAM_INVITE_ALREADY_INVITED", player);
return; return;
} }
@ -339,21 +386,21 @@ public class TeamCommand extends SWCommand {
Message.send("TEAM_INVITE_INVITED", player, args[1]); Message.send("TEAM_INVITE_INVITED", player, args[1]);
ProxiedPlayer p = ProxyServer.getInstance().getPlayer(target.getUuid()); ProxiedPlayer p = ProxyServer.getInstance().getPlayer(target.getUuid());
if(p != null) if (p != null)
Message.send("TEAM_INVITE_INVITED_TARGET", p, team.getTeamColor(), team.getTeamName()); Message.send("TEAM_INVITE_INVITED_TARGET", p, team.getTeamColor(), team.getTeamName());
} }
private void remove(ProxiedPlayer player, SteamwarUser user, Team team, String[] args){ private void remove(ProxiedPlayer player, SteamwarUser user, Team team, String[] args) {
if(notLeader(player, user, team)) if (notLeader(player, user, team))
return; return;
if(args.length != 2){ if (args.length != 2) {
Message.send("TEAM_REMOVE_USAGE", player); Message.send("TEAM_REMOVE_USAGE", player);
return; return;
} }
SteamwarUser target = SteamwarUser.get(args[1]); SteamwarUser target = SteamwarUser.get(args[1]);
if(target == null){ if (target == null) {
Message.send("TEAM_REMOVE_NOT_PLAYER", player); Message.send("TEAM_REMOVE_NOT_PLAYER", player);
return; return;
} }
@ -363,18 +410,18 @@ public class TeamCommand extends SWCommand {
return; return;
} }
if(teamInvitations.containsKey(target.getId())){ if (teamInvitations.containsKey(target.getId())) {
if(teamInvitations.get(target.getId()).remove((Integer) team.getTeamId())){ if (teamInvitations.get(target.getId()).remove((Integer) team.getTeamId())) {
Message.send("TEAM_REMOVE_INVITE", player); Message.send("TEAM_REMOVE_INVITE", player);
if(teamInvitations.get(target.getId()).isEmpty()) if (teamInvitations.get(target.getId()).isEmpty())
teamInvitations.remove(target.getId()); teamInvitations.remove(target.getId());
}else{ } else {
Message.send("TEAM_REMOVE_NO_INVITE", player); Message.send("TEAM_REMOVE_NO_INVITE", player);
} }
return; return;
} }
if(target.getTeam() != user.getTeam()){ if (target.getTeam() != user.getTeam()) {
Message.send("TEAM_REMOVE_NOT_IN_TEAM", player); Message.send("TEAM_REMOVE_NOT_IN_TEAM", player);
return; return;
} }
@ -383,67 +430,67 @@ public class TeamCommand extends SWCommand {
Message.send("TEAM_REMOVE_REMOVED", player); Message.send("TEAM_REMOVE_REMOVED", player);
ProxiedPlayer p = ProxyServer.getInstance().getPlayer(target.getUuid()); ProxiedPlayer p = ProxyServer.getInstance().getPlayer(target.getUuid());
if(p != null) if (p != null)
Message.send("TEAM_REMOVE_REMOVED_TARGET", player); Message.send("TEAM_REMOVE_REMOVED_TARGET", player);
} }
private void changekuerzel(ProxiedPlayer player, SteamwarUser user, Team team, String[] args){ private void changekuerzel(ProxiedPlayer player, SteamwarUser user, Team team, String[] args) {
if(notLeader(player, user, team)) if (notLeader(player, user, team))
return; return;
if(notDuringEvent(player)) if (notDuringEvent(player))
return; return;
if(args.length < 2){ if (args.length < 2) {
Message.send("TEAM_KUERZEL_USAGE", player); Message.send("TEAM_KUERZEL_USAGE", player);
return; return;
} }
if(checkTeamKuerzel(player, team, args[1])) if (checkTeamKuerzel(player, team, args[1]))
return; return;
team.setTeamKuerzel(args[1]); team.setTeamKuerzel(args[1]);
Message.send("TEAM_KUERZEL_CHANGED", player); Message.send("TEAM_KUERZEL_CHANGED", player);
} }
private void changename(ProxiedPlayer player, SteamwarUser user, Team team, String[] args){ private void changename(ProxiedPlayer player, SteamwarUser user, Team team, String[] args) {
if(notLeader(player, user, team)) if (notLeader(player, user, team))
return; return;
if(notDuringEvent(player)) if (notDuringEvent(player))
return; return;
if(args.length < 2){ if (args.length < 2) {
Message.send("TEAM_NAME_USAGE", player); Message.send("TEAM_NAME_USAGE", player);
return; return;
} }
if(checkTeamName(player, team, args[1])) if (checkTeamName(player, team, args[1]))
return; return;
team.setTeamName(args[1]); team.setTeamName(args[1]);
Message.send("TEAM_NAME_CHANGED", player); Message.send("TEAM_NAME_CHANGED", player);
} }
private void promote(ProxiedPlayer player, SteamwarUser user, Team team, String[] args){ private void promote(ProxiedPlayer player, SteamwarUser user, Team team, String[] args) {
if(notLeader(player, user, team)) if (notLeader(player, user, team))
return; return;
if(notDuringEvent(player)) if (notDuringEvent(player))
return; return;
if(args.length < 2){ if (args.length < 2) {
Message.send("TEAM_LEADER_USAGE", player); Message.send("TEAM_LEADER_USAGE", player);
return; return;
} }
SteamwarUser target = SteamwarUser.get(args[1]); SteamwarUser target = SteamwarUser.get(args[1]);
if(target == null){ if (target == null) {
Message.send("TEAM_LEADER_NOT_USER", player, args[1]); Message.send("TEAM_LEADER_NOT_USER", player, args[1]);
return; return;
} }
if(target.getTeam() != user.getTeam()){ if (target.getTeam() != user.getTeam()) {
Message.send("TEAM_LEADER_NOT_MEMBER", player); Message.send("TEAM_LEADER_NOT_MEMBER", player);
return; return;
} }
@ -452,19 +499,19 @@ public class TeamCommand extends SWCommand {
Message.send("TEAM_LEADER_PROMOTED", player, args[1]); Message.send("TEAM_LEADER_PROMOTED", player, args[1]);
} }
private String playerName(SteamwarUser user){ private String playerName(SteamwarUser user) {
return ProxyServer.getInstance().getPlayer(user.getUuid()) != null ? "§a" + user.getUserName() : "§e" + user.getUserName(); return ProxyServer.getInstance().getPlayer(user.getUuid()) != null ? "§a" + user.getUserName() : "§e" + user.getUserName();
} }
private void info(ProxiedPlayer player, SteamwarUser user, Team team, String[] args){ private void info(ProxiedPlayer player, SteamwarUser user, Team team, String[] args) {
if(args.length == 1 && user.getTeam() == 0){ if (args.length == 1 && user.getTeam() == 0) {
Message.send("TEAM_INFO_USAGE", player); Message.send("TEAM_INFO_USAGE", player);
return; return;
}else if(user.getTeam() == 0 || args.length == 2){ } else if (user.getTeam() == 0 || args.length == 2) {
team = Team.get(args[1]); team = Team.get(args[1]);
} }
if(team == null){ if (team == null) {
Message.send("UNKNOWN_TEAM", player); Message.send("UNKNOWN_TEAM", player);
return; return;
} }
@ -477,51 +524,51 @@ public class TeamCommand extends SWCommand {
String members = getMemberList(users, false); String members = getMemberList(users, false);
if(members.length() > 0) { if (members.length() > 0) {
Message.sendPrefixless("TEAM_INFO_MEMBER", player, members); Message.sendPrefixless("TEAM_INFO_MEMBER", player, members);
} }
Set<Event> events = TeamTeilnahme.getEvents(team.getTeamId()); Set<Event> events = TeamTeilnahme.getEvents(team.getTeamId());
if(!events.isEmpty()){ if (!events.isEmpty()) {
Message.sendPrefixless("TEAM_INFO_EVENTS", player, events.stream().map(Event::getEventName).collect(Collectors.joining(", "))); Message.sendPrefixless("TEAM_INFO_EVENTS", player, events.stream().map(Event::getEventName).collect(Collectors.joining(", ")));
} }
} }
private String getMemberList(List<SteamwarUser> users, boolean leaders) { private String getMemberList(List<SteamwarUser> users, boolean leaders) {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
for(SteamwarUser user : users) { for (SteamwarUser user : users) {
if(user.isLeader() == leaders) { if (user.isLeader() == leaders) {
sb.append(playerName(user)).append(" "); sb.append(playerName(user)).append(" ");
} }
} }
return sb.toString(); return sb.toString();
} }
private void list(ProxiedPlayer player, String[] args){ private void list(ProxiedPlayer player, String[] args) {
final int TEAMS_PER_PAGE = 10; final int TEAMS_PER_PAGE = 10;
int page; int page;
if(args.length > 1){ if (args.length > 1) {
try{ try {
page = Integer.parseInt(args[1]); page = Integer.parseInt(args[1]);
}catch(NumberFormatException e){ } catch (NumberFormatException e) {
Message.send("TEAM_LIST_NOT_PAGE", player); Message.send("TEAM_LIST_NOT_PAGE", player);
return; return;
} }
}else } else
page = 1; page = 1;
List<Team> all = Team.getAll(); List<Team> all = Team.getAll();
final int lastPage = ((all.size() - 1) / 10) + 1; final int lastPage = ((all.size() - 1) / 10) + 1;
if(page < 1 || page > lastPage){ if (page < 1 || page > lastPage) {
Message.send("TEAM_LIST_UNKNOWN_PAGE", player); Message.send("TEAM_LIST_UNKNOWN_PAGE", player);
return; return;
} }
Message.sendPrefixless("TEAM_LIST_HEADER", player, page, lastPage); Message.sendPrefixless("TEAM_LIST_HEADER", player, page, lastPage);
for(int i = (page-1) * TEAMS_PER_PAGE; i < (page-1) * TEAMS_PER_PAGE + TEAMS_PER_PAGE && i < all.size(); i++){ for (int i = (page - 1) * TEAMS_PER_PAGE; i < (page - 1) * TEAMS_PER_PAGE + TEAMS_PER_PAGE && i < all.size(); i++) {
Team tm = all.get(i); Team tm = all.get(i);
Message.sendPrefixless("TEAM_LIST_TEAM", player, Message.parse("TEAM_LIST_TEAM_HOVER", player), Message.sendPrefixless("TEAM_LIST_TEAM", player, Message.parse("TEAM_LIST_TEAM_HOVER", player),
@ -529,77 +576,77 @@ public class TeamCommand extends SWCommand {
} }
TextComponent beforePage = new TextComponent("««"); TextComponent beforePage = new TextComponent("««");
if(page > 1){ if (page > 1) {
beforePage.setColor(ChatColor.YELLOW); beforePage.setColor(ChatColor.YELLOW);
beforePage.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(Message.parse("TEAM_LIST_PREV", player)).create())); beforePage.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(Message.parse("TEAM_LIST_PREV", player)).create()));
beforePage.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/team list " + (page - 1))); beforePage.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/team list " + (page - 1)));
}else } else
beforePage.setColor(ChatColor.DARK_GRAY); beforePage.setColor(ChatColor.DARK_GRAY);
TextComponent nextPage = new TextComponent(" " + Message.parse("TEAM_LIST_PAGE", player) +" »»"); TextComponent nextPage = new TextComponent(" " + Message.parse("TEAM_LIST_PAGE", player) + " »»");
if(page < lastPage){ if (page < lastPage) {
nextPage.setColor(ChatColor.YELLOW); nextPage.setColor(ChatColor.YELLOW);
nextPage.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(Message.parse("TEAM_LIST_NEXT", player)).create())); nextPage.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(Message.parse("TEAM_LIST_NEXT", player)).create()));
nextPage.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/team list " + (page + 1))); nextPage.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/team list " + (page + 1)));
}else } else
nextPage.setColor(ChatColor.DARK_GRAY); nextPage.setColor(ChatColor.DARK_GRAY);
beforePage.addExtra(nextPage); beforePage.addExtra(nextPage);
player.sendMessage(beforePage); player.sendMessage(beforePage);
} }
private void event(ProxiedPlayer player, SteamwarUser user, Team team, String[] args){ private void event(ProxiedPlayer player, SteamwarUser user, Team team, String[] args) {
if(notInTeam(player, user)) if (notInTeam(player, user))
return; return;
if(args.length < 2){ if (args.length < 2) {
Message.send("TEAM_EVENT_USAGE", player); Message.send("TEAM_EVENT_USAGE", player);
Set<Event> events = TeamTeilnahme.getEvents(team.getTeamId()); Set<Event> events = TeamTeilnahme.getEvents(team.getTeamId());
if(!events.isEmpty()){ if (!events.isEmpty()) {
Message.send("TEAM_EVENT_HEADER", player); Message.send("TEAM_EVENT_HEADER", player);
DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern(Message.parse("EVENT_DATE_FORMAT", player)); DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern(Message.parse("EVENT_DATE_FORMAT", player));
for(Event e : events) for (Event e : events)
Message.sendPrefixless("TEAM_EVENT_EVENT", player, e.getStart().toLocalDateTime().format(dateFormat), e.getEventName()); Message.sendPrefixless("TEAM_EVENT_EVENT", player, e.getStart().toLocalDateTime().format(dateFormat), e.getEventName());
} }
return; return;
} }
if(notLeader(player, user, team)) if (notLeader(player, user, team))
return; return;
if(notDuringEvent(player)) if (notDuringEvent(player))
return; return;
Event event = Event.get(args[1]); Event event = Event.get(args[1]);
if(event == null){ if (event == null) {
Message.send("TEAM_EVENT_NO_EVENT", player); Message.send("TEAM_EVENT_NO_EVENT", player);
return; return;
} }
if(Instant.now().isAfter(event.getDeadline().toInstant())){ if (Instant.now().isAfter(event.getDeadline().toInstant())) {
Message.send("TEAM_EVENT_OVER", player); Message.send("TEAM_EVENT_OVER", player);
return; return;
} }
if(TeamTeilnahme.nimmtTeil(team.getTeamId(), event.getEventID())){ if (TeamTeilnahme.nimmtTeil(team.getTeamId(), event.getEventID())) {
TeamTeilnahme.notTeilnehmen(team.getTeamId(), event.getEventID()); TeamTeilnahme.notTeilnehmen(team.getTeamId(), event.getEventID());
Message.send("TEAM_EVENT_LEFT", player); Message.send("TEAM_EVENT_LEFT", player);
}else{ } else {
TeamTeilnahme.teilnehmen(team.getTeamId(), event.getEventID()); TeamTeilnahme.teilnehmen(team.getTeamId(), event.getEventID());
Message.send("TEAM_EVENT_JOINED", player, event.getEventName()); Message.send("TEAM_EVENT_JOINED", player, event.getEventName());
Message.sendPrefixless("TEAM_EVENT_HOW_TO_LEAVE", player); Message.sendPrefixless("TEAM_EVENT_HOW_TO_LEAVE", player);
} }
} }
private void tp(ProxiedPlayer player, SteamwarUser user, Team team, String[] args){ private void tp(ProxiedPlayer player, SteamwarUser user, Team team, String[] args) {
if(args.length == 1){ if (args.length == 1) {
if(notInTeam(player, user)) if (notInTeam(player, user))
return; return;
tp(player, team); tp(player, team);
return; return;
} }
Team targetTeam = Team.get(args[1]); Team targetTeam = Team.get(args[1]);
if(targetTeam == null){ if (targetTeam == null) {
Message.send("TEAM_TP_NO_TEAM", player); Message.send("TEAM_TP_NO_TEAM", player);
return; return;
} }
@ -618,15 +665,15 @@ public class TeamCommand extends SWCommand {
return info; return info;
}); });
player.connect(ServerConnectRequest.builder() player.connect(ServerConnectRequest.builder()
.target(serverInfo) .target(serverInfo)
.connectTimeout(BungeeCord.getInstance().getConfig().getServerConnectTimeout()) .connectTimeout(BungeeCord.getInstance().getConfig().getServerConnectTimeout())
.retry(false) .retry(false)
.reason(ServerConnectEvent.Reason.PLUGIN) .reason(ServerConnectEvent.Reason.PLUGIN)
.callback((success, error) -> { .callback((success, error) -> {
if (error != null) { if (error != null) {
Message.send("TEAM_OFFLINE", player); Message.send("TEAM_OFFLINE", player);
} }
}) })
.build()); .build());
/* /*
((UserConnection) player).connect(serverInfo, (success, error) -> { ((UserConnection) player).connect(serverInfo, (success, error) -> {
@ -637,8 +684,8 @@ public class TeamCommand extends SWCommand {
*/ */
} }
private void server(ProxiedPlayer player, SteamwarUser user, Team team, String[] args){ private void server(ProxiedPlayer player, SteamwarUser user, Team team, String[] args) {
if(notLeader(player, user, team)) if (notLeader(player, user, team))
return; return;
if (user.isPunishedWithMessage(ChatSender.of(player), Punishment.PunishmentType.NoTeamServer)) { if (user.isPunishedWithMessage(ChatSender.of(player), Punishment.PunishmentType.NoTeamServer)) {
return; return;
@ -690,10 +737,10 @@ public class TeamCommand extends SWCommand {
} }
private void changeColor(ProxiedPlayer player, SteamwarUser user, Team team) { private void changeColor(ProxiedPlayer player, SteamwarUser user, Team team) {
if(notLeader(player, user, team)) if (notLeader(player, user, team))
return; return;
if(notDuringEvent(player)) if (notDuringEvent(player))
return; return;
List<SWListInv.SWListEntry<String>> colors = new ArrayList<>(); List<SWListInv.SWListEntry<String>> colors = new ArrayList<>();
@ -703,7 +750,8 @@ public class TeamCommand extends SWCommand {
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,62 +759,54 @@ public class TeamCommand extends SWCommand {
inv.open(); inv.open();
} }
private boolean checkTeamName(ProxiedPlayer player, Team team, String arg){ private boolean checkTeamName(ProxiedPlayer player, Team team, String arg) {
if(arg.length() < 4 || arg.length() > 15){ if (arg.length() < 4 || arg.length() > 15) {
Message.send("TEAM_NAME_LENGHT", player); Message.send("TEAM_NAME_LENGHT", player);
return true; return true;
} }
Team t = Team.get(arg); Team t = Team.get(arg);
if(t != null && t.getTeamId() != team.getTeamId()){ if (t != null && t.getTeamId() != team.getTeamId()) {
Message.send("TEAM_NAME_TAKEN", player); Message.send("TEAM_NAME_TAKEN", player);
return true; return true;
} }
return false; return false;
} }
private boolean checkTeamKuerzel(ProxiedPlayer player, Team team, String arg){ private boolean checkTeamKuerzel(ProxiedPlayer player, Team team, String arg) {
if(arg.length() < 2 || arg.length() > 4){ if (arg.length() < 2 || arg.length() > 4) {
Message.send("TEAM_KUERZEL_LENGHT", player); Message.send("TEAM_KUERZEL_LENGHT", player);
return true; return true;
} }
Team t = Team.get(arg); Team t = Team.get(arg);
if(t != null && (team == null || t.getTeamId() != team.getTeamId())){ if (t != null && (team == null || t.getTeamId() != team.getTeamId())) {
Message.send("TEAM_KUERZEL_TAKEN", player); Message.send("TEAM_KUERZEL_TAKEN", player);
return true; return true;
} }
return false; return false;
} }
private boolean unwantedInTeam(ProxiedPlayer player, SteamwarUser user){ private boolean notInTeam(ProxiedPlayer player, SteamwarUser user) {
if(user.getTeam() != 0){ if (user.getTeam() == 0) {
Message.send("TEAM_IN_TEAM", player);
return true;
}
return false;
}
private boolean notInTeam(ProxiedPlayer player, SteamwarUser user){
if(user.getTeam() == 0){
Message.send("TEAM_NOT_IN_TEAM", player); Message.send("TEAM_NOT_IN_TEAM", player);
return true; return true;
} }
return false; return false;
} }
private boolean notLeader(ProxiedPlayer player, SteamwarUser user, Team team){ private boolean notLeader(ProxiedPlayer player, SteamwarUser user, Team team) {
if(notInTeam(player, user)) if (notInTeam(player, user))
return true; return true;
if(!user.isLeader()){ if (!user.isLeader()) {
Message.send("TEAM_NOT_LEADER", player); Message.send("TEAM_NOT_LEADER", player);
return true; return true;
} }
return false; return false;
} }
private boolean notDuringEvent(ProxiedPlayer player){ private boolean notDuringEvent(ProxiedPlayer player) {
if(Event.get() != null){ if (Event.get() != null) {
Message.send("TEAM_NOT_IN_EVENT", player); Message.send("TEAM_NOT_IN_EVENT", player);
return true; return true;
} }
@ -774,9 +814,9 @@ public class TeamCommand extends SWCommand {
} }
@Override @Override
public Iterable<String> onTabComplete(CommandSender commandSender, String[] args){ public Iterable<String> onTabComplete(CommandSender commandSender, String[] args) {
List<String> tab = new ArrayList<>(); List<String> tab = new ArrayList<>();
if(args.length == 1){ if (args.length == 1) {
tab.add("create"); tab.add("create");
tab.add("join"); tab.add("join");
tab.add("invite"); tab.add("invite");
@ -791,11 +831,11 @@ public class TeamCommand extends SWCommand {
tab.add("changecolor"); tab.add("changecolor");
tab.add("tp"); tab.add("tp");
tab.add("server"); tab.add("server");
}else if(args.length == 2){ } else if (args.length == 2) {
if(args[1].equalsIgnoreCase("event")){ if (args[1].equalsIgnoreCase("event")) {
List<Event> coming = Event.getComing(); List<Event> coming = Event.getComing();
coming.forEach(event -> tab.add(event.getEventName())); coming.forEach(event -> tab.add(event.getEventName()));
}else if(args[1].equalsIgnoreCase("join") || args[1].equalsIgnoreCase("info") || args[1].equalsIgnoreCase("tp")){ } else if (args[1].equalsIgnoreCase("join") || args[1].equalsIgnoreCase("info") || args[1].equalsIgnoreCase("tp")) {
List<Team> teams = Team.getAll(); List<Team> teams = Team.getAll();
teams.forEach(team -> { teams.forEach(team -> {
tab.add(team.getTeamName()); tab.add(team.getTeamName());