Weather.java 1.39 KB
Newer Older
Jaida Wu's avatar
Jaida Wu committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
package emu.grasscutter.command.commands;

import emu.grasscutter.command.Command;
import emu.grasscutter.command.CommandHandler;
import emu.grasscutter.game.GenshinPlayer;
import emu.grasscutter.game.props.ClimateType;
import emu.grasscutter.server.packet.send.PacketSceneAreaWeatherNotify;

import java.util.List;

@Command(label = "weather", usage = "weather <weatherId>",
        description = "Changes the weather.", aliases = {"w"}, permission = "player.weather")
public class Weather implements CommandHandler {

    @Override
KingRainbow44's avatar
KingRainbow44 committed
16
    public void execute(GenshinPlayer sender, List<String> args) {
Jaida Wu's avatar
Jaida Wu committed
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
        if (sender == null) {
            CommandHandler.sendMessage(null, "Run this command in-game.");
            return;
        }

        if (args.size() < 1) {
            CommandHandler.sendMessage(sender, "Usage: weather <weatherId>");
            return;
        }

        try {
            int weatherId = Integer.parseInt(args.get(0));

            ClimateType climate = ClimateType.getTypeByValue(weatherId);

            sender.getScene().setClimate(climate);
            sender.getScene().broadcastPacket(new PacketSceneAreaWeatherNotify(sender));
            CommandHandler.sendMessage(sender, "Changed weather to " + weatherId);
        } catch (NumberFormatException ignored) {
            CommandHandler.sendMessage(sender, "Invalid weather ID.");
        }
    }
}