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; 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;
@ -86,7 +91,7 @@ public class EventCommand extends SWCommand {
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()));
@ -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;
}
};
}
} }

Datei anzeigen

@ -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);
}
} }