mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-26 15:16:45 +01:00
Conversion functions
This commit is contained in:
parent
8c57bc7445
commit
ffb4710080
@ -53,9 +53,13 @@ public class Database extends SubCommand {
|
|||||||
for (final Plot p : plots) {
|
for (final Plot p : plots) {
|
||||||
ps.add(p);
|
ps.add(p);
|
||||||
}
|
}
|
||||||
manager.createPlots(ps);
|
sendMessageU(requester, "&6Starting...");
|
||||||
manager.createAllSettingsAndHelpers(ps);
|
manager.createPlotsAndData(ps, new Runnable() {
|
||||||
sendMessageU(requester, "&6Database conversion finished");
|
@Override
|
||||||
|
public void run() {
|
||||||
|
sendMessageU(requester, "&6Database conversion finished!");
|
||||||
|
}
|
||||||
|
});
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
sendMessageU(requester, "Failed to insert plot objects, see stacktrace for info");
|
sendMessageU(requester, "Failed to insert plot objects, see stacktrace for info");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -134,8 +134,12 @@ public class DebugClaimTest extends SubCommand {
|
|||||||
}
|
}
|
||||||
if (plots.size() > 0) {
|
if (plots.size() > 0) {
|
||||||
MainUtil.sendMessage(null, "&3Sign Block&8->&3PlotSquared&8: &7Updating '" + plots.size() + "' plots!");
|
MainUtil.sendMessage(null, "&3Sign Block&8->&3PlotSquared&8: &7Updating '" + plots.size() + "' plots!");
|
||||||
DBFunc.createPlots(plots);
|
DBFunc.createPlotsAndData(plots, new Runnable() {
|
||||||
DBFunc.createAllSettingsAndHelpers(plots);
|
@Override
|
||||||
|
public void run() {
|
||||||
|
MainUtil.sendMessage(null, "&6Database update finished!");
|
||||||
|
}
|
||||||
|
});
|
||||||
for (final Plot plot : plots) {
|
for (final Plot plot : plots) {
|
||||||
PlotSquared.updatePlot(plot);
|
PlotSquared.updatePlot(plot);
|
||||||
}
|
}
|
||||||
|
@ -41,8 +41,13 @@ public class DebugSaveTest extends SubCommand {
|
|||||||
if (plr == null) {
|
if (plr == null) {
|
||||||
final ArrayList<Plot> plots = new ArrayList<Plot>();
|
final ArrayList<Plot> plots = new ArrayList<Plot>();
|
||||||
plots.addAll(PlotSquared.getPlots());
|
plots.addAll(PlotSquared.getPlots());
|
||||||
DBFunc.createPlots(plots);
|
MainUtil.sendMessage(null, "&6Starting `DEBUGSAVETEST`");
|
||||||
DBFunc.createAllSettingsAndHelpers(plots);
|
DBFunc.createPlotsAndData(plots, new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
MainUtil.sendMessage(null, "&6Database sync finished!");
|
||||||
|
}
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
MainUtil.sendMessage(plr, "This debug command can only be executed by console as it has been deemed unsafe if abused");
|
MainUtil.sendMessage(plr, "This debug command can only be executed by console as it has been deemed unsafe if abused");
|
||||||
}
|
}
|
||||||
|
@ -242,7 +242,12 @@ public class DebugUUID extends SubCommand {
|
|||||||
plot.owner = value;
|
plot.owner = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
database.createPlots(new ArrayList<>(PlotSquared.getPlots()));
|
database.createPlotsAndData(new ArrayList<>(PlotSquared.getPlots()), new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
MainUtil.sendMessage(null, "&6Recovery was successful!");
|
||||||
|
}
|
||||||
|
});
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -257,14 +262,12 @@ public class DebugUUID extends SubCommand {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
ArrayList<Plot> plots = new ArrayList<>(PlotSquared.getPlots());
|
ArrayList<Plot> plots = new ArrayList<>(PlotSquared.getPlots());
|
||||||
database.createPlots(plots);
|
database.createPlotsAndData(plots, new Runnable() {
|
||||||
int size = plots.size();
|
@Override
|
||||||
ArrayList<Integer> ids = new ArrayList<Integer>();
|
public void run() {
|
||||||
for (int i = 1; i <= size; i++) {
|
MainUtil.sendConsoleMessage("&aConversion complete!");
|
||||||
ids.add(i);
|
}
|
||||||
}
|
});
|
||||||
database.createSettings(ids);
|
|
||||||
MainUtil.sendConsoleMessage("&aConversion complete!");
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -60,14 +60,7 @@ public interface AbstractDB {
|
|||||||
*
|
*
|
||||||
* @param plots Plots for which the default table entries should be created
|
* @param plots Plots for which the default table entries should be created
|
||||||
*/
|
*/
|
||||||
public void createAllSettingsAndHelpers(final ArrayList<Plot> plots);
|
public void createPlotsAndData(final ArrayList<Plot> plots, Runnable whenDone);
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a plot
|
|
||||||
*
|
|
||||||
* @param plots Plots that should be created
|
|
||||||
*/
|
|
||||||
public void createPlots(final ArrayList<Plot> plots);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a plot
|
* Create a plot
|
||||||
@ -338,8 +331,6 @@ public interface AbstractDB {
|
|||||||
|
|
||||||
public void movePlot(Plot originalPlot, Plot newPlot);
|
public void movePlot(Plot originalPlot, Plot newPlot);
|
||||||
|
|
||||||
public void createSettings(final ArrayList<Integer> mylist);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Don't fuck with this one, unless you enjoy it rough
|
* Don't fuck with this one, unless you enjoy it rough
|
||||||
*/
|
*/
|
||||||
|
@ -94,17 +94,8 @@ public class DBFunc {
|
|||||||
*
|
*
|
||||||
* @param plots List containing all plot objects
|
* @param plots List containing all plot objects
|
||||||
*/
|
*/
|
||||||
public static void createAllSettingsAndHelpers(final ArrayList<Plot> plots) {
|
public static void createPlotsAndData(final ArrayList<Plot> plots, Runnable whenDone) {
|
||||||
dbManager.createAllSettingsAndHelpers(plots);
|
dbManager.createPlotsAndData(plots, whenDone);
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create all plots
|
|
||||||
*
|
|
||||||
* @param plots A list containing plot objects
|
|
||||||
*/
|
|
||||||
public static void createPlots(final ArrayList<Plot> plots) {
|
|
||||||
dbManager.createPlots(plots);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -321,9 +321,12 @@ public class PlotMeConverter {
|
|||||||
}
|
}
|
||||||
sendMessage("Creating plot DB");
|
sendMessage("Creating plot DB");
|
||||||
Thread.sleep(1000);
|
Thread.sleep(1000);
|
||||||
DBFunc.createPlots(createdPlots);
|
DBFunc.createPlotsAndData(createdPlots, new Runnable() {
|
||||||
sendMessage("Creating settings/helpers DB");
|
@Override
|
||||||
DBFunc.createAllSettingsAndHelpers(createdPlots);
|
public void run() {
|
||||||
|
sendMessage("&aDatabase conversion is now complete!");
|
||||||
|
}
|
||||||
|
});
|
||||||
sendMessage("Saving configuration...");
|
sendMessage("Saving configuration...");
|
||||||
try {
|
try {
|
||||||
PlotSquared.config.save(PlotSquared.configFile);
|
PlotSquared.config.save(PlotSquared.configFile);
|
||||||
@ -378,7 +381,7 @@ public class PlotMeConverter {
|
|||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
sendMessage("Conversion has finished");
|
sendMessage("&cPlease wait until database conversion is complete. You will be notified when this happens");
|
||||||
PlotSquared.log("&c - Stop the server");
|
PlotSquared.log("&c - Stop the server");
|
||||||
PlotSquared.log("&c - Disable 'plotme-convert.enabled' in the settings.yml");
|
PlotSquared.log("&c - Disable 'plotme-convert.enabled' in the settings.yml");
|
||||||
PlotSquared.log("&c - Correct any generator settings that haven't copied to 'settings.yml' properly");
|
PlotSquared.log("&c - Correct any generator settings that haven't copied to 'settings.yml' properly");
|
||||||
|
@ -47,6 +47,7 @@ import com.intellectualcrafters.plot.object.Plot;
|
|||||||
import com.intellectualcrafters.plot.object.PlotCluster;
|
import com.intellectualcrafters.plot.object.PlotCluster;
|
||||||
import com.intellectualcrafters.plot.object.PlotClusterId;
|
import com.intellectualcrafters.plot.object.PlotClusterId;
|
||||||
import com.intellectualcrafters.plot.object.PlotId;
|
import com.intellectualcrafters.plot.object.PlotId;
|
||||||
|
import com.intellectualcrafters.plot.object.PlotSettings;
|
||||||
import com.intellectualcrafters.plot.object.RunnableVal;
|
import com.intellectualcrafters.plot.object.RunnableVal;
|
||||||
import com.intellectualcrafters.plot.object.comment.PlotComment;
|
import com.intellectualcrafters.plot.object.comment.PlotComment;
|
||||||
import com.intellectualcrafters.plot.util.ClusterManager;
|
import com.intellectualcrafters.plot.util.ClusterManager;
|
||||||
@ -61,7 +62,7 @@ public class SQLManager implements AbstractDB {
|
|||||||
public final String GET_ALL_PLOTS;
|
public final String GET_ALL_PLOTS;
|
||||||
public final String CREATE_PLOTS;
|
public final String CREATE_PLOTS;
|
||||||
public final String CREATE_SETTINGS;
|
public final String CREATE_SETTINGS;
|
||||||
public final String CREATE_HELPERS;
|
public final String CREATE_TIERS;
|
||||||
public final String CREATE_PLOT;
|
public final String CREATE_PLOT;
|
||||||
public final String CREATE_CLUSTER;
|
public final String CREATE_CLUSTER;
|
||||||
private final String prefix;
|
private final String prefix;
|
||||||
@ -89,7 +90,7 @@ public class SQLManager implements AbstractDB {
|
|||||||
this.GET_ALL_PLOTS = "SELECT `id`, `plot_id_x`, `plot_id_z`, `world` FROM `" + this.prefix + "plot`";
|
this.GET_ALL_PLOTS = "SELECT `id`, `plot_id_x`, `plot_id_z`, `world` FROM `" + this.prefix + "plot`";
|
||||||
this.CREATE_PLOTS = "INSERT INTO `" + this.prefix + "plot`(`plot_id_x`, `plot_id_z`, `owner`, `world`) values ";
|
this.CREATE_PLOTS = "INSERT INTO `" + this.prefix + "plot`(`plot_id_x`, `plot_id_z`, `owner`, `world`) values ";
|
||||||
this.CREATE_SETTINGS = "INSERT INTO `" + this.prefix + "plot_settings` (`plot_plot_id`) values ";
|
this.CREATE_SETTINGS = "INSERT INTO `" + this.prefix + "plot_settings` (`plot_plot_id`) values ";
|
||||||
this.CREATE_HELPERS = "INSERT INTO `" + this.prefix + "plot_helpers` (`plot_plot_id`, `user_uuid`) values ";
|
this.CREATE_TIERS = "INSERT INTO `" + this.prefix + "plot_%tier%` (`plot_plot_id`, `user_uuid`) values ";
|
||||||
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
|
||||||
@ -136,110 +137,193 @@ public class SQLManager implements AbstractDB {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private class UUIDPair {
|
||||||
public void createAllSettingsAndHelpers(final ArrayList<Plot> mylist) {
|
public final int id;
|
||||||
final int size = mylist.size();
|
public final UUID uuid;
|
||||||
int packet;
|
|
||||||
if (PlotSquared.getMySQL() != null) {
|
public UUIDPair(int id, UUID uuid) {
|
||||||
packet = Math.min(size, 50000);
|
this.id = id;
|
||||||
} else {
|
this.uuid = uuid;
|
||||||
packet = Math.min(size, 5000);
|
|
||||||
}
|
}
|
||||||
final int amount = size / packet;
|
}
|
||||||
for (int j = 0; j <= amount; j++) {
|
|
||||||
final List<Plot> plots = mylist.subList(j * packet, Math.min(size, (j + 1) * packet));
|
private class SettingsPair {
|
||||||
final HashMap<String, HashMap<PlotId, Integer>> stored = new HashMap<>();
|
public final int id;
|
||||||
final HashMap<Integer, ArrayList<UUID>> helpers = new HashMap<>();
|
public final PlotSettings settings;
|
||||||
try {
|
|
||||||
final PreparedStatement stmt = this.connection.prepareStatement(this.GET_ALL_PLOTS);
|
public SettingsPair(int id, PlotSettings settings) {
|
||||||
final ResultSet result = stmt.executeQuery();
|
this.id = id;
|
||||||
while (result.next()) {
|
this.settings = settings;
|
||||||
final int id = result.getInt("id");
|
}
|
||||||
final int idx = result.getInt("plot_id_x");
|
}
|
||||||
final int idz = result.getInt("plot_id_z");
|
|
||||||
final String world = result.getString("world");
|
@Override
|
||||||
if (!stored.containsKey(world)) {
|
public void createPlotsAndData(final ArrayList<Plot> myList, final Runnable whenDone) {
|
||||||
stored.put(world, new HashMap<PlotId, Integer>());
|
TaskManager.runTaskAsync(new Runnable() {
|
||||||
}
|
@Override
|
||||||
stored.get(world).put(new PlotId(idx, idz), id);
|
public void run() {
|
||||||
}
|
|
||||||
result.close();
|
|
||||||
stmt.close();
|
|
||||||
} catch (final SQLException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
for (final Plot plot : plots) {
|
|
||||||
final String world = plot.world;
|
|
||||||
if (stored.containsKey(world)) {
|
|
||||||
final Integer id = stored.get(world).get(plot.id);
|
|
||||||
if (id != null) {
|
|
||||||
helpers.put(id, plot.helpers);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (helpers.size() == 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// add plot settings
|
|
||||||
final Integer[] ids = helpers.keySet().toArray(new Integer[helpers.keySet().size()]);
|
|
||||||
StringBuilder statement = new StringBuilder(this.CREATE_SETTINGS);
|
|
||||||
for (int i = 0; i < (ids.length - 1); i++) {
|
|
||||||
statement.append("(?),");
|
|
||||||
}
|
|
||||||
statement.append("(?)");
|
|
||||||
PreparedStatement stmt = null;
|
|
||||||
try {
|
|
||||||
stmt = this.connection.prepareStatement(statement.toString());
|
|
||||||
for (int i = 0; i < ids.length; i++) {
|
|
||||||
stmt.setInt(i + 1, ids[i]);
|
|
||||||
}
|
|
||||||
stmt.executeUpdate();
|
|
||||||
stmt.close();
|
|
||||||
} catch (final SQLException e) {
|
|
||||||
for (final Integer id : ids) {
|
|
||||||
createPlotSettings(id, null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// add plot helpers
|
|
||||||
String prefix = "";
|
|
||||||
statement = new StringBuilder(this.CREATE_HELPERS);
|
|
||||||
for (final Integer id : helpers.keySet()) {
|
|
||||||
for (final UUID helper : helpers.get(id)) {
|
|
||||||
statement.append(prefix + "(?, ?)");
|
|
||||||
prefix = ",";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (prefix.equals("")) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
stmt = this.connection.prepareStatement(statement.toString());
|
|
||||||
int counter = 0;
|
|
||||||
for (final Integer id : helpers.keySet()) {
|
|
||||||
for (final UUID helper : helpers.get(id)) {
|
|
||||||
stmt.setInt((counter * 2) + 1, id);
|
|
||||||
stmt.setString((counter * 2) + 2, helper.toString());
|
|
||||||
counter++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
stmt.executeUpdate();
|
|
||||||
stmt.close();
|
|
||||||
} catch (final SQLException e) {
|
|
||||||
try {
|
try {
|
||||||
for (final Integer id : helpers.keySet()) {
|
// Create the plots
|
||||||
for (final UUID helper : helpers.get(id)) {
|
createPlots(myList);
|
||||||
setHelper(id, helper);
|
|
||||||
|
// Creating datastructures
|
||||||
|
HashMap<PlotId, Plot> plotMap = new HashMap<>();
|
||||||
|
for (Plot plot : myList) {
|
||||||
|
plotMap.put(plot.id, plot);
|
||||||
|
}
|
||||||
|
ArrayList<SettingsPair> settings = new ArrayList<>();
|
||||||
|
ArrayList<UUIDPair> helpers = new ArrayList<>();
|
||||||
|
ArrayList<UUIDPair> trusted = new ArrayList<>();
|
||||||
|
ArrayList<UUIDPair> denied = new ArrayList<>();
|
||||||
|
|
||||||
|
// Populating structures
|
||||||
|
final PreparedStatement stmt = connection.prepareStatement(GET_ALL_PLOTS);
|
||||||
|
final ResultSet result = stmt.executeQuery();
|
||||||
|
while (result.next()) {
|
||||||
|
final int id = result.getInt("id");
|
||||||
|
Plot plot = plotMap.get(id);
|
||||||
|
if (plot != null) {
|
||||||
|
settings.add(new SettingsPair(id, plot.settings));
|
||||||
|
if (plot.denied != null) {
|
||||||
|
for (UUID uuid : plot.denied) {
|
||||||
|
denied.add(new UUIDPair(id, uuid));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (plot.trusted != null) {
|
||||||
|
for (UUID uuid : plot.trusted) {
|
||||||
|
trusted.add(new UUIDPair(id, uuid));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (plot.helpers != null) {
|
||||||
|
for (UUID uuid : plot.helpers) {
|
||||||
|
helpers.add(new UUIDPair(id, uuid));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (final Exception e2) {
|
createSettings(settings);
|
||||||
|
createTiers(helpers, "helpers");
|
||||||
|
createTiers(trusted, "trusted");
|
||||||
|
createTiers(denied, "denied");
|
||||||
|
|
||||||
|
TaskManager.runTaskLater(whenDone, 20);
|
||||||
|
}
|
||||||
|
catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
PlotSquared.log("&7[WARN] " + "Failed to set all helpers for plots");
|
||||||
}
|
}
|
||||||
PlotSquared.log("&7[WARN] " + "Failed to set all helpers for plots");
|
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a plot
|
||||||
|
*
|
||||||
|
* @param myList list of plots to be created
|
||||||
|
*/
|
||||||
|
public void createTiers(final ArrayList<UUIDPair> myList, final String tier) {
|
||||||
|
final StmtMod<UUIDPair> mod = new StmtMod<UUIDPair>() {
|
||||||
|
@Override
|
||||||
|
public String getCreateMySQL(int size) {
|
||||||
|
return getCreateMySQL(size, CREATE_TIERS.replaceAll("%tier%", tier), 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getCreateSQLite(int size) {
|
||||||
|
return getCreateSQLite(size,
|
||||||
|
"INSERT INTO `" + prefix + "plot_" + tier + "` SELECT ? AS `plot_plot_id`, ? AS `user_uuid`", 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getCreateSQL() {
|
||||||
|
return "INSERT INTO `" + SQLManager.this.prefix + "plot_" + tier + "` (`plot_plot_id`, `user_uuid`) VALUES(?,?)";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setMySQL(PreparedStatement stmt, int i, UUIDPair pair) throws SQLException {
|
||||||
|
stmt.setInt((i * 2) + 1, pair.id);
|
||||||
|
stmt.setString((i * 2) + 2, pair.uuid.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setSQLite(PreparedStatement stmt, int i, UUIDPair pair) throws SQLException {
|
||||||
|
stmt.setInt((i * 2) + 1, pair.id);
|
||||||
|
stmt.setString((i * 2) + 2, pair.uuid.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setSQL(PreparedStatement stmt, UUIDPair pair) throws SQLException {
|
||||||
|
stmt.setInt(1, pair.id);
|
||||||
|
stmt.setString(2, pair.uuid.toString());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
setBulk(myList, mod);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a plot
|
||||||
|
*
|
||||||
|
* @param myList list of plots to be created
|
||||||
|
*/
|
||||||
|
public void createPlots(final ArrayList<Plot> myList) {
|
||||||
|
final StmtMod<Plot> mod = new StmtMod<Plot>() {
|
||||||
|
@Override
|
||||||
|
public String getCreateMySQL(int size) {
|
||||||
|
return getCreateMySQL(size, CREATE_PLOTS, 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getCreateSQLite(int size) {
|
||||||
|
return getCreateSQLite(size, "INSERT INTO `" + prefix + "plot` SELECT ? AS `id`, ? AS `plot_id_x`, ? AS `plot_id_z`, ? AS `owner`, ? AS `world`, ? AS `timestamp` ", 6);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getCreateSQL() {
|
||||||
|
return CREATE_PLOT;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setMySQL(PreparedStatement stmt, int i, Plot plot) throws SQLException {
|
||||||
|
stmt.setInt((i * 4) + 1, plot.id.x);
|
||||||
|
stmt.setInt((i * 4) + 2, plot.id.y);
|
||||||
|
try {
|
||||||
|
stmt.setString((i * 4) + 3, plot.owner.toString());
|
||||||
|
} catch (final Exception e) {
|
||||||
|
stmt.setString((i * 4) + 3, DBFunc.everyone.toString());
|
||||||
|
}
|
||||||
|
stmt.setString((i * 4) + 4, plot.world);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setSQLite(PreparedStatement stmt, int i, Plot plot) throws SQLException {
|
||||||
|
stmt.setNull((i * 6) + 1, 4);
|
||||||
|
stmt.setInt((i * 6) + 2, plot.id.x);
|
||||||
|
stmt.setInt((i * 6) + 3, plot.id.y);
|
||||||
|
try {
|
||||||
|
stmt.setString((i * 6) + 4, plot.owner.toString());
|
||||||
|
} catch (final Exception e1) {
|
||||||
|
stmt.setString((i * 6) + 4, DBFunc.everyone.toString());
|
||||||
|
}
|
||||||
|
stmt.setString((i * 6) + 5, plot.world);
|
||||||
|
stmt.setTimestamp((i * 6) + 6, new Timestamp(System.currentTimeMillis()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setSQL(PreparedStatement stmt, Plot plot) throws SQLException {
|
||||||
|
stmt.setInt(1, plot.id.x);
|
||||||
|
stmt.setInt(2, plot.id.y);
|
||||||
|
stmt.setString(3, plot.owner.toString());
|
||||||
|
stmt.setString(4, plot.world);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
setBulk(myList, mod);
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T> void setBulk(ArrayList<T> objList, StmtMod<T> mod) {
|
public <T> void setBulk(ArrayList<T> objList, StmtMod<T> mod) {
|
||||||
final int size = objList.size();
|
final int size = objList.size();
|
||||||
|
if (size == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
int packet;
|
int packet;
|
||||||
if (PlotSquared.getMySQL() != null) {
|
if (PlotSquared.getMySQL() != null) {
|
||||||
packet = Math.min(size, 50000);
|
packet = Math.min(size, 50000);
|
||||||
@ -295,32 +379,31 @@ public class SQLManager implements AbstractDB {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public void createSettings(final ArrayList<SettingsPair> myList) {
|
||||||
public void createSettings(final ArrayList<Integer> myList) {
|
final StmtMod<SettingsPair> mod = new StmtMod<SettingsPair>() {
|
||||||
final StmtMod<Integer> mod = new StmtMod<Integer>() {
|
@Override
|
||||||
@Override
|
public String getCreateMySQL(int size) {
|
||||||
public String getCreateMySQL(int size) {
|
return getCreateMySQL(size, CREATE_SETTINGS, 1);
|
||||||
return getCreateMySQL(size, CREATE_SETTINGS, 1);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getCreateSQLite(int size) {
|
public String getCreateSQLite(int size) {
|
||||||
return getCreateSQLite(size, "INSERT INTO `" + prefix + "plot_settings` SELECT ? AS `plot_plot_id`, ? AS `biome`, ? AS `rain`, ? AS `custom_time`, ? AS `time`, ? AS `deny_entry`, ? AS `alias`, ? AS `flags`, ? AS `merged`, ? AS `position` ", 10);
|
return getCreateSQLite(size, "INSERT INTO `" + prefix + "plot_settings` SELECT ? AS `plot_plot_id`, ? AS `biome`, ? AS `rain`, ? AS `custom_time`, ? AS `time`, ? AS `deny_entry`, ? AS `alias`, ? AS `flags`, ? AS `merged`, ? AS `position` ", 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getCreateSQL() {
|
public String getCreateSQL() {
|
||||||
return "INSERT INTO `" + SQLManager.this.prefix + "plot_settings`(`plot_plot_id`) VALUES(?)";
|
return "INSERT INTO `" + SQLManager.this.prefix + "plot_settings`(`plot_plot_id`) VALUES(?)";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setMySQL(PreparedStatement stmt, int i, Integer id) throws SQLException {
|
public void setMySQL(PreparedStatement stmt, int i, SettingsPair id) throws SQLException {
|
||||||
stmt.setInt((i * 1) + 1, id);
|
stmt.setInt((i * 1) + 1, id.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setSQLite(PreparedStatement stmt, int i, Integer id) throws SQLException {
|
public void setSQLite(PreparedStatement stmt, int i, SettingsPair id) throws SQLException {
|
||||||
stmt.setInt((i * 10) + 1, id);
|
stmt.setInt((i * 10) + 1, id.id );
|
||||||
stmt.setNull((i * 10) + 2, 4);
|
stmt.setNull((i * 10) + 2, 4);
|
||||||
stmt.setNull((i * 10) + 3, 4);
|
stmt.setNull((i * 10) + 3, 4);
|
||||||
stmt.setNull((i * 10) + 4, 4);
|
stmt.setNull((i * 10) + 4, 4);
|
||||||
@ -330,14 +413,14 @@ public class SQLManager implements AbstractDB {
|
|||||||
stmt.setNull((i * 10) + 8, 4);
|
stmt.setNull((i * 10) + 8, 4);
|
||||||
stmt.setNull((i * 10) + 9, 4);
|
stmt.setNull((i * 10) + 9, 4);
|
||||||
stmt.setString((i * 10) + 10, "DEFAULT");
|
stmt.setString((i * 10) + 10, "DEFAULT");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setSQL(PreparedStatement stmt, Integer id) throws SQLException {
|
public void setSQL(PreparedStatement stmt, SettingsPair id) throws SQLException {
|
||||||
stmt.setInt(1, id);
|
stmt.setInt(1, id.id);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
TaskManager.runTaskAsync(new Runnable() {
|
TaskManager.runTaskAsync(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
setBulk(myList, mod);
|
setBulk(myList, mod);
|
||||||
@ -345,61 +428,45 @@ public class SQLManager implements AbstractDB {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public void createEmptySettings(final ArrayList<Integer> myList) {
|
||||||
* Create a plot
|
final StmtMod<Integer> mod = new StmtMod<Integer>() {
|
||||||
*
|
|
||||||
* @param myList list of plots to be created
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void createPlots(final ArrayList<Plot> myList) {
|
|
||||||
final StmtMod<Plot> mod = new StmtMod<Plot>() {
|
|
||||||
@Override
|
@Override
|
||||||
public String getCreateMySQL(int size) {
|
public String getCreateMySQL(int size) {
|
||||||
return getCreateMySQL(size, CREATE_PLOTS, 4);
|
return getCreateMySQL(size, CREATE_SETTINGS, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getCreateSQLite(int size) {
|
public String getCreateSQLite(int size) {
|
||||||
return getCreateSQLite(size, "INSERT INTO `" + prefix + "plot` SELECT ? AS `id`, ? AS `plot_id_x`, ? AS `plot_id_z`, ? AS `owner`, ? AS `world`, ? AS `timestamp` ", 6);
|
return getCreateSQLite(size, "INSERT INTO `" + prefix + "plot_settings` SELECT ? AS `plot_plot_id`, ? AS `biome`, ? AS `rain`, ? AS `custom_time`, ? AS `time`, ? AS `deny_entry`, ? AS `alias`, ? AS `flags`, ? AS `merged`, ? AS `position` ", 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getCreateSQL() {
|
public String getCreateSQL() {
|
||||||
return CREATE_PLOT;
|
return "INSERT INTO `" + SQLManager.this.prefix + "plot_settings`(`plot_plot_id`) VALUES(?)";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setMySQL(PreparedStatement stmt, int i, Plot plot) throws SQLException {
|
public void setMySQL(PreparedStatement stmt, int i, Integer id) throws SQLException {
|
||||||
stmt.setInt((i * 4) + 1, plot.id.x);
|
stmt.setInt((i * 1) + 1, id);
|
||||||
stmt.setInt((i * 4) + 2, plot.id.y);
|
|
||||||
try {
|
|
||||||
stmt.setString((i * 4) + 3, plot.owner.toString());
|
|
||||||
} catch (final Exception e) {
|
|
||||||
stmt.setString((i * 4) + 3, DBFunc.everyone.toString());
|
|
||||||
}
|
|
||||||
stmt.setString((i * 4) + 4, plot.world);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setSQLite(PreparedStatement stmt, int i, Plot plot) throws SQLException {
|
public void setSQLite(PreparedStatement stmt, int i, Integer id) throws SQLException {
|
||||||
stmt.setNull((i * 6) + 1, 4);
|
stmt.setInt((i * 10) + 1, id );
|
||||||
stmt.setInt((i * 6) + 2, plot.id.x);
|
stmt.setNull((i * 10) + 2, 4);
|
||||||
stmt.setInt((i * 6) + 3, plot.id.y);
|
stmt.setNull((i * 10) + 3, 4);
|
||||||
try {
|
stmt.setNull((i * 10) + 4, 4);
|
||||||
stmt.setString((i * 6) + 4, plot.owner.toString());
|
stmt.setNull((i * 10) + 5, 4);
|
||||||
} catch (final Exception e1) {
|
stmt.setNull((i * 10) + 6, 4);
|
||||||
stmt.setString((i * 6) + 4, DBFunc.everyone.toString());
|
stmt.setNull((i * 10) + 7, 4);
|
||||||
}
|
stmt.setNull((i * 10) + 8, 4);
|
||||||
stmt.setString((i * 6) + 5, plot.world);
|
stmt.setNull((i * 10) + 9, 4);
|
||||||
stmt.setTimestamp((i * 6) + 6, new Timestamp(System.currentTimeMillis()));
|
stmt.setString((i * 10) + 10, "DEFAULT");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setSQL(PreparedStatement stmt, Plot plot) throws SQLException {
|
public void setSQL(PreparedStatement stmt, Integer id) throws SQLException {
|
||||||
stmt.setInt(1, plot.id.x);
|
stmt.setInt(1, id);
|
||||||
stmt.setInt(2, plot.id.y);
|
|
||||||
stmt.setString(3, plot.owner.toString());
|
|
||||||
stmt.setString(4, plot.world);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
TaskManager.runTaskAsync(new Runnable() {
|
TaskManager.runTaskAsync(new Runnable() {
|
||||||
@ -821,7 +888,7 @@ public class SQLManager implements AbstractDB {
|
|||||||
stmt.close();
|
stmt.close();
|
||||||
r.close();
|
r.close();
|
||||||
if (plots.keySet().size() > 0) {
|
if (plots.keySet().size() > 0) {
|
||||||
createSettings(new ArrayList<Integer>(plots.keySet()));
|
createEmptySettings(new ArrayList<Integer>(plots.keySet()));
|
||||||
}
|
}
|
||||||
boolean invalidPlot = false;
|
boolean invalidPlot = false;
|
||||||
for (final String worldname : noExist.keySet()) {
|
for (final String worldname : noExist.keySet()) {
|
||||||
|
@ -44,6 +44,11 @@ public abstract class TaskManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Run task later (delay in ticks)
|
||||||
|
* @param r
|
||||||
|
* @param delay
|
||||||
|
*/
|
||||||
public static void runTaskLater(final Runnable r, final int delay) {
|
public static void runTaskLater(final Runnable r, final int delay) {
|
||||||
if (r != null) {
|
if (r != null) {
|
||||||
PlotSquared.TASK.taskLater(r, delay);
|
PlotSquared.TASK.taskLater(r, delay);
|
||||||
|
Loading…
Reference in New Issue
Block a user