From d85b93364ef52ff7cff75329b67dac26900beea4 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Tue, 14 Jun 2022 21:42:05 +0200 Subject: [PATCH] Update EventRescheduleCommand --- .../commands/EventRescheduleCommand.java | 42 ++++++++++++------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/src/de/steamwar/bungeecore/commands/EventRescheduleCommand.java b/src/de/steamwar/bungeecore/commands/EventRescheduleCommand.java index 06934f3..bc7465c 100644 --- a/src/de/steamwar/bungeecore/commands/EventRescheduleCommand.java +++ b/src/de/steamwar/bungeecore/commands/EventRescheduleCommand.java @@ -23,35 +23,29 @@ import de.steamwar.bungeecore.Message; import de.steamwar.bungeecore.sql.Event; import de.steamwar.bungeecore.sql.EventFight; 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.connection.ProxiedPlayer; import java.sql.Timestamp; +import java.util.Collection; import java.util.Date; import java.util.List; 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() { super("eventreschedule", "bungeecore.softreload"); } - @Override - public void execute(CommandSender sender, String[] args) { - 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]); + @Register + public void reschedule(ProxiedPlayer player, Team teamBlue, Team teamRed) { Event event = Event.get(); - if(teamBlue == null || teamRed == null || event == null){ + if(event == null){ Message.send("EVENTRESCHEDULE_UNKNOWN_TEAM", player); return; } @@ -74,4 +68,22 @@ public class EventRescheduleCommand extends BasicCommand { Message.send("EVENTRESCHEDULE_NO_FIGHT", player); } + + @Register + public TypeMapper teamTypeMapper() { + return new TypeMapper() { + @Override + public Team map(CommandSender commandSender, String[] previousArguments, String s) { + return Team.get(s); + } + + @Override + public Collection tabCompletes(CommandSender sender, String[] previousArguments, String s) { + Event event = Event.get(); + if (event == null) return null; + List 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()); + } + }; + } }