Allows PlayerPartyStore's to have their own unique storage id, separate from the player uuid.

This commit is contained in:
Deltric
2023-10-20 01:53:32 -05:00
parent 24f07c58a0
commit 392b69937f
4 changed files with 14 additions and 5 deletions
@@ -48,7 +48,7 @@ open class JSONStoreAdapter(
val br = BufferedReader(FileReader(file))
val json = gson.fromJson<JsonObject>(br)
br.close()
val store = storeClass.getConstructor(UUID::class.java).newInstance(uuid)
val store = storeClass.getConstructor(UUID::class.java, UUID::class.java).newInstance(uuid, uuid)
store.loadFromJSON(json)
store
} catch (e: Exception) {
@@ -31,7 +31,7 @@ open class NBTStoreAdapter(
override fun <E : StorePosition, T : PokemonStore<E>> serialize(store: T) = store.saveToNBT(NbtCompound())
override fun save(file: File, serialized: NbtCompound) = NbtIo.writeCompressed(serialized, file)
override fun <E, T : PokemonStore<E>> load(file: File, storeClass: Class<out T>, uuid: UUID): T? {
val store = storeClass.getConstructor(UUID::class.java).newInstance(uuid)
val store = storeClass.getConstructor(UUID::class.java, UUID::class.java).newInstance(uuid, uuid)
return try {
val nbt = NbtIo.readCompressed(file)
store.loadFromNBT(nbt)
@@ -38,8 +38,10 @@ import kotlin.random.Random
*/
open class PlayerPartyStore(
/** The UUID of the player this store is for. */
val playerUUID: UUID
) : PartyStore(playerUUID) {
val playerUUID: UUID,
/** The UUID of the store. This is the same as [playerUUID] by default, but can be changed to allow for multiple parties. */
storageUUID: UUID = playerUUID
) : PartyStore(storageUUID) {
private var secondsSinceFriendshipUpdate = 0
@@ -928,7 +928,14 @@ open class Pokemon : ShowdownIdentifiable {
fun getOwnerUUID() : UUID? {
storeCoordinates.get().let {
if (isPlayerOwned()) return it!!.store.uuid
if (!isPlayerOwned()) {
return@let
}
if (it!!.store is PlayerPartyStore) {
return (it.store as PlayerPartyStore).playerUUID
}
return it.store.uuid
}
return null
}