SteamWar/BungeeCore
Archiviert
13
2

Add some QOL to EventCommand and EventRescheduleCommand
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Dieser Commit ist enthalten in:
yoyosource 2024-08-03 15:07:17 +02:00
Ursprung 209214a773
Commit c4cabdcdb6
2 geänderte Dateien mit 89 neuen und 15 gelöschten Zeilen

Datei anzeigen

@ -19,17 +19,22 @@
package de.steamwar.velocitycore.commands;
import de.steamwar.velocitycore.EventStarter;
import de.steamwar.persistent.Subserver;
import de.steamwar.velocitycore.SubserverSystem;
import de.steamwar.command.PreviousArguments;
import de.steamwar.command.SWCommand;
import de.steamwar.command.TypeMapper;
import de.steamwar.command.TypeValidator;
import de.steamwar.messages.Chatter;
import de.steamwar.messages.PlayerChatter;
import de.steamwar.persistent.Subserver;
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.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
@ -50,17 +55,17 @@ public class EventCommand extends SWCommand {
sender.system("EVENT_NO_CURRENT");
List<Event> coming = Event.getComing();
if(coming.isEmpty())
if (coming.isEmpty())
return;
sender.system("EVENT_COMING");
Instant now = Instant.now();
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());
if(now.isBefore(e.getDeadline().toInstant()))
if (now.isBefore(e.getDeadline().toInstant()))
sender.prefixless("EVENT_COMING_DEADLINE", e.getDeadline());
SchematicType schemType = e.getSchematicType();
@ -68,7 +73,7 @@ public class EventCommand extends SWCommand {
sender.prefixless("EVENT_COMING_SCHEM_DEADLINE", schemType.getDeadline());
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(" ")));
}
}
@ -81,13 +86,13 @@ public class EventCommand extends SWCommand {
sender.system("EVENT_CURRENT_EVENT", currentEvent.getEventName());
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 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()));
if(fight.hasFinished()){
switch(fight.getErgebnis()){
if (fight.hasFinished() || fight.getErgebnis() != 0) {
switch (fight.getErgebnis()) {
case 1:
fline.append(sender.parseToLegacy("EVENT_CURRENT_FIGHT_WIN", blue.getTeamColor(), blue.getTeamKuerzel()));
break;
@ -106,7 +111,7 @@ public class EventCommand extends SWCommand {
@Register
public void eventWithTeam(@Validator(value = "noEvent", invert = true) PlayerChatter sender, @ErrorMessage("EVENT_NO_TEAM") Team team) {
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");
return;
}
@ -114,4 +119,34 @@ public class EventCommand extends SWCommand {
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;
}
};
}
}

Datei anzeigen

@ -19,7 +19,9 @@
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;
import de.steamwar.sql.Event;
import de.steamwar.sql.EventFight;
@ -27,9 +29,8 @@ import de.steamwar.sql.Team;
import de.steamwar.sql.UserPerm;
import java.sql.Timestamp;
import java.util.Date;
import java.util.List;
import java.util.ListIterator;
import java.util.*;
import java.util.function.Function;
public class EventRescheduleCommand extends SWCommand {
@ -38,7 +39,7 @@ public class EventRescheduleCommand extends SWCommand {
}
@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();
if(event == null){
sender.system("EVENTRESCHEDULE_UNKNOWN_TEAM");
@ -63,4 +64,42 @@ 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;
}
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);
}
}