diff --git a/src/main/java/emu/grasscutter/game/player/Player.java b/src/main/java/emu/grasscutter/game/player/Player.java index 4f1db9c55..fa8c29590 100644 --- a/src/main/java/emu/grasscutter/game/player/Player.java +++ b/src/main/java/emu/grasscutter/game/player/Player.java @@ -67,6 +67,7 @@ import emu.grasscutter.net.proto.SocialDetailOuterClass.SocialDetail; import emu.grasscutter.net.proto.SocialShowAvatarInfoOuterClass; import emu.grasscutter.plugin.api.PlayerHook; import emu.grasscutter.scripts.data.SceneRegion; +import emu.grasscutter.server.event.player.PlayerEnterAreaEvent; import emu.grasscutter.server.event.player.PlayerJoinEvent; import emu.grasscutter.server.event.player.PlayerQuitEvent; import emu.grasscutter.server.game.GameServer; @@ -148,6 +149,8 @@ public class Player implements PlayerHook { @Transient private Scene scene; // Synchronized getter and setter @Transient @Getter private int weatherId = 0; @Transient @Getter private ClimateType climate = ClimateType.CLIMATE_SUNNY; + @Transient @Getter private int areaId = 0; + @Transient @Getter private int areaType = 0; // Player managers go here @Getter private transient AvatarStorage avatars; @@ -420,11 +423,11 @@ public class Player implements PlayerHook { this.session.send(new PacketSceneAreaWeatherNotify(this)); } - synchronized public void setWeather(int weather) { + public synchronized void setWeather(int weather) { this.setWeather(weather, ClimateType.CLIMATE_NONE); } - synchronized public void setWeather(int weatherId, ClimateType climate) { + public synchronized void setWeather(int weatherId, ClimateType climate) { // Lookup default climate for this weather if (climate == ClimateType.CLIMATE_NONE) { WeatherData w = GameData.getWeatherDataMap().get(weatherId); @@ -437,6 +440,21 @@ public class Player implements PlayerHook { this.session.send(new PacketSceneAreaWeatherNotify(this)); } + /** + * Sets the player's weather and climate. + * + * @param areaId The area ID. + * @param areaType The area type. + */ + public void setArea(int areaId, int areaType) { + this.areaId = areaId; + this.areaType = areaType; + + // Call the event. + var event = new PlayerEnterAreaEvent(this); + event.call(); + } + public void setNickname(String nickName) { this.nickname = nickName; this.updateProfile(); diff --git a/src/main/java/emu/grasscutter/server/event/player/PlayerEnterAreaEvent.java b/src/main/java/emu/grasscutter/server/event/player/PlayerEnterAreaEvent.java new file mode 100644 index 000000000..88c48c25e --- /dev/null +++ b/src/main/java/emu/grasscutter/server/event/player/PlayerEnterAreaEvent.java @@ -0,0 +1,16 @@ +package emu.grasscutter.server.event.player; + +import emu.grasscutter.game.player.Player; +import emu.grasscutter.server.event.types.PlayerEvent; +import lombok.Getter; + +public final class PlayerEnterAreaEvent extends PlayerEvent { + @Getter private final int areaId, areaType; + + public PlayerEnterAreaEvent(Player player) { + super(player); + + this.areaId = player.getAreaId(); + this.areaType = player.getAreaType(); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerEnterWorldAreaReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerEnterWorldAreaReq.java index def3d4e1d..9169463b8 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerEnterWorldAreaReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerEnterWorldAreaReq.java @@ -16,6 +16,7 @@ public class HandlerEnterWorldAreaReq extends PacketHandler { PacketHead head = PacketHead.parseFrom(header); EnterWorldAreaReq enterWorld = EnterWorldAreaReq.parseFrom(payload); + session.getPlayer().setArea(enterWorld.getAreaId(), enterWorld.getAreaType()); session.send(new PacketEnterWorldAreaRsp(head.getClientSequenceId(), enterWorld)); // session.send(new PacketScenePlayerLocationNotify(session.getPlayer())); }