mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-26 23:26:45 +01:00
I'll do this later.
This commit is contained in:
parent
57e8563b31
commit
424e032be4
@ -25,10 +25,12 @@ import java.io.IOException;
|
|||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.DriverManager;
|
import java.sql.DriverManager;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
import java.sql.Statement;
|
import java.sql.Statement;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.Map.Entry;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@ -63,87 +65,123 @@ public class PlotMeConverter {
|
|||||||
PlotSquared.log("&3PlotMe&8->&3PlotSquared&8: &7" + message);
|
PlotSquared.log("&3PlotMe&8->&3PlotSquared&8: &7" + message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getPlotMePath() {
|
||||||
|
return new File(".").getAbsolutePath() + File.separator + "plugins" + File.separator + "PlotMe" + File.separator;
|
||||||
|
}
|
||||||
|
|
||||||
|
public FileConfiguration getPlotMeConfig(String dataFolder) {
|
||||||
|
final File plotMeFile = new File(dataFolder + "config.yml");
|
||||||
|
if (!plotMeFile.exists()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
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<String> getPlotMeWorlds(FileConfiguration plotConfig) {
|
||||||
|
return plotConfig.getConfigurationSection("worlds").getKeys(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public HashMap<String, HashMap<PlotId, Plot>> getPlotMePlots(Connection connection) throws SQLException {
|
||||||
|
ResultSet r;
|
||||||
|
Statement 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`");
|
||||||
|
|
||||||
|
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<PlotId, Plot>());
|
||||||
|
}
|
||||||
|
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<UUID>(), new ArrayList<UUID>(), world);
|
||||||
|
plots.get(world).put(id, plot);
|
||||||
|
}
|
||||||
|
return plots;
|
||||||
|
}
|
||||||
|
|
||||||
public void runAsync() throws Exception {
|
public void runAsync() throws Exception {
|
||||||
// We have to make it wait a couple of seconds
|
// We have to make it wait a couple of seconds
|
||||||
TaskManager.runTaskLaterAsync(new Runnable() {
|
TaskManager.runTaskLaterAsync(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
final ArrayList<Plot> createdPlots = new ArrayList<>();
|
String dataFolder = getPlotMePath();
|
||||||
final String dataFolder = new File(".").getAbsolutePath() + File.separator + "plugins" + File.separator + "PlotMe" + File.separator;
|
FileConfiguration plotConfig = getPlotMeConfig(dataFolder);
|
||||||
final File plotMeFile = new File(dataFolder + "config.yml");
|
|
||||||
if (!plotMeFile.exists()) {
|
if (plotConfig == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Connection connection = getPlotMeConnection(plotConfig, dataFolder);
|
||||||
|
|
||||||
|
if (connection == null) {
|
||||||
|
sendMessage("Cannot connect to PlotMe DB. Conversion process will not continue");
|
||||||
|
}
|
||||||
|
|
||||||
sendMessage("PlotMe conversion has started. To disable this, please set 'plotme-convert.enabled' in the 'settings.yml'");
|
sendMessage("PlotMe conversion has started. To disable this, please set 'plotme-convert.enabled' in the 'settings.yml'");
|
||||||
sendMessage("Connecting to PlotMe DB");
|
sendMessage("Connecting to PlotMe DB");
|
||||||
|
|
||||||
final FileConfiguration plotConfig = YamlConfiguration.loadConfiguration(plotMeFile);
|
int plotCount = 0;
|
||||||
int count = 0;
|
final ArrayList<Plot> createdPlots = new ArrayList<>();
|
||||||
Connection connection;
|
|
||||||
if (plotConfig.getBoolean("usemySQL")) {
|
|
||||||
final String user = plotConfig.getString("mySQLuname");
|
|
||||||
final String password = plotConfig.getString("mySQLpass");
|
|
||||||
final String con = plotConfig.getString("mySQLconn");
|
|
||||||
connection = DriverManager.getConnection(con, user, password);
|
|
||||||
} else {
|
|
||||||
connection = new SQLite(PlotSquared.THIS, dataFolder + File.separator + "plots.db").openConnection();
|
|
||||||
}
|
|
||||||
sendMessage("Collecting plot data");
|
sendMessage("Collecting plot data");
|
||||||
sendMessage(" - plotmePlots");
|
sendMessage(" - plotmePlots");
|
||||||
|
|
||||||
ResultSet r;
|
final Set<String> worlds = getPlotMeWorlds(plotConfig);
|
||||||
Statement stmt;
|
HashMap<String, HashMap<PlotId, Plot>> plots = getPlotMePlots(connection);
|
||||||
final HashMap<String, Integer> plotSize = new HashMap<>();
|
for (Entry<String, HashMap<PlotId, Plot>> entry : plots.entrySet()) {
|
||||||
final HashMap<String, HashMap<PlotId, Plot>> plots = new HashMap<>();
|
plotCount += entry.getValue().size();
|
||||||
final Set<String> worlds = plotConfig.getConfigurationSection("worlds").getKeys(false);
|
|
||||||
stmt = connection.createStatement();
|
|
||||||
r = stmt.executeQuery("SELECT * FROM `plotmePlots`");
|
|
||||||
|
|
||||||
boolean checkUUID = DBFunc.hasColumn(r, "ownerid");
|
|
||||||
|
|
||||||
while (r.next()) {
|
|
||||||
count++;
|
|
||||||
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<PlotId, Plot>());
|
|
||||||
}
|
|
||||||
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<UUID>(), new ArrayList<UUID>(), world);
|
|
||||||
plots.get(world).put(id, plot);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Settings.CONVERT_PLOTME) {
|
if (!Settings.CONVERT_PLOTME) {
|
||||||
@ -151,6 +189,8 @@ public class PlotMeConverter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sendMessage(" - plotmeAllowed");
|
sendMessage(" - plotmeAllowed");
|
||||||
|
ResultSet r;
|
||||||
|
Statement stmt = connection.createStatement();
|
||||||
r = stmt.executeQuery("SELECT * FROM `plotmeAllowed`");
|
r = stmt.executeQuery("SELECT * FROM `plotmeAllowed`");
|
||||||
while (r.next()) {
|
while (r.next()) {
|
||||||
final PlotId id = new PlotId(r.getInt("idX"), r.getInt("idZ"));
|
final PlotId id = new PlotId(r.getInt("idX"), r.getInt("idZ"));
|
||||||
@ -188,7 +228,7 @@ public class PlotMeConverter {
|
|||||||
plots.get(world).get(id).denied.add(denied);
|
plots.get(world).get(id).denied.add(denied);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sendMessage("Collected " + count + " plots from PlotMe");
|
sendMessage("Collected " + plotCount + " plots from PlotMe");
|
||||||
for (final String world : plots.keySet()) {
|
for (final String world : plots.keySet()) {
|
||||||
sendMessage("Copying config for: " + world);
|
sendMessage("Copying config for: " + world);
|
||||||
try {
|
try {
|
||||||
|
Loading…
Reference in New Issue
Block a user