mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-26 12:35:15 +01:00
I'll do this later.
This commit is contained in:
parent
57e8563b31
commit
424e032be4
@ -25,10 +25,12 @@ import java.io.IOException;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
@ -63,48 +65,48 @@ public class PlotMeConverter {
|
||||
PlotSquared.log("&3PlotMe&8->&3PlotSquared&8: &7" + message);
|
||||
}
|
||||
|
||||
public void runAsync() throws Exception {
|
||||
// We have to make it wait a couple of seconds
|
||||
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;
|
||||
public String getPlotMePath() {
|
||||
return new File(".").getAbsolutePath() + File.separator + "plugins" + File.separator + "PlotMe" + File.separator;
|
||||
}
|
||||
|
||||
sendMessage("PlotMe conversion has started. To disable this, please set 'plotme-convert.enabled' in the 'settings.yml'");
|
||||
sendMessage("Connecting to PlotMe DB");
|
||||
public FileConfiguration getPlotMeConfig(String dataFolder) {
|
||||
final File plotMeFile = new File(dataFolder + "config.yml");
|
||||
if (!plotMeFile.exists()) {
|
||||
return null;
|
||||
}
|
||||
return YamlConfiguration.loadConfiguration(plotMeFile);
|
||||
}
|
||||
|
||||
final FileConfiguration plotConfig = YamlConfiguration.loadConfiguration(plotMeFile);
|
||||
int count = 0;
|
||||
Connection connection;
|
||||
public Connection getPlotMeConnection(FileConfiguration plotConfig, String dataFolder) {
|
||||
try {
|
||||
if (plotConfig.getBoolean("usemySQL")) {
|
||||
final String user = plotConfig.getString("mySQLuname");
|
||||
final String password = plotConfig.getString("mySQLpass");
|
||||
final String con = plotConfig.getString("mySQLconn");
|
||||
connection = DriverManager.getConnection(con, user, password);
|
||||
return DriverManager.getConnection(con, user, password);
|
||||
} 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;
|
||||
Statement stmt;
|
||||
final HashMap<String, Integer> plotSize = new HashMap<>();
|
||||
final HashMap<String, HashMap<PlotId, Plot>> plots = new HashMap<>();
|
||||
final Set<String> worlds = plotConfig.getConfigurationSection("worlds").getKeys(false);
|
||||
stmt = connection.createStatement();
|
||||
r = stmt.executeQuery("SELECT * FROM `plotmePlots`");
|
||||
|
||||
boolean checkUUID = DBFunc.hasColumn(r, "ownerid");
|
||||
|
||||
while (r.next()) {
|
||||
count++;
|
||||
final PlotId id = new PlotId(r.getInt("idX"), r.getInt("idZ"));
|
||||
final String name = r.getString("owner");
|
||||
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);
|
||||
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) {
|
||||
return;
|
||||
}
|
||||
|
||||
sendMessage(" - plotmeAllowed");
|
||||
ResultSet r;
|
||||
Statement stmt = connection.createStatement();
|
||||
r = stmt.executeQuery("SELECT * FROM `plotmeAllowed`");
|
||||
while (r.next()) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
sendMessage("Collected " + count + " plots from PlotMe");
|
||||
sendMessage("Collected " + plotCount + " plots from PlotMe");
|
||||
for (final String world : plots.keySet()) {
|
||||
sendMessage("Copying config for: " + world);
|
||||
try {
|
||||
|
Loading…
Reference in New Issue
Block a user