Fixed basic UUID conversion

This commit is contained in:
boy0001 2015-04-29 23:07:12 +10:00
parent ffb4710080
commit d790d5b7c8
5 changed files with 47 additions and 17 deletions

View File

@ -36,6 +36,7 @@ import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Configuration; import com.intellectualcrafters.plot.config.Configuration;
import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.database.Database;
import com.intellectualcrafters.plot.database.MySQL; import com.intellectualcrafters.plot.database.MySQL;
import com.intellectualcrafters.plot.database.SQLManager; import com.intellectualcrafters.plot.database.SQLManager;
import com.intellectualcrafters.plot.database.SQLite; import com.intellectualcrafters.plot.database.SQLite;
@ -94,11 +95,11 @@ public class PlotSquared {
private final static HashMap<String, PlotWorld> plotworlds = new HashMap<>(); private final static HashMap<String, PlotWorld> plotworlds = new HashMap<>();
private final static HashMap<String, PlotManager> plotmanagers = new HashMap<>(); private final static HashMap<String, PlotManager> plotmanagers = new HashMap<>();
private static LinkedHashMap<String, HashMap<PlotId, Plot>> plots; private static LinkedHashMap<String, HashMap<PlotId, Plot>> plots;
private static MySQL mySQL; private static Database database;
public static Connection connection; public static Connection connection;
public static MySQL getMySQL() { public static Database getDatabase() {
return mySQL; return database;
} }
public static void updatePlot(final Plot plot) { public static void updatePlot(final Plot plot) {
@ -631,12 +632,9 @@ public class PlotSquared {
public void disable() { public void disable() {
try { try {
connection.close(); database.closeConnection();
mySQL.closeConnection();
} catch (NullPointerException | SQLException e) { } catch (NullPointerException | SQLException e) {
if (mySQL != null) { log("&cCould not close database connection!");
log("&cCould not close mysql connection!");
}
} }
} }
@ -654,8 +652,8 @@ public class PlotSquared {
} }
if (Settings.DB.USE_MYSQL) { if (Settings.DB.USE_MYSQL) {
try { try {
mySQL = new MySQL(THIS, Settings.DB.HOST_NAME, Settings.DB.PORT, Settings.DB.DATABASE, Settings.DB.USER, Settings.DB.PASSWORD); database = new MySQL(THIS, Settings.DB.HOST_NAME, Settings.DB.PORT, Settings.DB.DATABASE, Settings.DB.USER, Settings.DB.PASSWORD);
connection = mySQL.openConnection(); connection = database.openConnection();
{ {
if (DBFunc.dbManager == null) { if (DBFunc.dbManager == null) {
DBFunc.dbManager = new SQLManager(connection, Settings.DB.PREFIX); DBFunc.dbManager = new SQLManager(connection, Settings.DB.PREFIX);
@ -693,7 +691,8 @@ public class PlotSquared {
log(C.PREFIX.s() + "MongoDB is not yet implemented"); log(C.PREFIX.s() + "MongoDB is not yet implemented");
} else if (Settings.DB.USE_SQLITE) { } else if (Settings.DB.USE_SQLITE) {
try { try {
connection = new SQLite(THIS, IMP.getDirectory() + File.separator + Settings.DB.SQLITE_DB + ".db").openConnection(); this.database = new SQLite(THIS, IMP.getDirectory() + File.separator + Settings.DB.SQLITE_DB + ".db");
connection = this.database.openConnection();
{ {
DBFunc.dbManager = new SQLManager(connection, Settings.DB.PREFIX); DBFunc.dbManager = new SQLManager(connection, Settings.DB.PREFIX);
final DatabaseMetaData meta = connection.getMetaData(); final DatabaseMetaData meta = connection.getMetaData();

View File

@ -32,6 +32,7 @@ import org.bukkit.Bukkit;
import com.intellectualcrafters.plot.PlotSquared; import com.intellectualcrafters.plot.PlotSquared;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.database.AbstractDB; import com.intellectualcrafters.plot.database.AbstractDB;
import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.database.SQLManager; import com.intellectualcrafters.plot.database.SQLManager;
@ -233,7 +234,7 @@ public class DebugUUID extends SubCommand {
MainUtil.sendConsoleMessage("&7 - Creating tables"); MainUtil.sendConsoleMessage("&7 - Creating tables");
try { try {
database.createTables(PlotSquared.getMySQL() != null ? "mysql" : "sqlite", true); database.createTables(Settings.DB.USE_MYSQL ? "mysql" : "sqlite", true);
if (!result) { if (!result) {
MainUtil.sendConsoleMessage("&cConversion failed! Attempting recovery"); MainUtil.sendConsoleMessage("&cConversion failed! Attempting recovery");
for (Plot plot : PlotSquared.getPlots()) { for (Plot plot : PlotSquared.getPlots()) {
@ -256,6 +257,25 @@ public class DebugUUID extends SubCommand {
return false; return false;
} }
if (newWrapper instanceof OfflineUUIDWrapper) {
PlotSquared.config.set("UUID.force-lowercase", false);
PlotSquared.config.set("UUID.offline", true);
}
else if (newWrapper instanceof LowerOfflineUUIDWrapper) {
PlotSquared.config.set("UUID.force-lowercase", true);
PlotSquared.config.set("UUID.offline", true);
}
else if (newWrapper instanceof DefaultUUIDWrapper) {
PlotSquared.config.set("UUID.force-lowercase", false);
PlotSquared.config.set("UUID.offline", false);
}
try {
PlotSquared.config.save(PlotSquared.configFile);
}
catch (Exception e) {
MainUtil.sendConsoleMessage("Could not save configuration. It will need to be manuall set!");
}
MainUtil.sendConsoleMessage("&7 - Populating tables"); MainUtil.sendConsoleMessage("&7 - Populating tables");
TaskManager.runTaskAsync(new Runnable() { TaskManager.runTaskAsync(new Runnable() {

View File

@ -47,6 +47,8 @@ public abstract class Database {
this.plotsquared = plotsquared; this.plotsquared = plotsquared;
} }
public abstract Connection forceConnection() throws SQLException, ClassNotFoundException ;
/** /**
* Opens a connection with the database * Opens a connection with the database
* *

View File

@ -40,6 +40,7 @@ import org.apache.commons.lang.StringUtils;
import org.bukkit.block.Biome; import org.bukkit.block.Biome;
import com.intellectualcrafters.plot.PlotSquared; import com.intellectualcrafters.plot.PlotSquared;
import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.flag.Flag; import com.intellectualcrafters.plot.flag.Flag;
import com.intellectualcrafters.plot.flag.FlagManager; import com.intellectualcrafters.plot.flag.FlagManager;
import com.intellectualcrafters.plot.object.BlockLoc; import com.intellectualcrafters.plot.object.BlockLoc;
@ -94,12 +95,12 @@ public class SQLManager implements AbstractDB {
this.CREATE_PLOT = "INSERT INTO `" + this.prefix + "plot`(`plot_id_x`, `plot_id_z`, `owner`, `world`) VALUES(?, ?, ?, ?)"; this.CREATE_PLOT = "INSERT INTO `" + this.prefix + "plot`(`plot_id_x`, `plot_id_z`, `owner`, `world`) VALUES(?, ?, ?, ?)";
this.CREATE_CLUSTER = "INSERT INTO `" + this.prefix + "cluster`(`pos1_x`, `pos1_z`, `pos2_x`, `pos2_z`, `owner`, `world`) VALUES(?, ?, ?, ?, ?, ?)"; this.CREATE_CLUSTER = "INSERT INTO `" + this.prefix + "cluster`(`pos1_x`, `pos1_z`, `pos2_x`, `pos2_z`, `owner`, `world`) VALUES(?, ?, ?, ?, ?, ?)";
// schedule reconnect // schedule reconnect
if (PlotSquared.getMySQL() != null) { if (Settings.DB.USE_MYSQL) {
TaskManager.runTaskRepeat(new Runnable() { TaskManager.runTaskRepeat(new Runnable() {
@Override @Override
public void run() { public void run() {
try { try {
SQLManager.this.connection = PlotSquared.getMySQL().forceConnection(); SQLManager.this.connection = PlotSquared.getDatabase().forceConnection();
} }
catch (Exception e) { catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
@ -325,7 +326,7 @@ public class SQLManager implements AbstractDB {
return; return;
} }
int packet; int packet;
if (PlotSquared.getMySQL() != null) { if (Settings.DB.USE_MYSQL) {
packet = Math.min(size, 50000); packet = Math.min(size, 50000);
} else { } else {
packet = Math.min(size, 50); packet = Math.min(size, 50);
@ -673,7 +674,7 @@ public class SQLManager implements AbstractDB {
try { try {
final Statement statement = this.connection.createStatement(); final Statement statement = this.connection.createStatement();
statement.addBatch("DROP TABLE `" + this.prefix + "plot_comments`"); statement.addBatch("DROP TABLE `" + this.prefix + "plot_comments`");
if (PlotSquared.getMySQL() != null) { if (Settings.DB.USE_MYSQL) {
statement.addBatch("CREATE TABLE IF NOT EXISTS `" + this.prefix + "plot_comments` (" + "`world` VARCHAR(40) NOT NULL, `hashcode` INT(11) NOT NULL," + "`comment` VARCHAR(40) NOT NULL," + "`inbox` VARCHAR(40) NOT NULL," + "`timestamp` INT(11) NOT NULL," + "`sender` VARCHAR(40) NOT NULL" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8"); statement.addBatch("CREATE TABLE IF NOT EXISTS `" + this.prefix + "plot_comments` (" + "`world` VARCHAR(40) NOT NULL, `hashcode` INT(11) NOT NULL," + "`comment` VARCHAR(40) NOT NULL," + "`inbox` VARCHAR(40) NOT NULL," + "`timestamp` INT(11) NOT NULL," + "`sender` VARCHAR(40) NOT NULL" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8");
} }
else { else {
@ -1971,7 +1972,8 @@ public class SQLManager implements AbstractDB {
@Override @Override
public boolean deleteTables() { public boolean deleteTables() {
try { try {
SQLManager.this.connection = PlotSquared.getMySQL().forceConnection(); SQLManager.this.connection.close();
SQLManager.this.connection = PlotSquared.getDatabase().forceConnection();
final Statement stmt = this.connection.createStatement(); final Statement stmt = this.connection.createStatement();
stmt.addBatch("DROP TABLE `" + prefix + "cluster_invited`"); stmt.addBatch("DROP TABLE `" + prefix + "cluster_invited`");
stmt.addBatch("DROP TABLE `" + prefix + "cluster_helpers`"); stmt.addBatch("DROP TABLE `" + prefix + "cluster_helpers`");

View File

@ -107,4 +107,11 @@ public class SQLite extends Database {
final Statement statement = this.connection.createStatement(); final Statement statement = this.connection.createStatement();
return statement.executeUpdate(query); return statement.executeUpdate(query);
} }
@Override
public Connection forceConnection() throws SQLException, ClassNotFoundException {
Class.forName("org.sqlite.JDBC");
this.connection = DriverManager.getConnection("jdbc:sqlite:" + this.dbLocation);
return this.connection;
}
} }