diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/plotme/APlotMeConnector.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/plotme/APlotMeConnector.java index 297847be3..9b9920b5d 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/plotme/APlotMeConnector.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/plotme/APlotMeConnector.java @@ -2,12 +2,14 @@ package com.intellectualcrafters.plot.database.plotme; import java.sql.Connection; import java.sql.SQLException; +import java.util.Arrays; import java.util.HashMap; import org.bukkit.Bukkit; import org.bukkit.World; import com.intellectualcrafters.configuration.file.FileConfiguration; +import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotId; @@ -28,6 +30,30 @@ public abstract class APlotMeConnector { return world; } + public boolean isValidConnection(Connection connection) { + return connection != null; + } + + public void copyConfig(FileConfiguration plotConfig, String world, String actualWorldName) { + final Integer pathwidth = plotConfig.getInt("worlds." + world + ".PathWidth"); // + PS.get().config.set("worlds." + actualWorldName + ".road.width", pathwidth); + final Integer plotsize = plotConfig.getInt("worlds." + world + ".PlotSize"); // + PS.get().config.set("worlds." + actualWorldName + ".plot.size", plotsize); + final String wallblock = plotConfig.getString("worlds." + world + ".WallBlockId"); // + PS.get().config.set("worlds." + actualWorldName + ".wall.block", wallblock); + final String floor = plotConfig.getString("worlds." + world + ".PlotFloorBlockId"); // + PS.get().config.set("worlds." + actualWorldName + ".plot.floor", Arrays.asList(floor)); + final String filling = plotConfig.getString("worlds." + world + ".PlotFillingBlockId"); // + PS.get().config.set("worlds." + actualWorldName + ".plot.filling", Arrays.asList(filling)); + final String road = plotConfig.getString("worlds." + world + ".RoadMainBlockId"); + PS.get().config.set("worlds." + actualWorldName + ".road.block", road); + Integer height = plotConfig.getInt("worlds." + world + ".RoadHeight"); // + if (height == null) { + height = 64; + } + PS.get().config.set("worlds." + actualWorldName + ".road.height", height); + } + public Location getPlotTopLocAbs(int path, int plot, final PlotId plotid) { final int px = plotid.x; final int pz = plotid.y; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/plotme/ClassicPlotMeConnector.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/plotme/ClassicPlotMeConnector.java index 07dd93846..63e162f19 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/plotme/ClassicPlotMeConnector.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/plotme/ClassicPlotMeConnector.java @@ -6,6 +6,7 @@ import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; +import java.util.Arrays; import java.util.HashMap; import java.util.Map.Entry; import java.util.UUID; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/plotme/LikePlotMeConverter.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/plotme/LikePlotMeConverter.java index 01cc063f3..a776a1e68 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/plotme/LikePlotMeConverter.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/plotme/LikePlotMeConverter.java @@ -133,7 +133,7 @@ public class LikePlotMeConverter { Connection connection = connector.getPlotMeConnection(plugin, plotConfig, dataFolder); - if (connection == null) { + if (!connector.isValidConnection(connection)) { sendMessage("Cannot connect to PlotMe DB. Conversion process will not continue"); return false; } @@ -158,23 +158,7 @@ public class LikePlotMeConverter { sendMessage("Copying config for: " + world); try { String actualWorldName = getWorld(world); - final Integer pathwidth = plotConfig.getInt("worlds." + world + ".PathWidth"); // - PS.get().config.set("worlds." + actualWorldName + ".road.width", pathwidth); - final Integer plotsize = plotConfig.getInt("worlds." + world + ".PlotSize"); // - PS.get().config.set("worlds." + actualWorldName + ".plot.size", plotsize); - final String wallblock = plotConfig.getString("worlds." + world + ".WallBlockId"); // - PS.get().config.set("worlds." + actualWorldName + ".wall.block", wallblock); - final String floor = plotConfig.getString("worlds." + world + ".PlotFloorBlockId"); // - PS.get().config.set("worlds." + actualWorldName + ".plot.floor", Arrays.asList(floor)); - final String filling = plotConfig.getString("worlds." + world + ".PlotFillingBlockId"); // - PS.get().config.set("worlds." + actualWorldName + ".plot.filling", Arrays.asList(filling)); - final String road = plotConfig.getString("worlds." + world + ".RoadMainBlockId"); - PS.get().config.set("worlds." + actualWorldName + ".road.block", road); - Integer height = plotConfig.getInt("worlds." + world + ".RoadHeight"); // - if (height == null) { - height = 64; - } - PS.get().config.set("worlds." + actualWorldName + ".road.height", height); + connector.copyConfig(plotConfig, world, actualWorldName); PS.get().config.save(PS.get().configFile); } catch (final Exception e) { sendMessage("&c-- &lFailed to save configuration for world '" + world + "'\nThis will need to be done using the setup command, or manually"); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/plotme/PlotMeConnector_017.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/plotme/PlotMeConnector_017.java index e2e62045e..d3ec39106 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/plotme/PlotMeConnector_017.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/plotme/PlotMeConnector_017.java @@ -6,6 +6,7 @@ import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; +import java.util.Arrays; import java.util.HashMap; import java.util.UUID; import java.util.Map.Entry; @@ -195,5 +196,4 @@ public class PlotMeConnector_017 extends APlotMeConnector { } return !PS.get().canUpdate(version, "0.17"); } - }