EnterDungeonCommand.java 1.78 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) {
AnimeGitB's avatar
AnimeGitB committed
16
        if (targetPlayer == null) {
Secretboy's avatar
Secretboy committed
17
            CommandHandler.sendMessage(null, translate(sender, "commands.execution.need_target"));
18
19
20
21
            return;
        }

        if (args.size() < 1) {
Secretboy's avatar
Secretboy committed
22
            CommandHandler.sendMessage(sender, translate(sender, "commands.enter_dungeon.usage"));
23
24
25
26
27
            return;
        }

        try {
            int dungeonId = Integer.parseInt(args.get(0));
AnimeGitB's avatar
AnimeGitB committed
28
            if (dungeonId == targetPlayer.getSceneId()) {
Secretboy's avatar
Secretboy committed
29
            	CommandHandler.sendMessage(sender, translate(sender, "commands.enter_dungeon.in_dungeon_error"));
30
31
32
            	return;
            }
            
AnimeGitB's avatar
AnimeGitB committed
33
            boolean result = targetPlayer.getServer().getDungeonManager().enterDungeon(targetPlayer.getSession().getPlayer(), 0, dungeonId);
Secretboy's avatar
Secretboy committed
34
            CommandHandler.sendMessage(sender, translate(sender, "commands.enter_dungeon.changed", dungeonId));
35
36

            if (!result) {
Secretboy's avatar
Secretboy committed
37
                CommandHandler.sendMessage(sender, translate(sender, "commands.enter_dungeon.not_found_error"));
38
39
            }
        } catch (Exception e) {
Secretboy's avatar
Secretboy committed
40
            CommandHandler.sendMessage(sender, translate(sender, "commands.enter_dungeon.usage"));
41
42
43
        }
    }
}