18
18
import net .minecraft .server .players .UserWhiteListEntry ;
19
19
import net .minecraft .stats .ServerStatsCounter ;
20
20
import net .minecraft .world .level .storage .PlayerDataStorage ;
21
+ import net .minecraft .world .phys .Vec2 ;
22
+ import net .minecraft .world .phys .Vec3 ;
21
23
import org .bukkit .BanEntry ;
22
24
import org .bukkit .BanList ;
23
25
import org .bukkit .Bukkit ;
26
28
import org .bukkit .OfflinePlayer ;
27
29
import org .bukkit .Server ;
28
30
import org .bukkit .Statistic ;
31
+ import org .bukkit .World ;
29
32
import org .bukkit .ban .ProfileBanList ;
30
33
import org .bukkit .configuration .serialization .ConfigurationSerializable ;
31
34
import org .bukkit .configuration .serialization .SerializableAs ;
@@ -79,9 +82,7 @@ public String getName() {
79
82
CompoundTag data = this .getBukkitData ();
80
83
81
84
if (data != null ) {
82
- if (data .contains ("lastKnownName" )) {
83
- return data .getString ("lastKnownName" );
84
- }
85
+ return data .getString ("lastKnownName" ).orElse (null );
85
86
}
86
87
87
88
return null ;
@@ -217,10 +218,7 @@ private CompoundTag getBukkitData() {
217
218
CompoundTag result = this .getData ();
218
219
219
220
if (result != null ) {
220
- if (!result .contains ("bukkit" )) {
221
- result .put ("bukkit" , new CompoundTag ());
222
- }
223
- result = result .getCompound ("bukkit" );
221
+ result = result .getCompound ("bukkit" ).orElse (null );
224
222
}
225
223
226
224
return result ;
@@ -238,12 +236,10 @@ public long getFirstPlayed() {
238
236
CompoundTag data = this .getBukkitData ();
239
237
240
238
if (data != null ) {
241
- if (data .contains ("firstPlayed" )) {
242
- return data .getLong ("firstPlayed" );
243
- } else {
239
+ return data .getLong ("firstPlayed" ).orElseGet (() -> {
244
240
File file = this .getDataFile ();
245
241
return file .lastModified ();
246
- }
242
+ });
247
243
} else {
248
244
return 0 ;
249
245
}
@@ -257,12 +253,10 @@ public long getLastPlayed() {
257
253
CompoundTag data = this .getBukkitData ();
258
254
259
255
if (data != null ) {
260
- if (data .contains ("lastPlayed" )) {
261
- return data .getLong ("lastPlayed" );
262
- } else {
256
+ return data .getLong ("lastPlayed" ).orElseGet (() -> {
263
257
File file = this .getDataFile ();
264
258
return file .lastModified ();
265
- }
259
+ });
266
260
} else {
267
261
return 0 ;
268
262
}
@@ -282,13 +276,11 @@ public long getLastLogin() {
282
276
CompoundTag data = getPaperData ();
283
277
284
278
if (data != null ) {
285
- if (data .contains ("LastLogin" )) {
286
- return data .getLong ("LastLogin" );
287
- } else {
279
+ return data .getLong ("LastLogin" ).orElseGet (() -> {
288
280
// if the player file cannot provide accurate data, this is probably the closest we can approximate
289
281
File file = getDataFile ();
290
282
return file .lastModified ();
291
- }
283
+ });
292
284
} else {
293
285
return 0 ;
294
286
}
@@ -302,13 +294,11 @@ public long getLastSeen() {
302
294
CompoundTag data = getPaperData ();
303
295
304
296
if (data != null ) {
305
- if (data .contains ("LastSeen" )) {
306
- return data .getLong ("LastSeen" );
307
- } else {
297
+ return data .getLong ("LastSeen" ).orElseGet (() -> {
308
298
// if the player file cannot provide accurate data, this is probably the closest we can approximate
309
299
File file = getDataFile ();
310
300
return file .lastModified ();
311
- }
301
+ });
312
302
} else {
313
303
return 0 ;
314
304
}
@@ -318,10 +308,7 @@ private CompoundTag getPaperData() {
318
308
CompoundTag result = getData ();
319
309
320
310
if (result != null ) {
321
- if (!result .contains ("Paper" )) {
322
- result .put ("Paper" , new CompoundTag ());
323
- }
324
- result = result .getCompound ("Paper" );
311
+ result = result .getCompound ("Paper" ).orElse (null );
325
312
}
326
313
327
314
return result ;
@@ -338,7 +325,7 @@ public io.papermc.paper.persistence.PersistentDataContainerView getPersistentDat
338
325
this .persistentDataContainerView = new io .papermc .paper .persistence .PaperPersistentDataContainerView (DATA_TYPE_REGISTRY ) {
339
326
340
327
private CompoundTag getPersistentTag () {
341
- return net .minecraft .Optionull .map (CraftOfflinePlayer .this .getData (), data -> data .getCompound ("BukkitValues" ));
328
+ return net .minecraft .Optionull .map (CraftOfflinePlayer .this .getData (), data -> data .getCompound ("BukkitValues" ). orElse ( null ) );
342
329
}
343
330
344
331
@ Override
@@ -358,10 +345,12 @@ public net.minecraft.nbt.Tag getTag(String key) {
358
345
359
346
@ Override
360
347
public Location getLastDeathLocation () {
361
- if (this .getData ().contains ("LastDeathLocation" , 10 )) {
362
- return GlobalPos .CODEC .parse (NbtOps .INSTANCE , this .getData ().get ("LastDeathLocation" )).result ().map (CraftLocation ::fromGlobalPos ).orElse (null );
348
+ CompoundTag data = this .getData ();
349
+ if (data == null ) {
350
+ return null ;
363
351
}
364
- return null ;
352
+
353
+ return data .read ("LastDeathLocation" , GlobalPos .CODEC ).map (CraftLocation ::fromGlobalPos ).orElse (null );
365
354
}
366
355
367
356
@ Override
@@ -371,18 +360,17 @@ public Location getLocation() {
371
360
return null ;
372
361
}
373
362
374
- if (data .contains ("Pos" ) && data .contains ("Rotation" )) {
375
- ListTag position = (ListTag ) data .get ("Pos" );
376
- ListTag rotation = (ListTag ) data .get ("Rotation" );
377
-
378
- UUID uuid = new UUID (data .getLong ("WorldUUIDMost" ), data .getLong ("WorldUUIDLeast" ));
363
+ Vec3 pos = data .read ("Pos" , Vec3 .CODEC ).orElse (null );
364
+ Vec2 rot = data .read ("Rotation" , Vec2 .CODEC ).orElse (null );
365
+ if (pos != null && rot != null ) {
366
+ Long msb = data .getLong ("WorldUUIDMost" ).orElse (null );
367
+ Long lsb = data .getLong ("WorldUUIDLeast" ).orElse (null );
368
+ World world = msb != null && lsb != null ? this .server .getWorld (new UUID (msb , lsb )) : null ;
379
369
380
- return new Location (this .server .getWorld (uuid ),
381
- position .getDouble (0 ),
382
- position .getDouble (1 ),
383
- position .getDouble (2 ),
384
- rotation .getFloat (0 ),
385
- rotation .getFloat (1 )
370
+ return new Location (
371
+ world ,
372
+ pos .x (), pos .y (), pos .z (),
373
+ rot .x , rot .y
386
374
);
387
375
}
388
376
0 commit comments