@@ -144,57 +144,95 @@ fun config(e: EventType.ConfigEvent) {
144144@Event
145145fun playerJoin (e : EventType .PlayerJoin ) {
146146 e.player.admin(false )
147+ val player = e.player
148+ val uuid = player.uuid()
149+ val plainName = player.plainName()
150+ val locale = player.locale
151+ val con = player.con
152+
147153 scope.launch {
148- val data: PlayerData ? = getPlayerData(e.player.uuid())
154+ val data: PlayerData ? = getPlayerData(uuid)
155+ if (data != null ) {
156+ data.player = player
157+ }
149158 if (conf.account.getAuthType() == ProtectConfig .AuthType .None || ! conf.account.enabled) {
150159 if (data == null ) {
151160 val exists = suspendTransaction {
152161 ! PlayerTable
153162 .select(PlayerTable .name)
154- .where { PlayerTable .name eq e.player. plainName() }
163+ .where { PlayerTable .name eq plainName }
155164 .empty()
156165 }
157166
158167 if (! exists) {
159168 try {
160- val newData = createPlayerData(e. player)
169+ val newData = createPlayerData(player)
161170 newData.permission = " user"
162171 newData.update()
163- Events .fire(CustomEvents .PlayerDataLoad (newData))
172+ arc.Core .app.post {
173+ val activePlayer = Groups .player.find { p -> p.uuid() == uuid }
174+ if (activePlayer != null ) {
175+ Events .fire(CustomEvents .PlayerDataLoad (newData))
176+ }
177+ }
164178 } catch (e: Exception ) {
165179 Log .err(" Failed to create player data" , e)
166180 }
167181 } else {
168- val reason = Bundle (e.player.locale)[" event.player.name.duplicate" ]
169- e.player.con.kick(reason, 0L )
182+ val reason = Bundle (locale)[" event.player.name.duplicate" ]
183+ arc.Core .app.post {
184+ con.kick(reason, 0L )
185+ }
170186 }
171187 } else {
172- Events .fire(CustomEvents .PlayerDataLoad (data))
188+ arc.Core .app.post {
189+ val activePlayer = Groups .player.find { p -> p.uuid() == uuid }
190+ if (activePlayer != null ) {
191+ Events .fire(CustomEvents .PlayerDataLoad (data))
192+ }
193+ }
173194 }
174195 } else if (conf.account.getAuthType() == ProtectConfig .AuthType .Discord ) {
175196 if (data == null ) {
176197 val exists = suspendTransaction {
177198 ! PlayerTable
178199 .select(PlayerTable .name)
179- .where { PlayerTable .name eq e.player. plainName() }
200+ .where { PlayerTable .name eq plainName }
180201 .empty()
181202 }
182203
183204 if (! exists) {
184205 // data.send("event.discord.not.registered")
185206 // TODO discord 로그인 추가
186207 } else {
187- val reason = Bundle (e.player.locale)[" event.player.name.duplicate" ]
188- e.player.con.kick(reason, 0L )
208+ val reason = Bundle (locale)[" event.player.name.duplicate" ]
209+ arc.Core .app.post {
210+ con.kick(reason, 0L )
211+ }
189212 }
190213 } else {
191- Events .fire(CustomEvents .PlayerDataLoad (data))
214+ arc.Core .app.post {
215+ val activePlayer = Groups .player.find { p -> p.uuid() == uuid }
216+ if (activePlayer != null ) {
217+ Events .fire(CustomEvents .PlayerDataLoad (data))
218+ }
219+ }
192220 }
193221 } else {
194222 if (data != null ) {
195- Events .fire(CustomEvents .PlayerDataLoad (data))
223+ arc.Core .app.post {
224+ val activePlayer = Groups .player.find { p -> p.uuid() == uuid }
225+ if (activePlayer != null ) {
226+ Events .fire(CustomEvents .PlayerDataLoad (data))
227+ }
228+ }
196229 } else {
197- e.player.sendMessage(Bundle (e.player.locale)[" event.player.first.register" ])
230+ arc.Core .app.post {
231+ val activePlayer = Groups .player.find { p -> p.uuid() == uuid }
232+ if (activePlayer != null ) {
233+ activePlayer.sendMessage(Bundle (locale)[" event.player.first.register" ])
234+ }
235+ }
198236 }
199237 }
200238 }
0 commit comments