QuestCommand.java 1.97 KB
Newer Older
Melledy's avatar
Melledy committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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
59
60
61
62
63
64
65
66
package emu.grasscutter.command.commands;

import emu.grasscutter.Grasscutter;
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;

@Command(label = "quest", usage = "quest <add|finish> [quest id]", permission = "player.quest", permissionTargeted = "player.quest.others", description = "commands.quest.description")
public final class QuestCommand implements CommandHandler {

    @Override
    public void execute(Player sender, Player targetPlayer, List<String> args) {
		if (targetPlayer == null) {
			CommandHandler.sendMessage(sender, translate(sender, "commands.execution.need_target"));
			return;
		}
		
		if (args.size() != 2) {
			CommandHandler.sendMessage(sender, translate(sender, "commands.quest.usage"));
            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" -> {
				GameQuest quest = sender.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 = sender.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 -> {
				CommandHandler.sendMessage(sender, translate(sender, "commands.quest.usage"));
			}
		}
    }
}