Dieser Commit ist enthalten in:
Ursprung
9b4bbf9ca4
Commit
dcb106f0aa
@ -34,6 +34,7 @@ import java.sql.Timestamp;
|
||||
import java.time.Instant;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class EventCommand extends SWCommand {
|
||||
@ -117,8 +118,7 @@ public class EventCommand extends SWCommand {
|
||||
}
|
||||
}
|
||||
|
||||
@ClassMapper(Team.class)
|
||||
public TypeMapper<Team> eventTeams() {
|
||||
protected static TypeMapper<Team> eventTeam(Function<EventFight, List<Integer>> teamMapper) {
|
||||
return new TypeMapper<>() {
|
||||
@Override
|
||||
public Team map(Chatter sender, PreviousArguments previousArguments, String s) {
|
||||
@ -134,16 +134,22 @@ public class EventCommand extends SWCommand {
|
||||
Event currentEvent = Event.get();
|
||||
for (EventFight fight : EventFight.getEvent(currentEvent.getEventID())) {
|
||||
if (fight.hasFinished()) continue;
|
||||
if (fight.getStartTime().after(new Timestamp(System.currentTimeMillis()))) continue;
|
||||
Team red = Team.get(fight.getTeamRed());
|
||||
teams.add(red.getTeamName());
|
||||
teams.add(red.getTeamKuerzel());
|
||||
Team blue = Team.get(fight.getTeamBlue());
|
||||
teams.add(blue.getTeamName());
|
||||
teams.add(blue.getTeamKuerzel());
|
||||
teamMapper.apply(fight).forEach(integer -> {
|
||||
Team team = Team.get(integer);
|
||||
teams.add(team.getTeamName());
|
||||
teams.add(team.getTeamKuerzel());
|
||||
});
|
||||
}
|
||||
return teams;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@ClassMapper(Team.class)
|
||||
public TypeMapper<Team> eventTeams() {
|
||||
return eventTeam(eventFight -> {
|
||||
if (eventFight.getStartTime().after(new Timestamp(System.currentTimeMillis()))) return Collections.emptyList();
|
||||
return List.of(eventFight.getTeamBlue(), eventFight.getTeamRed());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +19,6 @@
|
||||
|
||||
package de.steamwar.velocitycore.commands;
|
||||
|
||||
import de.steamwar.command.PreviousArguments;
|
||||
import de.steamwar.command.SWCommand;
|
||||
import de.steamwar.command.TypeMapper;
|
||||
import de.steamwar.messages.Chatter;
|
||||
@ -29,8 +28,9 @@ import de.steamwar.sql.Team;
|
||||
import de.steamwar.sql.UserPerm;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
|
||||
public class EventRescheduleCommand extends SWCommand {
|
||||
|
||||
@ -65,41 +65,13 @@ public class EventRescheduleCommand extends SWCommand {
|
||||
sender.system("EVENTRESCHEDULE_NO_FIGHT");
|
||||
}
|
||||
|
||||
private TypeMapper<Team> eventTeam(Function<EventFight, Integer> teamMapper) {
|
||||
return new TypeMapper<>() {
|
||||
@Override
|
||||
public Team map(Chatter sender, PreviousArguments previousArguments, String s) {
|
||||
if ("PUB".equalsIgnoreCase(s) || "public".equalsIgnoreCase(s)) {
|
||||
return Team.get(0);
|
||||
}
|
||||
return Team.get(s);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> tabCompletes(Chatter sender, PreviousArguments previousArguments, String s) {
|
||||
Event currentEvent = Event.get();
|
||||
if(currentEvent == null){
|
||||
return null;
|
||||
}
|
||||
Set<String> teams = new HashSet<>();
|
||||
for (EventFight fight : EventFight.getEvent(currentEvent.getEventID())) {
|
||||
if (fight.hasFinished()) continue;
|
||||
Team team = Team.get(teamMapper.apply(fight));
|
||||
teams.add(team.getTeamName());
|
||||
teams.add(team.getTeamKuerzel());
|
||||
}
|
||||
return teams;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Mapper("BLUE_TEAM")
|
||||
public TypeMapper<Team> eventBlueTeams() {
|
||||
return eventTeam(EventFight::getTeamBlue);
|
||||
return EventCommand.eventTeam(eventFight -> List.of(eventFight.getTeamBlue()));
|
||||
}
|
||||
|
||||
@Mapper("RED_TEAM")
|
||||
public TypeMapper<Team> eventRedTeams() {
|
||||
return eventTeam(EventFight::getTeamRed);
|
||||
return EventCommand.eventTeam(eventFight -> List.of(eventFight.getTeamRed()));
|
||||
}
|
||||
}
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren