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

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 25
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A StartLasertagGameCommand(boolean) 0 2 1
A register(LiteralArgumentBuilder) 0 6 1
A execute(CommandContext) 0 10 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
import net.minecraft.text.Text;
9
import net.minecraft.util.Formatting;
10
11
import java.util.Optional;
12
13
import static net.minecraft.server.command.CommandManager.literal;
14
15
/**
16
 * The start lasertag game command
17
 *
18
 * @author Étienne Muser
19
 */
20
public class StartLasertagGameCommand extends ServerFeedbackCommand {
21
    private boolean scanSpawnpoints;
22
23
    private StartLasertagGameCommand(boolean scanSpawnpoints) {
24
        this.scanSpawnpoints = scanSpawnpoints;
25
    }
26
27
    @Override
28
    protected Optional<CommandFeedback> execute(CommandContext<ServerCommandSource> context) {
29
30
        // Get the game managers
31
        var gameManager = context.getSource().getWorld().getServerLasertagManager();
32
33
        var abortReasons = gameManager.startGame(scanSpawnpoints);
34
35
        // If start game got aborted
36
        return abortReasons.map(s -> new CommandFeedback(Text.literal("Start game aborted. Reasons:\n" + s).formatted(Formatting.RED), false, true));
37
    }
38
39
    static void register(LiteralArgumentBuilder<ServerCommandSource> lab) {
40
        lab.then(literal("startLasertagGame")
41
                .requires(s -> s.hasPermissionLevel(1))
42
                .executes(new StartLasertagGameCommand(false))
43
                .then(literal("scanSpawnpoints")
44
                        .executes(new StartLasertagGameCommand(true))));
45
    }
46
}
47