WeatherCommand.java 1.54 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
9
10
import emu.grasscutter.game.props.ClimateType;
import emu.grasscutter.server.packet.send.PacketSceneAreaWeatherNotify;

import java.util.List;

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

    @Override
16
    public void execute(Player sender, List<String> args) {
KingRainbow44's avatar
KingRainbow44 committed
17
18
19
20
21
22
        if (sender == null) {
            CommandHandler.sendMessage(null, "Run this command in-game.");
            return;
        }

        if (args.size() < 1) {
yarik0chka's avatar
yarik0chka committed
23
            CommandHandler.sendMessage(sender, "Usage: weather <weatherId> [climateId]");
KingRainbow44's avatar
KingRainbow44 committed
24
25
26
27
28
            return;
        }

        try {
            int weatherId = Integer.parseInt(args.get(0));
yarik0chka's avatar
yarik0chka committed
29
            int climateId = args.size() > 1 ? Integer.parseInt(args.get(1)) : 1;
KingRainbow44's avatar
KingRainbow44 committed
30

yarik0chka's avatar
yarik0chka committed
31
            ClimateType climate = ClimateType.getTypeByValue(climateId);
KingRainbow44's avatar
KingRainbow44 committed
32

yarik0chka's avatar
yarik0chka committed
33
            sender.getScene().setWeather(weatherId);
KingRainbow44's avatar
KingRainbow44 committed
34
35
            sender.getScene().setClimate(climate);
            sender.getScene().broadcastPacket(new PacketSceneAreaWeatherNotify(sender));
yarik0chka's avatar
yarik0chka committed
36
            CommandHandler.sendMessage(sender, "Changed weather to " + weatherId + " with climate " + climateId);
KingRainbow44's avatar
KingRainbow44 committed
37
        } catch (NumberFormatException ignored) {
yarik0chka's avatar
yarik0chka committed
38
            CommandHandler.sendMessage(sender, "Invalid ID.");
KingRainbow44's avatar
KingRainbow44 committed
39
40
41
        }
    }
}