| Total Complexity | 2 |
| Total Lines | 28 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | package de.pewpewproject.lasertag.command.lasertag.game; |
||
| 18 | public class ReloadTeamConfigCommand extends ServerFeedbackCommand { |
||
| 19 | @Override |
||
| 20 | protected Optional<CommandFeedback> execute(CommandContext<ServerCommandSource> context) { |
||
| 21 | |||
| 22 | // Get the game managers |
||
| 23 | var gameManager = context.getSource().getWorld().getServerLasertagManager(); |
||
| 24 | var playerNamesState = gameManager.getSyncedState().getPlayerNamesState(); |
||
| 25 | var teamsManager = gameManager.getTeamsManager(); |
||
| 26 | |||
| 27 | var world = context.getSource().getWorld(); |
||
| 28 | |||
| 29 | // Throw every player out of his team |
||
| 30 | playerNamesState.forEachPlayer((playerUuid) -> { |
||
| 31 | teamsManager.playerLeaveHisTeam(playerUuid); |
||
| 32 | |||
| 33 | var playerOptional = Optional.ofNullable(world.getPlayerByUuid(playerUuid)); |
||
| 34 | playerOptional.ifPresent(playerEntity -> playerEntity.getInventory().clear()); |
||
| 35 | }); |
||
| 36 | |||
| 37 | teamsManager.reloadTeamsConfig(); |
||
| 38 | |||
| 39 | return Optional.empty(); |
||
| 40 | } |
||
| 41 | |||
| 42 | static void register(LiteralArgumentBuilder<ServerCommandSource> lab) { |
||
| 43 | lab.then(literal("reloadTeamConfig") |
||
| 44 | .requires(s -> s.hasPermissionLevel(4)) |
||
| 45 | .executes(new ReloadTeamConfigCommand())); |
||
| 46 | } |
||
| 48 |