SteamWar/BungeeCore
Archiviert
13
2

Merge pull request 'Update EventRescheduleCommand' (#379) from CommandEventReschedule into master
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Reviewed-on: #379
Reviewed-by: Lixfel <lixfel@steamwar.de>
Dieser Commit ist enthalten in:
Lixfel 2022-06-16 13:02:13 +02:00
Commit 2aee854b5c

Datei anzeigen

@ -23,35 +23,29 @@ import de.steamwar.bungeecore.Message;
import de.steamwar.bungeecore.sql.Event; import de.steamwar.bungeecore.sql.Event;
import de.steamwar.bungeecore.sql.EventFight; import de.steamwar.bungeecore.sql.EventFight;
import de.steamwar.bungeecore.sql.Team; import de.steamwar.bungeecore.sql.Team;
import de.steamwar.command.SWCommand;
import de.steamwar.command.TypeMapper;
import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.connection.ProxiedPlayer;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.util.Collection;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.ListIterator; import java.util.ListIterator;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class EventRescheduleCommand extends BasicCommand { public class EventRescheduleCommand extends SWCommand {
public EventRescheduleCommand() { public EventRescheduleCommand() {
super("eventreschedule", "bungeecore.softreload"); super("eventreschedule", "bungeecore.softreload");
} }
@Override @Register
public void execute(CommandSender sender, String[] args) { public void reschedule(ProxiedPlayer player, Team teamBlue, Team teamRed) {
if(!(sender instanceof ProxiedPlayer))
return;
ProxiedPlayer player = (ProxiedPlayer) sender;
if(args.length != 2){
Message.send("EVENTRESCHEDULE_USAGE", player);
return;
}
Team teamBlue = Team.get(args[0]);
Team teamRed = Team.get(args[1]);
Event event = Event.get(); Event event = Event.get();
if(teamBlue == null || teamRed == null || event == null){ if(event == null){
Message.send("EVENTRESCHEDULE_UNKNOWN_TEAM", player); Message.send("EVENTRESCHEDULE_UNKNOWN_TEAM", player);
return; return;
} }
@ -74,4 +68,22 @@ public class EventRescheduleCommand extends BasicCommand {
Message.send("EVENTRESCHEDULE_NO_FIGHT", player); Message.send("EVENTRESCHEDULE_NO_FIGHT", player);
} }
@Register
public TypeMapper<Team> teamTypeMapper() {
return new TypeMapper<Team>() {
@Override
public Team map(CommandSender commandSender, String[] previousArguments, String s) {
return Team.get(s);
}
@Override
public Collection<String> tabCompletes(CommandSender sender, String[] previousArguments, String s) {
Event event = Event.get();
if (event == null) return null;
List<EventFight> fights = EventFight.getEvent(event.getEventID());
return fights.stream().flatMap(fight -> Stream.of(fight.getTeamBlue(), fight.getTeamRed())).map(Team::get).map(Team::getTeamKuerzel).distinct().collect(Collectors.toList());
}
};
}
} }