execute(CommandContext)   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 20
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 8
dl 0
loc 20
rs 10
c 0
b 0
f 0
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