SetFetterLevelCommand.java 2.08 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
15
@Command(label = "setfetterlevel", usage = "setfetterlevel <level>",
        description = "Sets your fetter level for your current active character",
Yazawazi's avatar
Yazawazi committed
16
        aliases = {"setfetterlvl", "setfriendship"}, permission = "player.setfetterlevel")
Yazawazi's avatar
Yazawazi committed
17
18
19
public final class SetFetterLevelCommand implements CommandHandler {

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

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

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

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