RemoveCommand.java 2.03 KB
Newer Older
1
2
3
4
5
6
7
8
9
package emu.grasscutter.command.commands;

import emu.grasscutter.Grasscutter;
import emu.grasscutter.command.Command;
import emu.grasscutter.command.CommandHandler;
import emu.grasscutter.game.player.Player;
import emu.grasscutter.server.packet.send.PacketChangeMpTeamAvatarRsp;

import java.util.ArrayList;
10
11
import java.util.Collections;
import java.util.Comparator;
12
13
14
15
16
17
18
19
20
21
import java.util.List;

import static emu.grasscutter.utils.Language.translate;

@Command(label = "remove", usage = "remove [indexOfYourTeams] index start from 1",
        description = "commands.remove.description", permission = "player.remove")
public class RemoveCommand implements CommandHandler {

    @Override
    public void execute(Player sender, Player targetPlayer, List<String> args) {
22
23
24
25
26
        if (targetPlayer == null) {
            CommandHandler.sendMessage(sender, translate(sender, "commands.execution.need_target"));
            return;
        }
        
27
        List<Integer> avatarIndexList = new ArrayList<>();
28
29
        for (String arg : args) {
            try {
30
31
                int avatarIndex = Integer.parseInt(arg);
                avatarIndexList.add(avatarIndex);
32
33
34
35
36
37
38
            } catch (Exception ignored) {
                ignored.printStackTrace();
                CommandHandler.sendMessage(sender, translate("commands.remove.invalid_index"));
                return;
            }
        }

39
40
41
        Collections.reverse(avatarIndexList);

        for (int i = 0; i < avatarIndexList.size(); i++) {
42
43
            if (avatarIndexList.get(i) > targetPlayer.getTeamManager().getCurrentTeamInfo().getAvatars().size() || avatarIndexList.get(i) <= 0) {
                CommandHandler.sendMessage(targetPlayer, translate("commands.remove.invalid_index"));
44
45
                return;
            }
46
            targetPlayer.getTeamManager().getCurrentTeamInfo().removeAvatar(avatarIndexList.get(i) - 1);
47
48
49
        }

        // Packet
50
        targetPlayer.getTeamManager().updateTeamEntities(new PacketChangeMpTeamAvatarRsp(targetPlayer, targetPlayer.getTeamManager().getCurrentTeamInfo()));
51
52
    }
}