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", permissionTargeted = "player.changescene.others", 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());
KingRainbow44's avatar
KingRainbow44 committed
34
            if (!result) {
35
                CommandHandler.sendMessage(sender, translate("commands.changescene.exists_error"));
36
                return;
KingRainbow44's avatar
KingRainbow44 committed
37
            }
38
39

            CommandHandler.sendMessage(sender, translate("commands.changescene.success", Integer.toString(sceneId)));
KingRainbow44's avatar
KingRainbow44 committed
40
        } catch (Exception e) {
41
            CommandHandler.sendMessage(sender, translate("commands.execution.argument_error"));
KingRainbow44's avatar
KingRainbow44 committed
42
43
44
        }
    }
}