Improved server cli slightly.
This commit is contained in:
parent
289ce50552
commit
a1c1aad065
|
@ -5,10 +5,7 @@ import nl.andrewl.aos_core.model.Team;
|
|||
import org.joml.Vector3f;
|
||||
import org.joml.Vector3i;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Component that manages the teams on a server.
|
||||
|
@ -32,6 +29,21 @@ public class TeamManager {
|
|||
return teams.get(id);
|
||||
}
|
||||
|
||||
public Optional<Team> findByIdOrName(String ident) {
|
||||
for (var team : teams.values()) {
|
||||
if (team.getName().equals(ident)) return Optional.of(team);
|
||||
}
|
||||
try {
|
||||
int id = Integer.parseInt(ident);
|
||||
for (var team : teams.values()) {
|
||||
if (team.getId() == id) return Optional.of(team);
|
||||
}
|
||||
return Optional.empty();
|
||||
} catch (NumberFormatException e) {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
public Collection<Team> getTeams() {
|
||||
return Collections.unmodifiableCollection(teams.values());
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ import java.util.Comparator;
|
|||
public class PlayersCommand {
|
||||
@CommandLine.ParentCommand ServerCli cli;
|
||||
|
||||
@CommandLine.Command(description = "Lists all online players.")
|
||||
@CommandLine.Command(name = "list", description = "Lists all online players.")
|
||||
public void list() {
|
||||
var playerManager = cli.server.getPlayerManager();
|
||||
Collection<ServerPlayer> players = playerManager.getPlayers();
|
||||
|
@ -39,11 +39,27 @@ public class PlayersCommand {
|
|||
}
|
||||
}
|
||||
|
||||
@CommandLine.Command(description = "Kicks a player from the server.")
|
||||
public void kick(@CommandLine.Parameters(description = "The id or name of the player to kick.") String playerIdent) {
|
||||
@CommandLine.Command(name = "list", description = "Kicks a player from the server.")
|
||||
public void kick(
|
||||
@CommandLine.Parameters(paramLabel = "player", description = "The id or name of the player to kick.") String playerIdent
|
||||
) {
|
||||
cli.server.getPlayerManager().findByIdOrName(playerIdent)
|
||||
.ifPresentOrElse(player -> {
|
||||
cli.server.getPlayerManager().deregister(player);
|
||||
}, () -> cli.out.println("Player not found."));
|
||||
}
|
||||
|
||||
@CommandLine.Command(name = "set-team", description = "Sets a player's team.")
|
||||
public void setTeam(
|
||||
@CommandLine.Parameters(paramLabel = "player", description = "The id or name of the player to set the team of.", index = "0") String playerIdent,
|
||||
@CommandLine.Parameters(paramLabel = "team", description = "The id or name of the team to move the player to.", index = "1") String teamIdent
|
||||
) {
|
||||
cli.server.getPlayerManager().findByIdOrName(playerIdent)
|
||||
.ifPresentOrElse(player -> {
|
||||
cli.server.getTeamManager().findByIdOrName(teamIdent)
|
||||
.ifPresentOrElse(team -> {
|
||||
cli.out.println("Not yet implemented.");
|
||||
}, () -> cli.out.println("Team not found."));
|
||||
}, () -> cli.out.println("Player not found."));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue