WeatherCommand.java 2.15 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;

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

17
18
19
20
21
    @Override
    public String description() {
        return translate("commands.weather.description");
    }

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

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

AnimeGitB's avatar
AnimeGitB committed
50
        ClimateType climate = ClimateType.getTypeByValue(climateId);
KingRainbow44's avatar
KingRainbow44 committed
51

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