diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/BukkitMain.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/BukkitMain.java index 62ac491fa..c1d6fe751 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/BukkitMain.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/BukkitMain.java @@ -97,6 +97,7 @@ import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.database.plotme.ClassicPlotMeConnector; import com.intellectualcrafters.plot.database.plotme.LikePlotMeConverter; +import com.intellectualcrafters.plot.database.plotme.PlotMeConnector_017; import com.intellectualcrafters.plot.flag.FlagManager; import com.intellectualcrafters.plot.generator.BukkitHybridUtils; import com.intellectualcrafters.plot.generator.HybridGen; @@ -651,9 +652,9 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain { TaskManager.runTaskLaterAsync(new Runnable() { @Override public void run() { - if (!(new LikePlotMeConverter("PlotMe").run(new ClassicPlotMeConnector()))) { - new LikePlotMeConverter("AthionPlots").run(new ClassicPlotMeConnector()); - } + if (new LikePlotMeConverter("PlotMe").run(new ClassicPlotMeConnector())) return; + if (new LikePlotMeConverter("PlotMe").run(new PlotMeConnector_017())) return; + if (new LikePlotMeConverter("AthionPlots").run(new ClassicPlotMeConnector())) return; } }, 20); return Bukkit.getPluginManager().getPlugin("PlotMe") != null || Bukkit.getPluginManager().getPlugin("AthionPlots") != null; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/PS.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/PS.java index deac9cae2..8c9e59317 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/PS.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/PS.java @@ -830,7 +830,7 @@ public class PS { return true; } - private boolean canUpdate(String current, String other) { + public boolean canUpdate(String current, String other) { String s1 = normalisedVersion(current); String s2 = normalisedVersion(other); int cmp = s1.compareTo(s2); @@ -1367,6 +1367,9 @@ public class PS { try { styleFile = new File(IMP.getDirectory() + File.separator + "translations" + File.separator + "style.yml"); if (!styleFile.exists()) { + if (!styleFile.getParentFile().exists()) { + styleFile.getParentFile().mkdirs(); + } if (!styleFile.createNewFile()) { log("Could not create the style file, please create \"translations/style.yml\" manually"); } @@ -1374,6 +1377,7 @@ public class PS { style = YamlConfiguration.loadConfiguration(styleFile); setupStyle(); } catch (final Exception err) { + err.printStackTrace(); Logger.add(LogLevel.DANGER, "Failed to save style.yml"); log("failed to save style.yml"); } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/NamedSubCommand.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/NamedSubCommand.java deleted file mode 100644 index 3b859a83e..000000000 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/NamedSubCommand.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.intellectualcrafters.plot.commands; - -public abstract class NamedSubCommand extends SubCommand { - - public NamedSubCommand(Command command, String description, String usage, CommandCategory category, boolean isPlayer) { - super(command, description, usage, category, isPlayer); - } - public NamedSubCommand(String cmd, String permission, String description, String usage, CommandCategory category, boolean isPlayer, String[] aliases) { - super(cmd, permission, description, usage, category, isPlayer, aliases); - } - public NamedSubCommand(String cmd, String permission, String description, String usage, String alias, CommandCategory category, boolean isPlayer) { - super(cmd, permission, description, usage, alias, category, isPlayer); - } -} 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 ca6a9df9a..297847be3 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 @@ -4,7 +4,11 @@ import java.sql.Connection; import java.sql.SQLException; import java.util.HashMap; +import org.bukkit.Bukkit; +import org.bukkit.World; + import com.intellectualcrafters.configuration.file.FileConfiguration; +import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotId; @@ -12,4 +16,76 @@ public abstract class APlotMeConnector { public abstract Connection getPlotMeConnection(String plugin, FileConfiguration plotConfig, String dataFolder); public abstract HashMap> getPlotMePlots(Connection connection) throws SQLException; + + public abstract boolean accepts(String version); + + public String getWorld(final String world) { + for (final World newworld : Bukkit.getWorlds()) { + if (newworld.getName().equalsIgnoreCase(world)) { + return newworld.getName(); + } + } + return world; + } + + public Location getPlotTopLocAbs(int path, int plot, final PlotId plotid) { + final int px = plotid.x; + final int pz = plotid.y; + final int x = (px * (path + plot)) - ((int) Math.floor(path / 2)) - 1; + final int z = (pz * (path + plot)) - ((int) Math.floor(path / 2)) - 1; + return new Location(null, x, 256, z); + } + + public Location getPlotBottomLocAbs(int path, int plot, final PlotId plotid) { + final int px = plotid.x; + final int pz = plotid.y; + final int x = (px * (path + plot)) - plot - ((int) Math.floor(path / 2)) - 1; + final int z = (pz * (path + plot)) - plot - ((int) Math.floor(path / 2)) - 1; + return new Location(null, x, 1, z); + } + + public void setMerged(HashMap> merges, String world, PlotId id, int direction) { + HashMap plots = merges.get(world); + PlotId id2; + switch (direction) { + case 0: { + id2 = new PlotId(id.x, id.y); + break; + } + case 1: { + id2 = new PlotId(id.x, id.y); + break; + } + case 2: { + id2 = new PlotId(id.x, id.y); + break; + } + case 3: { + id2 = new PlotId(id.x, id.y); + break; + } + default: { + return; + } + } + boolean[] merge1; + boolean[] merge2; + if (plots.containsKey(id)) { + merge1 = plots.get(id); + } + else { + merge1 = new boolean[]{false, false, false, false}; + } + if (plots.containsKey(id2)) { + merge2 = plots.get(id2); + } + else { + merge2 = new boolean[]{false, false, false, false}; + } + merge1[direction] = true; + merge2[(direction + 2) % 4] = true; + plots.put(id, merge1); + plots.put(id2, merge1); + } + } 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 267b50fa1..6bb331648 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 @@ -28,15 +28,6 @@ public class ClassicPlotMeConnector extends APlotMeConnector { private String plugin; - public static String getWorld(final String world) { - for (final World newworld : Bukkit.getWorlds()) { - if (newworld.getName().equalsIgnoreCase(world)) { - return newworld.getName(); - } - } - return world; - } - @Override public Connection getPlotMeConnection(String plugin, FileConfiguration plotConfig, String dataFolder) { this.plugin = plugin.toLowerCase(); @@ -55,50 +46,6 @@ public class ClassicPlotMeConnector extends APlotMeConnector { return null; } - public void setMerged(HashMap> merges, String world, PlotId id, int direction) { - HashMap plots = merges.get(world); - PlotId id2; - switch (direction) { - case 0: { - id2 = new PlotId(id.x, id.y); - break; - } - case 1: { - id2 = new PlotId(id.x, id.y); - break; - } - case 2: { - id2 = new PlotId(id.x, id.y); - break; - } - case 3: { - id2 = new PlotId(id.x, id.y); - break; - } - default: { - return; - } - } - boolean[] merge1; - boolean[] merge2; - if (plots.containsKey(id)) { - merge1 = plots.get(id); - } - else { - merge1 = new boolean[]{false, false, false, false}; - } - if (plots.containsKey(id2)) { - merge2 = plots.get(id2); - } - else { - merge2 = new boolean[]{false, false, false, false}; - } - merge1[direction] = true; - merge2[(direction + 2) % 4] = true; - plots.put(id, merge1); - plots.put(id2, merge1); - } - @Override public HashMap> getPlotMePlots(Connection connection) throws SQLException { ResultSet r; @@ -118,9 +65,6 @@ public class ClassicPlotMeConnector extends APlotMeConnector { if (!plots.containsKey(world)) { int plot = PS.get().config.getInt("worlds." + world + ".plot.size"); int path = PS.get().config.getInt("worlds." + world + ".road.width"); - if (plot == 0 && path == 0) { - - } plotWidth.put(world, plot); roadWidth.put(world, path); plots.put(world, new HashMap()); @@ -249,21 +193,15 @@ public class ClassicPlotMeConnector extends APlotMeConnector { catch (Exception e) {} return plots; } - - public Location getPlotTopLocAbs(int path, int plot, final PlotId plotid) { - final int px = plotid.x; - final int pz = plotid.y; - final int x = (px * (path + plot)) - ((int) Math.floor(path / 2)) - 1; - final int z = (pz * (path + plot)) - ((int) Math.floor(path / 2)) - 1; - return new Location(null, x, 256, z); + + @Override + public boolean accepts(String version) { + System.out.print("CHECKING VERSION"); + if (version == null) { + System.out.print("VERSION IS NULL"); + return true; + } + System.out.print("VERSION IS: " + version); + return PS.get().canUpdate(version, "0.17.0"); } - - public Location getPlotBottomLocAbs(int path, int plot, final PlotId plotid) { - final int px = plotid.x; - final int pz = plotid.y; - final int x = (px * (path + plot)) - plot - ((int) Math.floor(path / 2)) - 1; - final int z = (pz * (path + plot)) - plot - ((int) Math.floor(path / 2)) - 1; - return new Location(null, x, 1, z); - } - } 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 870bbaacb..9537ae17c 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 @@ -119,11 +119,18 @@ public class LikePlotMeConverter { try { String dataFolder = getPlotMePath(); FileConfiguration plotConfig = getPlotMeConfig(dataFolder); - if (plotConfig == null) { return false; } - + + String version = plotConfig.getString("Version"); + if (version == null) version = plotConfig.getString("version"); + if (!connector.accepts(version)) { + return false; + } + + System.out.print("CONNECTOR ACCEPTS VERSION"); + Connection connection = connector.getPlotMeConnection(plugin, plotConfig, dataFolder); if (connection == null) { @@ -322,6 +329,7 @@ public class LikePlotMeConverter { } }); } catch (final Exception e) { + e.printStackTrace(); PS.log("&/end/"); } return true; 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 new file mode 100644 index 000000000..e23eeb75b --- /dev/null +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/plotme/PlotMeConnector_017.java @@ -0,0 +1,214 @@ +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.util.HashMap; +import java.util.UUID; +import java.util.Map.Entry; + +import com.intellectualcrafters.configuration.file.FileConfiguration; +import com.intellectualcrafters.plot.PS; +import com.intellectualcrafters.plot.database.DBFunc; +import com.intellectualcrafters.plot.database.SQLite; +import com.intellectualcrafters.plot.object.Location; +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 PlotMeConnector_017 extends APlotMeConnector { + private String plugin; + + @Override + public Connection getPlotMeConnection(String plugin, FileConfiguration plotConfig, String dataFolder) { + this.plugin = plugin.toLowerCase(); + try { + if (plotConfig.getBoolean("usemySQL")) { + String user = plotConfig.getString("mySQLuname"); + String password = plotConfig.getString("mySQLpass"); + String con = plotConfig.getString("mySQLconn"); + return DriverManager.getConnection(con, user, password); + } else { + File file = new File(dataFolder + File.separator + "plotmecore.db"); + if (file.exists()) { + return new SQLite(dataFolder + File.separator + "plotmecore.db").openConnection(); + } + return new SQLite(dataFolder + File.separator + "plots.db").openConnection(); + } + } + catch (SQLException | ClassNotFoundException e) {} + return null; + } + + @Override + public HashMap> getPlotMePlots(Connection connection) throws SQLException { + ResultSet r; + PreparedStatement stmt; + HashMap plotWidth = new HashMap<>(); + HashMap roadWidth = new HashMap<>(); + final HashMap plots = new HashMap<>(); + HashMap> merges = new HashMap<>(); + stmt = connection.prepareStatement("SELECT * FROM `" + plugin + "core_plots`"); + r = stmt.executeQuery(); + boolean checkUUID = DBFunc.hasColumn(r, "ownerID"); + boolean merge = !plugin.equals("plotme"); + while (r.next()) { + int key = r.getInt("plot_id"); + PlotId id = new PlotId(r.getInt("plotX"), r.getInt("plotZ")); + String name = r.getString("owner"); + String world = LikePlotMeConverter.getWorld(r.getString("world")); + if (!plots.containsKey(world)) { + int plot = PS.get().config.getInt("worlds." + world + ".plot.size"); + int path = PS.get().config.getInt("worlds." + world + ".road.width"); + plotWidth.put(world, plot); + roadWidth.put(world, path); + if (merge) { + merges.put(world, new HashMap()); + } + } + if (merge) { + int tx = r.getInt("topX"); + int tz = r.getInt("topZ"); + int bx = r.getInt("bottomX") - 1; + int bz = r.getInt("bottomZ") - 1; + int path = roadWidth.get(world); + int plot = plotWidth.get(world); + Location top = getPlotTopLocAbs(path, plot, id); + Location bot = getPlotBottomLocAbs(path, plot, id); + if (tx > top.getX()) { + setMerged(merges, world, id, 1); + } + if (tz > top.getZ()) { + setMerged(merges, world, id, 2); + } + if (bx < bot.getX()) { + setMerged(merges, world, id, 3); + } + if (bz > bot.getZ()) { + setMerged(merges, world, id, 0); + } + } + 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); + } + Plot plot = new Plot(world, id, owner); + plots.put(key, plot); + } + for (Entry entry : plots.entrySet()) { + Plot plot = entry.getValue(); + HashMap mergeMap = merges.get(plot.world); + if (mergeMap != null) { + if (mergeMap.containsKey(plot.id)) { + plot.settings.setMerged(mergeMap.get(plot.id)); + } + } + } + r.close(); + stmt.close(); + try { + MainUtil.sendConsoleMessage(" - " + plugin + "_denied"); + stmt = connection.prepareStatement("SELECT * FROM `" + plugin + "_denied`"); + r = stmt.executeQuery(); + + while (r.next()) { + int key = r.getInt("plot_id"); + Plot plot = plots.get(key); + if (plot == null) { + MainUtil.sendConsoleMessage("&6Denied (" + key + ") references deleted plot; ignoring entry."); + continue; + } + String name = r.getString("player"); + UUID denied = UUIDHandler.getUUID(name); + if (denied == null) { + if (name.equals("*")) { + denied = DBFunc.everyone; + } else { + MainUtil.sendConsoleMessage("&6Denied (" + key + ") references incorrect name (`" + name + "`)"); + continue; + } + } + plot.denied.add(denied); + } + + MainUtil.sendConsoleMessage(" - " + plugin + "_allowed"); + stmt = connection.prepareStatement("SELECT * FROM `" + plugin + "_allowed`"); + r = stmt.executeQuery(); + + while (r.next()) { + int key = r.getInt("plot_id"); + Plot plot = plots.get(key); + if (plot == null) { + MainUtil.sendConsoleMessage("&6Allowed (" + key + ") references deleted plot; ignoring entry."); + continue; + } + String name = r.getString("player"); + UUID allowed = UUIDHandler.getUUID(name); + if (allowed == null) { + if (name.equals("*")) { + allowed = DBFunc.everyone; + } else { + MainUtil.sendConsoleMessage("&6Allowed (" + key + ") references incorrect name (`" + name + "`)"); + continue; + } + } + plot.trusted.add(allowed); + } + r.close(); + stmt.close(); + + } + catch (Exception e) {} + HashMap> processed = new HashMap<>(); + + for (Entry entry : plots.entrySet()) { + Plot plot = entry.getValue(); + HashMap map = processed.get(plot.world); + if (map == null) { + map = new HashMap<>(); + processed.put(plot.world, map); + } + map.put(plot.id, plot); + } + return processed ; + } + + @Override + public boolean accepts(String version) { + if (version == null) { + return false; + } + return !PS.get().canUpdate(version, "0.17"); + } + +}