1
0
mirror of https://e.coding.net/circlecloud/AuthMe.git synced 2024-11-09 23:48:58 +00:00
AuthMe/src/main/java/fr/xephi/authme/converter/vAuthFileReader.java
502647092 a1176afa15 init project...
Signed-off-by: 502647092 <jtb1@163.com>
2015-10-12 15:26:15 +08:00

78 lines
2.1 KiB
Java

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.ConsoleLogger;
import fr.xephi.authme.cache.auth.PlayerAuth;
import fr.xephi.authme.datasource.DataSource;
public class vAuthFileReader {
public DataSource database;
public AuthMe plugin;
public CommandSender sender;
public vAuthFileReader(AuthMe plugin, CommandSender sender) {
this.plugin = plugin;
this.database = plugin.database;
this.sender = sender;
}
public void convert() throws IOException {
final File file = new File(plugin.getDataFolder().getParent() + "" + File.separator + "vAuth" + File.separator + "passwords.yml");
Scanner scanner;
try {
scanner = new Scanner(file);
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
String name = line.split(": ")[0];
String password = line.split(": ")[1];
PlayerAuth auth;
if (isUUIDinstance(password)) {
String pname;
try {
pname = Bukkit.getOfflinePlayer(UUID.fromString(name)).getName();
} catch (Exception | 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.toLowerCase(), password, "127.0.0.1", System.currentTimeMillis(), "your@email.com", name);
}
database.saveAuth(auth);
}
} catch (Exception e) {
ConsoleLogger.writeStackTrace(e);
}
}
private String getName(UUID uuid) {
try {
for (OfflinePlayer op : Bukkit.getOfflinePlayers()) {
if (op.getUniqueId().compareTo(uuid) == 0)
return op.getName();
}
} catch (Exception ignored) {
}
return null;
}
private boolean isUUIDinstance(String s) {
if (String.valueOf(s.charAt(8)).equalsIgnoreCase("-"))
return true;
return true;
}
}