SetFetterLevelCommand.java 2.05 KB
Newer Older
Yazawazi's avatar
Yazawazi committed
1
2
3
4
5
6
package emu.grasscutter.command.commands;

import java.util.List;

import emu.grasscutter.command.Command;
import emu.grasscutter.command.CommandHandler;
7
8
import emu.grasscutter.data.GameData;
import emu.grasscutter.game.avatar.Avatar;
Melledy's avatar
Melledy committed
9
import emu.grasscutter.game.player.Player;
Yazawazi's avatar
Yazawazi committed
10
import emu.grasscutter.server.packet.send.PacketAvatarFetterDataNotify;
Yazawazi's avatar
Yazawazi committed
11

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

Yazawazi's avatar
Yazawazi committed
14
@Command(label = "setfetterlevel", usage = "setfetterlevel <level>",
方块君's avatar
方块君 committed
15
        aliases = {"setfetterlvl", "setfriendship"}, permission = "player.setfetterlevel", description = "commands.setFetterLevel.description")
Yazawazi's avatar
Yazawazi committed
16
17
18
public final class SetFetterLevelCommand implements CommandHandler {

    @Override
AnimeGitB's avatar
AnimeGitB committed
19
    public void execute(Player sender, Player targetPlayer, List<String> args) {
AnimeGitB's avatar
AnimeGitB committed
20
        if (targetPlayer == null) {
21
            CommandHandler.sendMessage(sender, translate("commands.execution.need_target"));
Yazawazi's avatar
Yazawazi committed
22
23
24
            return;
        }

AnimeGitB's avatar
AnimeGitB committed
25
        if (args.size() != 1) {
26
            CommandHandler.sendMessage(sender, translate("commands.setFetterLevel.usage"));
Yazawazi's avatar
Yazawazi committed
27
28
29
30
31
32
            return;
        }

        try {
            int fetterLevel = Integer.parseInt(args.get(0));
            if (fetterLevel < 0 || fetterLevel > 10) {
33
                CommandHandler.sendMessage(sender, translate("commands.setFetterLevel.range_error"));
Yazawazi's avatar
Yazawazi committed
34
35
                return;
            }
AnimeGitB's avatar
AnimeGitB committed
36
            Avatar avatar = targetPlayer.getTeamManager().getCurrentAvatarEntity().getAvatar();
Yazawazi's avatar
Yazawazi committed
37
38

            avatar.setFetterLevel(fetterLevel);
Yazawazi's avatar
Yazawazi committed
39
            if (fetterLevel != 10) {
40
                avatar.setFetterExp(GameData.getAvatarFetterLevelDataMap().get(fetterLevel).getExp());
Yazawazi's avatar
Yazawazi committed
41
            }
Yazawazi's avatar
Yazawazi committed
42
43
		    avatar.save();
		
AnimeGitB's avatar
AnimeGitB committed
44
		    targetPlayer.sendPacket(new PacketAvatarFetterDataNotify(avatar));
45
            CommandHandler.sendMessage(sender, translate("commands.setFetterLevel.success", fetterLevel));
Yazawazi's avatar
Yazawazi committed
46
        } catch (NumberFormatException ignored) {
47
            CommandHandler.sendMessage(sender, translate("commands.setFetterLevel.level_error"));
Yazawazi's avatar
Yazawazi committed
48
49
50
51
        }
    }
    
}