Skip to content

Commit

Permalink
add editOfflinePDC inline function
Browse files Browse the repository at this point in the history
  • Loading branch information
Boy0000 committed Sep 9, 2023
1 parent b1d7824 commit 3b6a8cf
Showing 1 changed file with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.mineinabyss.idofront.nms.nbt

import jdk.jfr.internal.management.ManagementSupport.logError
import net.minecraft.nbt.CompoundTag
import net.minecraft.nbt.NbtIo
import org.bukkit.Bukkit
Expand Down Expand Up @@ -41,13 +40,19 @@ fun OfflinePlayer.saveOfflinePDC(pdc: WrappedPDC): Boolean {
runCatching {
Files.newOutputStream(tempFile.toPath()).use { outStream ->
NbtIo.writeCompressed(mainPDc, outStream)
if (playerFile.exists() && !playerFile.delete()) logError("Failed to delete player file $uniqueId")
if (!tempFile.renameTo(playerFile)) logError("Failed to rename player file $uniqueId")
if (playerFile.exists() && !playerFile.delete()) Bukkit.getLogger().severe("Failed to delete player file $uniqueId")
if (!tempFile.renameTo(playerFile)) Bukkit.getLogger().severe("Failed to rename player file $uniqueId")
}
}.onFailure {
logError("Failed to save player file $uniqueId")
Bukkit.getLogger().severe("Failed to save player file $uniqueId")
it.printStackTrace()
return false
}
return true
}

inline fun OfflinePlayer.editOfflinePDC(apply: WrappedPDC.() -> Unit): Boolean {
val pdc = getOfflinePDC() ?: return false
apply(pdc)
return saveOfflinePDC(pdc)
}

0 comments on commit 3b6a8cf

Please sign in to comment.