I'll do this later.

This commit is contained in:
boy0001 2015-04-01 23:41:11 +11:00
parent 57e8563b31
commit 424e032be4

View File

@ -25,10 +25,12 @@ import java.io.IOException;
import java.sql.Connection; import java.sql.Connection;
import java.sql.DriverManager; import java.sql.DriverManager;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement; import java.sql.Statement;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map.Entry;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
@ -63,48 +65,48 @@ public class PlotMeConverter {
PlotSquared.log("&3PlotMe&8->&3PlotSquared&8: &7" + message); PlotSquared.log("&3PlotMe&8->&3PlotSquared&8: &7" + message);
} }
public void runAsync() throws Exception { public String getPlotMePath() {
// We have to make it wait a couple of seconds return new File(".").getAbsolutePath() + File.separator + "plugins" + File.separator + "PlotMe" + File.separator;
TaskManager.runTaskLaterAsync(new Runnable() {
@Override
public void run() {
try {
final ArrayList<Plot> createdPlots = new ArrayList<>();
final String dataFolder = new File(".").getAbsolutePath() + File.separator + "plugins" + File.separator + "PlotMe" + File.separator;
final File plotMeFile = new File(dataFolder + "config.yml");
if (!plotMeFile.exists()) {
return;
} }
sendMessage("PlotMe conversion has started. To disable this, please set 'plotme-convert.enabled' in the 'settings.yml'"); public FileConfiguration getPlotMeConfig(String dataFolder) {
sendMessage("Connecting to PlotMe DB"); final File plotMeFile = new File(dataFolder + "config.yml");
if (!plotMeFile.exists()) {
return null;
}
return YamlConfiguration.loadConfiguration(plotMeFile);
}
final FileConfiguration plotConfig = YamlConfiguration.loadConfiguration(plotMeFile); public Connection getPlotMeConnection(FileConfiguration plotConfig, String dataFolder) {
int count = 0; try {
Connection connection;
if (plotConfig.getBoolean("usemySQL")) { if (plotConfig.getBoolean("usemySQL")) {
final String user = plotConfig.getString("mySQLuname"); final String user = plotConfig.getString("mySQLuname");
final String password = plotConfig.getString("mySQLpass"); final String password = plotConfig.getString("mySQLpass");
final String con = plotConfig.getString("mySQLconn"); final String con = plotConfig.getString("mySQLconn");
connection = DriverManager.getConnection(con, user, password); return DriverManager.getConnection(con, user, password);
} else { } else {
connection = new SQLite(PlotSquared.THIS, dataFolder + File.separator + "plots.db").openConnection(); return new SQLite(PlotSquared.THIS, dataFolder + File.separator + "plots.db").openConnection();
}
}
catch (SQLException | ClassNotFoundException e) {}
return null;
} }
sendMessage("Collecting plot data");
sendMessage(" - plotmePlots");
public Set<String> getPlotMeWorlds(FileConfiguration plotConfig) {
return plotConfig.getConfigurationSection("worlds").getKeys(false);
}
public HashMap<String, HashMap<PlotId, Plot>> getPlotMePlots(Connection connection) throws SQLException {
ResultSet r; ResultSet r;
Statement stmt; Statement stmt;
final HashMap<String, Integer> plotSize = new HashMap<>(); final HashMap<String, Integer> plotSize = new HashMap<>();
final HashMap<String, HashMap<PlotId, Plot>> plots = new HashMap<>(); final HashMap<String, HashMap<PlotId, Plot>> plots = new HashMap<>();
final Set<String> worlds = plotConfig.getConfigurationSection("worlds").getKeys(false);
stmt = connection.createStatement(); stmt = connection.createStatement();
r = stmt.executeQuery("SELECT * FROM `plotmePlots`"); r = stmt.executeQuery("SELECT * FROM `plotmePlots`");
boolean checkUUID = DBFunc.hasColumn(r, "ownerid"); boolean checkUUID = DBFunc.hasColumn(r, "ownerid");
while (r.next()) { while (r.next()) {
count++;
final PlotId id = new PlotId(r.getInt("idX"), r.getInt("idZ")); final PlotId id = new PlotId(r.getInt("idX"), r.getInt("idZ"));
final String name = r.getString("owner"); final String name = r.getString("owner");
final String world = getWorld(r.getString("world")); final String world = getWorld(r.getString("world"));
@ -145,12 +147,50 @@ public class PlotMeConverter {
final Plot plot = new Plot(id, owner, new ArrayList<UUID>(), new ArrayList<UUID>(), world); final Plot plot = new Plot(id, owner, new ArrayList<UUID>(), new ArrayList<UUID>(), world);
plots.get(world).put(id, plot); plots.get(world).put(id, plot);
} }
return plots;
}
public void runAsync() throws Exception {
// We have to make it wait a couple of seconds
TaskManager.runTaskLaterAsync(new Runnable() {
@Override
public void run() {
try {
String dataFolder = getPlotMePath();
FileConfiguration plotConfig = getPlotMeConfig(dataFolder);
if (plotConfig == null) {
return;
}
Connection connection = getPlotMeConnection(plotConfig, dataFolder);
if (connection == null) {
sendMessage("Cannot connect to PlotMe DB. Conversion process will not continue");
}
sendMessage("PlotMe conversion has started. To disable this, please set 'plotme-convert.enabled' in the 'settings.yml'");
sendMessage("Connecting to PlotMe DB");
int plotCount = 0;
final ArrayList<Plot> createdPlots = new ArrayList<>();
sendMessage("Collecting plot data");
sendMessage(" - plotmePlots");
final Set<String> worlds = getPlotMeWorlds(plotConfig);
HashMap<String, HashMap<PlotId, Plot>> plots = getPlotMePlots(connection);
for (Entry<String, HashMap<PlotId, Plot>> entry : plots.entrySet()) {
plotCount += entry.getValue().size();
}
if (!Settings.CONVERT_PLOTME) { if (!Settings.CONVERT_PLOTME) {
return; return;
} }
sendMessage(" - plotmeAllowed"); sendMessage(" - plotmeAllowed");
ResultSet r;
Statement stmt = connection.createStatement();
r = stmt.executeQuery("SELECT * FROM `plotmeAllowed`"); r = stmt.executeQuery("SELECT * FROM `plotmeAllowed`");
while (r.next()) { while (r.next()) {
final PlotId id = new PlotId(r.getInt("idX"), r.getInt("idZ")); final PlotId id = new PlotId(r.getInt("idX"), r.getInt("idZ"));
@ -188,7 +228,7 @@ public class PlotMeConverter {
plots.get(world).get(id).denied.add(denied); plots.get(world).get(id).denied.add(denied);
} }
} }
sendMessage("Collected " + count + " plots from PlotMe"); sendMessage("Collected " + plotCount + " plots from PlotMe");
for (final String world : plots.keySet()) { for (final String world : plots.keySet()) {
sendMessage("Copying config for: " + world); sendMessage("Copying config for: " + world);
try { try {