More implementation of the block restore queue functionality
This commit is contained in:
parent
b20e56a7d8
commit
40ce8774fb
9 changed files with 363 additions and 6 deletions
|
@ -0,0 +1,91 @@
|
|||
package dev.zontreck.libzontreck.config.sections;
|
||||
|
||||
import dev.zontreck.libzontreck.config.ServerConfig;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
|
||||
public class DatabaseSection
|
||||
{
|
||||
public static final String TAG_NAME = "database";
|
||||
public static final String TAG_USER = "username";
|
||||
public static final String TAG_PASSWORD = "password";
|
||||
public static final String TAG_HOST = "host";
|
||||
public static final String TAG_DATABASE = "database";
|
||||
public static final String TAG_VERSION = "rev";
|
||||
|
||||
|
||||
public String user = "root";
|
||||
public String password = "";
|
||||
public String host = "localhost:3306"; // IP:port
|
||||
public String database = "savedBlocks";
|
||||
public int version;
|
||||
|
||||
public static final int VERSION = 1;
|
||||
|
||||
private boolean migrated=false;
|
||||
|
||||
public static DatabaseSection deserialize(CompoundTag tag)
|
||||
{
|
||||
int ver = tag.getInt(TAG_VERSION);
|
||||
DatabaseSection section = new DatabaseSection();
|
||||
section.doMigrations(ver, tag);
|
||||
|
||||
|
||||
return section;
|
||||
}
|
||||
|
||||
public void doMigrations(int ver, CompoundTag tag)
|
||||
{
|
||||
switch (ver)
|
||||
{
|
||||
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:{
|
||||
if(migrated)
|
||||
{
|
||||
ServerConfig.commit();
|
||||
migrated=false;
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
doMigrations(ver, tag);
|
||||
}
|
||||
|
||||
public DatabaseSection(){
|
||||
|
||||
}
|
||||
|
||||
public DatabaseSection(String user, String password, String host, String database)
|
||||
{
|
||||
this.user = user;
|
||||
this.password = password;
|
||||
this.host = host;
|
||||
this.database = database;
|
||||
}
|
||||
|
||||
public String getAsSQLFileName()
|
||||
{
|
||||
return database + ".sql";
|
||||
}
|
||||
|
||||
public CompoundTag serialize()
|
||||
{
|
||||
CompoundTag tag = new CompoundTag();
|
||||
tag.putString(TAG_USER, user);
|
||||
tag.putString(TAG_PASSWORD, password);
|
||||
tag.putString(TAG_HOST, host);
|
||||
tag.putString(TAG_DATABASE, database);
|
||||
return tag;
|
||||
}
|
||||
}
|
Reference in a new issue