SetFetterLevelCommand.java 1.92 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;
Yazawazi's avatar
Yazawazi committed
7
import emu.grasscutter.data.GenshinData;
Yazawazi's avatar
Yazawazi committed
8
import emu.grasscutter.game.GenshinPlayer;
Yazawazi's avatar
Yazawazi committed
9
10
import emu.grasscutter.game.avatar.GenshinAvatar;
import emu.grasscutter.server.packet.send.PacketAvatarFetterDataNotify;
Yazawazi's avatar
Yazawazi committed
11
12
13

@Command(label = "setfetterlevel", usage = "setfetterlevel <level>",
        description = "Sets your fetter level for your current active character",
Yazawazi's avatar
Yazawazi committed
14
        aliases = {"setfetterlvl", "setfriendship"}, permission = "player.setfetterlevel")
Yazawazi's avatar
Yazawazi committed
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
public final class SetFetterLevelCommand implements CommandHandler {

    @Override
    public void execute(GenshinPlayer sender, List<String> args) {
        if (sender == null) {
            CommandHandler.sendMessage(null, "Run this command in-game.");
            return;
        }

        if (args.size() < 1) {
            CommandHandler.sendMessage(sender, "Usage: setfetterlevel <level>");
            return;
        }

        try {
            int fetterLevel = Integer.parseInt(args.get(0));
            if (fetterLevel < 0 || fetterLevel > 10) {
                CommandHandler.sendMessage(sender, "Fetter level must be between 0 and 10.");
                return;
            }
Yazawazi's avatar
Yazawazi committed
35
36
37
            GenshinAvatar avatar = sender.getTeamManager().getCurrentAvatarEntity().getAvatar();

            avatar.setFetterLevel(fetterLevel);
Yazawazi's avatar
Yazawazi committed
38
39
40
            if (fetterLevel != 10) {
                avatar.setFetterExp(GenshinData.getAvatarFetterLevelDataMap().get(fetterLevel).getExp());
            }
Yazawazi's avatar
Yazawazi committed
41
42
43
		    avatar.save();
		
		    sender.sendPacket(new PacketAvatarFetterDataNotify(avatar));
Yazawazi's avatar
Yazawazi committed
44
45
            CommandHandler.sendMessage(sender, "Fetter level set to " + fetterLevel);
        } catch (NumberFormatException ignored) {
KingRainbow44's avatar
KingRainbow44 committed
46
            CommandHandler.sendMessage(sender, "Invalid fetter level.");
Yazawazi's avatar
Yazawazi committed
47
48
49
50
        }
    }
    
}