Add Converter command
This commit is contained in:
@@ -60,18 +60,18 @@ public class FlatToSql implements Converter {
|
||||
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 DEFAULT '0',"
|
||||
+ 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 + "));";
|
||||
+ 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;
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
package fr.xephi.authme.converter;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
|
||||
public class vAuthConverter implements Converter {
|
||||
|
||||
public AuthMe plugin;
|
||||
public DataSource database;
|
||||
public CommandSender sender;
|
||||
|
||||
public vAuthConverter(AuthMe plugin, DataSource database, CommandSender sender) {
|
||||
this.plugin = plugin;
|
||||
this.database = database;
|
||||
this.sender = sender;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
new vAuthFileReader(plugin, database, sender).convert();
|
||||
} catch (Exception e) {
|
||||
sender.sendMessage(e.getMessage());
|
||||
ConsoleLogger.showError(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
package fr.xephi.authme.converter;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Scanner;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.api.API;
|
||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
|
||||
public class vAuthFileReader {
|
||||
|
||||
public AuthMe plugin;
|
||||
public DataSource database;
|
||||
public CommandSender sender;
|
||||
|
||||
public vAuthFileReader(AuthMe plugin, DataSource database, CommandSender sender) {
|
||||
this.plugin = plugin;
|
||||
this.database = database;
|
||||
this.sender = sender;
|
||||
}
|
||||
|
||||
public void convert() throws IOException {
|
||||
final File file = new File(plugin.getDataFolder().getParent() + "/vAuth/passwords.yml");
|
||||
Scanner scanner = null;
|
||||
try {
|
||||
scanner = new Scanner(file);
|
||||
while(scanner.hasNextLine()) {
|
||||
String line = scanner.nextLine();
|
||||
String name = line.split(": ")[0];
|
||||
String password = line.split(": ")[1];
|
||||
PlayerAuth auth = null;
|
||||
if (isUUIDinstance(password)) {
|
||||
String pname = null;
|
||||
try {
|
||||
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);
|
||||
} else {
|
||||
auth = new PlayerAuth(name, password, "127.0.0.1", System.currentTimeMillis(), "your@email.com", API.getPlayerRealName(name));
|
||||
}
|
||||
if (auth != null) database.saveAuth(auth);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private boolean isUUIDinstance(String s) {
|
||||
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();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user