Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
ziqian zhang
Grasscutter
Commits
f4ba460d
Commit
f4ba460d
authored
Jun 23, 2022
by
KingRainbow44
Browse files
Fix `PlayerCreationEvent` to match expected logic
parent
c76f0c0e
Changes
2
Show whitespace changes
Inline
Side-by-side
src/main/java/emu/grasscutter/database/DatabaseHelper.java
View file @
f4ba460d
...
...
@@ -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
;
}
...
...
src/main/java/emu/grasscutter/server/packet/recv/HandlerGetPlayerTokenReq.java
View file @
f4ba460d
...
...
@@ -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
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment