EnterDungeonCommand.java 1.62 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 = "enterdungeon", usage = "enterdungeon <dungeon id>", 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);
Secretboy's avatar
Secretboy committed
29
            CommandHandler.sendMessage(sender, translate(sender, "commands.enter_dungeon.changed", dungeonId));
30
31

            if (!result) {
Secretboy's avatar
Secretboy committed
32
                CommandHandler.sendMessage(sender, translate(sender, "commands.enter_dungeon.not_found_error"));
33
34
            }
        } catch (Exception e) {
Secretboy's avatar
Secretboy committed
35
            CommandHandler.sendMessage(sender, translate(sender, "commands.enter_dungeon.usage"));
36
37
38
        }
    }
}