@@ -1116,7 +1116,6 @@ open class Player(
11161116
11171117 fun checkNearEntities () {
11181118 for (entity in level!! .getNearbyEntities(boundingBox.grow(1.0 , 0.5 , 1.0 ), this )) {
1119- if (entity == null ) continue
11201119 entity.scheduleUpdate()
11211120
11221121 if (! entity.isAlive() || ! this .isAlive()) {
@@ -1485,8 +1484,8 @@ open class Player(
14851484
14861485 adventureSettings.init (nbt)
14871486
1488- val level: Level ?
1489- if (Server .instance.getLevelByName(nbt.getString( " Level " )). also { level = it } == null ) {
1487+ val level: Level ? = Server .instance.getLevelByName(nbt.getString( " Level " ))
1488+ if (level == null ) {
14901489 this .level = Server .instance.defaultLevel
14911490 nbt.putString(" Level" , this .level!! .getLevelName())
14921491 val spawnLocation = this .level!! .safeSpawn
@@ -1905,10 +1904,10 @@ open class Player(
19051904 get() = this
19061905
19071906 override val firstPlayed: Long?
1908- get() = if ( this . namedTag != null ) namedTag !! .getLong(" firstPlayed" ) else null
1907+ get() = namedTag.getLong(" firstPlayed" )
19091908
19101909 override val lastPlayed: Long?
1911- get() = if ( this . namedTag != null ) namedTag !! .getLong(" lastPlayed" ) else null
1910+ get() = namedTag.getLong(" lastPlayed" )
19121911
19131912 override fun hasPlayedBefore (): Boolean {
19141913 return this .playedBefore
@@ -2908,18 +2907,16 @@ open class Player(
29082907 // 鞘翅检查和耐久计算
29092908 if (this .isGliding()) {
29102909 val playerInventory = this .inventory
2911- if (playerInventory != null ) {
2912- val chestplate = playerInventory.chestplate
2913- if ((chestplate == null || chestplate.id != ItemID .ELYTRA )) {
2910+ val chestplate = playerInventory.chestplate
2911+ if (chestplate.id != ItemID .ELYTRA ) {
2912+ this .setGliding(false )
2913+ } else if (this .age % (20 * (chestplate.getEnchantmentLevel(Enchantment .ID_DURABILITY ) + 1 )) == 0 && ! isCreative) {
2914+ val newDamage = chestplate.damage + 1
2915+ if (newDamage < chestplate.maxDurability) {
2916+ chestplate.damage = newDamage
2917+ playerInventory.setChestplate(chestplate)
2918+ } else {
29142919 this .setGliding(false )
2915- } else if (this .age % (20 * (chestplate.getEnchantmentLevel(Enchantment .ID_DURABILITY ) + 1 )) == 0 && ! isCreative) {
2916- val newDamage = chestplate.damage + 1
2917- if (newDamage < chestplate.maxDurability) {
2918- chestplate.damage = newDamage
2919- playerInventory.setChestplate(chestplate)
2920- } else {
2921- this .setGliding(false )
2922- }
29232920 }
29242921 }
29252922 }
@@ -3830,38 +3827,38 @@ open class Player(
38303827 saveNBT()
38313828
38323829 if (this .level != null ) {
3833- namedTag!! .putString(" Level" , level!! .getLevelName())
3830+ namedTag.putString(" Level" , level!! .getLevelName())
38343831
38353832 val achievements = CompoundTag ()
38363833 for (achievement in this .achievements) {
38373834 achievements.putByte(achievement!! , 1 )
38383835 }
38393836
3840- namedTag!! .putCompound(" Achievements" , achievements)
3841- namedTag!! .putInt(" playerGameType" , this .gamemode)
3842- namedTag!! .putLong(" lastPlayed" , System .currentTimeMillis() / 1000 )
3843- namedTag!! .putString(" lastIP" , this .address)
3844- namedTag!! .putInt(" EXP" , this .experience)
3845- namedTag!! .putInt(" expLevel" , this .experienceLevel)
3846- namedTag!! .putInt(" foodLevel" , foodData!! .getFood())
3847- namedTag!! .putFloat(" foodSaturationLevel" , foodData!! .getSaturation())
3848- namedTag!! .putInt(" enchSeed" , this .enchSeed)
3837+ namedTag.putCompound(" Achievements" , achievements)
3838+ namedTag.putInt(" playerGameType" , this .gamemode)
3839+ namedTag.putLong(" lastPlayed" , System .currentTimeMillis() / 1000 )
3840+ namedTag.putString(" lastIP" , this .address)
3841+ namedTag.putInt(" EXP" , this .experience)
3842+ namedTag.putInt(" expLevel" , this .experienceLevel)
3843+ namedTag.putInt(" foodLevel" , foodData!! .getFood())
3844+ namedTag.putFloat(" foodSaturationLevel" , foodData!! .getSaturation())
3845+ namedTag.putInt(" enchSeed" , this .enchSeed)
38493846
38503847 val fogIdentifiers = ListTag <StringTag >()
38513848 val userProvidedFogIds = ListTag <StringTag >()
38523849 fogStack.forEach { fog ->
38533850 userProvidedFogIds.add(StringTag (fog.first))
38543851 fogIdentifiers.add(StringTag (fog.second))
38553852 }
3856- namedTag!! .putList(" fogIdentifiers" , fogIdentifiers)
3857- namedTag!! .putList(" userProvidedFogIds" , userProvidedFogIds)
3853+ namedTag.putList(" fogIdentifiers" , fogIdentifiers)
3854+ namedTag.putList(" userProvidedFogIds" , userProvidedFogIds)
38583855
3859- namedTag!! .putInt(" TimeSinceRest" , this .timeSinceRest)
3856+ namedTag.putInt(" TimeSinceRest" , this .timeSinceRest)
38603857
3861- if (getEntityName().isNotBlank() && this .namedTag != null ) {
3858+ if (getEntityName().isNotBlank()) {
38623859 Server .instance.saveOfflinePlayerData(
38633860 uuid,
3864- namedTag!! , async
3861+ namedTag, async
38653862 )
38663863 }
38673864 }
@@ -3896,7 +3893,7 @@ open class Player(
38963893 params.add(this .displayName)
38973894
38983895 run switch@{
3899- when (if ( cause == null ) DamageCause .CUSTOM else cause.cause ) {
3896+ when (cause?.cause ? : DamageCause .CUSTOM ) {
39003897 DamageCause .ENTITY_ATTACK -> if (cause is EntityDamageByEntityEvent ) {
39013898 val e = cause.damager
39023899 killer = e
@@ -4034,11 +4031,9 @@ open class Player(
40344031 }
40354032 }
40364033
4037- if (this .offhandInventory != null ) {
4038- offhandInventory.contents.forEach { (slot, item) ->
4039- if (! item.keepOnDeath()) {
4040- offhandInventory.clear(slot)
4041- }
4034+ offhandInventory.contents.forEach { (slot, item) ->
4035+ if (! item.keepOnDeath()) {
4036+ offhandInventory.clear(slot)
40424037 }
40434038 }
40444039 }
@@ -5102,7 +5097,7 @@ open class Player(
51025097 if (near) {
51035098 var inventory: Inventory ? = this .inventory
51045099 if (entity is EntityArrow && entity.hadCollision) {
5105- val item = if ( entity.getArrowItem() != null ) entity.getArrowItem() else ItemArrow ()
5100+ val item = entity.getArrowItem()
51065101 if (! this .isCreative) {
51075102 // Should only collect to the offhand slot if the item matches what is already there
51085103 if (offhandInventory.getItem(0 ).id == item.id && offhandInventory.canAddItem(
@@ -5263,7 +5258,7 @@ open class Player(
52635258
52645259 override fun hashCode (): Int {
52655260 if ((this .hash == 0 ) || (this .hash == 485 )) {
5266- this .hash = (485 + ( if ( getUniqueID() != null ) getUniqueID() .hashCode() else 0 ))
5261+ this .hash = (485 + getUniqueID().hashCode())
52675262 }
52685263
52695264 return this .hash
0 commit comments