mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2025-12-17 09:25:06 +01:00
Add default Climates per weather
This commit is contained in:
@@ -1,47 +1,45 @@
|
||||
package emu.grasscutter.command.commands;
|
||||
|
||||
import emu.grasscutter.Grasscutter;
|
||||
import emu.grasscutter.command.Command;
|
||||
import emu.grasscutter.command.CommandHandler;
|
||||
import emu.grasscutter.game.player.Player;
|
||||
import emu.grasscutter.game.props.ClimateType;
|
||||
import emu.grasscutter.server.packet.send.PacketSceneAreaWeatherNotify;
|
||||
import emu.grasscutter.game.world.Scene;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static emu.grasscutter.utils.Language.translate;
|
||||
|
||||
@Command(label = "weather", usage = "weather <climate type(weatherId)> <weather type(climateId)>", aliases = {"w"}, permission = "player.weather", permissionTargeted = "player.weather.others", description = "commands.weather.description")
|
||||
@Command(label = "weather", usage = "weather [weatherId] [climateType]", aliases = {"w"}, permission = "player.weather", permissionTargeted = "player.weather.others", description = "commands.weather.description")
|
||||
public final class WeatherCommand implements CommandHandler {
|
||||
|
||||
@Override
|
||||
public void execute(Player sender, Player targetPlayer, List<String> args) {
|
||||
int weatherId = 0;
|
||||
int climateId = 1;
|
||||
switch (args.size()) {
|
||||
case 2:
|
||||
try {
|
||||
climateId = Integer.parseInt(args.get(1));
|
||||
} catch (NumberFormatException ignored) {
|
||||
CommandHandler.sendMessage(sender, translate(sender, "commands.weather.invalid_id"));
|
||||
}
|
||||
case 1:
|
||||
try {
|
||||
weatherId = Integer.parseInt(args.get(0));
|
||||
} catch (NumberFormatException ignored) {
|
||||
CommandHandler.sendMessage(sender, translate(sender, "commands.weather.invalid_id"));
|
||||
}
|
||||
break;
|
||||
default:
|
||||
CommandHandler.sendMessage(sender, translate(sender, "commands.weather.usage"));
|
||||
return;
|
||||
Scene scene = targetPlayer.getScene();
|
||||
int weatherId = scene.getWeather();
|
||||
ClimateType climate = ClimateType.CLIMATE_NONE; // Sending ClimateType.CLIMATE_NONE to Scene.setWeather will use the default climate for that weather
|
||||
|
||||
if (args.isEmpty()) {
|
||||
climate = scene.getClimate();
|
||||
CommandHandler.sendTranslatedMessage(sender, "commands.weather.status", Integer.toString(weatherId), climate.getShortName());
|
||||
return;
|
||||
}
|
||||
|
||||
ClimateType climate = ClimateType.getTypeByValue(climateId);
|
||||
for (String arg : args) {
|
||||
ClimateType c = ClimateType.getTypeByShortName(arg.toLowerCase());
|
||||
if (c != ClimateType.CLIMATE_NONE) {
|
||||
climate = c;
|
||||
} else {
|
||||
try {
|
||||
weatherId = Integer.parseInt(arg);
|
||||
} catch (NumberFormatException ignored) {
|
||||
CommandHandler.sendTranslatedMessage(sender, "commands.generic.invalid.id");
|
||||
CommandHandler.sendTranslatedMessage(sender, "commands.weather.usage");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
targetPlayer.getScene().setWeather(weatherId);
|
||||
targetPlayer.getScene().setClimate(climate);
|
||||
targetPlayer.getScene().broadcastPacket(new PacketSceneAreaWeatherNotify(targetPlayer));
|
||||
CommandHandler.sendMessage(sender, translate(sender, "commands.weather.success", Integer.toString(weatherId), Integer.toString(climateId)));
|
||||
scene.setWeather(weatherId, climate);
|
||||
climate = scene.getClimate(); // Might be different to what we set
|
||||
CommandHandler.sendTranslatedMessage(sender, "commands.weather.success", Integer.toString(weatherId), climate.getShortName());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user