de.pewpewproject.lasertag.command.lasertag.game.ReloadTeamConfigCommand   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 17
dl 0
loc 28
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A execute(CommandContext) 0 21 1
A register(LiteralArgumentBuilder) 0 4 1
1
package de.pewpewproject.lasertag.command.lasertag.game;
2
3
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
4
import com.mojang.brigadier.context.CommandContext;
5
import de.pewpewproject.lasertag.command.CommandFeedback;
6
import de.pewpewproject.lasertag.command.ServerFeedbackCommand;
7
import net.minecraft.server.command.ServerCommandSource;
8
9
import java.util.Optional;
10
11
import static net.minecraft.server.command.CommandManager.literal;
12
13
/**
14
 * The reload team config command
15
 *
16
 * @author Étienne Muser
17
 */
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
    }
47
}
48