mirror of
https://github.com/Melledy/Grasscutter.git
synced 2024-11-23 02:34:07 +00:00
Fix PlayerCreationEvent
to match expected logic
This commit is contained in:
parent
c76f0c0e70
commit
f4ba460de1
@ -154,10 +154,15 @@ public final class DatabaseHelper {
|
||||
return DatabaseManager.getGameDatastore().find(Player.class).filter(Filters.eq("_id", id)).first();
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static Player getPlayerByAccount(Account account) {
|
||||
return DatabaseManager.getGameDatastore().find(Player.class).filter(Filters.eq("accountId", account.getId())).first();
|
||||
}
|
||||
|
||||
public static Player getPlayerByAccount(Account account, Class<? extends Player> playerClass) {
|
||||
return DatabaseManager.getGameDatastore().find(playerClass).filter(Filters.eq("accountId", account.getId())).first();
|
||||
}
|
||||
|
||||
public static boolean checkIfPlayerExists(int uid) {
|
||||
return DatabaseManager.getGameDatastore().find(Player.class).filter(Filters.eq("_id", uid)).count() > 0;
|
||||
}
|
||||
|
@ -11,7 +11,6 @@ import emu.grasscutter.net.packet.PacketOpcodes;
|
||||
import emu.grasscutter.net.proto.GetPlayerTokenReqOuterClass.GetPlayerTokenReq;
|
||||
import emu.grasscutter.net.packet.PacketHandler;
|
||||
import emu.grasscutter.server.event.game.PlayerCreationEvent;
|
||||
import emu.grasscutter.server.game.GameServer;
|
||||
import emu.grasscutter.server.game.GameSession;
|
||||
import emu.grasscutter.server.game.GameSession.SessionState;
|
||||
import emu.grasscutter.server.packet.send.PacketGetPlayerTokenRsp;
|
||||
@ -58,15 +57,15 @@ public class HandlerGetPlayerTokenReq extends PacketHandler {
|
||||
}
|
||||
}
|
||||
|
||||
// Get player
|
||||
Player player = DatabaseHelper.getPlayerByAccount(account);
|
||||
// Call creation event.
|
||||
PlayerCreationEvent event = new PlayerCreationEvent(session, Player.class); event.call();
|
||||
|
||||
// Get player.
|
||||
Player player = DatabaseHelper.getPlayerByAccount(account, event.getPlayerClass());
|
||||
|
||||
if (player == null) {
|
||||
int nextPlayerUid = DatabaseHelper.getNextPlayerId(session.getAccount().getReservedPlayerUid());
|
||||
|
||||
// Call creation event.
|
||||
PlayerCreationEvent event = new PlayerCreationEvent(session, Player.class); event.call();
|
||||
|
||||
// Create player instance from event.
|
||||
player = event.getPlayerClass().getDeclaredConstructor(GameSession.class).newInstance(session);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user