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

Complexity

Total Complexity 2

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 26
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A register(LiteralArgumentBuilder) 0 3 1
A execute(CommandContext) 0 20 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
10
import java.util.Optional;
11
12
import static net.minecraft.server.command.CommandManager.literal;
13
14
/**
15
 * The leave team command
16
 *
17
 * @author Étienne Muser
18
 */
19
public class LeaveLasertagTeamCommand extends ServerFeedbackCommand {
20
    protected Optional<CommandFeedback> execute(CommandContext<ServerCommandSource> context) {
21
22
        // Get the game managers
23
        var gameManager = context.getSource().getWorld().getServerLasertagManager();
24
        var teamsManager = gameManager.getTeamsManager();
25
26
        // Get the server
27
        var server = context.getSource().getServer();
28
29
        // Get executing player
30
        var player = context.getSource().getPlayer();
31
32
        // Leave team
33
        teamsManager.playerLeaveHisTeam(player);
34
35
        // Clear inventory
36
        player.getInventory().clear();
37
38
        // Notify player in chat
39
        return Optional.of(new CommandFeedback(Text.literal("You left your team"), true, false));
40
    }
41
42
    static void register(LiteralArgumentBuilder<ServerCommandSource> lab) {
43
        lab.then(literal("leaveTeam")
44
                .executes(new LeaveLasertagTeamCommand()));
45
    }
46
}
47