2015-08-21 15:10:08 +02:00
|
|
|
/**
|
|
|
|
* Jobs Plugin for Bukkit
|
|
|
|
* Copyright (C) 2011 Zak Ford <zak.j.ford@gmail.com>
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package com.gamingmesh.jobs.dao;
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
import java.sql.PreparedStatement;
|
|
|
|
import java.sql.ResultSet;
|
|
|
|
import java.sql.SQLException;
|
2016-03-30 15:42:36 +02:00
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Map.Entry;
|
2015-08-21 15:10:08 +02:00
|
|
|
|
2016-06-09 17:35:24 +02:00
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
|
2015-08-21 15:10:08 +02:00
|
|
|
import com.gamingmesh.jobs.Jobs;
|
2016-03-30 15:42:36 +02:00
|
|
|
import com.gamingmesh.jobs.container.PlayerInfo;
|
2015-08-21 15:10:08 +02:00
|
|
|
import com.gamingmesh.jobs.stuff.UUIDUtil;
|
|
|
|
|
|
|
|
public class JobsDAOSQLite extends JobsDAO {
|
2015-09-17 09:48:10 +02:00
|
|
|
public static JobsDAOSQLite initialize() {
|
|
|
|
JobsDAOSQLite dao = new JobsDAOSQLite();
|
|
|
|
File dir = Jobs.getDataFolder();
|
|
|
|
if (!dir.exists())
|
|
|
|
dir.mkdirs();
|
|
|
|
try {
|
|
|
|
dao.setUp();
|
|
|
|
} catch (SQLException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
return dao;
|
|
|
|
}
|
|
|
|
|
|
|
|
private JobsDAOSQLite() {
|
|
|
|
super("org.sqlite.JDBC", "jdbc:sqlite:" + new File(Jobs.getDataFolder(), "jobs.sqlite.db").getPath(), null, null, "");
|
|
|
|
}
|
|
|
|
|
2016-06-25 14:51:21 +02:00
|
|
|
private static void close(ResultSet res) {
|
|
|
|
if (res != null) {
|
|
|
|
try {
|
|
|
|
res.close();
|
|
|
|
} catch (SQLException e) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void close(PreparedStatement prest) {
|
|
|
|
if (prest != null) {
|
|
|
|
try {
|
|
|
|
prest.close();
|
|
|
|
} catch (SQLException e) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-17 09:48:10 +02:00
|
|
|
@Override
|
|
|
|
protected synchronized void setupConfig() throws SQLException {
|
|
|
|
JobsConnection conn = getConnection();
|
|
|
|
if (conn == null) {
|
|
|
|
Jobs.getPluginLogger().severe("Could not run database updates! Could not connect to MySQL!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
PreparedStatement prest = null;
|
2016-06-25 14:51:21 +02:00
|
|
|
ResultSet res = null;
|
2015-09-17 09:48:10 +02:00
|
|
|
int rows = 0;
|
|
|
|
try {
|
|
|
|
// Check for config table
|
|
|
|
prest = conn.prepareStatement("SELECT COUNT(*) FROM sqlite_master WHERE name = ?;");
|
|
|
|
prest.setString(1, getPrefix() + "config");
|
2016-06-25 14:51:21 +02:00
|
|
|
res = prest.executeQuery();
|
2015-09-17 09:48:10 +02:00
|
|
|
if (res.next()) {
|
|
|
|
rows = res.getInt(1);
|
|
|
|
}
|
|
|
|
} finally {
|
2016-06-25 14:51:21 +02:00
|
|
|
close(res);
|
|
|
|
close(prest);
|
2015-08-21 15:10:08 +02:00
|
|
|
}
|
|
|
|
|
2015-09-17 09:48:10 +02:00
|
|
|
if (rows == 0) {
|
|
|
|
PreparedStatement insert = null;
|
|
|
|
try {
|
|
|
|
executeSQL("CREATE TABLE `" + getPrefix() + "config` (`key` varchar(50) NOT NULL PRIMARY KEY, `value` varchar(100) NOT NULL);");
|
2015-08-21 15:10:08 +02:00
|
|
|
|
2015-09-17 09:48:10 +02:00
|
|
|
insert = conn.prepareStatement("INSERT INTO `" + getPrefix() + "config` (`key`, `value`) VALUES (?, ?);");
|
|
|
|
insert.setString(1, "version");
|
|
|
|
insert.setString(2, "1");
|
|
|
|
insert.execute();
|
|
|
|
} finally {
|
2016-06-25 14:51:21 +02:00
|
|
|
close(insert);
|
2015-09-17 09:48:10 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-08-21 15:10:08 +02:00
|
|
|
|
2015-09-17 09:48:10 +02:00
|
|
|
@Override
|
2016-04-21 17:10:27 +02:00
|
|
|
protected synchronized void checkUpdate() throws SQLException {
|
2015-09-17 09:48:10 +02:00
|
|
|
JobsConnection conn = getConnection();
|
|
|
|
if (conn == null) {
|
|
|
|
Jobs.getPluginLogger().severe("Could not run database updates! Could not connect to MySQL!");
|
|
|
|
return;
|
|
|
|
}
|
2016-04-21 17:10:27 +02:00
|
|
|
createDefaultJobsBase();
|
|
|
|
createDefaultLogBase();
|
|
|
|
createDefaultArchiveBase();
|
|
|
|
createDefaultPointsBase();
|
|
|
|
createDefaultExploreBase();
|
|
|
|
createDefaultUsersBase();
|
2015-09-17 09:48:10 +02:00
|
|
|
}
|
2015-08-21 15:10:08 +02:00
|
|
|
|
2015-09-17 09:48:10 +02:00
|
|
|
@Override
|
|
|
|
protected synchronized void checkUpdate2() throws SQLException {
|
|
|
|
JobsConnection conn = getConnection();
|
|
|
|
if (conn == null) {
|
|
|
|
Jobs.getPluginLogger().severe("Could not run database updates! Could not connect to MySQL!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
PreparedStatement prest = null;
|
2016-06-25 14:51:21 +02:00
|
|
|
ResultSet res = null;
|
2015-09-17 09:48:10 +02:00
|
|
|
int rows = 0;
|
|
|
|
try {
|
|
|
|
// Check for jobs table
|
|
|
|
prest = conn.prepareStatement("SELECT COUNT(*) FROM sqlite_master WHERE name = ?;");
|
|
|
|
prest.setString(1, getPrefix() + "jobs");
|
2016-06-25 14:51:21 +02:00
|
|
|
res = prest.executeQuery();
|
2015-09-17 09:48:10 +02:00
|
|
|
if (res.next()) {
|
|
|
|
rows = res.getInt(1);
|
|
|
|
}
|
|
|
|
} finally {
|
2016-06-25 14:51:21 +02:00
|
|
|
close(res);
|
|
|
|
close(prest);
|
2015-09-17 09:48:10 +02:00
|
|
|
}
|
2015-08-21 15:10:08 +02:00
|
|
|
|
2015-09-17 09:48:10 +02:00
|
|
|
try {
|
|
|
|
if (rows > 0) {
|
|
|
|
executeSQL("ALTER TABLE `" + getPrefix() + "jobs` ADD COLUMN `username` varchar(20);");
|
|
|
|
}
|
2015-08-21 15:10:08 +02:00
|
|
|
|
2015-09-17 09:48:10 +02:00
|
|
|
} finally {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected synchronized void checkUpdate4() throws SQLException {
|
|
|
|
JobsConnection conn = getConnection();
|
|
|
|
if (conn == null) {
|
|
|
|
Jobs.getPluginLogger().severe("Could not run database updates! Could not connect to MySQL!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
PreparedStatement prest = null;
|
2016-06-25 14:51:21 +02:00
|
|
|
ResultSet res = null;
|
2015-09-17 09:48:10 +02:00
|
|
|
int rows = 0;
|
|
|
|
try {
|
|
|
|
// Check for jobs table
|
|
|
|
prest = conn.prepareStatement("SELECT COUNT(*) FROM sqlite_master WHERE name = ?;");
|
|
|
|
prest.setString(1, getPrefix() + "archive");
|
2016-06-25 14:51:21 +02:00
|
|
|
res = prest.executeQuery();
|
2015-09-17 09:48:10 +02:00
|
|
|
if (res.next()) {
|
|
|
|
rows = res.getInt(1);
|
|
|
|
}
|
|
|
|
} finally {
|
2016-06-25 14:51:21 +02:00
|
|
|
close(res);
|
|
|
|
close(prest);
|
2015-09-17 09:48:10 +02:00
|
|
|
}
|
2015-08-21 15:10:08 +02:00
|
|
|
|
2015-09-17 09:48:10 +02:00
|
|
|
try {
|
|
|
|
if (rows == 0) {
|
|
|
|
executeSQL("CREATE TABLE `" + getPrefix()
|
|
|
|
+ "archive` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `player_uuid` binary(16) NOT NULL, `username` varchar(20), `job` varchar(20), `experience` int, `level` int);");
|
|
|
|
}
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
}
|
|
|
|
}
|
2015-08-21 15:10:08 +02:00
|
|
|
|
2015-09-17 09:48:10 +02:00
|
|
|
@Override
|
|
|
|
protected synchronized void checkUpdate5() throws SQLException {
|
|
|
|
JobsConnection conn = getConnection();
|
|
|
|
if (conn == null) {
|
|
|
|
Jobs.getPluginLogger().severe("Could not run database updates! Could not connect to MySQL!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
PreparedStatement prest = null;
|
2016-06-25 14:51:21 +02:00
|
|
|
ResultSet res = null;
|
2015-09-17 09:48:10 +02:00
|
|
|
int rows = 0;
|
|
|
|
try {
|
|
|
|
// Check for jobs table
|
|
|
|
prest = conn.prepareStatement("SELECT COUNT(*) FROM sqlite_master WHERE name = ?;");
|
|
|
|
prest.setString(1, getPrefix() + "log");
|
2016-06-25 14:51:21 +02:00
|
|
|
res = prest.executeQuery();
|
2015-09-17 09:48:10 +02:00
|
|
|
if (res.next()) {
|
|
|
|
rows = res.getInt(1);
|
|
|
|
}
|
|
|
|
} finally {
|
2016-06-25 14:51:21 +02:00
|
|
|
close(res);
|
|
|
|
close(prest);
|
2015-09-17 09:48:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
if (rows == 0)
|
|
|
|
executeSQL("CREATE TABLE `" + getPrefix()
|
2015-11-25 16:14:48 +01:00
|
|
|
+ "log` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `player_uuid` binary(16) NOT NULL, `username` varchar(20), `time` bigint, `action` varchar(20), `itemname` varchar(60), `count` int, `money` double, `exp` double);");
|
2015-09-17 09:48:10 +02:00
|
|
|
} finally {
|
2015-08-21 15:10:08 +02:00
|
|
|
}
|
2015-09-17 09:48:10 +02:00
|
|
|
}
|
2015-11-25 16:14:48 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
protected synchronized void checkUpdate6() throws SQLException {
|
|
|
|
JobsConnection conn = getConnection();
|
|
|
|
if (conn == null) {
|
|
|
|
Jobs.getPluginLogger().severe("Could not run database updates! Could not connect to MySQL!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-04-21 13:47:10 +02:00
|
|
|
try {
|
|
|
|
executeSQL("CREATE TABLE `" + getPrefix()
|
|
|
|
+ "log_temp` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `player_uuid` binary(16) NOT NULL, `username` varchar(20), `time` bigint, `action` varchar(20), `itemname` varchar(60), `count` int, `money` double, `exp` double);");
|
|
|
|
} catch (Exception e) {
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
executeSQL("INSERT INTO `" + getPrefix() + "log_temp` SELECT `id`, `player_uuid`, `username`, `time`, `action`, `itemname`, `count`, `money`, `exp` FROM `"
|
|
|
|
+ getPrefix() + "log`;");
|
|
|
|
} catch (Exception e) {
|
|
|
|
}
|
2015-11-25 16:14:48 +01:00
|
|
|
executeSQL("DROP TABLE IF EXISTS `" + getPrefix() + "log`;");
|
2016-04-21 13:47:10 +02:00
|
|
|
try {
|
|
|
|
executeSQL("ALTER TABLE `" + getPrefix() + "log_temp` RENAME TO `" + getPrefix() + "log`;");
|
|
|
|
} catch (Exception e) {
|
|
|
|
}
|
2015-11-25 16:14:48 +01:00
|
|
|
}
|
2015-12-10 14:13:57 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
protected synchronized void checkUpdate7() throws SQLException {
|
|
|
|
JobsConnection conn = getConnection();
|
|
|
|
if (conn == null) {
|
|
|
|
Jobs.getPluginLogger().severe("Could not run database updates! Could not connect to MySQL!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-04-21 13:47:10 +02:00
|
|
|
boolean convertJobs = true;
|
|
|
|
PreparedStatement tempPst = conn.prepareStatement("SELECT * FROM `" + getPrefix() + "jobs`;");
|
|
|
|
ResultSet tempRes = tempPst.executeQuery();
|
2015-12-10 14:13:57 +01:00
|
|
|
|
2016-04-21 16:26:17 +02:00
|
|
|
boolean noJobsdata = true;
|
2016-04-21 13:47:10 +02:00
|
|
|
try {
|
|
|
|
while (tempRes.next()) {
|
2016-04-21 16:26:17 +02:00
|
|
|
noJobsdata = false;
|
2016-04-21 13:47:10 +02:00
|
|
|
tempRes.getByte("player_uuid");
|
2016-04-21 16:26:17 +02:00
|
|
|
break;
|
2016-04-21 13:47:10 +02:00
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
convertJobs = false;
|
|
|
|
} finally {
|
|
|
|
tempRes.close();
|
|
|
|
tempPst.close();
|
|
|
|
}
|
2016-04-21 16:26:17 +02:00
|
|
|
if (noJobsdata) {
|
|
|
|
dropDataBase("jobs");
|
2016-06-09 17:35:24 +02:00
|
|
|
try {
|
|
|
|
executeSQL("CREATE TABLE `" + getPrefix()
|
|
|
|
+ "jobs` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `userid` int, `job` varchar(20), `experience` int, `level` int);");
|
|
|
|
} catch (SQLException e) {
|
|
|
|
}
|
2016-04-21 16:26:17 +02:00
|
|
|
convertJobs = false;
|
|
|
|
}
|
2015-12-10 14:13:57 +01:00
|
|
|
|
2016-04-21 13:47:10 +02:00
|
|
|
if (convertJobs) {
|
2016-06-11 08:03:01 +02:00
|
|
|
|
2016-06-09 17:35:24 +02:00
|
|
|
Bukkit.getConsoleSender().sendMessage("convert jobs table from byte");
|
2016-06-11 08:03:01 +02:00
|
|
|
|
2016-04-21 13:47:10 +02:00
|
|
|
Jobs.getPluginLogger().info("Converting byte uuids to string. This could take a long time!!!");
|
|
|
|
try {
|
|
|
|
executeSQL("CREATE TABLE `" + getPrefix()
|
|
|
|
+ "jobs_temp` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `player_uuid` varchar(36) NOT NULL,`username` varchar(20), `job` varchar(20), `experience` int, `level` int);");
|
|
|
|
} catch (Exception e) {
|
|
|
|
}
|
|
|
|
PreparedStatement pst1 = conn.prepareStatement("SELECT * FROM `" + getPrefix() + "jobs`;");
|
|
|
|
ResultSet rs = pst1.executeQuery();
|
|
|
|
PreparedStatement insert = null;
|
|
|
|
conn.setAutoCommit(false);
|
|
|
|
while (rs.next()) {
|
|
|
|
byte[] uuidBytes = rs.getBytes("player_uuid");
|
|
|
|
|
|
|
|
if (uuidBytes == null)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
String uuid = UUIDUtil.fromBytes(uuidBytes).toString();
|
|
|
|
|
|
|
|
if (uuid != null) {
|
|
|
|
insert = conn.prepareStatement("INSERT INTO `" + getPrefix()
|
|
|
|
+ "jobs_temp` (`player_uuid`, `username`, `job`, `experience`, `level`) VALUES (?, ?, ?, ?, ?);");
|
|
|
|
insert.setString(1, uuid);
|
|
|
|
insert.setString(2, rs.getString("username"));
|
|
|
|
insert.setString(3, rs.getString("job"));
|
|
|
|
insert.setInt(4, rs.getInt("experience"));
|
|
|
|
insert.setInt(5, rs.getInt("level"));
|
|
|
|
insert.addBatch();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (insert != null)
|
|
|
|
insert.executeBatch();
|
|
|
|
conn.commit();
|
|
|
|
conn.setAutoCommit(true);
|
2016-03-10 13:48:15 +01:00
|
|
|
|
2016-06-25 14:51:21 +02:00
|
|
|
if (rs != null)
|
|
|
|
rs.close();
|
|
|
|
if (pst1 != null)
|
|
|
|
pst1.close();
|
2016-04-21 13:47:10 +02:00
|
|
|
if (insert != null)
|
|
|
|
insert.close();
|
2015-12-10 14:13:57 +01:00
|
|
|
|
2016-04-21 13:47:10 +02:00
|
|
|
executeSQL("DROP TABLE IF EXISTS `" + getPrefix() + "jobs`;");
|
|
|
|
try {
|
|
|
|
executeSQL("ALTER TABLE `" + getPrefix() + "jobs_temp` RENAME TO `" + getPrefix() + "jobs`;");
|
|
|
|
} catch (Exception e) {
|
2015-12-10 14:13:57 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-21 13:47:10 +02:00
|
|
|
boolean convertArchive = true;
|
|
|
|
PreparedStatement tempArchivePst = conn.prepareStatement("SELECT * FROM `" + getPrefix() + "archive`;");
|
|
|
|
ResultSet tempArchiveRes = tempArchivePst.executeQuery();
|
2015-12-10 14:13:57 +01:00
|
|
|
|
2016-04-21 16:26:17 +02:00
|
|
|
boolean noArchivedata = true;
|
2016-04-21 13:47:10 +02:00
|
|
|
try {
|
|
|
|
while (tempArchiveRes.next()) {
|
2016-04-21 16:26:17 +02:00
|
|
|
noArchivedata = false;
|
2016-04-21 13:47:10 +02:00
|
|
|
tempArchiveRes.getByte("player_uuid");
|
2016-04-21 16:26:17 +02:00
|
|
|
break;
|
2016-04-21 13:47:10 +02:00
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
convertArchive = false;
|
|
|
|
} finally {
|
|
|
|
tempArchiveRes.close();
|
|
|
|
tempArchivePst.close();
|
|
|
|
}
|
2016-04-21 16:26:17 +02:00
|
|
|
if (noArchivedata) {
|
|
|
|
dropDataBase("archive");
|
2016-06-09 17:35:24 +02:00
|
|
|
try {
|
|
|
|
executeSQL("CREATE TABLE `" + getPrefix()
|
|
|
|
+ "archive` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `userid` int, `job` varchar(20), `experience` int, `level` int);");
|
|
|
|
} catch (SQLException e) {
|
|
|
|
}
|
2016-04-21 16:26:17 +02:00
|
|
|
convertArchive = false;
|
|
|
|
}
|
2015-12-10 14:13:57 +01:00
|
|
|
|
2016-04-21 13:47:10 +02:00
|
|
|
if (convertArchive) {
|
|
|
|
// Converting archive players byte uuid into string
|
|
|
|
try {
|
|
|
|
executeSQL("CREATE TABLE `" + getPrefix()
|
|
|
|
+ "archive_temp` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `player_uuid` varchar(36) NOT NULL, `username` varchar(20), `job` varchar(20), `experience` int, `level` int);");
|
|
|
|
} catch (Exception e) {
|
|
|
|
}
|
|
|
|
PreparedStatement pst11 = conn.prepareStatement("SELECT * FROM `" + getPrefix() + "archive`;");
|
|
|
|
ResultSet rs1 = pst11.executeQuery();
|
|
|
|
PreparedStatement insert1 = null;
|
|
|
|
conn.setAutoCommit(false);
|
|
|
|
while (rs1.next()) {
|
|
|
|
|
|
|
|
String uuid = UUIDUtil.fromBytes(rs1.getBytes("player_uuid")).toString();
|
|
|
|
|
|
|
|
if (uuid != null) {
|
|
|
|
insert1 = conn.prepareStatement("INSERT INTO `" + getPrefix()
|
|
|
|
+ "archive_temp` (`player_uuid`, `username`, `job`, `experience`, `level`) VALUES (?, ?, ?, ?, ?);");
|
|
|
|
insert1.setString(1, uuid);
|
|
|
|
insert1.setString(2, rs1.getString("username"));
|
|
|
|
insert1.setString(3, rs1.getString("job"));
|
|
|
|
insert1.setInt(4, rs1.getInt("experience"));
|
|
|
|
insert1.setInt(5, rs1.getInt("level"));
|
|
|
|
insert1.addBatch();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (insert1 != null)
|
|
|
|
insert1.executeBatch();
|
|
|
|
conn.commit();
|
|
|
|
conn.setAutoCommit(true);
|
2016-06-25 14:51:21 +02:00
|
|
|
if (rs1 != null)
|
|
|
|
rs1.close();
|
|
|
|
if (pst11 != null)
|
|
|
|
pst11.close();
|
2016-04-21 13:47:10 +02:00
|
|
|
if (insert1 != null)
|
|
|
|
insert1.close();
|
|
|
|
executeSQL("DROP TABLE IF EXISTS `" + getPrefix() + "archive`;");
|
|
|
|
try {
|
|
|
|
executeSQL("ALTER TABLE `" + getPrefix() + "archive_temp` RENAME TO `" + getPrefix() + "archive`;");
|
|
|
|
} catch (Exception e) {
|
2015-12-10 14:13:57 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Converting log players byte uuid into string
|
2016-04-21 13:47:10 +02:00
|
|
|
boolean convertLog = true;
|
|
|
|
PreparedStatement tempLogPst = conn.prepareStatement("SELECT * FROM `" + getPrefix() + "log`;");
|
|
|
|
ResultSet tempLogRes = tempLogPst.executeQuery();
|
2015-12-10 14:13:57 +01:00
|
|
|
|
2016-04-21 16:26:17 +02:00
|
|
|
boolean nodata = true;
|
2016-04-21 13:47:10 +02:00
|
|
|
try {
|
|
|
|
while (tempLogRes.next()) {
|
2016-04-21 16:26:17 +02:00
|
|
|
nodata = false;
|
2016-04-21 13:47:10 +02:00
|
|
|
tempLogRes.getByte("player_uuid");
|
2016-04-21 16:26:17 +02:00
|
|
|
break;
|
2016-04-21 13:47:10 +02:00
|
|
|
}
|
2016-04-21 16:26:17 +02:00
|
|
|
|
2016-04-21 13:47:10 +02:00
|
|
|
} catch (Exception e) {
|
|
|
|
convertLog = false;
|
|
|
|
} finally {
|
|
|
|
tempLogRes.close();
|
|
|
|
tempLogPst.close();
|
|
|
|
}
|
2016-04-21 16:26:17 +02:00
|
|
|
if (nodata) {
|
|
|
|
dropDataBase("log");
|
2016-06-09 17:35:24 +02:00
|
|
|
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) {
|
|
|
|
}
|
2016-04-21 16:26:17 +02:00
|
|
|
convertLog = false;
|
|
|
|
}
|
2016-04-21 13:47:10 +02:00
|
|
|
|
|
|
|
if (convertLog) {
|
|
|
|
try {
|
|
|
|
executeSQL("CREATE TABLE `" + getPrefix()
|
|
|
|
+ "log_temp` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `player_uuid` varchar(36) NOT NULL, `username` varchar(20), `time` bigint, `action` varchar(20), `itemname` varchar(60), `count` int, `money` double, `exp` double);");
|
|
|
|
} catch (Exception e) {
|
|
|
|
}
|
|
|
|
PreparedStatement pst111 = conn.prepareStatement("SELECT * FROM `" + getPrefix() + "log`;");
|
|
|
|
ResultSet rs11 = pst111.executeQuery();
|
|
|
|
PreparedStatement insert11 = null;
|
|
|
|
conn.setAutoCommit(false);
|
|
|
|
while (rs11.next()) {
|
|
|
|
|
|
|
|
String uuid = UUIDUtil.fromBytes(rs11.getBytes("player_uuid")).toString();
|
|
|
|
|
|
|
|
if (uuid != null) {
|
|
|
|
insert11 = conn.prepareStatement("INSERT INTO `" + getPrefix()
|
|
|
|
+ "log_temp` (`player_uuid`, `username`, `time`, `action`, `itemname`, `count`, `money`, `exp`) VALUES (?, ?, ?, ?, ?, ?, ?, ?);");
|
|
|
|
insert11.setString(1, uuid);
|
|
|
|
insert11.setString(2, rs11.getString("username"));
|
|
|
|
insert11.setLong(3, rs11.getLong("time"));
|
|
|
|
insert11.setString(4, rs11.getString("action"));
|
|
|
|
insert11.setString(5, rs11.getString("itemname"));
|
|
|
|
insert11.setInt(6, rs11.getInt("count"));
|
|
|
|
insert11.setDouble(7, rs11.getDouble("money"));
|
|
|
|
insert11.setDouble(8, rs11.getDouble("exp"));
|
|
|
|
insert11.addBatch();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (insert11 != null)
|
|
|
|
insert11.executeBatch();
|
|
|
|
conn.commit();
|
|
|
|
conn.setAutoCommit(true);
|
2016-06-25 14:51:21 +02:00
|
|
|
if (rs11 != null)
|
|
|
|
rs11.close();
|
|
|
|
if (pst111 != null)
|
|
|
|
pst111.close();
|
2016-04-21 13:47:10 +02:00
|
|
|
if (insert11 != null)
|
|
|
|
insert11.close();
|
|
|
|
|
|
|
|
executeSQL("DROP TABLE IF EXISTS `" + getPrefix() + "log`;");
|
|
|
|
try {
|
|
|
|
executeSQL("ALTER TABLE `" + getPrefix() + "log_temp` RENAME TO `" + getPrefix() + "log`;");
|
|
|
|
} catch (Exception e) {
|
|
|
|
}
|
|
|
|
}
|
2015-12-10 14:13:57 +01:00
|
|
|
}
|
|
|
|
|
2016-01-09 13:58:33 +01:00
|
|
|
@Override
|
|
|
|
protected synchronized void checkUpdate8() throws SQLException {
|
|
|
|
JobsConnection conn = getConnection();
|
|
|
|
if (conn == null) {
|
|
|
|
Jobs.getPluginLogger().severe("Could not run database updates! Could not connect to MySQL!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
PreparedStatement prest = null;
|
2016-06-25 14:51:21 +02:00
|
|
|
ResultSet res = null;
|
2016-01-09 13:58:33 +01:00
|
|
|
int rows = 0;
|
|
|
|
try {
|
|
|
|
// Check for jobs table
|
|
|
|
prest = conn.prepareStatement("SELECT COUNT(*) FROM sqlite_master WHERE name = ?;");
|
|
|
|
prest.setString(1, getPrefix() + "explore");
|
2016-06-25 14:51:21 +02:00
|
|
|
res = prest.executeQuery();
|
2016-01-09 13:58:33 +01:00
|
|
|
if (res.next()) {
|
|
|
|
rows = res.getInt(1);
|
|
|
|
}
|
|
|
|
} finally {
|
2016-06-25 14:51:21 +02:00
|
|
|
close(res);
|
|
|
|
close(prest);
|
2016-01-09 13:58:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
if (rows == 0)
|
|
|
|
executeSQL("CREATE TABLE `" + getPrefix()
|
|
|
|
+ "explore` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `worldname` varchar(64), `chunkX` int, `chunkZ` int, `playerName` varchar(32));");
|
2016-04-21 13:47:10 +02:00
|
|
|
} catch (Exception e) {
|
2016-01-09 13:58:33 +01:00
|
|
|
} finally {
|
|
|
|
}
|
|
|
|
}
|
2016-03-30 15:42:36 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
protected synchronized void checkUpdate9() throws SQLException {
|
|
|
|
JobsConnection conn = getConnection();
|
|
|
|
if (conn == null) {
|
|
|
|
Jobs.getPluginLogger().severe("Could not run database updates! Could not connect to SQLite!");
|
|
|
|
return;
|
|
|
|
}
|
2016-04-21 13:47:10 +02:00
|
|
|
PreparedStatement prestTemp = null;
|
2016-06-25 14:51:21 +02:00
|
|
|
ResultSet res1 = null;
|
2016-04-21 13:47:10 +02:00
|
|
|
int rows = 0;
|
2016-03-30 15:42:36 +02:00
|
|
|
try {
|
2016-04-21 13:47:10 +02:00
|
|
|
// Check for jobs table
|
|
|
|
prestTemp = conn.prepareStatement("SELECT COUNT(*) FROM sqlite_master WHERE name = ?;");
|
|
|
|
prestTemp.setString(1, getPrefix() + "users");
|
2016-06-25 14:51:21 +02:00
|
|
|
res1 = prestTemp.executeQuery();
|
|
|
|
if (res1.next()) {
|
|
|
|
rows = res1.getInt(1);
|
2016-03-30 15:42:36 +02:00
|
|
|
}
|
|
|
|
} finally {
|
2016-06-25 14:51:21 +02:00
|
|
|
close(res1);
|
|
|
|
close(prestTemp);
|
2016-03-30 15:42:36 +02:00
|
|
|
}
|
2016-06-15 12:27:43 +02:00
|
|
|
|
2016-06-12 14:42:33 +02:00
|
|
|
// Create new points table
|
|
|
|
try {
|
|
|
|
executeSQL("CREATE TABLE `" + getPrefix()
|
|
|
|
+ "points` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `userid` int, `totalpoints` double, `currentpoints` double);");
|
|
|
|
} catch (Exception e) {
|
|
|
|
}
|
2016-06-15 12:27:43 +02:00
|
|
|
|
|
|
|
// checking log table, recreating if old version present
|
|
|
|
PreparedStatement prestLogTemp = null;
|
|
|
|
ResultSet rsLogTemp = null;
|
2016-06-15 19:30:21 +02:00
|
|
|
boolean next = false;
|
2016-06-15 12:27:43 +02:00
|
|
|
try {
|
|
|
|
prestLogTemp = conn.prepareStatement("SELECT * FROM `" + getPrefix() + "log`;");
|
|
|
|
rsLogTemp = prestLogTemp.executeQuery();
|
2016-06-25 15:27:01 +02:00
|
|
|
while (rsLogTemp.next()) {
|
|
|
|
next = true;
|
2016-06-15 12:27:43 +02:00
|
|
|
rsLogTemp.getInt("userid");
|
|
|
|
rsLogTemp.getLong("time");
|
|
|
|
rsLogTemp.getString("action");
|
|
|
|
rsLogTemp.getString("itemname");
|
|
|
|
rsLogTemp.getInt("count");
|
|
|
|
rsLogTemp.getDouble("money");
|
|
|
|
rsLogTemp.getDouble("exp");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} catch (Exception ex) {
|
2016-06-15 19:30:21 +02:00
|
|
|
|
2016-06-15 12:27:43 +02:00
|
|
|
} finally {
|
2016-06-25 14:51:21 +02:00
|
|
|
close(rsLogTemp);
|
|
|
|
close(prestLogTemp);
|
2016-06-15 12:27:43 +02:00
|
|
|
}
|
2016-06-25 14:51:21 +02:00
|
|
|
|
|
|
|
if (!next) {
|
2016-06-15 19:30:21 +02:00
|
|
|
executeSQL("DROP TABLE IF EXISTS `" + getPrefix() + "log`;");
|
|
|
|
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 (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
2016-06-15 12:27:43 +02:00
|
|
|
|
2016-06-09 17:35:24 +02:00
|
|
|
if (rows != 0)
|
|
|
|
return;
|
2016-06-11 08:03:01 +02:00
|
|
|
|
2016-06-09 17:35:24 +02:00
|
|
|
HashMap<String, String> tempMap = new HashMap<String, String>();
|
|
|
|
PreparedStatement prestJobs = null;
|
2016-06-25 14:51:21 +02:00
|
|
|
ResultSet res2 = null;
|
2016-06-09 17:35:24 +02:00
|
|
|
try {
|
|
|
|
prestJobs = conn.prepareStatement("SELECT * FROM " + getPrefix() + "jobs;");
|
2016-06-25 14:51:21 +02:00
|
|
|
res2 = prestJobs.executeQuery();
|
|
|
|
while (res2.next()) {
|
|
|
|
Bukkit.getConsoleSender().sendMessage(res2.getString("player_uuid") + " -> " + res2.getString("username"));
|
|
|
|
tempMap.put(res2.getString("player_uuid"), res2.getString("username"));
|
2016-03-30 15:42:36 +02:00
|
|
|
}
|
2016-06-09 17:35:24 +02:00
|
|
|
} finally {
|
2016-06-25 14:51:21 +02:00
|
|
|
close(res2);
|
|
|
|
close(prestJobs);
|
2016-06-09 17:35:24 +02:00
|
|
|
}
|
2016-06-25 14:51:21 +02:00
|
|
|
|
2016-06-09 17:35:24 +02:00
|
|
|
PreparedStatement prestArchive = null;
|
2016-06-25 14:51:21 +02:00
|
|
|
ResultSet res3 = null;
|
2016-06-09 17:35:24 +02:00
|
|
|
try {
|
|
|
|
prestArchive = conn.prepareStatement("SELECT * FROM " + getPrefix() + "archive;");
|
2016-06-25 14:51:21 +02:00
|
|
|
res3 = prestArchive.executeQuery();
|
|
|
|
while (res3.next()) {
|
|
|
|
tempMap.put(res3.getString("player_uuid"), res3.getString("username"));
|
|
|
|
Bukkit.getConsoleSender().sendMessage(res3.getString("player_uuid") + " -> " + res3.getString("username"));
|
2016-06-09 17:35:24 +02:00
|
|
|
}
|
|
|
|
} finally {
|
2016-06-25 14:51:21 +02:00
|
|
|
close(res3);
|
|
|
|
close(prestArchive);
|
2016-06-09 17:35:24 +02:00
|
|
|
}
|
2016-03-30 15:42:36 +02:00
|
|
|
|
2016-06-09 17:35:24 +02:00
|
|
|
try {
|
|
|
|
executeSQL("CREATE TABLE `" + getPrefix()
|
|
|
|
+ "users` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `player_uuid` varchar(36) NOT NULL, `username` varchar(20));");
|
|
|
|
} catch (Exception e) {
|
|
|
|
}
|
|
|
|
PreparedStatement prestUsers = null;
|
|
|
|
try {
|
|
|
|
prestUsers = conn.prepareStatement("INSERT INTO `" + getPrefix() + "users` (`player_uuid`, `username`) VALUES (?, ?);");
|
|
|
|
conn.setAutoCommit(false);
|
|
|
|
for (Entry<String, String> users : tempMap.entrySet()) {
|
|
|
|
Bukkit.getConsoleSender().sendMessage(users.getKey() + " -----> " + users.getValue());
|
|
|
|
prestUsers.setString(1, users.getKey());
|
|
|
|
prestUsers.setString(2, users.getValue());
|
|
|
|
prestUsers.addBatch();
|
2016-03-30 15:42:36 +02:00
|
|
|
}
|
2016-06-09 17:35:24 +02:00
|
|
|
prestUsers.executeBatch();
|
|
|
|
conn.commit();
|
|
|
|
conn.setAutoCommit(true);
|
|
|
|
} finally {
|
2016-06-25 14:51:21 +02:00
|
|
|
close(prestUsers);
|
2016-06-09 17:35:24 +02:00
|
|
|
}
|
2016-03-30 15:42:36 +02:00
|
|
|
|
2016-06-09 17:35:24 +02:00
|
|
|
HashMap<String, PlayerInfo> tempPlayerMap = new HashMap<String, PlayerInfo>();
|
2016-03-30 15:42:36 +02:00
|
|
|
|
2016-06-09 17:35:24 +02:00
|
|
|
PreparedStatement prestUsers2 = null;
|
2016-06-25 14:51:21 +02:00
|
|
|
ResultSet res4 = null;
|
2016-06-09 17:35:24 +02:00
|
|
|
try {
|
|
|
|
prestUsers2 = conn.prepareStatement("SELECT * FROM " + getPrefix() + "users;");
|
2016-06-25 14:51:21 +02:00
|
|
|
res4 = prestUsers2.executeQuery();
|
|
|
|
while (res4.next()) {
|
|
|
|
tempPlayerMap.put(res4.getString("player_uuid"), new PlayerInfo(res4.getString("username"), res4.getInt("id")));
|
2016-06-09 17:35:24 +02:00
|
|
|
}
|
|
|
|
} finally {
|
2016-06-25 14:51:21 +02:00
|
|
|
close(res4);
|
|
|
|
close(prestUsers2);
|
2016-06-09 17:35:24 +02:00
|
|
|
}
|
2016-03-30 15:42:36 +02:00
|
|
|
|
2016-06-09 17:35:24 +02:00
|
|
|
// Modifying jobs main table
|
|
|
|
try {
|
|
|
|
executeSQL("ALTER TABLE `" + getPrefix() + "jobs` ADD COLUMN `userid` int;");
|
|
|
|
} catch (Exception e) {
|
|
|
|
}
|
|
|
|
PreparedStatement prestJobsT = null;
|
|
|
|
try {
|
|
|
|
prestJobsT = conn.prepareStatement("UPDATE `" + getPrefix() + "jobs` SET `userid` = ? WHERE `player_uuid` = ?;");
|
|
|
|
conn.setAutoCommit(false);
|
|
|
|
for (Entry<String, PlayerInfo> users : tempPlayerMap.entrySet()) {
|
|
|
|
prestJobsT.setInt(1, users.getValue().getID());
|
|
|
|
prestJobsT.setString(2, users.getKey());
|
|
|
|
prestJobsT.addBatch();
|
2016-03-30 15:42:36 +02:00
|
|
|
}
|
2016-06-09 17:35:24 +02:00
|
|
|
prestJobsT.executeBatch();
|
|
|
|
conn.commit();
|
|
|
|
conn.setAutoCommit(true);
|
|
|
|
} catch (Exception e) {
|
|
|
|
} finally {
|
2016-06-25 14:51:21 +02:00
|
|
|
close(prestJobsT);
|
2016-06-09 17:35:24 +02:00
|
|
|
}
|
2016-03-30 15:42:36 +02:00
|
|
|
|
2016-06-09 17:35:24 +02:00
|
|
|
// dropping 2 columns
|
|
|
|
try {
|
|
|
|
executeSQL("CREATE TABLE `" + getPrefix()
|
|
|
|
+ "jobs_temp` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `userid` int, `job` varchar(20), `experience` int, `level` int);");
|
|
|
|
} catch (Exception e) {
|
|
|
|
}
|
2016-04-21 13:47:10 +02:00
|
|
|
|
2016-06-09 17:35:24 +02:00
|
|
|
PreparedStatement pst111 = conn.prepareStatement("SELECT * FROM `" + getPrefix() + "jobs`;");
|
|
|
|
ResultSet rs11 = pst111.executeQuery();
|
|
|
|
PreparedStatement insert11 = null;
|
|
|
|
while (rs11.next()) {
|
|
|
|
String uuid = UUIDUtil.fromBytes(rs11.getBytes("player_uuid")).toString();
|
|
|
|
if (uuid != null) {
|
|
|
|
insert11 = conn.prepareStatement("INSERT INTO `" + getPrefix() + "jobs_temp` (`userid`, `job`, `experience`, `level`) VALUES (?, ?, ?, ?);");
|
|
|
|
insert11.setInt(1, rs11.getInt("userid"));
|
|
|
|
insert11.setString(2, rs11.getString("job"));
|
|
|
|
insert11.setInt(3, rs11.getInt("experience"));
|
|
|
|
insert11.setInt(4, rs11.getInt("level"));
|
|
|
|
insert11.execute();
|
2016-03-30 15:42:36 +02:00
|
|
|
}
|
2016-06-09 17:35:24 +02:00
|
|
|
}
|
2016-06-25 14:51:21 +02:00
|
|
|
if (rs11 != null)
|
|
|
|
rs11.close();
|
|
|
|
if (pst111 != null)
|
|
|
|
pst111.close();
|
2016-06-09 17:35:24 +02:00
|
|
|
if (insert11 != null)
|
|
|
|
insert11.close();
|
|
|
|
try {
|
|
|
|
executeSQL("DROP TABLE IF EXISTS `" + getPrefix() + "jobs`;");
|
|
|
|
executeSQL("ALTER TABLE `" + getPrefix() + "jobs_temp` RENAME TO `" + getPrefix() + "jobs`;");
|
|
|
|
} catch (Exception e) {
|
|
|
|
}
|
2016-03-30 15:42:36 +02:00
|
|
|
|
2016-06-09 17:35:24 +02:00
|
|
|
// Modifying jobs archive table
|
|
|
|
try {
|
|
|
|
executeSQL("ALTER TABLE `" + getPrefix() + "archive` ADD COLUMN `userid` int;");
|
|
|
|
} catch (Exception e) {
|
|
|
|
}
|
|
|
|
PreparedStatement prestArchiveT = null;
|
|
|
|
try {
|
|
|
|
prestArchiveT = conn.prepareStatement("UPDATE `" + getPrefix() + "archive` SET `userid` = ? WHERE `player_uuid` = ?;");
|
|
|
|
conn.setAutoCommit(false);
|
|
|
|
for (Entry<String, PlayerInfo> users : tempPlayerMap.entrySet()) {
|
|
|
|
prestArchiveT.setInt(1, users.getValue().getID());
|
|
|
|
prestArchiveT.setString(2, users.getKey());
|
|
|
|
prestArchiveT.addBatch();
|
2016-03-30 15:42:36 +02:00
|
|
|
}
|
2016-06-09 17:35:24 +02:00
|
|
|
prestArchiveT.executeBatch();
|
|
|
|
conn.commit();
|
|
|
|
conn.setAutoCommit(true);
|
|
|
|
} finally {
|
2016-06-25 14:51:21 +02:00
|
|
|
close(prestArchiveT);
|
2016-06-09 17:35:24 +02:00
|
|
|
}
|
2016-03-30 15:42:36 +02:00
|
|
|
|
2016-06-09 17:35:24 +02:00
|
|
|
// dropping 2 columns
|
|
|
|
try {
|
|
|
|
executeSQL("CREATE TABLE `" + getPrefix()
|
|
|
|
+ "archive_temp` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `userid` int, `job` varchar(20), `experience` int, `level` int);");
|
|
|
|
} catch (Exception e) {
|
|
|
|
}
|
2016-04-21 13:47:10 +02:00
|
|
|
|
2016-06-15 12:27:43 +02:00
|
|
|
PreparedStatement pstArchive = null;
|
|
|
|
ResultSet rsArchive = null;
|
2016-06-09 17:35:24 +02:00
|
|
|
PreparedStatement insertArchive = null;
|
2016-06-15 12:27:43 +02:00
|
|
|
try {
|
|
|
|
pstArchive = conn.prepareStatement("SELECT * FROM `" + getPrefix() + "archive`;");
|
|
|
|
rsArchive = pstArchive.executeQuery();
|
|
|
|
while (rsArchive.next()) {
|
|
|
|
String uuid = UUIDUtil.fromBytes(rsArchive.getBytes("player_uuid")).toString();
|
|
|
|
if (uuid != null) {
|
|
|
|
insertArchive = conn.prepareStatement("INSERT INTO `" + getPrefix() + "archive_temp` (`userid`, `job`, `experience`, `level`) VALUES (?, ?, ?, ?);");
|
|
|
|
insertArchive.setInt(1, rsArchive.getInt("userid"));
|
|
|
|
insertArchive.setString(2, rsArchive.getString("job"));
|
|
|
|
insertArchive.setInt(3, rsArchive.getInt("experience"));
|
|
|
|
insertArchive.setInt(4, rsArchive.getInt("level"));
|
|
|
|
insertArchive.execute();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
} finally {
|
|
|
|
if (rsArchive != null)
|
|
|
|
rsArchive.close();
|
|
|
|
if (insertArchive != null)
|
|
|
|
insertArchive.close();
|
|
|
|
if (pstArchive != null)
|
|
|
|
pstArchive.close();
|
|
|
|
}
|
|
|
|
|
2016-06-09 17:35:24 +02:00
|
|
|
executeSQL("DROP TABLE IF EXISTS `" + getPrefix() + "archive`;");
|
|
|
|
try {
|
|
|
|
executeSQL("ALTER TABLE `" + getPrefix() + "archive_temp` RENAME TO `" + getPrefix() + "archive`;");
|
|
|
|
} catch (Exception e) {
|
|
|
|
}
|
|
|
|
// Modifying jobs log table
|
|
|
|
PreparedStatement prestPreLog = null;
|
|
|
|
try {
|
|
|
|
executeSQL("ALTER TABLE `" + getPrefix() + "log` ADD COLUMN `userid` int;");
|
|
|
|
prestPreLog = conn.prepareStatement("UPDATE `" + getPrefix() + "log` SET `userid` = ? WHERE `player_uuid` = ?;");
|
|
|
|
conn.setAutoCommit(false);
|
|
|
|
for (Entry<String, PlayerInfo> users : tempPlayerMap.entrySet()) {
|
|
|
|
prestPreLog.setInt(1, users.getValue().getID());
|
|
|
|
prestPreLog.setString(2, users.getKey());
|
|
|
|
prestPreLog.addBatch();
|
2016-03-30 15:42:36 +02:00
|
|
|
}
|
2016-06-09 17:35:24 +02:00
|
|
|
prestPreLog.executeBatch();
|
|
|
|
conn.commit();
|
|
|
|
conn.setAutoCommit(true);
|
|
|
|
} finally {
|
2016-06-25 14:51:21 +02:00
|
|
|
close(prestPreLog);
|
2016-06-09 17:35:24 +02:00
|
|
|
}
|
2016-03-30 15:42:36 +02:00
|
|
|
|
|
|
|
}
|
2016-04-21 16:26:17 +02:00
|
|
|
|
2016-04-21 17:10:27 +02:00
|
|
|
private boolean createDefaultExploreBase() {
|
|
|
|
try {
|
|
|
|
executeSQL("CREATE TABLE `" + getPrefix()
|
|
|
|
+ "explore` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `worldname` varchar(64), `chunkX` int, `chunkZ` int, `playerName` varchar(32));");
|
|
|
|
} catch (SQLException e) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean createDefaultPointsBase() {
|
|
|
|
try {
|
|
|
|
executeSQL("CREATE TABLE `" + getPrefix()
|
|
|
|
+ "points` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `userid` int, `totalpoints` double, `currentpoints` double);");
|
|
|
|
} catch (SQLException e) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean createDefaultUsersBase() {
|
|
|
|
try {
|
|
|
|
executeSQL("CREATE TABLE `" + getPrefix()
|
|
|
|
+ "users` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `player_uuid` varchar(36) NOT NULL, `username` varchar(20));");
|
|
|
|
} catch (SQLException e) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-06-25 17:56:59 +02:00
|
|
|
@Override
|
2016-06-25 09:13:06 +02:00
|
|
|
protected boolean createDefaultLogBase() {
|
2016-04-21 16:26:17 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2016-06-26 15:12:44 +02:00
|
|
|
@Override
|
|
|
|
protected boolean createDefaultArchiveBase() {
|
2016-04-21 16:26:17 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2016-06-25 17:56:59 +02:00
|
|
|
@Override
|
2016-06-25 09:13:06 +02:00
|
|
|
protected boolean dropDataBase(String name) {
|
2016-04-21 16:26:17 +02:00
|
|
|
try {
|
|
|
|
executeSQL("DROP TABLE IF EXISTS `" + getPrefix() + name + "`;");
|
|
|
|
} catch (SQLException e) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2015-08-21 15:10:08 +02:00
|
|
|
}
|