Updated PlotMe converter

This commit is contained in:
boy0001 2015-07-09 14:19:49 +10:00
parent 0b0461f5f4
commit 8ee90263bb
7 changed files with 319 additions and 92 deletions

View File

@ -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;

View File

@ -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");
}

View File

@ -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);
}
}

View File

@ -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<String, HashMap<PlotId, Plot>> 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<String, HashMap<PlotId, boolean[]>> merges, String world, PlotId id, int direction) {
HashMap<PlotId, boolean[]> 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);
}
}

View File

@ -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<String, HashMap<PlotId, boolean[]>> merges, String world, PlotId id, int direction) {
HashMap<PlotId, boolean[]> 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<String, HashMap<PlotId, Plot>> 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<PlotId, Plot>());
@ -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);
}
}

View File

@ -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;

View File

@ -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<String, HashMap<PlotId, Plot>> getPlotMePlots(Connection connection) throws SQLException {
ResultSet r;
PreparedStatement stmt;
HashMap<String, Integer> plotWidth = new HashMap<>();
HashMap<String, Integer> roadWidth = new HashMap<>();
final HashMap<Integer, Plot> plots = new HashMap<>();
HashMap<String, HashMap<PlotId, boolean[]>> 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<PlotId,boolean[]>());
}
}
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<Integer, Plot> entry : plots.entrySet()) {
Plot plot = entry.getValue();
HashMap<PlotId, boolean[]> 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<String, HashMap<PlotId, Plot>> processed = new HashMap<>();
for (Entry<Integer, Plot> entry : plots.entrySet()) {
Plot plot = entry.getValue();
HashMap<PlotId, Plot> 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");
}
}