Commit f4ba460d authored by KingRainbow44's avatar KingRainbow44
Browse files

Fix `PlayerCreationEvent` to match expected logic

parent c76f0c0e
......@@ -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);
......
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