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

Complexity

Total Complexity 2

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 19
dl 0
loc 31
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A execute(CommandContext) 0 23 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 reset team config command
15
 *
16
 * @author Étienne Muser
17
 */
18
public class ResetTeamConfigCommand extends ServerFeedbackCommand {
19
20
    @Override
21
    protected Optional<CommandFeedback> execute(CommandContext<ServerCommandSource> context) {
22
23
        // Get the game managers
24
        var gameManager = context.getSource().getWorld().getServerLasertagManager();
25
        var teamsManager = gameManager.getTeamsManager();
26
        var playerNamesState = gameManager.getSyncedState().getPlayerNamesState();
27
        var syncedState = gameManager.getSyncedState();
28
        var teamsConfigState = syncedState.getTeamsConfigState();
29
30
        var world = context.getSource().getWorld();
31
32
        // Throw every player out of his team
33
        playerNamesState.forEachPlayer((playerUuid) -> {
34
            teamsManager.playerLeaveHisTeam(playerUuid);
35
36
            var playerOptional = Optional.ofNullable(world.getPlayerByUuid(playerUuid));
37
            playerOptional.ifPresent(playerEntity -> playerEntity.getInventory().clear());
38
        });
39
40
        teamsConfigState.reset();
41
42
        return Optional.empty();
43
    }
44
45
    static void register(LiteralArgumentBuilder<ServerCommandSource> lab) {
46
        lab.then(literal("resetTeamConfig")
47
                .requires(s -> s.hasPermissionLevel(4))
48
                .executes(new ResetTeamConfigCommand()));
49
    }
50
}
51