mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-25 22:56:45 +01:00
PlotMe converter changes
This commit is contained in:
parent
efd3cde86b
commit
c4d328455e
@ -65,6 +65,74 @@ public class DBFunc {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void createAllSettings() {
|
||||||
|
final ArrayList<Integer> ids = new ArrayList<Integer>();
|
||||||
|
try {
|
||||||
|
PreparedStatement stmt = connection.prepareStatement("SELECT `id` FROM `plot`");
|
||||||
|
ResultSet result = stmt.executeQuery();
|
||||||
|
while (result.next()) {
|
||||||
|
int id = result.getInt("id");
|
||||||
|
ids.add(id);
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
if (ids.size()==0) {
|
||||||
|
System.out.print("ERROR: No plots found");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
final StringBuilder statement = new StringBuilder("INSERT INTO `plot_settings`(`plot_plot_id`) values ");
|
||||||
|
for (int i = 0; i<ids.size()-1; i++) {
|
||||||
|
statement.append("(?),");
|
||||||
|
}
|
||||||
|
statement.append("(?)");
|
||||||
|
PreparedStatement stmt = null;
|
||||||
|
try {
|
||||||
|
stmt = connection.prepareStatement(statement.toString());
|
||||||
|
for (int i = 0; i<ids.size(); i++) {
|
||||||
|
stmt.setInt(i+1, ids.get(i));
|
||||||
|
}
|
||||||
|
stmt.executeUpdate();
|
||||||
|
stmt.close();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a plot
|
||||||
|
*
|
||||||
|
* @param plot
|
||||||
|
*/
|
||||||
|
public static void createPlots(ArrayList<Plot> plots) {
|
||||||
|
if (plots.size()==0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
StringBuilder statement = new StringBuilder("INSERT INTO `plot`(`plot_id_x`, `plot_id_z`, `owner`, `world`) values ");
|
||||||
|
|
||||||
|
for (int i = 0; i<plots.size()-1; i++) {
|
||||||
|
statement.append("(?, ?, ?, ?),");
|
||||||
|
}
|
||||||
|
statement.append("(?, ?, ?, ?)");
|
||||||
|
|
||||||
|
PreparedStatement stmt = null;
|
||||||
|
try {
|
||||||
|
stmt = connection.prepareStatement(statement.toString());
|
||||||
|
for (int i = 0; i<plots.size(); i++) {
|
||||||
|
Plot plot = plots.get(i);
|
||||||
|
stmt.setInt(i*4+1, plot.id.x);
|
||||||
|
stmt.setInt(i*4+2, plot.id.y);
|
||||||
|
stmt.setString(i*4+3, plot.owner.toString());
|
||||||
|
stmt.setString(i*4+4, plot.world);
|
||||||
|
}
|
||||||
|
stmt.executeUpdate();
|
||||||
|
stmt.close();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
Logger.add(LogLevel.DANGER, "Failed to save plots!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a plot
|
* Create a plot
|
||||||
*
|
*
|
||||||
|
@ -13,6 +13,7 @@ import org.bukkit.World;
|
|||||||
import com.intellectualcrafters.plot.PlotHomePosition;
|
import com.intellectualcrafters.plot.PlotHomePosition;
|
||||||
import com.intellectualcrafters.plot.PlotId;
|
import com.intellectualcrafters.plot.PlotId;
|
||||||
import com.intellectualcrafters.plot.PlotMain;
|
import com.intellectualcrafters.plot.PlotMain;
|
||||||
|
import com.sun.org.apache.xerces.internal.impl.dv.DVFactoryException;
|
||||||
import com.worldcretornica.plotme.PlayerList;
|
import com.worldcretornica.plotme.PlayerList;
|
||||||
import com.worldcretornica.plotme.Plot;
|
import com.worldcretornica.plotme.Plot;
|
||||||
import com.worldcretornica.plotme.PlotManager;
|
import com.worldcretornica.plotme.PlotManager;
|
||||||
@ -35,6 +36,8 @@ public class PlotMeConverter {
|
|||||||
Bukkit.getScheduler().runTaskAsynchronously(this.plugin, new Runnable() {
|
Bukkit.getScheduler().runTaskAsynchronously(this.plugin, new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
ArrayList<com.intellectualcrafters.plot.Plot> createdPlots = new ArrayList<com.intellectualcrafters.plot.Plot>();
|
||||||
|
ArrayList<Integer> createdIds = new ArrayList<Integer>();
|
||||||
for (World world : Bukkit.getWorlds()) {
|
for (World world : Bukkit.getWorlds()) {
|
||||||
HashMap<String, Plot> plots = PlotManager.getPlots(world);
|
HashMap<String, Plot> plots = PlotManager.getPlots(world);
|
||||||
if (plots!=null) {
|
if (plots!=null) {
|
||||||
@ -85,11 +88,13 @@ public class PlotMeConverter {
|
|||||||
|
|
||||||
// TODO createPlot doesn't add helpers / denied users
|
// TODO createPlot doesn't add helpers / denied users
|
||||||
|
|
||||||
DBFunc.createPlot(pl);
|
createdPlots.add(pl);
|
||||||
DBFunc.createPlotSettings(DBFunc.getId(world.getName(), pl.id), pl);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
PlotMain.sendConsoleSenderMessage("PlotMe->PlotSquared Saving to DB");
|
||||||
|
DBFunc.createPlots(createdPlots);
|
||||||
|
DBFunc.createAllSettings();
|
||||||
stream.close();
|
stream.close();
|
||||||
PlotMain.sendConsoleSenderMessage("PlotMe->PlotSquared Conversion has finished");
|
PlotMain.sendConsoleSenderMessage("PlotMe->PlotSquared Conversion has finished");
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user