summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLane Kolbly <lane@rscheme.org>2017-09-07 11:57:12 +0200
committerMattes D <github@xoft.cz>2017-09-07 11:57:12 +0200
commitdc294cdc51135f38bc4417834e473c8fc4d92b1a (patch)
treea66378a8ced95ca25bc86e3854eca09910193375
parentFire effect now shown for creative and spectator mode players (#3998) (diff)
downloadcuberite-dc294cdc51135f38bc4417834e473c8fc4d92b1a.tar
cuberite-dc294cdc51135f38bc4417834e473c8fc4d92b1a.tar.gz
cuberite-dc294cdc51135f38bc4417834e473c8fc4d92b1a.tar.bz2
cuberite-dc294cdc51135f38bc4417834e473c8fc4d92b1a.tar.lz
cuberite-dc294cdc51135f38bc4417834e473c8fc4d92b1a.tar.xz
cuberite-dc294cdc51135f38bc4417834e473c8fc4d92b1a.tar.zst
cuberite-dc294cdc51135f38bc4417834e473c8fc4d92b1a.zip
Diffstat (limited to '')
-rw-r--r--src/Entities/Player.cpp4
-rw-r--r--src/WorldStorage/StatSerializer.cpp11
-rw-r--r--src/WorldStorage/StatSerializer.h3
3 files changed, 12 insertions, 6 deletions
diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp
index f9804569f..614edef75 100644
--- a/src/Entities/Player.cpp
+++ b/src/Entities/Player.cpp
@@ -2203,7 +2203,7 @@ bool cPlayer::LoadFromFile(const AString & a_FileName, cWorldPtr & a_World)
// Load the player stats.
// We use the default world name (like bukkit) because stats are shared between dimensions / worlds.
- cStatSerializer StatSerializer(cRoot::Get()->GetDefaultWorld()->GetName(), GetName(), &m_Stats);
+ cStatSerializer StatSerializer(cRoot::Get()->GetDefaultWorld()->GetName(), GetName(), GetUUID().ToLongString(), &m_Stats);
StatSerializer.Load();
LOGD("Player %s was read from file \"%s\", spawning at {%.2f, %.2f, %.2f} in world \"%s\"",
@@ -2301,7 +2301,7 @@ bool cPlayer::SaveToDisk()
// Save the player stats.
// We use the default world name (like bukkit) because stats are shared between dimensions / worlds.
- cStatSerializer StatSerializer(cRoot::Get()->GetDefaultWorld()->GetName(), GetName(), &m_Stats);
+ cStatSerializer StatSerializer(cRoot::Get()->GetDefaultWorld()->GetName(), GetName(), GetUUID().ToLongString(), &m_Stats);
if (!StatSerializer.Save())
{
LOGWARNING("Could not save stats for player %s", GetName().c_str());
diff --git a/src/WorldStorage/StatSerializer.cpp b/src/WorldStorage/StatSerializer.cpp
index 16128966b..c8a4c0951 100644
--- a/src/WorldStorage/StatSerializer.cpp
+++ b/src/WorldStorage/StatSerializer.cpp
@@ -11,7 +11,7 @@
-cStatSerializer::cStatSerializer(const AString & a_WorldName, const AString & a_PlayerName, cStatManager * a_Manager)
+cStatSerializer::cStatSerializer(const AString & a_WorldName, const AString & a_PlayerName, const AString & a_FileName, cStatManager * a_Manager)
: m_Manager(a_Manager)
{
// Even though stats are shared between worlds, they are (usually) saved
@@ -20,7 +20,8 @@ cStatSerializer::cStatSerializer(const AString & a_WorldName, const AString & a_
AString StatsPath;
Printf(StatsPath, "%s%cstats", a_WorldName.c_str(), cFile::PathSeparator);
- m_Path = StatsPath + "/" + a_PlayerName + ".json";
+ m_LegacyPath = StatsPath + "/" + a_PlayerName + ".json";
+ m_Path = StatsPath + "/" + a_FileName + ".json";
// Ensure that the directory exists.
cFile::CreateFolder(FILE_IO_PREFIX + StatsPath);
@@ -35,7 +36,11 @@ bool cStatSerializer::Load(void)
AString Data = cFile::ReadWholeFile(FILE_IO_PREFIX + m_Path);
if (Data.empty())
{
- return false;
+ Data = cFile::ReadWholeFile(FILE_IO_PREFIX + m_LegacyPath);
+ if (Data.empty())
+ {
+ return false;
+ }
}
Json::Value Root;
diff --git a/src/WorldStorage/StatSerializer.h b/src/WorldStorage/StatSerializer.h
index 6b7efddbb..8e8e4ffdb 100644
--- a/src/WorldStorage/StatSerializer.h
+++ b/src/WorldStorage/StatSerializer.h
@@ -25,7 +25,7 @@ class cStatSerializer
{
public:
- cStatSerializer(const AString & a_WorldName, const AString & a_PlayerName, cStatManager * a_Manager);
+ cStatSerializer(const AString & a_WorldName, const AString & a_PlayerName, const AString & a_FileName, cStatManager * a_Manager);
/* Try to load the player statistics. Returns whether the operation was successful or not. */
bool Load(void);
@@ -45,6 +45,7 @@ private:
cStatManager * m_Manager;
+ AString m_LegacyPath; // The old <username>.json path to try to read from if the uuid path doesn't exist on load
AString m_Path;