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

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

    @Override
AnimeGitB's avatar
AnimeGitB committed
17
    public void execute(Player sender, Player targetPlayer, List<String> args) {
KingRainbow44's avatar
KingRainbow44 committed
18
        if (sender == null) {
方块君's avatar
方块君 committed
19
            CommandHandler.sendMessage(null, Grasscutter.getLanguage().Run_this_command_in_game);
KingRainbow44's avatar
KingRainbow44 committed
20
21
22
23
            return;
        }

        if (args.size() < 1) {
方块君's avatar
方块君 committed
24
            CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Weather_usage);
KingRainbow44's avatar
KingRainbow44 committed
25
26
27
28
29
            return;
        }

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

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

yarik0chka's avatar
yarik0chka committed
34
            sender.getScene().setWeather(weatherId);
KingRainbow44's avatar
KingRainbow44 committed
35
36
            sender.getScene().setClimate(climate);
            sender.getScene().broadcastPacket(new PacketSceneAreaWeatherNotify(sender));
37
            CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Weather_message.replace("{weatherId}", Integer.toString(weatherId)).replace("{climateId}", Integer.toString(climateId)));
KingRainbow44's avatar
KingRainbow44 committed
38
        } catch (NumberFormatException ignored) {
方块君's avatar
方块君 committed
39
            CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Weather_invalid_id);
KingRainbow44's avatar
KingRainbow44 committed
40
41
42
        }
    }
}