mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-26 07:06:44 +01:00
Fixed basic UUID conversion
This commit is contained in:
parent
ffb4710080
commit
d790d5b7c8
@ -36,6 +36,7 @@ import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.config.Configuration;
|
||||
import com.intellectualcrafters.plot.config.Settings;
|
||||
import com.intellectualcrafters.plot.database.DBFunc;
|
||||
import com.intellectualcrafters.plot.database.Database;
|
||||
import com.intellectualcrafters.plot.database.MySQL;
|
||||
import com.intellectualcrafters.plot.database.SQLManager;
|
||||
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, PlotManager> plotmanagers = new HashMap<>();
|
||||
private static LinkedHashMap<String, HashMap<PlotId, Plot>> plots;
|
||||
private static MySQL mySQL;
|
||||
private static Database database;
|
||||
public static Connection connection;
|
||||
|
||||
public static MySQL getMySQL() {
|
||||
return mySQL;
|
||||
public static Database getDatabase() {
|
||||
return database;
|
||||
}
|
||||
|
||||
public static void updatePlot(final Plot plot) {
|
||||
@ -631,12 +632,9 @@ public class PlotSquared {
|
||||
|
||||
public void disable() {
|
||||
try {
|
||||
connection.close();
|
||||
mySQL.closeConnection();
|
||||
database.closeConnection();
|
||||
} catch (NullPointerException | SQLException e) {
|
||||
if (mySQL != null) {
|
||||
log("&cCould not close mysql connection!");
|
||||
}
|
||||
log("&cCould not close database connection!");
|
||||
}
|
||||
}
|
||||
|
||||
@ -654,8 +652,8 @@ public class PlotSquared {
|
||||
}
|
||||
if (Settings.DB.USE_MYSQL) {
|
||||
try {
|
||||
mySQL = new MySQL(THIS, Settings.DB.HOST_NAME, Settings.DB.PORT, Settings.DB.DATABASE, Settings.DB.USER, Settings.DB.PASSWORD);
|
||||
connection = mySQL.openConnection();
|
||||
database = new MySQL(THIS, Settings.DB.HOST_NAME, Settings.DB.PORT, Settings.DB.DATABASE, Settings.DB.USER, Settings.DB.PASSWORD);
|
||||
connection = database.openConnection();
|
||||
{
|
||||
if (DBFunc.dbManager == null) {
|
||||
DBFunc.dbManager = new SQLManager(connection, Settings.DB.PREFIX);
|
||||
@ -693,7 +691,8 @@ public class PlotSquared {
|
||||
log(C.PREFIX.s() + "MongoDB is not yet implemented");
|
||||
} else if (Settings.DB.USE_SQLITE) {
|
||||
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);
|
||||
final DatabaseMetaData meta = connection.getMetaData();
|
||||
|
@ -32,6 +32,7 @@ import org.bukkit.Bukkit;
|
||||
|
||||
import com.intellectualcrafters.plot.PlotSquared;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.config.Settings;
|
||||
import com.intellectualcrafters.plot.database.AbstractDB;
|
||||
import com.intellectualcrafters.plot.database.DBFunc;
|
||||
import com.intellectualcrafters.plot.database.SQLManager;
|
||||
@ -233,7 +234,7 @@ public class DebugUUID extends SubCommand {
|
||||
MainUtil.sendConsoleMessage("&7 - Creating tables");
|
||||
|
||||
try {
|
||||
database.createTables(PlotSquared.getMySQL() != null ? "mysql" : "sqlite", true);
|
||||
database.createTables(Settings.DB.USE_MYSQL ? "mysql" : "sqlite", true);
|
||||
if (!result) {
|
||||
MainUtil.sendConsoleMessage("&cConversion failed! Attempting recovery");
|
||||
for (Plot plot : PlotSquared.getPlots()) {
|
||||
@ -256,6 +257,25 @@ public class DebugUUID extends SubCommand {
|
||||
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");
|
||||
|
||||
TaskManager.runTaskAsync(new Runnable() {
|
||||
|
@ -47,6 +47,8 @@ public abstract class Database {
|
||||
this.plotsquared = plotsquared;
|
||||
}
|
||||
|
||||
public abstract Connection forceConnection() throws SQLException, ClassNotFoundException ;
|
||||
|
||||
/**
|
||||
* Opens a connection with the database
|
||||
*
|
||||
|
@ -40,6 +40,7 @@ import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.block.Biome;
|
||||
|
||||
import com.intellectualcrafters.plot.PlotSquared;
|
||||
import com.intellectualcrafters.plot.config.Settings;
|
||||
import com.intellectualcrafters.plot.flag.Flag;
|
||||
import com.intellectualcrafters.plot.flag.FlagManager;
|
||||
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_CLUSTER = "INSERT INTO `" + this.prefix + "cluster`(`pos1_x`, `pos1_z`, `pos2_x`, `pos2_z`, `owner`, `world`) VALUES(?, ?, ?, ?, ?, ?)";
|
||||
// schedule reconnect
|
||||
if (PlotSquared.getMySQL() != null) {
|
||||
if (Settings.DB.USE_MYSQL) {
|
||||
TaskManager.runTaskRepeat(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
SQLManager.this.connection = PlotSquared.getMySQL().forceConnection();
|
||||
SQLManager.this.connection = PlotSquared.getDatabase().forceConnection();
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
@ -325,7 +326,7 @@ public class SQLManager implements AbstractDB {
|
||||
return;
|
||||
}
|
||||
int packet;
|
||||
if (PlotSquared.getMySQL() != null) {
|
||||
if (Settings.DB.USE_MYSQL) {
|
||||
packet = Math.min(size, 50000);
|
||||
} else {
|
||||
packet = Math.min(size, 50);
|
||||
@ -673,7 +674,7 @@ public class SQLManager implements AbstractDB {
|
||||
try {
|
||||
final Statement statement = this.connection.createStatement();
|
||||
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");
|
||||
}
|
||||
else {
|
||||
@ -1971,7 +1972,8 @@ public class SQLManager implements AbstractDB {
|
||||
@Override
|
||||
public boolean deleteTables() {
|
||||
try {
|
||||
SQLManager.this.connection = PlotSquared.getMySQL().forceConnection();
|
||||
SQLManager.this.connection.close();
|
||||
SQLManager.this.connection = PlotSquared.getDatabase().forceConnection();
|
||||
final Statement stmt = this.connection.createStatement();
|
||||
stmt.addBatch("DROP TABLE `" + prefix + "cluster_invited`");
|
||||
stmt.addBatch("DROP TABLE `" + prefix + "cluster_helpers`");
|
||||
|
@ -107,4 +107,11 @@ public class SQLite extends Database {
|
||||
final Statement statement = this.connection.createStatement();
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user