mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2025-01-10 18:12:53 +08:00
Create player creation event & move join event to player
This commit is contained in:
parent
4db1724d06
commit
f73a713fac
@ -37,6 +37,7 @@ import emu.grasscutter.net.proto.PlayerWorldLocationInfoOuterClass;
|
|||||||
import emu.grasscutter.net.proto.ProfilePictureOuterClass.ProfilePicture;
|
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.PlayerJoinEvent;
|
||||||
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.event.player.PlayerReceiveMailEvent;
|
||||||
import emu.grasscutter.server.game.GameServer;
|
import emu.grasscutter.server.game.GameServer;
|
||||||
@ -1014,6 +1015,11 @@ public class Player {
|
|||||||
|
|
||||||
// First notify packets sent
|
// First notify packets sent
|
||||||
this.setHasSentAvatarDataNotify(true);
|
this.setHasSentAvatarDataNotify(true);
|
||||||
|
|
||||||
|
// Call join event.
|
||||||
|
PlayerJoinEvent event = new PlayerJoinEvent(this); event.call();
|
||||||
|
if(event.isCanceled()) // If event is not cancelled, continue.
|
||||||
|
session.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onLogout() {
|
public void onLogout() {
|
||||||
|
@ -0,0 +1,27 @@
|
|||||||
|
package emu.grasscutter.server.event.game;
|
||||||
|
|
||||||
|
import emu.grasscutter.game.player.Player;
|
||||||
|
import emu.grasscutter.server.event.types.GameEvent;
|
||||||
|
import emu.grasscutter.server.game.GameSession;
|
||||||
|
|
||||||
|
public final class PlayerCreationEvent extends GameEvent {
|
||||||
|
private final GameSession session;
|
||||||
|
private Class<? extends Player> playerClass;
|
||||||
|
|
||||||
|
public PlayerCreationEvent(GameSession session, Class<? extends Player> playerClass) {
|
||||||
|
this.session = session;
|
||||||
|
this.playerClass = playerClass;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GameSession getSession() {
|
||||||
|
return this.session;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPlayerClass(Class<? extends Player> playerClass) {
|
||||||
|
this.playerClass = playerClass;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Class<? extends Player> getPlayerClass() {
|
||||||
|
return this.playerClass;
|
||||||
|
}
|
||||||
|
}
|
@ -13,7 +13,7 @@ import emu.grasscutter.net.packet.Opcodes;
|
|||||||
import emu.grasscutter.net.packet.PacketOpcodes;
|
import emu.grasscutter.net.packet.PacketOpcodes;
|
||||||
import emu.grasscutter.net.proto.SetPlayerBornDataReqOuterClass.SetPlayerBornDataReq;
|
import emu.grasscutter.net.proto.SetPlayerBornDataReqOuterClass.SetPlayerBornDataReq;
|
||||||
import emu.grasscutter.net.packet.PacketHandler;
|
import emu.grasscutter.net.packet.PacketHandler;
|
||||||
import emu.grasscutter.server.event.game.PlayerJoinEvent;
|
import emu.grasscutter.server.event.game.PlayerCreationEvent;
|
||||||
import emu.grasscutter.server.game.GameSession;
|
import emu.grasscutter.server.game.GameSession;
|
||||||
import emu.grasscutter.server.game.GameSession.SessionState;
|
import emu.grasscutter.server.game.GameSession.SessionState;
|
||||||
|
|
||||||
@ -40,8 +40,10 @@ public class HandlerSetPlayerBornDataReq extends PacketHandler {
|
|||||||
nickname = "Traveler";
|
nickname = "Traveler";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create character
|
// Call creation event.
|
||||||
Player player = new Player(session);
|
PlayerCreationEvent event = new PlayerCreationEvent(session, Player.class); event.call();
|
||||||
|
// Create player instance from event.
|
||||||
|
Player player = event.getPlayerClass().getDeclaredConstructor(GameSession.class).newInstance(session);
|
||||||
player.setNickname(nickname);
|
player.setNickname(nickname);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -92,10 +94,5 @@ public class HandlerSetPlayerBornDataReq extends PacketHandler {
|
|||||||
Grasscutter.getLogger().error("Error creating player object: ", e);
|
Grasscutter.getLogger().error("Error creating player object: ", e);
|
||||||
session.close();
|
session.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Call join event.
|
|
||||||
PlayerJoinEvent event = new PlayerJoinEvent(player); event.call();
|
|
||||||
if(event.isCanceled()) // If event is not cancelled, continue.
|
|
||||||
session.close();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user