diff --git a/server/src/main/java/nl/andrewl/aos2_server/TeamManager.java b/server/src/main/java/nl/andrewl/aos2_server/TeamManager.java index 8850d0d..532a3db 100644 --- a/server/src/main/java/nl/andrewl/aos2_server/TeamManager.java +++ b/server/src/main/java/nl/andrewl/aos2_server/TeamManager.java @@ -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 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 getTeams() { return Collections.unmodifiableCollection(teams.values()); } diff --git a/server/src/main/java/nl/andrewl/aos2_server/cli/PlayersCommand.java b/server/src/main/java/nl/andrewl/aos2_server/cli/PlayersCommand.java index db73cda..d61123d 100644 --- a/server/src/main/java/nl/andrewl/aos2_server/cli/PlayersCommand.java +++ b/server/src/main/java/nl/andrewl/aos2_server/cli/PlayersCommand.java @@ -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 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.")); + } }