ChangeSceneCommand.java 1.74 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;

11
@Command(label = "changescene", usage = "changescene <scene id>", aliases = {"scene"}, permission = "player.changescene")
KingRainbow44's avatar
KingRainbow44 committed
12
public final class ChangeSceneCommand implements CommandHandler {
13
14
15
16
17
    @Override
    public String description() {
        return translate("commands.changescene.description");
    }

KingRainbow44's avatar
KingRainbow44 committed
18
    @Override
AnimeGitB's avatar
AnimeGitB committed
19
    public void execute(Player sender, Player targetPlayer, List<String> args) {
AnimeGitB's avatar
AnimeGitB committed
20
        if (targetPlayer == null) {
21
            CommandHandler.sendMessage(sender, translate("commands.execution.need_target"));
KingRainbow44's avatar
KingRainbow44 committed
22
23
24
            return;
        }

AnimeGitB's avatar
AnimeGitB committed
25
        if (args.size() != 1) {
26
            CommandHandler.sendMessage(sender, translate("commands.changescene.usage"));
KingRainbow44's avatar
KingRainbow44 committed
27
28
29
30
31
            return;
        }

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