Player events + mail receive event

This commit is contained in:
KingRainbow44 2022-04-28 22:21:55 -04:00
parent 2e119efb86
commit 7e4021889c
No known key found for this signature in database
GPG Key ID: FC2CB64B00D257BE
3 changed files with 49 additions and 1 deletions

View File

@ -38,6 +38,7 @@ import emu.grasscutter.net.proto.ProfilePictureOuterClass.ProfilePicture;
import emu.grasscutter.net.proto.SocialDetailOuterClass.SocialDetail; import emu.grasscutter.net.proto.SocialDetailOuterClass.SocialDetail;
import emu.grasscutter.net.proto.SocialShowAvatarInfoOuterClass; import emu.grasscutter.net.proto.SocialShowAvatarInfoOuterClass;
import emu.grasscutter.server.event.game.PlayerQuitEvent; 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.GameServer;
import emu.grasscutter.server.game.GameSession; import emu.grasscutter.server.game.GameSession;
import emu.grasscutter.server.packet.send.*; import emu.grasscutter.server.packet.send.*;
@ -726,9 +727,13 @@ public class Player {
public List<Mail> getAllMail() { return this.mail; } public List<Mail> getAllMail() { return this.mail; }
public void sendMail(Mail message) { 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.mail.add(message);
this.save(); 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()) { if(this.isOnline()) {
this.sendPacket(new PacketMailChangeNotify(this, message)); 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 } // TODO: setup a way for the mail notification to show up when someone receives mail when they were offline

View File

@ -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;
}
}

View File

@ -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;
}
}