ChangeSceneCommand.java 1.68 KB
Newer Older
KingRainbow44's avatar
KingRainbow44 committed
1
2
3
4
package emu.grasscutter.command.commands;

import emu.grasscutter.command.Command;
import emu.grasscutter.command.CommandHandler;
Melledy's avatar
Melledy committed
5
import emu.grasscutter.game.player.Player;
KingRainbow44's avatar
KingRainbow44 committed
6
7
8

import java.util.List;

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

方块君's avatar
方块君 committed
11
@Command(label = "changescene", usage = "changescene <scene id>", aliases = {"scene"}, permission = "player.changescene", description = "commands.changescene.description")
KingRainbow44's avatar
KingRainbow44 committed
12
public final class ChangeSceneCommand implements CommandHandler {
13

KingRainbow44's avatar
KingRainbow44 committed
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) {
17
            CommandHandler.sendMessage(sender, translate("commands.execution.need_target"));
KingRainbow44's avatar
KingRainbow44 committed
18
19
20
            return;
        }

AnimeGitB's avatar
AnimeGitB committed
21
        if (args.size() != 1) {
22
            CommandHandler.sendMessage(sender, translate("commands.changescene.usage"));
KingRainbow44's avatar
KingRainbow44 committed
23
24
25
26
27
            return;
        }

        try {
            int sceneId = Integer.parseInt(args.get(0));
AnimeGitB's avatar
AnimeGitB committed
28
            if (sceneId == targetPlayer.getSceneId()) {
29
            	CommandHandler.sendMessage(sender, translate("commands.changescene.already_in_scene"));
30
31
32
            	return;
            }
            
AnimeGitB's avatar
AnimeGitB committed
33
            boolean result = targetPlayer.getWorld().transferPlayerToScene(targetPlayer, sceneId, targetPlayer.getPos());
34
            CommandHandler.sendMessage(sender, translate("commands.changescene.result", Integer.toString(sceneId)));
35
            
KingRainbow44's avatar
KingRainbow44 committed
36
            if (!result) {
37
                CommandHandler.sendMessage(sender, translate("commands.changescene.exists_error"));
KingRainbow44's avatar
KingRainbow44 committed
38
39
            }
        } catch (Exception e) {
40
            CommandHandler.sendMessage(sender, translate("commands.execution.argument_error"));
KingRainbow44's avatar
KingRainbow44 committed
41
42
43
        }
    }
}