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

tester233's avatar
tester233 committed
11
@Command(label = "changescene", usage = "changescene <sceneId>", 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 (args.size() != 1) {
Secretboy's avatar
Secretboy committed
17
            CommandHandler.sendMessage(sender, translate(sender, "commands.changescene.usage"));
KingRainbow44's avatar
KingRainbow44 committed
18
19
20
21
22
            return;
        }

        try {
            int sceneId = Integer.parseInt(args.get(0));
AnimeGitB's avatar
AnimeGitB committed
23
            if (sceneId == targetPlayer.getSceneId()) {
Secretboy's avatar
Secretboy committed
24
            	CommandHandler.sendMessage(sender, translate(sender, "commands.changescene.already_in_scene"));
25
26
27
            	return;
            }
            
AnimeGitB's avatar
AnimeGitB committed
28
            boolean result = targetPlayer.getWorld().transferPlayerToScene(targetPlayer, sceneId, targetPlayer.getPos());
KingRainbow44's avatar
KingRainbow44 committed
29
            if (!result) {
Secretboy's avatar
Secretboy committed
30
                CommandHandler.sendMessage(sender, translate(sender, "commands.changescene.exists_error"));
31
                return;
KingRainbow44's avatar
KingRainbow44 committed
32
            }
33

Secretboy's avatar
Secretboy committed
34
            CommandHandler.sendMessage(sender, translate(sender, "commands.changescene.success", Integer.toString(sceneId)));
KingRainbow44's avatar
KingRainbow44 committed
35
        } catch (Exception e) {
Secretboy's avatar
Secretboy committed
36
            CommandHandler.sendMessage(sender, translate(sender, "commands.execution.argument_error"));
KingRainbow44's avatar
KingRainbow44 committed
37
38
39
        }
    }
}