Automatically drop unique_alias for MySQL

This commit is contained in:
Jesse Boyd 2016-03-18 03:05:36 +11:00
parent 3921fdfc3f
commit 9e32ce9885
7 changed files with 49 additions and 27 deletions

View file

@ -163,8 +163,9 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
}
@Override
public String getPluginVersion() {
return getDescription().getVersion();
public int[] getPluginVersion() {
final String[] split = getDescription().getVersion().split("\\.");
return new int[] { Integer.parseInt(split[0]), Integer.parseInt(split[1]), Integer.parseInt(split[2]) };
}
@Override

View file

@ -57,7 +57,7 @@ public interface IPlotMain {
* Get the version of the PlotSquared being used
* @return
*/
String getPluginVersion();
int[] getPluginVersion();
/**
* Get the version of Minecraft that is running

View file

@ -126,9 +126,9 @@ public class PS {
// private:
private File storageFile;
private File FILE = null; // This file
private String VERSION = null;
private int[] VERSION = null;
private int[] LAST_VERSION;
private String PLATFORM = null;
private String LAST_VERSION;
private Database database;
private Thread thread;
@ -278,8 +278,11 @@ public class PS {
final URL url = Updater.getUpdate();
if (url != null) {
update = url;
} else if ((LAST_VERSION != null) && !VERSION.equals(LAST_VERSION)) {
log("&aThanks for updating from: " + LAST_VERSION + " to " + VERSION);
} else if (LAST_VERSION == null) {
log("&aThanks for installing PlotSquared!");
} else if (!PS.get().checkVersion(LAST_VERSION, VERSION)) {
log("&aThanks for updating from " + StringMan.join(LAST_VERSION, ".") + " to " + StringMan.join(VERSION, ".") + "!");
DBFunc.dbManager.updateTables(LAST_VERSION);
}
}
});
@ -366,16 +369,22 @@ public class PS {
return this.thread == thread;
}
public boolean checkVersion(final int[] version, final int major, final int minor, final int minor2) {
return (version[0] > major) || ((version[0] == major) && (version[1] > minor)) || ((version[0] == major) && (version[1] == minor) && (
version[2] >= minor2));
/**
* Check if `version` is >= `version2`
* @param version
* @param version2
* @return true if `version` is >= `version2`
*/
public boolean checkVersion(final int[] version, int... version2) {
return (version[0] > version2[0]) || ((version[0] == version2[0]) && (version[1] > version2[1])) || ((version[0] == version2[0]) && (version[1] == version2[1]) && (
version[2] >= version2[2]));
}
/**
* Get the last PlotSquared version
* @return last version in config or null
*/
public String getLastVersion() {
public int[] getLastVersion() {
return LAST_VERSION;
}
@ -383,7 +392,7 @@ public class PS {
* Get the current PlotSquared version
* @return current version in config or null
*/
public String getVersion() {
public int[] getVersion() {
return VERSION;
}
@ -2039,8 +2048,13 @@ public class PS {
* Setup the default configuration (settings.yml)
*/
public void setupConfig() {
LAST_VERSION = config.getString("version");
config.set("version", VERSION);
String lastVersionString = config.getString("version");
if (lastVersionString != null) {
String[] split = lastVersionString.split("\\.");
LAST_VERSION = new int[] { Integer.parseInt(split[0]), Integer.parseInt(split[1]), Integer.parseInt(split[2]) };
}
config.set("version", StringMan.join(VERSION, "."));
config.set("platform", PLATFORM);
final Map<String, Object> options = new HashMap<>();
@ -2365,7 +2379,7 @@ public class PS {
* Setup the storage file (load + save missing nodes)
*/
private void setupStorage() {
storage.set("version", VERSION);
storage.set("version", StringMan.join(VERSION, "."));
final Map<String, Object> options = new HashMap<>(9);
options.put("mysql.use", false);
options.put("sqlite.use", true);
@ -2417,7 +2431,7 @@ public class PS {
* Setup the style.yml file
*/
private void setupStyle() {
style.set("version", VERSION);
style.set("version", StringMan.join(VERSION, "."));
final Map<String, Object> o = new HashMap<>();
o.put("color.1", "6");
o.put("color.2", "7");

View file

@ -3,6 +3,7 @@ package com.intellectualcrafters.plot;
import com.intellectualcrafters.json.JSONArray;
import com.intellectualcrafters.json.JSONObject;
import com.intellectualcrafters.plot.util.StringMan;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
@ -51,13 +52,15 @@ public class Updater {
String name = asset.getString("name");
if (downloadURL.equals(name)) {
try {
String version = release.getString("name");
String[] split = release.getString("name").split("\\.");
int[] version = new int[] { Integer.parseInt(split[0]), Integer.parseInt(split[1]), (split.length == 3) ? Integer.parseInt(split[2]) : 0 };
URL url = new URL(asset.getString("browser_download_url"));
if (!PS.get().canUpdate(PS.get().config.getString("version"), version)) {
// If current version >= update
if (PS.get().checkVersion(PS.get().getVersion(), version)) {
PS.debug("&7PlotSquared is already up to date!");
return null;
}
log("&6PlotSquared " + version + " is available:");
log("&6PlotSquared " + StringMan.join(split, ".") + " is available:");
log("&8 - &3Use: &7/plot update");
log("&8 - &3Or: &7" + downloadURL);
return url;

View file

@ -353,4 +353,6 @@ public interface AbstractDB {
void close();
void replaceWorld(String oldWorld, String newWorld, PlotId min, PlotId max);
void updateTables(int[] oldVersion);
}

View file

@ -173,7 +173,6 @@ public class SQLManager implements AbstractDB {
CREATE_TIERS = "INSERT INTO `" + prefix + "plot_%tier%` (`plot_plot_id`, `user_uuid`) values ";
CREATE_PLOT = "INSERT INTO `" + prefix + "plot`(`plot_id_x`, `plot_id_z`, `owner`, `world`, `timestamp`) VALUES(?, ?, ?, ?, ?)";
CREATE_CLUSTER = "INSERT INTO `" + prefix + "cluster`(`pos1_x`, `pos1_z`, `pos2_x`, `pos2_z`, `owner`, `world`) VALUES(?, ?, ?, ?, ?, ?)";
updateTables();
createTables();
}
@ -1468,11 +1467,14 @@ public class SQLManager implements AbstractDB {
return Integer.MAX_VALUE;
}
public void updateTables() {
if (PS.get().getVersion().equals(PS.get().getLastVersion()) || (PS.get().getLastVersion() == null)) {
return;
}
public void updateTables(int[] oldVersion) {
try {
if (MYSQL && !PS.get().checkVersion(oldVersion, 3, 3, 2)) {
try (Statement stmt = connection.createStatement()) {
stmt.executeUpdate("ALTER TABLE `" + prefix + "plots` DROP INDEX `unique_alias`");
}
catch (SQLException ignore) {}
}
final DatabaseMetaData data = connection.getMetaData();
ResultSet rs = data.getColumns(null, null, prefix + "plot_comments", "plot_plot_id");
if (rs.next()) {

View file

@ -164,11 +164,11 @@ public class SpongeMain implements IPlotMain {
}
@Override
public String getPluginVersion() {
public int[] getPluginVersion() {
PluginContainer plugin = game.getPluginManager().fromInstance(this).get();
String version = plugin.getVersion().get();
log("Checking plugin version: PlotSquared: ");
return version;
final String[] split = version.split("\\.");
return new int[] { Integer.parseInt(split[0]), Integer.parseInt(split[1]), (split.length == 3) ? Integer.parseInt(split[2]) : 0 };
}
@Override