diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/BukkitMain.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/BukkitMain.java index 71f0d8c20..6f95a95c7 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/BukkitMain.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/BukkitMain.java @@ -76,7 +76,7 @@ import com.intellectualcrafters.plot.commands.list; import com.intellectualcrafters.plot.commands.plugin; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.Settings; -import com.intellectualcrafters.plot.database.PlotMeConverter; +import com.intellectualcrafters.plot.database.plotme.PlotMeConverter; import com.intellectualcrafters.plot.flag.FlagManager; import com.intellectualcrafters.plot.generator.BukkitHybridUtils; import com.intellectualcrafters.plot.generator.HybridGen; 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 new file mode 100644 index 000000000..6341e47a2 --- /dev/null +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/plotme/APlotMeConnector.java @@ -0,0 +1,16 @@ +package com.intellectualcrafters.plot.database.plotme; + +import java.sql.Connection; +import java.sql.SQLException; +import java.util.HashMap; + +import org.bukkit.configuration.file.FileConfiguration; + +import com.intellectualcrafters.plot.object.Plot; +import com.intellectualcrafters.plot.object.PlotId; + +public abstract class APlotMeConnector { + public abstract Connection getPlotMeConnection(FileConfiguration plotConfig, String dataFolder); + + public abstract HashMap> getPlotMePlots(Connection connection) throws SQLException; +} 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 new file mode 100644 index 000000000..ea2add089 --- /dev/null +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/plotme/ClassicPlotMeConnector.java @@ -0,0 +1,141 @@ +package com.intellectualcrafters.plot.database.plotme; + +import java.io.File; +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.HashMap; +import java.util.UUID; + +import org.bukkit.configuration.file.FileConfiguration; + +import com.intellectualcrafters.plot.PlotSquared; +import com.intellectualcrafters.plot.database.DBFunc; +import com.intellectualcrafters.plot.database.SQLite; +import com.intellectualcrafters.plot.object.Plot; +import com.intellectualcrafters.plot.object.PlotId; +import com.intellectualcrafters.plot.object.StringWrapper; +import com.intellectualcrafters.plot.util.MainUtil; +import com.intellectualcrafters.plot.util.bukkit.UUIDHandler; + +public class ClassicPlotMeConnector extends APlotMeConnector { + + @Override + 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"); + return DriverManager.getConnection(con, user, password); + } else { + return new SQLite(PlotSquared.THIS, dataFolder + File.separator + "plots.db").openConnection(); + } + } + catch (SQLException | ClassNotFoundException e) {} + return null; + } + + @Override + public HashMap> getPlotMePlots(Connection connection) throws SQLException { + ResultSet r; + Statement stmt; + final HashMap plotSize = new HashMap<>(); + final HashMap> plots = new HashMap<>(); + stmt = connection.createStatement(); + r = stmt.executeQuery("SELECT * FROM `plotmePlots`"); + + boolean checkUUID = DBFunc.hasColumn(r, "ownerid"); + + while (r.next()) { + final PlotId id = new PlotId(r.getInt("idX"), r.getInt("idZ")); + final String name = r.getString("owner"); + final String world = PlotMeConverter.getWorld(r.getString("world")); + if (!plotSize.containsKey(world)) { + final int size = r.getInt("topZ") - r.getInt("bottomZ"); + plotSize.put(world, size); + plots.put(world, new HashMap()); + } + UUID owner = UUIDHandler.getUUID(name); + if (owner == null) { + if (name.equals("*")) { + owner = DBFunc.everyone; + } + else { + if (checkUUID){ + try { + byte[] bytes = r.getBytes("ownerid"); + if (bytes != null) { + owner = UUID.nameUUIDFromBytes(bytes); + if (owner != null) { + UUIDHandler.add(new StringWrapper(name), owner); + } + } + } + catch (Exception e) { + e.printStackTrace(); + } + } + if (owner == null) { + MainUtil.sendConsoleMessage("&cCould not identify owner for plot: " + id + " -> '" + name + "'"); + continue; + } + } + } + else { + UUIDHandler.add(new StringWrapper(name), owner); + } + final Plot plot = new Plot(id, owner, new ArrayList(), new ArrayList(), 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); + } + } + + MainUtil.sendConsoleMessage(" - plotmeDenied"); + r = stmt.executeQuery("SELECT * FROM `plotmeDenied`"); + + 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 denied = UUIDHandler.getUUID(name); + if (denied == null) { + if (name.equals("*")) { + denied = DBFunc.everyone; + } else { + MainUtil.sendConsoleMessage("&6Could not identify denied for plot: " + id); + continue; + } + } + if (plots.get(world).containsKey(id)) { + plots.get(world).get(id).denied.add(denied); + } + } + + return plots; + } + +} diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/PlotMeConverter.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/plotme/PlotMeConverter.java similarity index 76% rename from PlotSquared/src/main/java/com/intellectualcrafters/plot/database/PlotMeConverter.java rename to PlotSquared/src/main/java/com/intellectualcrafters/plot/database/plotme/PlotMeConverter.java index 70e7c4c68..99ebe7f96 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/PlotMeConverter.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/plotme/PlotMeConverter.java @@ -18,7 +18,7 @@ // / // You can contact us via: support@intellectualsites.com / //////////////////////////////////////////////////////////////////////////////////////////////////// -package com.intellectualcrafters.plot.database; +package com.intellectualcrafters.plot.database.plotme; import java.io.File; import java.io.IOException; @@ -42,6 +42,8 @@ import org.bukkit.configuration.file.YamlConfiguration; import com.intellectualcrafters.plot.PlotSquared; import com.intellectualcrafters.plot.config.Settings; +import com.intellectualcrafters.plot.database.DBFunc; +import com.intellectualcrafters.plot.database.SQLite; import com.intellectualcrafters.plot.generator.HybridGen; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotId; @@ -77,80 +79,11 @@ public class PlotMeConverter { return YamlConfiguration.loadConfiguration(plotMeFile); } - 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"); - return DriverManager.getConnection(con, user, password); - } else { - return new SQLite(PlotSquared.THIS, dataFolder + File.separator + "plots.db").openConnection(); - } - } - catch (SQLException | ClassNotFoundException e) {} - return null; - } - public Set getPlotMeWorlds(FileConfiguration plotConfig) { return plotConfig.getConfigurationSection("worlds").getKeys(false); } - public HashMap> getPlotMePlots(Connection connection) throws SQLException { - ResultSet r; - Statement stmt; - final HashMap plotSize = new HashMap<>(); - final HashMap> plots = new HashMap<>(); - stmt = connection.createStatement(); - r = stmt.executeQuery("SELECT * FROM `plotmePlots`"); - - boolean checkUUID = DBFunc.hasColumn(r, "ownerid"); - - while (r.next()) { - final PlotId id = new PlotId(r.getInt("idX"), r.getInt("idZ")); - final String name = r.getString("owner"); - final String world = getWorld(r.getString("world")); - if (!plotSize.containsKey(world)) { - final int size = r.getInt("topZ") - r.getInt("bottomZ"); - plotSize.put(world, size); - plots.put(world, new HashMap()); - } - UUID owner = UUIDHandler.getUUID(name); - if (owner == null) { - if (name.equals("*")) { - owner = DBFunc.everyone; - } - else { - if (checkUUID){ - try { - byte[] bytes = r.getBytes("ownerid"); - if (bytes != null) { - owner = UUID.nameUUIDFromBytes(bytes); - if (owner != null) { - UUIDHandler.add(new StringWrapper(name), owner); - } - } - } - catch (Exception e) { - e.printStackTrace(); - } - } - if (owner == null) { - sendMessage("&cCould not identify owner for plot: " + id + " -> '" + name + "'"); - continue; - } - } - } - else { - UUIDHandler.add(new StringWrapper(name), owner); - } - final Plot plot = new Plot(id, owner, new ArrayList(), new ArrayList(), world); - plots.get(world).put(id, plot); - } - return plots; - } - - public void runAsync() throws Exception { + public void runAsync(final APlotMeConnector connector) throws Exception { // We have to make it wait a couple of seconds TaskManager.runTaskLaterAsync(new Runnable() { @Override @@ -163,7 +96,7 @@ public class PlotMeConverter { return; } - Connection connection = getPlotMeConnection(plotConfig, dataFolder); + Connection connection = connector.getPlotMeConnection(plotConfig, dataFolder); if (connection == null) { sendMessage("Cannot connect to PlotMe DB. Conversion process will not continue"); @@ -179,7 +112,7 @@ public class PlotMeConverter { sendMessage(" - plotmePlots"); final Set worlds = getPlotMeWorlds(plotConfig); - HashMap> plots = getPlotMePlots(connection); + HashMap> plots = connector.getPlotMePlots(connection); for (Entry> entry : plots.entrySet()) { plotCount += entry.getValue().size(); } @@ -189,45 +122,7 @@ public class PlotMeConverter { } 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")); - final String name = r.getString("player"); - final String world = getWorld(r.getString("world")); - UUID helper = UUIDHandler.getUUID(name); - if (helper == null) { - if (name.equals("*")) { - helper = DBFunc.everyone; - } else { - sendMessage("&6Could not identify helper for plot: " + id); - continue; - } - } - if (plots.get(world).containsKey(id)) { - plots.get(world).get(id).helpers.add(helper); - } - } - sendMessage(" - plotmeDenied"); - r = stmt.executeQuery("SELECT * FROM `plotmeDenied`"); - while (r.next()) { - final PlotId id = new PlotId(r.getInt("idX"), r.getInt("idZ")); - final String name = r.getString("player"); - final String world = getWorld(r.getString("world")); - UUID denied = UUIDHandler.getUUID(name); - if (denied == null) { - if (name.equals("*")) { - denied = DBFunc.everyone; - } else { - sendMessage("&6Could not identify denied for plot: " + id); - continue; - } - } - if (plots.get(world).containsKey(id)) { - plots.get(world).get(id).denied.add(denied); - } - } + sendMessage("Collected " + plotCount + " plots from PlotMe"); for (final String world : plots.keySet()) { sendMessage("Copying config for: " + world); @@ -346,6 +241,9 @@ public class PlotMeConverter { } for (final String worldname : worlds) { final World world = Bukkit.getWorld(getWorld(worldname)); + if (world == null) { + sendMessage("&cInvalid world in PlotMe configuration: " + worldname); + } final String actualWorldName = world.getName(); sendMessage("Reloading generator for world: '" + actualWorldName + "'..."); PlotSquared.removePlotWorld(actualWorldName); @@ -394,7 +292,7 @@ public class PlotMeConverter { }, 20); } - public String getWorld(final String world) { + public static String getWorld(final String world) { for (final World newworld : Bukkit.getWorlds()) { if (newworld.getName().equalsIgnoreCase(world)) { return newworld.getName(); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java index a6e7c267b..5ec80bad2 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java @@ -94,22 +94,26 @@ public class MainUtil { myplot.settings.setMerged(new boolean[] { false, false, false, false }); DBFunc.setMerged(world, myplot, myplot.settings.getMerged()); } - // FIXME unlink augmented - for (int x = pos1.x; x <= pos2.x; x++) { - for (int y = pos1.y; y <= pos2.y; y++) { - final boolean lx = x < pos2.x; - final boolean ly = y < pos2.y; - final Plot p = MainUtil.getPlot(world, new PlotId(x, y)); - if (lx) { - manager.createRoadEast(plotworld, p); - if (ly) { - manager.createRoadSouthEast(plotworld, p); + if (plotworld.TYPE != 0 && plotworld.TERRAIN < 2) { + // FIXME unlink augmented + } + else { + for (int x = pos1.x; x <= pos2.x; x++) { + for (int y = pos1.y; y <= pos2.y; y++) { + final boolean lx = x < pos2.x; + final boolean ly = y < pos2.y; + final Plot p = MainUtil.getPlot(world, new PlotId(x, y)); + if (lx) { + manager.createRoadEast(plotworld, p); + if (ly) { + manager.createRoadSouthEast(plotworld, p); + } } + if (ly) { + manager.createRoadSouth(plotworld, p); + } + MainUtil.setSign(UUIDHandler.getName(plot.owner), plot); } - if (ly) { - manager.createRoadSouth(plotworld, p); - } - MainUtil.setSign(UUIDHandler.getName(plot.owner), plot); } } manager.finishPlotUnlink(plotworld, ids);