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;

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

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

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

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