Add some QOL to EventCommand and EventRescheduleCommand
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful
Dieser Commit ist enthalten in:
Ursprung
209214a773
Commit
c4cabdcdb6
@ -19,17 +19,22 @@
|
|||||||
|
|
||||||
package de.steamwar.velocitycore.commands;
|
package de.steamwar.velocitycore.commands;
|
||||||
|
|
||||||
import de.steamwar.velocitycore.EventStarter;
|
import de.steamwar.command.PreviousArguments;
|
||||||
import de.steamwar.persistent.Subserver;
|
|
||||||
import de.steamwar.velocitycore.SubserverSystem;
|
|
||||||
import de.steamwar.command.SWCommand;
|
import de.steamwar.command.SWCommand;
|
||||||
|
import de.steamwar.command.TypeMapper;
|
||||||
import de.steamwar.command.TypeValidator;
|
import de.steamwar.command.TypeValidator;
|
||||||
import de.steamwar.messages.Chatter;
|
import de.steamwar.messages.Chatter;
|
||||||
import de.steamwar.messages.PlayerChatter;
|
import de.steamwar.messages.PlayerChatter;
|
||||||
|
import de.steamwar.persistent.Subserver;
|
||||||
import de.steamwar.sql.*;
|
import de.steamwar.sql.*;
|
||||||
|
import de.steamwar.velocitycore.EventStarter;
|
||||||
|
import de.steamwar.velocitycore.SubserverSystem;
|
||||||
|
|
||||||
|
import java.sql.Timestamp;
|
||||||
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.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@ -50,17 +55,17 @@ public class EventCommand extends SWCommand {
|
|||||||
sender.system("EVENT_NO_CURRENT");
|
sender.system("EVENT_NO_CURRENT");
|
||||||
|
|
||||||
List<Event> coming = Event.getComing();
|
List<Event> coming = Event.getComing();
|
||||||
if(coming.isEmpty())
|
if (coming.isEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
sender.system("EVENT_COMING");
|
sender.system("EVENT_COMING");
|
||||||
|
|
||||||
Instant now = Instant.now();
|
Instant now = Instant.now();
|
||||||
DateTimeFormatter format = DateTimeFormatter.ofPattern(sender.parseToPlain("EVENT_DATE_FORMAT"));
|
DateTimeFormatter format = DateTimeFormatter.ofPattern(sender.parseToPlain("EVENT_DATE_FORMAT"));
|
||||||
for(Event e : coming){
|
for (Event e : coming) {
|
||||||
sender.prefixless("EVENT_COMING_EVENT", e.getStart().toLocalDateTime().format(format), e.getEnd().toLocalDateTime().format(format), e.getEventName());
|
sender.prefixless("EVENT_COMING_EVENT", e.getStart().toLocalDateTime().format(format), e.getEnd().toLocalDateTime().format(format), e.getEventName());
|
||||||
|
|
||||||
if(now.isBefore(e.getDeadline().toInstant()))
|
if (now.isBefore(e.getDeadline().toInstant()))
|
||||||
sender.prefixless("EVENT_COMING_DEADLINE", e.getDeadline());
|
sender.prefixless("EVENT_COMING_DEADLINE", e.getDeadline());
|
||||||
|
|
||||||
SchematicType schemType = e.getSchematicType();
|
SchematicType schemType = e.getSchematicType();
|
||||||
@ -68,7 +73,7 @@ public class EventCommand extends SWCommand {
|
|||||||
sender.prefixless("EVENT_COMING_SCHEM_DEADLINE", schemType.getDeadline());
|
sender.prefixless("EVENT_COMING_SCHEM_DEADLINE", schemType.getDeadline());
|
||||||
|
|
||||||
Set<Team> teams = TeamTeilnahme.getTeams(e.getEventID());
|
Set<Team> teams = TeamTeilnahme.getTeams(e.getEventID());
|
||||||
if(!teams.isEmpty())
|
if (!teams.isEmpty())
|
||||||
sender.prefixless("EVENT_COMING_TEAMS", teams.stream().map(team -> sender.parseToLegacy("EVENT_COMING_TEAM", team.getTeamColor(), team.getTeamKuerzel())).collect(Collectors.joining(" ")));
|
sender.prefixless("EVENT_COMING_TEAMS", teams.stream().map(team -> sender.parseToLegacy("EVENT_COMING_TEAM", team.getTeamColor(), team.getTeamKuerzel())).collect(Collectors.joining(" ")));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -81,13 +86,13 @@ public class EventCommand extends SWCommand {
|
|||||||
sender.system("EVENT_CURRENT_EVENT", currentEvent.getEventName());
|
sender.system("EVENT_CURRENT_EVENT", currentEvent.getEventName());
|
||||||
|
|
||||||
DateTimeFormatter format = DateTimeFormatter.ofPattern(sender.parseToPlain("EVENT_TIME_FORMAT"));
|
DateTimeFormatter format = DateTimeFormatter.ofPattern(sender.parseToPlain("EVENT_TIME_FORMAT"));
|
||||||
for(EventFight fight : EventFight.getEvent(currentEvent.getEventID())){
|
for (EventFight fight : EventFight.getEvent(currentEvent.getEventID())) {
|
||||||
Team blue = Team.get(fight.getTeamBlue());
|
Team blue = Team.get(fight.getTeamBlue());
|
||||||
Team red = Team.get(fight.getTeamRed());
|
Team red = Team.get(fight.getTeamRed());
|
||||||
StringBuilder fline = new StringBuilder(sender.parseToLegacy("EVENT_CURRENT_FIGHT", fight.getStartTime().toLocalDateTime().format(format), blue.getTeamColor(), blue.getTeamKuerzel(), red.getTeamColor(), red.getTeamKuerzel()));
|
StringBuilder fline = new StringBuilder(sender.parseToLegacy("EVENT_CURRENT_FIGHT", fight.getStartTime().toLocalDateTime().format(format), blue.getTeamColor(), blue.getTeamKuerzel(), red.getTeamColor(), red.getTeamKuerzel()));
|
||||||
|
|
||||||
if(fight.hasFinished()){
|
if (fight.hasFinished() || fight.getErgebnis() != 0) {
|
||||||
switch(fight.getErgebnis()){
|
switch (fight.getErgebnis()) {
|
||||||
case 1:
|
case 1:
|
||||||
fline.append(sender.parseToLegacy("EVENT_CURRENT_FIGHT_WIN", blue.getTeamColor(), blue.getTeamKuerzel()));
|
fline.append(sender.parseToLegacy("EVENT_CURRENT_FIGHT_WIN", blue.getTeamColor(), blue.getTeamKuerzel()));
|
||||||
break;
|
break;
|
||||||
@ -106,7 +111,7 @@ public class EventCommand extends SWCommand {
|
|||||||
@Register
|
@Register
|
||||||
public void eventWithTeam(@Validator(value = "noEvent", invert = true) PlayerChatter sender, @ErrorMessage("EVENT_NO_TEAM") Team team) {
|
public void eventWithTeam(@Validator(value = "noEvent", invert = true) PlayerChatter sender, @ErrorMessage("EVENT_NO_TEAM") Team team) {
|
||||||
Subserver eventArena = EventStarter.getEventServer().get(team.getTeamId());
|
Subserver eventArena = EventStarter.getEventServer().get(team.getTeamId());
|
||||||
if(eventArena == null || !Subserver.getServerList().contains(eventArena)){
|
if (eventArena == null || !Subserver.getServerList().contains(eventArena)) {
|
||||||
sender.system("EVENT_NO_FIGHT_TEAM");
|
sender.system("EVENT_NO_FIGHT_TEAM");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -114,4 +119,34 @@ public class EventCommand extends SWCommand {
|
|||||||
SubserverSystem.sendPlayer(eventArena, sender.getPlayer());
|
SubserverSystem.sendPlayer(eventArena, sender.getPlayer());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ClassMapper(Team.class)
|
||||||
|
public TypeMapper<Team> eventTeams() {
|
||||||
|
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) {
|
||||||
|
List<String> teams = new ArrayList<>();
|
||||||
|
Event currentEvent = Event.get();
|
||||||
|
for (EventFight fight : EventFight.getEvent(currentEvent.getEventID())) {
|
||||||
|
if (fight.hasFinished() || fight.getErgebnis() != 0) 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());
|
||||||
|
}
|
||||||
|
return teams;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,9 @@
|
|||||||
|
|
||||||
package de.steamwar.velocitycore.commands;
|
package de.steamwar.velocitycore.commands;
|
||||||
|
|
||||||
|
import de.steamwar.command.PreviousArguments;
|
||||||
import de.steamwar.command.SWCommand;
|
import de.steamwar.command.SWCommand;
|
||||||
|
import de.steamwar.command.TypeMapper;
|
||||||
import de.steamwar.messages.Chatter;
|
import de.steamwar.messages.Chatter;
|
||||||
import de.steamwar.sql.Event;
|
import de.steamwar.sql.Event;
|
||||||
import de.steamwar.sql.EventFight;
|
import de.steamwar.sql.EventFight;
|
||||||
@ -27,9 +29,8 @@ import de.steamwar.sql.Team;
|
|||||||
import de.steamwar.sql.UserPerm;
|
import de.steamwar.sql.UserPerm;
|
||||||
|
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
import java.util.Date;
|
import java.util.*;
|
||||||
import java.util.List;
|
import java.util.function.Function;
|
||||||
import java.util.ListIterator;
|
|
||||||
|
|
||||||
public class EventRescheduleCommand extends SWCommand {
|
public class EventRescheduleCommand extends SWCommand {
|
||||||
|
|
||||||
@ -38,7 +39,7 @@ public class EventRescheduleCommand extends SWCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Register
|
@Register
|
||||||
public void reschedule(Chatter sender, Team teamBlue, Team teamRed) {
|
public void reschedule(Chatter sender, @Mapper("BLUE_TEAM") Team teamBlue, @Mapper("RED_TEAM") Team teamRed) {
|
||||||
Event event = Event.get();
|
Event event = Event.get();
|
||||||
if(event == null){
|
if(event == null){
|
||||||
sender.system("EVENTRESCHEDULE_UNKNOWN_TEAM");
|
sender.system("EVENTRESCHEDULE_UNKNOWN_TEAM");
|
||||||
@ -63,4 +64,42 @@ public class EventRescheduleCommand extends SWCommand {
|
|||||||
|
|
||||||
sender.system("EVENTRESCHEDULE_NO_FIGHT");
|
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;
|
||||||
|
}
|
||||||
|
List<String> teams = new ArrayList<>();
|
||||||
|
for (EventFight fight : EventFight.getEvent(currentEvent.getEventID())) {
|
||||||
|
if (fight.hasFinished() || fight.getErgebnis() != 0) 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Mapper("RED_TEAM")
|
||||||
|
public TypeMapper<Team> eventRedTeams() {
|
||||||
|
return eventTeam(EventFight::getTeamRed);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren