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 @Override
public String getPluginVersion() { public int[] getPluginVersion() {
return getDescription().getVersion(); final String[] split = getDescription().getVersion().split("\\.");
return new int[] { Integer.parseInt(split[0]), Integer.parseInt(split[1]), Integer.parseInt(split[2]) };
} }
@Override @Override

View file

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

View file

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

View file

@ -3,6 +3,7 @@ package com.intellectualcrafters.plot;
import com.intellectualcrafters.json.JSONArray; import com.intellectualcrafters.json.JSONArray;
import com.intellectualcrafters.json.JSONObject; import com.intellectualcrafters.json.JSONObject;
import com.intellectualcrafters.plot.util.StringMan;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
@ -51,13 +52,15 @@ public class Updater {
String name = asset.getString("name"); String name = asset.getString("name");
if (downloadURL.equals(name)) { if (downloadURL.equals(name)) {
try { 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")); 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!"); PS.debug("&7PlotSquared is already up to date!");
return null; return null;
} }
log("&6PlotSquared " + version + " is available:"); log("&6PlotSquared " + StringMan.join(split, ".") + " is available:");
log("&8 - &3Use: &7/plot update"); log("&8 - &3Use: &7/plot update");
log("&8 - &3Or: &7" + downloadURL); log("&8 - &3Or: &7" + downloadURL);
return url; return url;

View file

@ -353,4 +353,6 @@ public interface AbstractDB {
void close(); void close();
void replaceWorld(String oldWorld, String newWorld, PlotId min, PlotId max); 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_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_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(?, ?, ?, ?, ?, ?)"; CREATE_CLUSTER = "INSERT INTO `" + prefix + "cluster`(`pos1_x`, `pos1_z`, `pos2_x`, `pos2_z`, `owner`, `world`) VALUES(?, ?, ?, ?, ?, ?)";
updateTables();
createTables(); createTables();
} }
@ -1468,11 +1467,14 @@ public class SQLManager implements AbstractDB {
return Integer.MAX_VALUE; return Integer.MAX_VALUE;
} }
public void updateTables() { public void updateTables(int[] oldVersion) {
if (PS.get().getVersion().equals(PS.get().getLastVersion()) || (PS.get().getLastVersion() == null)) {
return;
}
try { 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(); final DatabaseMetaData data = connection.getMetaData();
ResultSet rs = data.getColumns(null, null, prefix + "plot_comments", "plot_plot_id"); ResultSet rs = data.getColumns(null, null, prefix + "plot_comments", "plot_plot_id");
if (rs.next()) { if (rs.next()) {

View file

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