Replace all '/' in path to File.separator - Code Refactor

This commit is contained in:
Xephi
2014-08-25 03:12:28 +02:00
parent 12795436a0
commit d7cb60c1fe
104 changed files with 2470 additions and 3690 deletions
@@ -41,11 +41,9 @@ public class CrazyLoginConverter implements Converter {
public void run() {
fileName = Settings.crazyloginFileName;
try {
source = new File(AuthMe.getInstance().getDataFolder()
+ File.separator + fileName);
source = new File(AuthMe.getInstance().getDataFolder() + File.separator + fileName);
if (!source.exists()) {
sender.sendMessage("Error while trying to import datas, please put "
+ fileName + " in AuthMe folder!");
sender.sendMessage("Error while trying to import datas, please put " + fileName + " in AuthMe folder!");
return;
}
source.createNewFile();
@@ -55,14 +53,15 @@ public class CrazyLoginConverter implements Converter {
while ((line = users.readLine()) != null) {
if (line.contains("|")) {
String[] args = line.split("\\|");
if (args.length < 2) continue;
if (args[0].equalsIgnoreCase("name")) continue;
if (args.length < 2)
continue;
if (args[0].equalsIgnoreCase("name"))
continue;
String player = args[0].toLowerCase();
String psw = args[1];
try {
if (player != null && psw != null) {
PlayerAuth auth = new PlayerAuth(player, psw,
"127.0.0.1", System.currentTimeMillis());
PlayerAuth auth = new PlayerAuth(player, psw, "127.0.0.1", System.currentTimeMillis());
database.saveAuth(auth);
}
} catch (Exception e) {
@@ -70,8 +69,7 @@ public class CrazyLoginConverter implements Converter {
}
}
users.close();
ConsoleLogger
.info("CrazyLogin database has been imported correctly");
ConsoleLogger.info("CrazyLogin database has been imported correctly");
} catch (FileNotFoundException ex) {
ConsoleLogger.showError(ex.getMessage());
} catch (IOException ex) {
@@ -51,78 +51,35 @@ public class FlatToSql implements Converter {
@Override
public void run() {
try {
source = new File(AuthMe.getInstance().getDataFolder()
+ File.separator + "auths.db");
source = new File(AuthMe.getInstance().getDataFolder() + File.separator + "auths.db");
source.createNewFile();
output = new File(AuthMe.getInstance().getDataFolder()
+ File.separator + "authme.sql");
output = new File(AuthMe.getInstance().getDataFolder() + File.separator + "authme.sql");
BufferedReader br = null;
BufferedWriter sql = null;
br = new BufferedReader(new FileReader(source));
sql = new BufferedWriter(new FileWriter(output));
String createDB = "CREATE TABLE IF NOT EXISTS " + tableName + " ("
+ columnID + " INTEGER AUTO_INCREMENT," + columnName
+ " VARCHAR(255) NOT NULL UNIQUE," + columnPassword
+ " VARCHAR(255) NOT NULL," + columnIp
+ " VARCHAR(40) NOT NULL DEFAULT '127.0.0.1',"
+ columnLastLogin + " BIGINT NOT NULL DEFAULT '"
+ System.currentTimeMillis() + "'," + lastlocX
+ " DOUBLE NOT NULL DEFAULT '0.0'," + lastlocY
+ " DOUBLE NOT NULL DEFAULT '0.0'," + lastlocZ
+ " DOUBLE NOT NULL DEFAULT '0.0'," + lastlocWorld
+ " VARCHAR(255) DEFAULT 'world'," + columnEmail
+ " VARCHAR(255) DEFAULT 'your@email.com'," + columnLogged
+ " SMALLINT NOT NULL DEFAULT '0',"
+ "CONSTRAINT table_const_prim PRIMARY KEY (" + columnID
+ "));";
String createDB = "CREATE TABLE IF NOT EXISTS " + tableName + " (" + columnID + " INTEGER AUTO_INCREMENT," + columnName + " VARCHAR(255) NOT NULL UNIQUE," + columnPassword + " VARCHAR(255) NOT NULL," + columnIp + " VARCHAR(40) NOT NULL DEFAULT '127.0.0.1'," + columnLastLogin + " BIGINT NOT NULL DEFAULT '" + System.currentTimeMillis() + "'," + lastlocX + " DOUBLE NOT NULL DEFAULT '0.0'," + lastlocY + " DOUBLE NOT NULL DEFAULT '0.0'," + lastlocZ + " DOUBLE NOT NULL DEFAULT '0.0'," + lastlocWorld + " VARCHAR(255) DEFAULT 'world'," + columnEmail + " VARCHAR(255) DEFAULT 'your@email.com'," + columnLogged + " SMALLINT NOT NULL DEFAULT '0'," + "CONSTRAINT table_const_prim PRIMARY KEY (" + columnID + "));";
sql.write(createDB);
String line;
String newline;
while ((line = br.readLine()) != null) {
sql.newLine();
String[] args = line.split(":");
if (args.length == 4) newline = "INSERT INTO " + tableName
+ "(" + columnName + "," + columnPassword + ","
+ columnIp + "," + columnLastLogin + "," + lastlocX
+ "," + lastlocY + "," + lastlocZ + "," + lastlocWorld
+ "," + columnEmail + "," + columnLogged
+ ") VALUES ('" + args[0] + "', '" + args[1] + "', '"
+ args[2] + "', " + args[3]
+ ", 0.0, 0.0, 0.0, 'world', 'your@email.com', 0);";
else if (args.length == 7) newline = "INSERT INTO " + tableName
+ "(" + columnName + "," + columnPassword + ","
+ columnIp + "," + columnLastLogin + "," + lastlocX
+ "," + lastlocY + "," + lastlocZ + "," + lastlocWorld
+ "," + columnEmail + "," + columnLogged
+ ") VALUES ('" + args[0] + "', '" + args[1] + "', '"
+ args[2] + "', " + args[3] + ", " + args[4] + ", "
+ args[5] + ", " + args[6]
+ ", 'world', 'your@email.com', 0);";
else if (args.length == 8) newline = "INSERT INTO " + tableName
+ "(" + columnName + "," + columnPassword + ","
+ columnIp + "," + columnLastLogin + "," + lastlocX
+ "," + lastlocY + "," + lastlocZ + "," + lastlocWorld
+ "," + columnEmail + "," + columnLogged
+ ") VALUES ('" + args[0] + "', '" + args[1] + "', '"
+ args[2] + "', " + args[3] + ", " + args[4] + ", "
+ args[5] + ", " + args[6] + ", '" + args[7]
+ "', 'your@email.com', 0);";
else if (args.length == 9) newline = "INSERT INTO " + tableName
+ "(" + columnName + "," + columnPassword + ","
+ columnIp + "," + columnLastLogin + "," + lastlocX
+ "," + lastlocY + "," + lastlocZ + "," + lastlocWorld
+ "," + columnEmail + "," + columnLogged
+ ") VALUES ('" + args[0] + "', '" + args[1] + "', '"
+ args[2] + "', " + args[3] + ", " + args[4] + ", "
+ args[5] + ", " + args[6] + ", '" + args[7] + "', '"
+ args[8] + "', 0);";
if (args.length == 4)
newline = "INSERT INTO " + tableName + "(" + columnName + "," + columnPassword + "," + columnIp + "," + columnLastLogin + "," + lastlocX + "," + lastlocY + "," + lastlocZ + "," + lastlocWorld + "," + columnEmail + "," + columnLogged + ") VALUES ('" + args[0] + "', '" + args[1] + "', '" + args[2] + "', " + args[3] + ", 0.0, 0.0, 0.0, 'world', 'your@email.com', 0);";
else if (args.length == 7)
newline = "INSERT INTO " + tableName + "(" + columnName + "," + columnPassword + "," + columnIp + "," + columnLastLogin + "," + lastlocX + "," + lastlocY + "," + lastlocZ + "," + lastlocWorld + "," + columnEmail + "," + columnLogged + ") VALUES ('" + args[0] + "', '" + args[1] + "', '" + args[2] + "', " + args[3] + ", " + args[4] + ", " + args[5] + ", " + args[6] + ", 'world', 'your@email.com', 0);";
else if (args.length == 8)
newline = "INSERT INTO " + tableName + "(" + columnName + "," + columnPassword + "," + columnIp + "," + columnLastLogin + "," + lastlocX + "," + lastlocY + "," + lastlocZ + "," + lastlocWorld + "," + columnEmail + "," + columnLogged + ") VALUES ('" + args[0] + "', '" + args[1] + "', '" + args[2] + "', " + args[3] + ", " + args[4] + ", " + args[5] + ", " + args[6] + ", '" + args[7] + "', 'your@email.com', 0);";
else if (args.length == 9)
newline = "INSERT INTO " + tableName + "(" + columnName + "," + columnPassword + "," + columnIp + "," + columnLastLogin + "," + lastlocX + "," + lastlocY + "," + lastlocZ + "," + lastlocWorld + "," + columnEmail + "," + columnLogged + ") VALUES ('" + args[0] + "', '" + args[1] + "', '" + args[2] + "', " + args[3] + ", " + args[4] + ", " + args[5] + ", " + args[6] + ", '" + args[7] + "', '" + args[8] + "', 0);";
else newline = "";
if (newline != "") sql.write(newline);
if (newline != "")
sql.write(newline);
}
sql.close();
br.close();
ConsoleLogger
.info("The FlatFile has been converted to authme.sql file");
ConsoleLogger.info("The FlatFile has been converted to authme.sql file");
} catch (FileNotFoundException ex) {
ConsoleLogger.showError(ex.getMessage());
} catch (IOException ex) {
@@ -56,24 +56,20 @@ public class FlatToSqlite implements Converter {
columnEmail = Settings.getMySQLColumnEmail;
columnID = Settings.getMySQLColumnId;
ConsoleLogger.info("Converting FlatFile to SQLite ...");
if (new File(AuthMe.getInstance().getDataFolder() + File.separator
+ database + ".db").exists()) {
sender.sendMessage("The Database " + database
+ ".db can't be created cause the file already exist");
if (new File(AuthMe.getInstance().getDataFolder() + File.separator + database + ".db").exists()) {
sender.sendMessage("The Database " + database + ".db can't be created cause the file already exist");
return;
}
try {
connect();
setup();
} catch (Exception e) {
ConsoleLogger
.showError("Problem while trying to convert to sqlite !");
ConsoleLogger.showError("Problem while trying to convert to sqlite !");
sender.sendMessage("Problem while trying to convert to sqlite !");
return;
}
try {
source = new File(AuthMe.getInstance().getDataFolder()
+ File.separator + "auths.db");
source = new File(AuthMe.getInstance().getDataFolder() + File.separator + "auths.db");
source.createNewFile();
BufferedReader br = new BufferedReader(new FileReader(source));
String line;
@@ -81,35 +77,23 @@ public class FlatToSqlite implements Converter {
String newline;
while ((line = br.readLine()) != null) {
String[] args = line.split(":");
if (args.length == 4) newline = "INSERT INTO " + tableName
+ " VALUES (" + i + ", '" + args[0] + "', '" + args[1]
+ "', '" + args[2] + "', " + args[3]
+ ", 0, 0, 0, 'world', 'your@email.com');";
else if (args.length == 7) newline = "INSERT INTO " + tableName
+ " VALUES (" + i + ", '" + args[0] + "', '" + args[1]
+ "', '" + args[2] + "', " + args[3] + ", " + args[4]
+ ", " + args[5] + ", " + args[6]
+ ", 'world', 'your@email.com');";
else if (args.length == 8) newline = "INSERT INTO " + tableName
+ " VALUES (" + i + ", '" + args[0] + "', '" + args[1]
+ "', '" + args[2] + "', " + args[3] + ", " + args[4]
+ ", " + args[5] + ", " + args[6] + ", '" + args[7]
+ "', 'your@email.com');";
else if (args.length == 9) newline = "INSERT INTO " + tableName
+ " VALUES (" + i + ", '" + args[0] + "', '" + args[1]
+ "', '" + args[2] + "', " + args[3] + ", " + args[4]
+ ", " + args[5] + ", " + args[6] + ", '" + args[7]
+ "', '" + args[8] + "');";
if (args.length == 4)
newline = "INSERT INTO " + tableName + " VALUES (" + i + ", '" + args[0] + "', '" + args[1] + "', '" + args[2] + "', " + args[3] + ", 0, 0, 0, 'world', 'your@email.com');";
else if (args.length == 7)
newline = "INSERT INTO " + tableName + " VALUES (" + i + ", '" + args[0] + "', '" + args[1] + "', '" + args[2] + "', " + args[3] + ", " + args[4] + ", " + args[5] + ", " + args[6] + ", 'world', 'your@email.com');";
else if (args.length == 8)
newline = "INSERT INTO " + tableName + " VALUES (" + i + ", '" + args[0] + "', '" + args[1] + "', '" + args[2] + "', " + args[3] + ", " + args[4] + ", " + args[5] + ", " + args[6] + ", '" + args[7] + "', 'your@email.com');";
else if (args.length == 9)
newline = "INSERT INTO " + tableName + " VALUES (" + i + ", '" + args[0] + "', '" + args[1] + "', '" + args[2] + "', " + args[3] + ", " + args[4] + ", " + args[5] + ", " + args[6] + ", '" + args[7] + "', '" + args[8] + "');";
else newline = "";
if (newline != "") saveAuth(newline);
if (newline != "")
saveAuth(newline);
i = i + 1;
}
br.close();
ConsoleLogger.info("The FlatFile has been converted to " + database
+ ".db file");
ConsoleLogger.info("The FlatFile has been converted to " + database + ".db file");
close();
sender.sendMessage("The FlatFile has been converted to " + database
+ ".db file");
sender.sendMessage("The FlatFile has been converted to " + database + ".db file");
return;
} catch (FileNotFoundException ex) {
ConsoleLogger.showError(ex.getMessage());
@@ -124,8 +108,7 @@ public class FlatToSqlite implements Converter {
SQLException {
Class.forName("org.sqlite.JDBC");
ConsoleLogger.info("SQLite driver loaded");
con = DriverManager.getConnection("jdbc:sqlite:plugins/AuthMe/"
+ database + ".db");
con = DriverManager.getConnection("jdbc:sqlite:plugins/AuthMe/" + database + ".db");
}
private synchronized static void setup() throws SQLException {
@@ -133,63 +116,35 @@ public class FlatToSqlite implements Converter {
ResultSet rs = null;
try {
st = con.createStatement();
st.executeUpdate("CREATE TABLE IF NOT EXISTS " + tableName + " ("
+ columnID + " INTEGER AUTO_INCREMENT," + columnName
+ " VARCHAR(255) NOT NULL UNIQUE," + columnPassword
+ " VARCHAR(255) NOT NULL," + columnIp
+ " VARCHAR(40) NOT NULL," + columnLastLogin + " BIGINT,"
+ lastlocX + " smallint(6) DEFAULT '0'," + lastlocY
+ " smallint(6) DEFAULT '0'," + lastlocZ
+ " smallint(6) DEFAULT '0'," + lastlocWorld
+ " VARCHAR(255) DEFAULT 'world'," + columnEmail
+ " VARCHAR(255) DEFAULT 'your@email.com',"
+ "CONSTRAINT table_const_prim PRIMARY KEY (" + columnID
+ "));");
rs = con.getMetaData().getColumns(null, null, tableName,
columnPassword);
st.executeUpdate("CREATE TABLE IF NOT EXISTS " + tableName + " (" + columnID + " INTEGER AUTO_INCREMENT," + columnName + " VARCHAR(255) NOT NULL UNIQUE," + columnPassword + " VARCHAR(255) NOT NULL," + columnIp + " VARCHAR(40) NOT NULL," + columnLastLogin + " BIGINT," + lastlocX + " smallint(6) DEFAULT '0'," + lastlocY + " smallint(6) DEFAULT '0'," + lastlocZ + " smallint(6) DEFAULT '0'," + lastlocWorld + " VARCHAR(255) DEFAULT 'world'," + columnEmail + " VARCHAR(255) DEFAULT 'your@email.com'," + "CONSTRAINT table_const_prim PRIMARY KEY (" + columnID + "));");
rs = con.getMetaData().getColumns(null, null, tableName, columnPassword);
if (!rs.next()) {
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN "
+ columnPassword + " VARCHAR(255) NOT NULL;");
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + columnPassword + " VARCHAR(255) NOT NULL;");
}
rs.close();
rs = con.getMetaData().getColumns(null, null, tableName, columnIp);
if (!rs.next()) {
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN "
+ columnIp + " VARCHAR(40) NOT NULL;");
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + columnIp + " VARCHAR(40) NOT NULL;");
}
rs.close();
rs = con.getMetaData().getColumns(null, null, tableName,
columnLastLogin);
rs = con.getMetaData().getColumns(null, null, tableName, columnLastLogin);
if (!rs.next()) {
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN "
+ columnLastLogin + " BIGINT;");
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + columnLastLogin + " BIGINT;");
}
rs.close();
rs = con.getMetaData().getColumns(null, null, tableName, lastlocX);
if (!rs.next()) {
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN "
+ lastlocX + " smallint(6) NOT NULL DEFAULT '0'; "
+ "ALTER TABLE " + tableName + " ADD COLUMN "
+ lastlocY + " smallint(6) NOT NULL DEFAULT '0'; "
+ "ALTER TABLE " + tableName + " ADD COLUMN "
+ lastlocZ + " smallint(6) NOT NULL DEFAULT '0';");
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + lastlocX + " smallint(6) NOT NULL DEFAULT '0'; " + "ALTER TABLE " + tableName + " ADD COLUMN " + lastlocY + " smallint(6) NOT NULL DEFAULT '0'; " + "ALTER TABLE " + tableName + " ADD COLUMN " + lastlocZ + " smallint(6) NOT NULL DEFAULT '0';");
}
rs.close();
rs = con.getMetaData().getColumns(null, null, tableName,
lastlocWorld);
rs = con.getMetaData().getColumns(null, null, tableName, lastlocWorld);
if (!rs.next()) {
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN "
+ lastlocWorld
+ " VARCHAR(255) NOT NULL DEFAULT 'world' AFTER "
+ lastlocZ + ";");
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + lastlocWorld + " VARCHAR(255) NOT NULL DEFAULT 'world' AFTER " + lastlocZ + ";");
}
rs.close();
rs = con.getMetaData().getColumns(null, null, tableName,
columnEmail);
rs = con.getMetaData().getColumns(null, null, tableName, columnEmail);
if (!rs.next()) {
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN "
+ columnEmail
+ " VARCHAR(255) DEFAULT 'your@email.com';");
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + columnEmail + " VARCHAR(255) DEFAULT 'your@email.com';");
}
} finally {
close(rs);
@@ -55,10 +55,8 @@ public class RakamakConverter implements Converter {
HashMap<String, String> playerIP = new HashMap<String, String>();
HashMap<String, String> playerPSW = new HashMap<String, String>();
try {
source = new File(AuthMe.getInstance().getDataFolder()
+ File.separator + fileName);
ipfiles = new File(AuthMe.getInstance().getDataFolder()
+ File.separator + ipFileName);
source = new File(AuthMe.getInstance().getDataFolder() + File.separator + fileName);
ipfiles = new File(AuthMe.getInstance().getDataFolder() + File.separator + ipFileName);
source.createNewFile();
ipfiles.createNewFile();
BufferedReader users = null;
@@ -80,8 +78,7 @@ public class RakamakConverter implements Converter {
if (line.contains("=")) {
String[] arguments = line.split("=");
try {
playerPSW.put(arguments[0], PasswordSecurity.getHash(
hash, arguments[1], arguments[0]));
playerPSW.put(arguments[0], PasswordSecurity.getHash(hash, arguments[1], arguments[0]));
} catch (NoSuchAlgorithmException e) {
ConsoleLogger.showError(e.getMessage());
}
@@ -97,10 +94,9 @@ public class RakamakConverter implements Converter {
} else {
ip = "127.0.0.1";
}
PlayerAuth auth = new PlayerAuth(player, psw, ip,
System.currentTimeMillis());
if (PasswordSecurity.userSalt.containsKey(player)) auth
.setSalt(PasswordSecurity.userSalt.get(player));
PlayerAuth auth = new PlayerAuth(player, psw, ip, System.currentTimeMillis());
if (PasswordSecurity.userSalt.containsKey(player))
auth.setSalt(PasswordSecurity.userSalt.get(player));
database.saveAuth(auth);
}
ConsoleLogger.info("Rakamak database has been imported correctly");
@@ -25,19 +25,16 @@ public class RoyalAuthConverter implements Converter {
try {
String name = o.getName().toLowerCase();
String separator = File.separator;
File file = new File("." + separator + "plugins" + separator
+ "RoyalAuth" + separator + "userdata" + separator
+ name + ".yml");
if (data.isAuthAvailable(name)) continue;
if (!file.exists()) continue;
File file = new File("." + separator + "plugins" + separator + "RoyalAuth" + separator + "userdata" + separator + name + ".yml");
if (data.isAuthAvailable(name))
continue;
if (!file.exists())
continue;
RoyalAuthYamlReader ra = new RoyalAuthYamlReader(file);
PlayerAuth auth = new PlayerAuth(name, ra.getHash(),
"127.0.0.1", ra.getLastLogin(), "your@email.com",
o.getName());
PlayerAuth auth = new PlayerAuth(name, ra.getHash(), "127.0.0.1", ra.getLastLogin(), "your@email.com", o.getName());
data.saveAuth(auth);
} catch (Exception e) {
ConsoleLogger.showError("Error while trying to import "
+ o.getName() + " RoyalAuth datas");
ConsoleLogger.showError("Error while trying to import " + o.getName() + " RoyalAuth datas");
}
}
}
@@ -37,7 +37,7 @@ public class newxAuthToFlat {
sender.sendMessage("[AuthMe] xAuth plugin not found");
return false;
}
if (!(new File("./plugins/xAuth/xAuth.h2.db").exists())) {
if (!(new File(instance.getDataFolder().getParent() + File.separator + "xAuth" + File.separator + "xAuth.h2.db").exists())) {
sender.sendMessage("[AuthMe] xAuth H2 database not found, checking for MySQL or SQLite data...");
}
List<Integer> players = getXAuthPlayers();
@@ -51,8 +51,7 @@ public class newxAuthToFlat {
String pl = getIdPlayer(id);
String psw = getPassword(id);
if (psw != null && !psw.isEmpty() && pl != null) {
PlayerAuth auth = new PlayerAuth(pl, psw, "198.18.0.1", 0,
"your@email.com", API.getPlayerRealName(pl));
PlayerAuth auth = new PlayerAuth(pl, psw, "198.18.0.1", 0, "your@email.com", API.getPlayerRealName(pl));
database.saveAuth(auth);
}
}
@@ -65,19 +64,16 @@ public class newxAuthToFlat {
public String getIdPlayer(int id) {
String realPass = "";
Connection conn = xAuth.getPlugin().getDatabaseController()
.getConnection();
Connection conn = xAuth.getPlugin().getDatabaseController().getConnection();
PreparedStatement ps = null;
ResultSet rs = null;
try {
String sql = String.format(
"SELECT `playername` FROM `%s` WHERE `id` = ?",
xAuth.getPlugin().getDatabaseController()
.getTable(Table.ACCOUNT));
String sql = String.format("SELECT `playername` FROM `%s` WHERE `id` = ?", xAuth.getPlugin().getDatabaseController().getTable(Table.ACCOUNT));
ps = conn.prepareStatement(sql);
ps.setInt(1, id);
rs = ps.executeQuery();
if (!rs.next()) return null;
if (!rs.next())
return null;
realPass = rs.getString("playername").toLowerCase();
} catch (SQLException e) {
xAuthLog.severe("Failed to retrieve name for account: " + id, e);
@@ -90,13 +86,11 @@ public class newxAuthToFlat {
public List<Integer> getXAuthPlayers() {
List<Integer> xP = new ArrayList<Integer>();
Connection conn = xAuth.getPlugin().getDatabaseController()
.getConnection();
Connection conn = xAuth.getPlugin().getDatabaseController().getConnection();
PreparedStatement ps = null;
ResultSet rs = null;
try {
String sql = String.format("SELECT * FROM `%s`", xAuth.getPlugin()
.getDatabaseController().getTable(Table.ACCOUNT));
String sql = String.format("SELECT * FROM `%s`", xAuth.getPlugin().getDatabaseController().getTable(Table.ACCOUNT));
ps = conn.prepareStatement(sql);
rs = ps.executeQuery();
while (rs.next()) {
@@ -113,23 +107,19 @@ public class newxAuthToFlat {
public String getPassword(int accountId) {
String realPass = "";
Connection conn = xAuth.getPlugin().getDatabaseController()
.getConnection();
Connection conn = xAuth.getPlugin().getDatabaseController().getConnection();
PreparedStatement ps = null;
ResultSet rs = null;
try {
String sql = String.format(
"SELECT `password`, `pwtype` FROM `%s` WHERE `id` = ?",
xAuth.getPlugin().getDatabaseController()
.getTable(Table.ACCOUNT));
String sql = String.format("SELECT `password`, `pwtype` FROM `%s` WHERE `id` = ?", xAuth.getPlugin().getDatabaseController().getTable(Table.ACCOUNT));
ps = conn.prepareStatement(sql);
ps.setInt(1, accountId);
rs = ps.executeQuery();
if (!rs.next()) return null;
if (!rs.next())
return null;
realPass = rs.getString("password");
} catch (SQLException e) {
xAuthLog.severe("Failed to retrieve password hash for account: "
+ accountId, e);
xAuthLog.severe("Failed to retrieve password hash for account: " + accountId, e);
return null;
} finally {
xAuth.getPlugin().getDatabaseController().close(conn, ps, rs);
@@ -41,7 +41,7 @@ public class oldxAuthToFlat {
sender.sendMessage("[AuthMe] xAuth plugin not found");
return false;
}
if (!(new File("./plugins/xAuth/xAuth.h2.db").exists())) {
if (!(new File(instance.getDataFolder().getParent() + File.separator + "xAuth" + File.separator + "xAuth.h2.db").exists())) {
sender.sendMessage("[AuthMe] xAuth H2 database not found, checking for MySQL or SQLite data...");
}
List<Integer> players = getXAuthPlayers();
@@ -55,8 +55,7 @@ public class oldxAuthToFlat {
String pl = getIdPlayer(id);
String psw = getPassword(id);
if (psw != null && !psw.isEmpty() && pl != null) {
PlayerAuth auth = new PlayerAuth(pl, psw, "198.18.0.1", 0,
"your@email.com", API.getPlayerRealName(pl));
PlayerAuth auth = new PlayerAuth(pl, psw, "198.18.0.1", 0, "your@email.com", API.getPlayerRealName(pl));
database.saveAuth(auth);
}
}
@@ -69,19 +68,16 @@ public class oldxAuthToFlat {
public String getIdPlayer(int id) {
String realPass = "";
Connection conn = xAuth.getPlugin().getDatabaseController()
.getConnection();
Connection conn = xAuth.getPlugin().getDatabaseController().getConnection();
PreparedStatement ps = null;
ResultSet rs = null;
try {
String sql = String.format(
"SELECT `playername` FROM `%s` WHERE `id` = ?",
xAuth.getPlugin().getDatabaseController()
.getTable(Table.ACCOUNT));
String sql = String.format("SELECT `playername` FROM `%s` WHERE `id` = ?", xAuth.getPlugin().getDatabaseController().getTable(Table.ACCOUNT));
ps = conn.prepareStatement(sql);
ps.setInt(1, id);
rs = ps.executeQuery();
if (!rs.next()) return null;
if (!rs.next())
return null;
realPass = rs.getString("playername").toLowerCase();
} catch (SQLException e) {
xAuthLog.severe("Failed to retrieve name for account: " + id, e);
@@ -94,13 +90,11 @@ public class oldxAuthToFlat {
public List<Integer> getXAuthPlayers() {
List<Integer> xP = new ArrayList<Integer>();
Connection conn = xAuth.getPlugin().getDatabaseController()
.getConnection();
Connection conn = xAuth.getPlugin().getDatabaseController().getConnection();
PreparedStatement ps = null;
ResultSet rs = null;
try {
String sql = String.format("SELECT * FROM `%s`", xAuth.getPlugin()
.getDatabaseController().getTable(Table.ACCOUNT));
String sql = String.format("SELECT * FROM `%s`", xAuth.getPlugin().getDatabaseController().getTable(Table.ACCOUNT));
ps = conn.prepareStatement(sql);
rs = ps.executeQuery();
while (rs.next()) {
@@ -117,23 +111,19 @@ public class oldxAuthToFlat {
public String getPassword(int accountId) {
String realPass = "";
Connection conn = xAuth.getPlugin().getDatabaseController()
.getConnection();
Connection conn = xAuth.getPlugin().getDatabaseController().getConnection();
PreparedStatement ps = null;
ResultSet rs = null;
try {
String sql = String.format(
"SELECT `password`, `pwtype` FROM `%s` WHERE `id` = ?",
xAuth.getPlugin().getDatabaseController()
.getTable(Table.ACCOUNT));
String sql = String.format("SELECT `password`, `pwtype` FROM `%s` WHERE `id` = ?", xAuth.getPlugin().getDatabaseController().getTable(Table.ACCOUNT));
ps = conn.prepareStatement(sql);
ps.setInt(1, accountId);
rs = ps.executeQuery();
if (!rs.next()) return null;
if (!rs.next())
return null;
realPass = rs.getString("password");
} catch (SQLException e) {
xAuthLog.severe("Failed to retrieve password hash for account: "
+ accountId, e);
xAuthLog.severe("Failed to retrieve password hash for account: " + accountId, e);
return null;
} finally {
xAuth.getPlugin().getDatabaseController().close(conn, ps, rs);
@@ -28,8 +28,7 @@ public class vAuthFileReader {
}
public void convert() throws IOException {
final File file = new File(plugin.getDataFolder().getParent()
+ "/vAuth/passwords.yml");
final File file = new File(plugin.getDataFolder().getParent() + "" + File.separator + "vAuth" + File.separator + "passwords.yml");
Scanner scanner = null;
try {
scanner = new Scanner(file);
@@ -41,23 +40,20 @@ public class vAuthFileReader {
if (isUUIDinstance(password)) {
String pname = null;
try {
pname = Bukkit.getOfflinePlayer(UUID.fromString(name))
.getName();
pname = Bukkit.getOfflinePlayer(UUID.fromString(name)).getName();
} catch (Exception e) {
pname = getName(UUID.fromString(name));
} catch (NoSuchMethodError e) {
pname = getName(UUID.fromString(name));
}
if (pname == null) continue;
auth = new PlayerAuth(pname.toLowerCase(), password,
"127.0.0.1", System.currentTimeMillis(),
"your@email.com", pname);
if (pname == null)
continue;
auth = new PlayerAuth(pname.toLowerCase(), password, "127.0.0.1", System.currentTimeMillis(), "your@email.com", pname);
} else {
auth = new PlayerAuth(name, password, "127.0.0.1",
System.currentTimeMillis(), "your@email.com",
API.getPlayerRealName(name));
auth = new PlayerAuth(name, password, "127.0.0.1", System.currentTimeMillis(), "your@email.com", API.getPlayerRealName(name));
}
if (auth != null) database.saveAuth(auth);
if (auth != null)
database.saveAuth(auth);
}
} catch (Exception e) {
}
@@ -65,14 +61,16 @@ public class vAuthFileReader {
}
private boolean isUUIDinstance(String s) {
if (String.valueOf(s.charAt(8)).equalsIgnoreCase("-")) return true;
if (String.valueOf(s.charAt(8)).equalsIgnoreCase("-"))
return true;
return true;
}
private String getName(UUID uuid) {
try {
for (OfflinePlayer op : Bukkit.getOfflinePlayers()) {
if (op.getUniqueId().compareTo(uuid) == 0) return op.getName();
if (op.getUniqueId().compareTo(uuid) == 0)
return op.getName();
}
} catch (Exception e) {
}
@@ -22,14 +22,12 @@ public class xAuthConverter implements Converter {
public void run() {
try {
Class.forName("com.cypherx.xauth.xAuth");
oldxAuthToFlat converter = new oldxAuthToFlat(plugin, database,
sender);
oldxAuthToFlat converter = new oldxAuthToFlat(plugin, database, sender);
converter.convert();
} catch (ClassNotFoundException e) {
try {
Class.forName("de.luricos.bukkit.xAuth.xAuth");
newxAuthToFlat converter = new newxAuthToFlat(plugin, database,
sender);
newxAuthToFlat converter = new newxAuthToFlat(plugin, database, sender);
converter.convert();
} catch (ClassNotFoundException ce) {
sender.sendMessage("xAuth has not been found, please put xAuth.jar in your plugin folder and restart!");