EnterDungeonCommand.java 1.47 KB
Newer Older
1
2
3
4
5
6
7
8
package emu.grasscutter.command.commands;

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

import java.util.List;

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

11
@Command(label = "enter_dungeon", aliases = {"enterdungeon", "dungeon"}, usage = {"<dungeonId>"}, permission = "player.enterdungeon", permissionTargeted = "player.enterdungeon.others")
12
public final class EnterDungeonCommand implements CommandHandler {
13

14
    @Override
AnimeGitB's avatar
AnimeGitB committed
15
    public void execute(Player sender, Player targetPlayer, List<String> args) {
16
        if (args.size() < 1) {
17
            sendUsageMessage(sender);
18
19
20
21
22
            return;
        }

        try {
            int dungeonId = Integer.parseInt(args.get(0));
AnimeGitB's avatar
AnimeGitB committed
23
            if (dungeonId == targetPlayer.getSceneId()) {
github-actions's avatar
github-actions committed
24
25
                CommandHandler.sendMessage(sender, translate(sender, "commands.enter_dungeon.in_dungeon_error"));
                return;
26
            }
github-actions's avatar
github-actions committed
27

28
            boolean result = targetPlayer.getServer().getDungeonSystem().enterDungeon(targetPlayer.getSession().getPlayer(), 0, dungeonId);
29
30

            if (!result) {
Secretboy's avatar
Secretboy committed
31
                CommandHandler.sendMessage(sender, translate(sender, "commands.enter_dungeon.not_found_error"));
shädam's avatar
shädam committed
32
33
            } else {
                CommandHandler.sendMessage(sender, translate(sender, "commands.enter_dungeon.changed", dungeonId));
34
35
            }
        } catch (Exception e) {
36
            sendUsageMessage(sender);
37
38
39
        }
    }
}