WeatherCommand.java 1.88 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
import emu.grasscutter.game.props.ClimateType;

import java.util.List;

10
@Command(label = "weather", aliases = {"w"}, usage = {"weather [<weatherId>] [<climateType>]"}, permission = "player.weather", permissionTargeted = "player.weather.others")
KingRainbow44's avatar
KingRainbow44 committed
11
12
13
public final class WeatherCommand implements CommandHandler {

    @Override
AnimeGitB's avatar
AnimeGitB committed
14
    public void execute(Player sender, Player targetPlayer, List<String> args) {
AnimeGitB's avatar
AnimeGitB committed
15
        int weatherId = targetPlayer.getWeatherId();
AnimeGitB's avatar
AnimeGitB committed
16
17
18
        ClimateType climate = ClimateType.CLIMATE_NONE;  // Sending ClimateType.CLIMATE_NONE to Scene.setWeather will use the default climate for that weather

        if (args.isEmpty()) {
AnimeGitB's avatar
AnimeGitB committed
19
            climate = targetPlayer.getClimate();
AnimeGitB's avatar
AnimeGitB committed
20
21
22
23
24
25
26
27
28
            CommandHandler.sendTranslatedMessage(sender, "commands.weather.status", Integer.toString(weatherId), climate.getShortName());
            return;
        }

        for (String arg : args) {
            ClimateType c = ClimateType.getTypeByShortName(arg.toLowerCase());
            if (c != ClimateType.CLIMATE_NONE) {
                climate = c;
            } else {
AnimeGitB's avatar
AnimeGitB committed
29
                try {
AnimeGitB's avatar
AnimeGitB committed
30
                    weatherId = Integer.parseInt(arg);
AnimeGitB's avatar
AnimeGitB committed
31
                } catch (NumberFormatException ignored) {
AnimeGitB's avatar
AnimeGitB committed
32
33
34
                    CommandHandler.sendTranslatedMessage(sender, "commands.generic.invalid.id");
                    CommandHandler.sendTranslatedMessage(sender, "commands.weather.usage");
                    return;
AnimeGitB's avatar
AnimeGitB committed
35
                }
AnimeGitB's avatar
AnimeGitB committed
36
            }
KingRainbow44's avatar
KingRainbow44 committed
37
38
        }

AnimeGitB's avatar
AnimeGitB committed
39
40
        targetPlayer.setWeather(weatherId, climate);
        climate = targetPlayer.getClimate();  // Might be different to what we set
AnimeGitB's avatar
AnimeGitB committed
41
        CommandHandler.sendTranslatedMessage(sender, "commands.weather.success", Integer.toString(weatherId), climate.getShortName());
KingRainbow44's avatar
KingRainbow44 committed
42
43
    }
}