mirror of
https://github.com/Melledy/Grasscutter.git
synced 2024-11-27 22:18:09 +00:00
Player events + mail receive event
This commit is contained in:
parent
2e119efb86
commit
7e4021889c
@ -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
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user