More work on unlinking

This commit is contained in:
boy0001 2015-05-01 21:00:17 +10:00
parent e792a85c00
commit 435e33d079
5 changed files with 254 additions and 244 deletions

View File

@ -410,11 +410,12 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
@Override
public boolean initPlotMeConverter() {
try {
new PlotMeConverter().runAsync(new ClassicPlotMeConnector());
} catch (final Exception e) {
e.printStackTrace();
TaskManager.runTaskLaterAsync(new Runnable() {
@Override
public void run() {
new PlotMeConverter().run(new ClassicPlotMeConnector());
}
}, 20);
if (Bukkit.getPluginManager().getPlugin("PlotMe") != null) {
return true;
}

View File

@ -570,7 +570,7 @@ public class PlotSquared {
log("&cTHIS MESSAGE MAY BE EXTREMELY HELPFUL IF YOU HAVE TROUBLE CONVERTING PLOTME!");
log("&c - Make sure 'UUID.read-from-disk' is disabled (false)!");
log("&c - Sometimes the database can be locked, deleting PlotMe.jar beforehand will fix the issue!");
log("&c - After the conversion is finished, please set 'plotme-convert.enabled' to false in the 'settings.yml@'");
log("&c - After the conversion is finished, please set 'plotme-convert.enabled' to false in the 'settings.yml'");
}
}
}, 200);

View File

@ -3,6 +3,7 @@ package com.intellectualcrafters.plot.database.plotme;
import java.io.File;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
@ -14,6 +15,7 @@ import org.bukkit.configuration.file.FileConfiguration;
import com.intellectualcrafters.plot.PlotSquared;
import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.database.MySQL;
import com.intellectualcrafters.plot.database.SQLite;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotId;
@ -31,6 +33,7 @@ public class ClassicPlotMeConnector extends APlotMeConnector {
final String password = plotConfig.getString("mySQLpass");
final String con = plotConfig.getString("mySQLconn");
return DriverManager.getConnection(con, user, password);
// return new MySQL(plotsquared, hostname, port, database, username, password)
} else {
return new SQLite(PlotSquared.THIS, dataFolder + File.separator + "plots.db").openConnection();
}
@ -42,12 +45,11 @@ public class ClassicPlotMeConnector extends APlotMeConnector {
@Override
public HashMap<String, HashMap<PlotId, Plot>> getPlotMePlots(Connection connection) throws SQLException {
ResultSet r;
Statement stmt;
PreparedStatement stmt;
final HashMap<String, Integer> plotSize = new HashMap<>();
final HashMap<String, HashMap<PlotId, Plot>> plots = new HashMap<>();
stmt = connection.createStatement();
r = stmt.executeQuery("SELECT * FROM `plotmePlots`");
stmt = connection.prepareStatement("SELECT * FROM `plotmePlots`");
r = stmt.executeQuery();
boolean checkUUID = DBFunc.hasColumn(r, "ownerid");
while (r.next()) {
@ -91,31 +93,15 @@ public class ClassicPlotMeConnector extends APlotMeConnector {
final Plot plot = new Plot(id, owner, new ArrayList<UUID>(), new ArrayList<UUID>(), world);
plots.get(world).put(id, plot);
}
r.close();
stmt.close();
stmt = connection.createStatement();
r = stmt.executeQuery("SELECT * FROM `plotmeAllowed`");
while (r.next()) {
final PlotId id = new PlotId(r.getInt("idX"), r.getInt("idZ"));
final String name = r.getString("player");
final String world = PlotMeConverter.getWorld(r.getString("world"));
UUID helper = UUIDHandler.getUUID(name);
if (helper == null) {
if (name.equals("*")) {
helper = DBFunc.everyone;
} else {
MainUtil.sendConsoleMessage("&6Could not identify helper for plot: " + id);
continue;
}
}
if (plots.get(world).containsKey(id)) {
plots.get(world).get(id).helpers.add(helper);
}
}
try {
MainUtil.sendConsoleMessage(" - plotmeDenied");
r = stmt.executeQuery("SELECT * FROM `plotmeDenied`");
stmt = connection.prepareStatement("SELECT * FROM `plotmeDenied`");
r = stmt.executeQuery();
while (r.next()) {
final PlotId id = new PlotId(r.getInt("idX"), r.getInt("idZ"));
@ -135,6 +121,35 @@ public class ClassicPlotMeConnector extends APlotMeConnector {
}
}
stmt = connection.prepareStatement("SELECT * FROM `plotmeAllowed`");
r = stmt.executeQuery();
while (r.next()) {
final PlotId id = new PlotId(r.getInt("idX"), r.getInt("idZ"));
final String name = r.getString("player");
final String world = PlotMeConverter.getWorld(r.getString("world"));
UUID helper = UUIDHandler.getUUID(name);
if (helper == null) {
if (name.equals("*")) {
helper = DBFunc.everyone;
} else {
MainUtil.sendConsoleMessage("&6Could not identify helper for plot: " + id);
continue;
}
}
if (plots.get(world).containsKey(id)) {
plots.get(world).get(id).helpers.add(helper);
}
}
r.close();
stmt.close();
}
catch (Exception e) {
}
return plots;
}

View File

@ -83,11 +83,7 @@ public class PlotMeConverter {
return plotConfig.getConfigurationSection("worlds").getKeys(false);
}
public void runAsync(final APlotMeConnector connector) throws Exception {
// We have to make it wait a couple of seconds
TaskManager.runTaskLaterAsync(new Runnable() {
@Override
public void run() {
public void run(final APlotMeConnector connector) {
try {
String dataFolder = getPlotMePath();
FileConfiguration plotConfig = getPlotMeConfig(dataFolder);
@ -100,6 +96,7 @@ public class PlotMeConverter {
if (connection == null) {
sendMessage("Cannot connect to PlotMe DB. Conversion process will not continue");
return;
}
sendMessage("PlotMe conversion has started. To disable this, please set 'plotme-convert.enabled' in the 'settings.yml'");
@ -110,13 +107,11 @@ public class PlotMeConverter {
sendMessage("Collecting plot data");
sendMessage(" - plotmePlots");
final Set<String> worlds = getPlotMeWorlds(plotConfig);
HashMap<String, HashMap<PlotId, Plot>> plots = connector.getPlotMePlots(connection);
for (Entry<String, HashMap<PlotId, Plot>> entry : plots.entrySet()) {
plotCount += entry.getValue().size();
}
if (!Settings.CONVERT_PLOTME) {
return;
}
@ -287,10 +282,9 @@ public class PlotMeConverter {
}
});
} catch (final Exception e) {
PlotSquared.log("&/end/");
}
}
}, 20);
}
public static String getWorld(final String world) {
for (final World newworld : Bukkit.getWorlds()) {

View File

@ -420,7 +420,7 @@ public class MainUtil {
if (ly) {
if (!plot.settings.getMerged(1) || !plot.settings.getMerged(2)) {
if (removeRoads) {
manager.removeRoadSouthEast(plotworld, plot);
MainUtil.removeRoadSouthEast(plotworld, plot);
}
}
}
@ -512,7 +512,7 @@ public class MainUtil {
lesserPlot.settings.setMerged(2, true);
greaterPlot.settings.setMerged(0, true);
if (removeRoads) {
manager.removeRoadSouth(plotworld, lesserPlot);
MainUtil.removeRoadSouth(plotworld, lesserPlot);
}
}
} else {
@ -520,7 +520,7 @@ public class MainUtil {
lesserPlot.settings.setMerged(1, true);
greaterPlot.settings.setMerged(3, true);
if (removeRoads) {
manager.removeRoadEast(plotworld, lesserPlot);
MainUtil.removeRoadEast(plotworld, lesserPlot);
}
}
}