Commit d359e511 authored by KingRainbow44's avatar KingRainbow44
Browse files

Player events + mail receive event

parent d7016138
...@@ -38,6 +38,7 @@ import emu.grasscutter.net.proto.ProfilePictureOuterClass.ProfilePicture; ...@@ -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 { ...@@ -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
......
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;
}
}
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;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment