diff --git a/src/main/java/emu/grasscutter/game/player/Player.java b/src/main/java/emu/grasscutter/game/player/Player.java index 32e583fc5..46205d01d 100644 --- a/src/main/java/emu/grasscutter/game/player/Player.java +++ b/src/main/java/emu/grasscutter/game/player/Player.java @@ -38,6 +38,7 @@ import emu.grasscutter.net.proto.ProfilePictureOuterClass.ProfilePicture; import emu.grasscutter.net.proto.SocialDetailOuterClass.SocialDetail; import emu.grasscutter.net.proto.SocialShowAvatarInfoOuterClass; import emu.grasscutter.server.event.game.PlayerQuitEvent; +import emu.grasscutter.server.event.player.PlayerReceiveMailEvent; import emu.grasscutter.server.game.GameServer; import emu.grasscutter.server.game.GameSession; import emu.grasscutter.server.packet.send.*; @@ -726,9 +727,13 @@ public class Player { public List getAllMail() { return this.mail; } public void sendMail(Mail message) { + // Call mail receive event. + PlayerReceiveMailEvent event = new PlayerReceiveMailEvent(this, message); event.call(); + if(event.isCanceled()) return; message = event.getMessage(); + this.mail.add(message); this.save(); - Grasscutter.getLogger().info("Mail sent to user [" + this.getUid() + ":" + this.getNickname() + "]!"); + Grasscutter.getLogger().debug("Mail sent to user [" + this.getUid() + ":" + this.getNickname() + "]!"); if(this.isOnline()) { this.sendPacket(new PacketMailChangeNotify(this, message)); } // TODO: setup a way for the mail notification to show up when someone receives mail when they were offline diff --git a/src/main/java/emu/grasscutter/server/event/player/PlayerReceiveMailEvent.java b/src/main/java/emu/grasscutter/server/event/player/PlayerReceiveMailEvent.java new file mode 100644 index 000000000..c38740ae4 --- /dev/null +++ b/src/main/java/emu/grasscutter/server/event/player/PlayerReceiveMailEvent.java @@ -0,0 +1,24 @@ +package emu.grasscutter.server.event.player; + +import emu.grasscutter.game.mail.Mail; +import emu.grasscutter.game.player.Player; +import emu.grasscutter.server.event.Cancellable; +import emu.grasscutter.server.event.types.PlayerEvent; + +public final class PlayerReceiveMailEvent extends PlayerEvent implements Cancellable { + private Mail message; + + public PlayerReceiveMailEvent(Player player, Mail message) { + super(player); + + this.message = message; + } + + public void setMessage(Mail message) { + this.message = message; + } + + public Mail getMessage() { + return this.message; + } +} diff --git a/src/main/java/emu/grasscutter/server/event/types/PlayerEvent.java b/src/main/java/emu/grasscutter/server/event/types/PlayerEvent.java new file mode 100644 index 000000000..eb55f2d58 --- /dev/null +++ b/src/main/java/emu/grasscutter/server/event/types/PlayerEvent.java @@ -0,0 +1,19 @@ +package emu.grasscutter.server.event.types; + +import emu.grasscutter.game.player.Player; +import emu.grasscutter.server.event.Event; + +/** + * An event that is related to player interactions. + */ +public abstract class PlayerEvent extends Event { + protected final Player player; + + public PlayerEvent(Player player) { + this.player = player; + } + + public Player getPlayer() { + return this.player; + } +}