Shaun Wild
11/29/2025, 12:06 PM!! everywhere, use null checks, or ?.let etc, my question is: Is there a better way to handle this?Shaun Wild
11/29/2025, 12:07 PMShaun Wild
11/29/2025, 12:08 PM@Serializable
data class AbilityPacket(
var abilityId: Int? = null,
var targeting: AbilityTargeting? = null,
var entity: Entity? = null
) : NetworkPacket {
override fun reset() {
abilityId = null
targeting = null
entity = null
}
}Shaun Wild
11/29/2025, 12:08 PMShaun Wild
11/29/2025, 12:12 PMShaun Wild
11/29/2025, 12:13 PMdata class AbilityPacket(
var abilityId: Int! = null,
var targeting: AbilityTargeting! = null,
var entity: Entity! = null
) ......
which would allow us to decide whether the usage of this type is null-safe or not.Youssef Shoaib [MOD]
11/29/2025, 12:18 PMlateinit, but obviously it doesn't help here because of your reset. You can use some property delegation to help out.Shaun Wild
11/29/2025, 12:20 PMShaun Wild
11/29/2025, 12:21 PMShaun Wild
11/29/2025, 12:25 PM@Serializable
data class AbilityPacket(
reinit var abilityId: Int,
reinit var targeting: AbilityTargeting,
reinit var entity: Entity
) : NetworkPacket {
override fun reset() {
::abilityId.reset()
::targeting.reset()
::entity.reset()
}
}ephemient
11/29/2025, 1:48 PMclass Packet(
var _id: Int?,
) {
val id: Int
get() = _id!!
is possible of course, but the better design IMO would be to create a separate type with non-nullable properties, which you convert into after validationShaun Wild
11/29/2025, 1:52 PMphldavies
11/29/2025, 5:25 PMShaun Wild
11/29/2025, 5:27 PMphldavies
11/29/2025, 5:36 PM@JvmInline
value class PopulatedPacket(@PublishedApi internal val packet: AbilityPacket) {
inline val abilityId: Int get() = packet.abilityId!!
inline val targeting: AbilityTargeting get() = packet.targeting!!
inline val entity: Entity get() = packet.entity!!
}Shaun Wild
11/29/2025, 5:38 PMphldavies
11/29/2025, 5:38 PMShaun Wild
11/29/2025, 5:40 PMShaun Wild
11/29/2025, 5:41 PMShaun Wild
11/29/2025, 5:41 PM