WeatherCommand.java 2.08 KB
Newer Older
KingRainbow44's avatar
KingRainbow44 committed
1
2
package emu.grasscutter.command.commands;

方块君's avatar
方块君 committed
3
import emu.grasscutter.Grasscutter;
KingRainbow44's avatar
KingRainbow44 committed
4
5
import emu.grasscutter.command.Command;
import emu.grasscutter.command.CommandHandler;
Melledy's avatar
Melledy committed
6
import emu.grasscutter.game.player.Player;
KingRainbow44's avatar
KingRainbow44 committed
7
8
9
10
11
import emu.grasscutter.game.props.ClimateType;
import emu.grasscutter.server.packet.send.PacketSceneAreaWeatherNotify;

import java.util.List;

12
13
import static emu.grasscutter.utils.Language.translate;

方块君's avatar
方块君 committed
14
@Command(label = "weather", usage = "weather <weatherId> [climateId]", aliases = {"w"}, permission = "player.weather", description = "commands.weather.description")
KingRainbow44's avatar
KingRainbow44 committed
15
16
17
public final class WeatherCommand implements CommandHandler {

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

AnimeGitB's avatar
AnimeGitB committed
24
25
26
27
28
29
30
        int weatherId = 0;
        int climateId = 1;
        switch (args.size()) {
            case 2:
                try {
                    climateId = Integer.parseInt(args.get(1));
                } catch (NumberFormatException ignored) {
31
                        CommandHandler.sendMessage(sender, translate("commands.weather.invalid_id"));
AnimeGitB's avatar
AnimeGitB committed
32
33
34
35
36
                }
            case 1:
                try {
                    weatherId = Integer.parseInt(args.get(0));
                } catch (NumberFormatException ignored) {
37
                    CommandHandler.sendMessage(sender, translate("commands.weather.invalid_id"));
AnimeGitB's avatar
AnimeGitB committed
38
39
40
                }
                break;
            default:
41
                CommandHandler.sendMessage(sender, translate("commands.weather.usage"));
AnimeGitB's avatar
AnimeGitB committed
42
                return;
KingRainbow44's avatar
KingRainbow44 committed
43
44
        }

AnimeGitB's avatar
AnimeGitB committed
45
        ClimateType climate = ClimateType.getTypeByValue(climateId);
KingRainbow44's avatar
KingRainbow44 committed
46

AnimeGitB's avatar
AnimeGitB committed
47
48
49
        targetPlayer.getScene().setWeather(weatherId);
        targetPlayer.getScene().setClimate(climate);
        targetPlayer.getScene().broadcastPacket(new PacketSceneAreaWeatherNotify(targetPlayer));
50
        CommandHandler.sendMessage(sender, translate("commands.weather.success", Integer.toString(weatherId), Integer.toString(climateId)));
KingRainbow44's avatar
KingRainbow44 committed
51
52
    }
}