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;

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) {
AnimeGitB's avatar
AnimeGitB committed
18
        if (targetPlayer == null) {
19
            CommandHandler.sendMessage(sender, translate("commands.execution.need_target"));
KingRainbow44's avatar
KingRainbow44 committed
20
21
22
            return;
        }

AnimeGitB's avatar
AnimeGitB committed
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
        int weatherId = 0;
        int climateId = 1;
        switch (args.size()) {
            case 2:
                try {
                    climateId = Integer.parseInt(args.get(1));
                } catch (NumberFormatException ignored) {
                    CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Weather_invalid_id);
                }
            case 1:
                try {
                    weatherId = Integer.parseInt(args.get(0));
                } catch (NumberFormatException ignored) {
                    CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Weather_invalid_id);
                }
                break;
            default:
                CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Weather_usage);
                return;
KingRainbow44's avatar
KingRainbow44 committed
42
43
        }

AnimeGitB's avatar
AnimeGitB committed
44
        ClimateType climate = ClimateType.getTypeByValue(climateId);
KingRainbow44's avatar
KingRainbow44 committed
45

AnimeGitB's avatar
AnimeGitB committed
46
47
48
        targetPlayer.getScene().setWeather(weatherId);
        targetPlayer.getScene().setClimate(climate);
        targetPlayer.getScene().broadcastPacket(new PacketSceneAreaWeatherNotify(targetPlayer));
AnimeGitB's avatar
AnimeGitB committed
49
        CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Weather_message.replace("{weatherId}", Integer.toString(weatherId)).replace("{climateId}", Integer.toString(climateId)));
KingRainbow44's avatar
KingRainbow44 committed
50
51
52

    }
}