QuestCommand.java 1.94 KB
Newer Older
Melledy's avatar
Melledy committed
1
2
3
4
5
6
7
8
9
10
11
package emu.grasscutter.command.commands;

import emu.grasscutter.command.Command;
import emu.grasscutter.command.CommandHandler;
import emu.grasscutter.game.player.Player;
import emu.grasscutter.game.quest.GameQuest;

import java.util.List;

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

12
@Command(label = "quest", usage = {"(add|finish) [<questId>]"}, permission = "player.quest", permissionTargeted = "player.quest.others")
Melledy's avatar
Melledy committed
13
14
15
16
public final class QuestCommand implements CommandHandler {

    @Override
    public void execute(Player sender, Player targetPlayer, List<String> args) {
github-actions's avatar
github-actions committed
17
18
        if (args.size() != 2) {
            sendUsageMessage(sender);
Melledy's avatar
Melledy committed
19
            return;
github-actions's avatar
github-actions committed
20
21
22
23
24
25
26
27
28
        }

        String cmd = args.get(0).toLowerCase();
        int questId;

        try {
            questId = Integer.parseInt(args.get(1));
        } catch (Exception e) {
            CommandHandler.sendMessage(sender, translate(sender, "commands.quest.invalid_id"));
Melledy's avatar
Melledy committed
29
            return;
github-actions's avatar
github-actions committed
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
        }

        switch (cmd) {
            case "add" -> {
                GameQuest quest = targetPlayer.getQuestManager().addQuest(questId);

                if (quest != null) {
                    CommandHandler.sendMessage(sender, translate(sender, "commands.quest.added", questId));
                    return;
                }

                CommandHandler.sendMessage(sender, translate(sender, "commands.quest.not_found"));
            }
            case "finish" -> {
                GameQuest quest = targetPlayer.getQuestManager().getQuestById(questId);

                if (quest == null) {
                    CommandHandler.sendMessage(sender, translate(sender, "commands.quest.not_found"));
                    return;
                }

                quest.finish();

                CommandHandler.sendMessage(sender, translate(sender, "commands.quest.finished", questId));
            }
            default -> {
                sendUsageMessage(sender);
            }
        }
Melledy's avatar
Melledy committed
59
60
    }
}