mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-14 04:59:57 +00:00
Fix currency storage to use main PlayerData file
- Currency now stored in main player save file, not separate file - Currency excluded from getNBT/setNBT (slot-specific data) - Currency saved in save() after getNBT(), loaded before setNBT() - This ensures currency is preserved during profile slot changes - Removed loadCurrency() and saveCurrency() separate file methods - Updated VaultHelper to call save() instead of saveCurrency()
This commit is contained in:
2 files changed
+11
-64
No files matched your search
@@ -409,6 +409,9 @@ public class PlayerData implements IExtendedEntityProperties, IPlayerData {
|
||||
}
|
||||
|
||||
final NBTTagCompound compound = getNBT();
|
||||
// Add currency data to main save (NOT slot-bound, preserved across profile changes)
|
||||
currencyData.writeToNBT(compound);
|
||||
|
||||
final String filename;
|
||||
if (ConfigMain.DatFormat) {
|
||||
filename = uuid + ".dat";
|
||||
@@ -445,70 +448,14 @@ public class PlayerData implements IExtendedEntityProperties, IPlayerData {
|
||||
if (data.hasNoTags()) {
|
||||
data = getNBT();
|
||||
}
|
||||
setNBT(data);
|
||||
|
||||
// Load currency data separately (not slot-bound)
|
||||
loadCurrency();
|
||||
}
|
||||
|
||||
/**
|
||||
* Load currency data from separate file (shared across profile slots)
|
||||
*/
|
||||
public void loadCurrency() {
|
||||
if (player == null) return;
|
||||
|
||||
File saveDir = PlayerDataController.Instance.getSaveDir();
|
||||
String filename = player.getPersistentID().toString() + "_currency";
|
||||
|
||||
try {
|
||||
File file = new File(saveDir, filename + ".json");
|
||||
if (file.exists()) {
|
||||
NBTTagCompound compound = NBTJsonUtil.LoadFile(file);
|
||||
currencyData.readFromNBT(compound);
|
||||
return;
|
||||
}
|
||||
|
||||
// Try dat format
|
||||
file = new File(saveDir, filename + ".dat");
|
||||
if (file.exists()) {
|
||||
NBTTagCompound compound = NBTJsonUtil.loadNBTData(file);
|
||||
currencyData.readFromNBT(compound);
|
||||
return;
|
||||
}
|
||||
|
||||
// No currency file exists, use defaults (new player)
|
||||
currencyData = new PlayerCurrencyData();
|
||||
} catch (Exception e) {
|
||||
LogWriter.error("Error loading currency data for " + player.getCommandSenderName(), e);
|
||||
currencyData = new PlayerCurrencyData();
|
||||
// Load currency BEFORE setNBT so we can preserve it
|
||||
// Currency is stored in main file but NOT in slot data
|
||||
if (data.hasKey("CurrencyBalance")) {
|
||||
currencyData.readFromNBT(data);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Save currency data to separate file (shared across profile slots)
|
||||
*/
|
||||
public synchronized void saveCurrency() {
|
||||
if (uuid == null || uuid.isEmpty()) return;
|
||||
|
||||
final NBTTagCompound compound = new NBTTagCompound();
|
||||
currencyData.writeToNBT(compound);
|
||||
|
||||
final String filename = uuid + "_currency.json";
|
||||
|
||||
CustomNPCsThreader.customNPCThread.execute(() -> {
|
||||
try {
|
||||
File saveDir = PlayerDataController.Instance.getSaveDir();
|
||||
File file = new File(saveDir, filename + "_new");
|
||||
File file1 = new File(saveDir, filename);
|
||||
NBTJsonUtil.SaveFile(file, compound);
|
||||
if (file1.exists()) {
|
||||
file1.delete();
|
||||
}
|
||||
file.renameTo(file1);
|
||||
} catch (Exception e) {
|
||||
LogWriter.except(e);
|
||||
}
|
||||
});
|
||||
setNBT(data);
|
||||
}
|
||||
|
||||
public static PlayerData get(EntityPlayer player) {
|
||||
|
||||
Reference in new issue
Block a user