Again... try to fix null config sections
This commit is contained in:
parent
09426dc0b4
commit
f039eb2abf
3 changed files with 17 additions and 40 deletions
|
@ -53,7 +53,7 @@ mod_name=Zontreck's Library Mod
|
|||
# The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default.
|
||||
mod_license=GPLv3
|
||||
# The mod version. See https://semver.org/
|
||||
mod_version=1201.13.042324.2239
|
||||
mod_version=1201.13.042324.2250
|
||||
# The group ID for the mod. It is only important when publishing as an artifact to a Maven repository.
|
||||
# This should match the base package used for the mod sources.
|
||||
# See https://maven.apache.org/guides/mini/guide-naming-conventions.html
|
||||
|
|
|
@ -20,6 +20,8 @@ public class ServerConfig
|
|||
var config = SNbtIo.loadSnbt(BASE);
|
||||
|
||||
database = DatabaseSection.deserialize(config.getCompound(DatabaseSection.TAG_NAME));
|
||||
|
||||
commit();
|
||||
} else {
|
||||
database = new DatabaseSection();
|
||||
|
||||
|
|
|
@ -25,49 +25,24 @@ public class DatabaseSection
|
|||
|
||||
public static DatabaseSection deserialize(CompoundTag tag)
|
||||
{
|
||||
int ver = tag.getInt(TAG_VERSION);
|
||||
DatabaseSection section = new DatabaseSection();
|
||||
section.doMigrations(ver, tag);
|
||||
DatabaseSection ret = new DatabaseSection();
|
||||
ret.version = tag.getInt(TAG_VERSION);
|
||||
|
||||
|
||||
return section;
|
||||
}
|
||||
|
||||
public void doMigrations(int ver, CompoundTag tag)
|
||||
{
|
||||
switch (ver)
|
||||
if(ret.version == 0)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
ver++;
|
||||
user = tag.getString(TAG_USER);
|
||||
password = tag.getString(TAG_PASSWORD);
|
||||
host = tag.getString(TAG_HOST);
|
||||
database = tag.getString(TAG_DATABASE);
|
||||
version = ver;
|
||||
migrated=true;
|
||||
break;
|
||||
}
|
||||
default:{
|
||||
|
||||
user = tag.getString(TAG_USER);
|
||||
password = tag.getString(TAG_PASSWORD);
|
||||
host = tag.getString(TAG_HOST);
|
||||
database = tag.getString(TAG_DATABASE);
|
||||
version = ver;
|
||||
|
||||
if(migrated)
|
||||
{
|
||||
ServerConfig.commit();
|
||||
migrated=false;
|
||||
return;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
ret.version = VERSION;
|
||||
return ret;
|
||||
}
|
||||
|
||||
doMigrations(ver, tag);
|
||||
if(ret.version >= 1)
|
||||
{
|
||||
ret.user = tag.getString(TAG_USER);
|
||||
ret.password = tag.getString(TAG_PASSWORD);
|
||||
ret.host = tag.getString(TAG_HOST);
|
||||
ret.database = tag.getString(TAG_DATABASE);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public DatabaseSection(){
|
||||
|
|
Reference in a new issue