QuestCommand.java 1.66 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
17
public final class QuestCommand implements CommandHandler {

    @Override
    public void execute(Player sender, Player targetPlayer, List<String> args) {
		if (args.size() != 2) {
18
			sendUsageMessage(sender);
Melledy's avatar
Melledy committed
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
            return;
		}
		
		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"));
            return;
		}
		
		switch (cmd) {
			case "add" -> {
34
				GameQuest quest = targetPlayer.getQuestManager().addQuest(questId);
Melledy's avatar
Melledy committed
35
36
37
38
39
40
41
42
43
				
				if (quest != null) {
					CommandHandler.sendMessage(sender, translate(sender, "commands.quest.added", questId));
					return;
				}
				
				CommandHandler.sendMessage(sender, translate(sender, "commands.quest.not_found"));
			}
			case "finish" -> {
44
				GameQuest quest = targetPlayer.getQuestManager().getQuestById(questId);
Melledy's avatar
Melledy committed
45
46
47
48
49
50
51
52
53
54
55
				
				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 -> {
56
				sendUsageMessage(sender);
Melledy's avatar
Melledy committed
57
58
59
60
			}
		}
    }
}