SetFetterLevelCommand.java 1.86 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;

14
15
16
17
18
19
@Command(
    label = "setFetterLevel",
    usage = {"<level>"},
    aliases = {"setfetterlvl", "setfriendship"},
    permission = "player.setfetterlevel",
    permissionTargeted = "player.setfetterlevel.others")
Yazawazi's avatar
Yazawazi committed
20
21
22
public final class SetFetterLevelCommand implements CommandHandler {

    @Override
AnimeGitB's avatar
AnimeGitB committed
23
    public void execute(Player sender, Player targetPlayer, List<String> args) {
AnimeGitB's avatar
AnimeGitB committed
24
        if (args.size() != 1) {
25
            sendUsageMessage(sender);
Yazawazi's avatar
Yazawazi committed
26
27
28
29
30
31
            return;
        }

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

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