SteamWar/BungeeCore
Archiviert
13
2

Update EventCommand
Einige Prüfungen sind fehlgeschlagen
SteamWarCI Build failed

Dieser Commit ist enthalten in:
yoyosource 2023-01-21 22:17:41 +01:00
Ursprung 9f9d082042
Commit 29945a351b

Datei anzeigen

@ -21,54 +21,33 @@ package de.steamwar.bungeecore.commands;
import de.steamwar.bungeecore.*; import de.steamwar.bungeecore.*;
import de.steamwar.bungeecore.sql.*; import de.steamwar.bungeecore.sql.*;
import net.md_5.bungee.api.CommandSender; import de.steamwar.command.SWCommand;
import de.steamwar.command.SWCommandUtils;
import de.steamwar.command.TypeMapper;
import de.steamwar.command.TypeValidator;
import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.connection.ProxiedPlayer;
import java.time.Instant; import java.time.Instant;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.Arrays;
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;
public class EventCommand extends BasicCommand { public class EventCommand extends SWCommand {
public EventCommand() { public EventCommand() {
super("event", ""); super("event");
} }
@Override @Validator("noEvent")
public void execute(CommandSender sender, String[] args) { public TypeValidator<ProxiedPlayer> noEventValidator() {
if(!(sender instanceof ProxiedPlayer)) return (sender, value, messageSender) -> Event.get() == null;
return;
ProxiedPlayer player = (ProxiedPlayer) sender;
Event currentEvent = Event.get();
if(currentEvent == null) {
noCurrentEvent(player);
return;
}
if(args.length != 1){
eventOverview(player, currentEvent);
return;
}
Team team = Team.get(args[0]);
if(team == null){
Message.send("EVENT_NO_TEAM", player);
return;
}
Subserver eventArena = EventStarter.getEventServer().get(team.getTeamId());
if(eventArena == null || !Subserver.getServerList().contains(eventArena)){
Message.send("EVENT_NO_FIGHT_TEAM", player);
return;
}
SubserverSystem.sendPlayer(eventArena, player);
} }
private void noCurrentEvent(ProxiedPlayer player){ @Register
public void noCurrentEvent(@Validator("noEvent") ProxiedPlayer player){
Message.send("EVENT_NO_CURRENT", player); Message.send("EVENT_NO_CURRENT", player);
List<Event> coming = Event.getComing(); List<Event> coming = Event.getComing();
Instant now = Instant.now(); Instant now = Instant.now();
@ -99,7 +78,9 @@ public class EventCommand extends BasicCommand {
} }
} }
private void eventOverview(ProxiedPlayer player, Event currentEvent){ @Register
public void eventOverview(@Validator(value = "noEvent", invert = true) ProxiedPlayer player) {
Event currentEvent = Event.get();
Message.send("EVENT_USAGE", player); Message.send("EVENT_USAGE", player);
List<EventFight> fights = EventFight.getEvent(currentEvent.getEventID()); List<EventFight> fights = EventFight.getEvent(currentEvent.getEventID());
@ -129,4 +110,26 @@ public class EventCommand extends BasicCommand {
BungeeCore.send(player, fline.toString()); BungeeCore.send(player, fline.toString());
} }
} }
@Register
public void eventWithTeam(@Validator(value = "noEvent", invert = true) ProxiedPlayer player, @ErrorMessage("EVENT_NO_TEAM") Team team) {
Subserver eventArena = EventStarter.getEventServer().get(team.getTeamId());
if(eventArena == null || !Subserver.getServerList().contains(eventArena)){
Message.send("EVENT_NO_FIGHT_TEAM", player);
return;
}
SubserverSystem.sendPlayer(eventArena, player);
}
@ClassMapper(Team.class)
@Cached(cacheDuration = 10, global = true)
public TypeMapper<Team> teamMapper() {
return SWCommandUtils.createMapper(Team::get, s -> EventStarter.getEventServer()
.keySet()
.stream()
.map(Team::get)
.map(t -> Arrays.asList(t.getTeamKuerzel(), t.getTeamColor()))
.flatMap(Collection::stream)
.collect(Collectors.toList()));
}
} }