EnterDungeonCommand.java 1.64 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;

tester233's avatar
tester233 committed
11
@Command(label = "enterdungeon", usage = "enterdungeon <dungeonId>", aliases = {"dungeon"}, permission = "player.enterdungeon", permissionTargeted = "player.enterdungeon.others", description = "commands.enter_dungeon.description")
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) {
Secretboy's avatar
Secretboy committed
17
            CommandHandler.sendMessage(sender, translate(sender, "commands.enter_dungeon.usage"));
18
19
20
21
22
            return;
        }

        try {
            int dungeonId = Integer.parseInt(args.get(0));
AnimeGitB's avatar
AnimeGitB committed
23
            if (dungeonId == targetPlayer.getSceneId()) {
Secretboy's avatar
Secretboy committed
24
            	CommandHandler.sendMessage(sender, translate(sender, "commands.enter_dungeon.in_dungeon_error"));
25
26
27
            	return;
            }
            
AnimeGitB's avatar
AnimeGitB committed
28
            boolean result = targetPlayer.getServer().getDungeonManager().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) {
Secretboy's avatar
Secretboy committed
36
            CommandHandler.sendMessage(sender, translate(sender, "commands.enter_dungeon.usage"));
37
38
39
        }
    }
}