From 0dabb4c7c230c7044e708e2eed16d04ad5844ac2 Mon Sep 17 00:00:00 2001 From: Jaida Wu Date: Wed, 20 Apr 2022 21:03:30 +0800 Subject: [PATCH] Add weather command Signed-off-by: Jaida Wu --- .../grasscutter/command/commands/Weather.java | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/main/java/emu/grasscutter/command/commands/Weather.java diff --git a/src/main/java/emu/grasscutter/command/commands/Weather.java b/src/main/java/emu/grasscutter/command/commands/Weather.java new file mode 100644 index 000000000..569080820 --- /dev/null +++ b/src/main/java/emu/grasscutter/command/commands/Weather.java @@ -0,0 +1,39 @@ +package emu.grasscutter.command.commands; + +import emu.grasscutter.command.Command; +import emu.grasscutter.command.CommandHandler; +import emu.grasscutter.game.GenshinPlayer; +import emu.grasscutter.game.props.ClimateType; +import emu.grasscutter.server.packet.send.PacketSceneAreaWeatherNotify; + +import java.util.List; + +@Command(label = "weather", usage = "weather ", + description = "Changes the weather.", aliases = {"w"}, permission = "player.weather") +public class Weather implements CommandHandler { + + @Override + public void onCommand(GenshinPlayer sender, List args) { + if (sender == null) { + CommandHandler.sendMessage(null, "Run this command in-game."); + return; + } + + if (args.size() < 1) { + CommandHandler.sendMessage(sender, "Usage: weather "); + return; + } + + try { + int weatherId = Integer.parseInt(args.get(0)); + + ClimateType climate = ClimateType.getTypeByValue(weatherId); + + sender.getScene().setClimate(climate); + sender.getScene().broadcastPacket(new PacketSceneAreaWeatherNotify(sender)); + CommandHandler.sendMessage(sender, "Changed weather to " + weatherId); + } catch (NumberFormatException ignored) { + CommandHandler.sendMessage(sender, "Invalid weather ID."); + } + } +}