1
0
mirror of https://github.com/Zrips/Jobs.git synced 2025-01-16 05:01:34 +01:00

We need to count in empty data bases

This commit is contained in:
Zrips 2016-04-21 17:26:17 +03:00
parent f2c4f39322
commit 258362144d
3 changed files with 126 additions and 1 deletions

View File

@ -348,8 +348,10 @@ public class JobsDAOMySQL extends JobsDAO {
PreparedStatement tempPst = conn.prepareStatement("SELECT * FROM `" + getPrefix() + "jobs`;");
ResultSet tempRes = tempPst.executeQuery();
boolean noJobsdata = true;
try {
while (tempRes.next()) {
noJobsdata = false;
tempRes.getByte("player_uuid");
break;
}
@ -359,6 +361,11 @@ public class JobsDAOMySQL extends JobsDAO {
tempRes.close();
tempPst.close();
}
if (noJobsdata) {
dropDataBase("jobs");
createDefaultJobsBase();
convertJobs = false;
}
if (convertJobs) {
Jobs.getPluginLogger().info("Converting byte uuids to string. This could take a long time!!!");
@ -413,8 +420,10 @@ public class JobsDAOMySQL extends JobsDAO {
PreparedStatement tempArchivePst = conn.prepareStatement("SELECT * FROM `" + getPrefix() + "archive`;");
ResultSet tempArchiveRes = tempArchivePst.executeQuery();
boolean noArchivedata = true;
try {
while (tempArchiveRes.next()) {
noArchivedata = false;
tempArchiveRes.getByte("player_uuid");
break;
}
@ -424,6 +433,11 @@ public class JobsDAOMySQL extends JobsDAO {
tempArchiveRes.close();
tempArchivePst.close();
}
if (noArchivedata) {
dropDataBase("archive");
createDefaultArchiveBase();
convertArchive = false;
}
if (convertArchive) {
// Converting archive players byte uuid into string
@ -472,8 +486,10 @@ public class JobsDAOMySQL extends JobsDAO {
PreparedStatement tempLogPst = conn.prepareStatement("SELECT * FROM `" + getPrefix() + "log`;");
ResultSet tempLogRes = tempLogPst.executeQuery();
boolean nodata = true;
try {
while (tempLogRes.next()) {
nodata = false;
tempLogRes.getByte("player_uuid");
break;
}
@ -483,8 +499,14 @@ public class JobsDAOMySQL extends JobsDAO {
tempLogRes.close();
tempLogPst.close();
}
if (nodata) {
dropDataBase("log");
createDefaultLogBase();
convertLog = false;
}
if (convertLog) {
Bukkit.getConsoleSender().sendMessage("Converting log database");
// Converting log players byte uuid into string
try {
executeSQL("CREATE TABLE `" + getPrefix()
@ -777,4 +799,43 @@ public class JobsDAOMySQL extends JobsDAO {
}
}
}
private boolean createDefaultLogBase() {
try {
executeSQL("CREATE TABLE `" + getPrefix()
+ "log` (`id` int NOT NULL AUTO_INCREMENT PRIMARY KEY, `userid` int, `time` bigint, `action` varchar(20), `itemname` varchar(60), `count` int, `money` double, `exp` double);");
} catch (SQLException e) {
return false;
}
return true;
}
private boolean createDefaultArchiveBase() {
try {
executeSQL("CREATE TABLE `" + getPrefix()
+ "archive` (`id` int NOT NULL AUTO_INCREMENT PRIMARY KEY, `userid` int, `job` varchar(20), `experience` int, `level` int);");
} catch (SQLException e) {
return false;
}
return true;
}
private boolean createDefaultJobsBase() {
try {
executeSQL("CREATE TABLE `" + getPrefix()
+ "jobs` (`id` int NOT NULL AUTO_INCREMENT PRIMARY KEY, `userid` int, `job` varchar(20), `experience` int, `level` int);");
} catch (SQLException e) {
return false;
}
return true;
}
private boolean dropDataBase(String name) {
try {
executeSQL("DROP TABLE IF EXISTS `" + getPrefix() + name + "`;");
} catch (SQLException e) {
return false;
}
return true;
}
}

View File

@ -331,9 +331,12 @@ public class JobsDAOSQLite extends JobsDAO {
PreparedStatement tempPst = conn.prepareStatement("SELECT * FROM `" + getPrefix() + "jobs`;");
ResultSet tempRes = tempPst.executeQuery();
boolean noJobsdata = true;
try {
while (tempRes.next()) {
noJobsdata = false;
tempRes.getByte("player_uuid");
break;
}
} catch (Exception e) {
convertJobs = false;
@ -341,6 +344,11 @@ public class JobsDAOSQLite extends JobsDAO {
tempRes.close();
tempPst.close();
}
if (noJobsdata) {
dropDataBase("jobs");
createDefaultJobsBase();
convertJobs = false;
}
if (convertJobs) {
Jobs.getPluginLogger().info("Converting byte uuids to string. This could take a long time!!!");
@ -392,9 +400,12 @@ public class JobsDAOSQLite extends JobsDAO {
PreparedStatement tempArchivePst = conn.prepareStatement("SELECT * FROM `" + getPrefix() + "archive`;");
ResultSet tempArchiveRes = tempArchivePst.executeQuery();
boolean noArchivedata = true;
try {
while (tempArchiveRes.next()) {
noArchivedata = false;
tempArchiveRes.getByte("player_uuid");
break;
}
} catch (Exception e) {
convertArchive = false;
@ -402,6 +413,11 @@ public class JobsDAOSQLite extends JobsDAO {
tempArchiveRes.close();
tempArchivePst.close();
}
if (noArchivedata) {
dropDataBase("archive");
createDefaultArchiveBase();
convertArchive = false;
}
if (convertArchive) {
// Converting archive players byte uuid into string
@ -449,16 +465,25 @@ public class JobsDAOSQLite extends JobsDAO {
PreparedStatement tempLogPst = conn.prepareStatement("SELECT * FROM `" + getPrefix() + "log`;");
ResultSet tempLogRes = tempLogPst.executeQuery();
boolean nodata = true;
try {
while (tempLogRes.next()) {
nodata = false;
tempLogRes.getByte("player_uuid");
break;
}
} catch (Exception e) {
convertLog = false;
} finally {
tempLogRes.close();
tempLogPst.close();
}
if (nodata) {
dropDataBase("log");
createDefaultLogBase();
convertLog = false;
}
if (convertLog) {
try {
@ -841,4 +866,43 @@ public class JobsDAOSQLite extends JobsDAO {
}
}
}
private boolean createDefaultLogBase() {
try {
executeSQL("CREATE TABLE `" + getPrefix()
+ "log` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `userid` int, `time` bigint, `action` varchar(20), `itemname` varchar(60), `count` int, `money` double, `exp` double);");
} catch (SQLException e) {
return false;
}
return true;
}
private boolean createDefaultArchiveBase() {
try {
executeSQL("CREATE TABLE `" + getPrefix()
+ "archive` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `userid` int, `job` varchar(20), `experience` int, `level` int);");
} catch (SQLException e) {
return false;
}
return true;
}
private boolean createDefaultJobsBase() {
try {
executeSQL("CREATE TABLE `" + getPrefix()
+ "jobs` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `userid` int, `job` varchar(20), `experience` int, `level` int);");
} catch (SQLException e) {
return false;
}
return true;
}
private boolean dropDataBase(String name) {
try {
executeSQL("DROP TABLE IF EXISTS `" + getPrefix() + name + "`;");
} catch (SQLException e) {
return false;
}
return true;
}
}

View File

@ -1,7 +1,7 @@
name: Jobs
description: Jobs Plugin for the BukkitAPI
main: com.gamingmesh.jobs.JobsPlugin
version: 3.3.2
version: 3.3.3
author: phrstbrn
depend: [Vault]
softdepend: [CoreProtect, MythicMobs, McMMO]