diff --git a/src/de/steamwar/bungeecore/commands/TeamCommand.java b/src/de/steamwar/bungeecore/commands/TeamCommand.java index 877b2a26..2e647ebf 100644 --- a/src/de/steamwar/bungeecore/commands/TeamCommand.java +++ b/src/de/steamwar/bungeecore/commands/TeamCommand.java @@ -24,7 +24,9 @@ import de.steamwar.bungeecore.Storage; import de.steamwar.bungeecore.inventory.SWItem; import de.steamwar.bungeecore.inventory.SWListInv; import de.steamwar.bungeecore.sql.*; +import de.steamwar.command.PreviousArguments; import de.steamwar.command.SWCommand; +import de.steamwar.command.TypeMapper; import de.steamwar.messages.ChatSender; import net.md_5.bungee.BungeeCord; import net.md_5.bungee.api.ChatColor; @@ -42,10 +44,7 @@ import net.md_5.bungee.api.event.ServerConnectEvent; import java.net.*; import java.time.Instant; import java.time.format.DateTimeFormatter; -import java.util.ArrayList; -import java.util.LinkedList; -import java.util.List; -import java.util.Set; +import java.util.*; import java.util.stream.Collectors; import static de.steamwar.bungeecore.Storage.teamInvitations; @@ -445,23 +444,28 @@ public class TeamCommand extends SWCommand { } @Register("event") - public void event(ProxiedPlayer player, String... args){ + public void event(ProxiedPlayer player) { SteamwarUser user = SteamwarUser.get(player.getUniqueId()); Team team = Team.get(user.getTeam()); if(notInTeam(player, user)) return; - if(args.length < 2){ - Message.send("TEAM_EVENT_USAGE", player); - Set events = TeamTeilnahme.getEvents(team.getTeamId()); - if(!events.isEmpty()){ - Message.send("TEAM_EVENT_HEADER", player); - DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern(Message.parse("EVENT_DATE_FORMAT", player)); - for(Event e : events) - Message.sendPrefixless("TEAM_EVENT_EVENT", player, e.getStart().toLocalDateTime().format(dateFormat), e.getEventName()); - } - return; + Message.send("TEAM_EVENT_USAGE", player); + Set events = TeamTeilnahme.getEvents(team.getTeamId()); + if(!events.isEmpty()){ + Message.send("TEAM_EVENT_HEADER", player); + DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern(Message.parse("EVENT_DATE_FORMAT", player)); + for(Event e : events) + Message.sendPrefixless("TEAM_EVENT_EVENT", player, e.getStart().toLocalDateTime().format(dateFormat), e.getEventName()); } + } + + @Register("event") + public void event(ProxiedPlayer player, Event event){ + SteamwarUser user = SteamwarUser.get(player.getUniqueId()); + Team team = Team.get(user.getTeam()); + if(notInTeam(player, user)) + return; if(notLeader(player, user)) return; @@ -469,12 +473,6 @@ public class TeamCommand extends SWCommand { if(notDuringEvent(player)) return; - Event event = Event.get(args[1]); - if(event == null){ - Message.send("TEAM_EVENT_NO_EVENT", player); - return; - } - if(Instant.now().isAfter(event.getDeadline().toInstant())){ Message.send("TEAM_EVENT_OVER", player); return; @@ -603,6 +601,31 @@ public class TeamCommand extends SWCommand { inv.open(); } + @ClassMapper(Event.class) + public TypeMapper eventTypeMapper() { + return new TypeMapper() { + @Override + public Event map(CommandSender commandSender, String[] previousArguments, String s) { + return Event.get(s); + } + + @Override + public boolean validate(CommandSender sender, Event value, MessageSender messageSender) { + if (value == null) { + messageSender.send("TEAM_EVENT_NO_EVENT", sender); + return false; + } else { + return true; + } + } + + @Override + public Collection tabCompletes(CommandSender sender, PreviousArguments previousArguments, String s) { + return Event.getComing().stream().map(Event::getEventName).collect(Collectors.toList()); + } + }; + } + private boolean checkTeamName(ProxiedPlayer player, Team team, String arg){ Team t = Team.get(arg); if(t != null && t.getTeamId() != team.getTeamId()){