port_to_commandframework #457
@ -21,54 +21,33 @@ package de.steamwar.bungeecore.commands;
|
||||
|
||||
import de.steamwar.bungeecore.*;
|
||||
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 java.time.Instant;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class EventCommand extends BasicCommand {
|
||||
public class EventCommand extends SWCommand {
|
||||
|
||||
public EventCommand() {
|
||||
super("event", "");
|
||||
super("event");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
if(!(sender instanceof ProxiedPlayer))
|
||||
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);
|
||||
@Validator("noEvent")
|
||||
public TypeValidator<ProxiedPlayer> noEventValidator() {
|
||||
return (sender, value, messageSender) -> Event.get() == null;
|
||||
}
|
||||
|
||||
private void noCurrentEvent(ProxiedPlayer player){
|
||||
@Register
|
||||
public void noCurrentEvent(@Validator("noEvent") ProxiedPlayer player){
|
||||
Message.send("EVENT_NO_CURRENT", player);
|
||||
List<Event> coming = Event.getComing();
|
||||
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);
|
||||
|
||||
List<EventFight> fights = EventFight.getEvent(currentEvent.getEventID());
|
||||
@ -129,4 +110,26 @@ public class EventCommand extends BasicCommand {
|
||||
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()));
|
||||
}
|
||||
}
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren