mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2024-11-03 01:00:18 +01:00
#603 Delete CustomConfiguration class
This commit is contained in:
parent
3522a5b0c0
commit
ef980bd654
@ -5,35 +5,46 @@ import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import static fr.xephi.authme.util.StringUtils.makePath;
|
||||
|
||||
public class RoyalAuthConverter implements Converter {
|
||||
|
||||
private static final String LAST_LOGIN_PATH = "timestamps.quit";
|
||||
private static final String PASSWORD_PATH = "login.password";
|
||||
private final AuthMe plugin;
|
||||
private final DataSource data;
|
||||
private final DataSource dataSource;
|
||||
|
||||
public RoyalAuthConverter(AuthMe plugin) {
|
||||
this.plugin = plugin;
|
||||
this.data = plugin.getDataSource();
|
||||
this.dataSource = plugin.getDataSource();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
for (OfflinePlayer o : plugin.getServer().getOfflinePlayers()) {
|
||||
for (OfflinePlayer player : plugin.getServer().getOfflinePlayers()) {
|
||||
try {
|
||||
String name = o.getName().toLowerCase();
|
||||
String sp = File.separator;
|
||||
File file = new File("." + sp + "plugins" + sp + "RoyalAuth" + sp + "userdata" + sp + name + ".yml");
|
||||
if (data.isAuthAvailable(name))
|
||||
String name = player.getName().toLowerCase();
|
||||
File file = new File(makePath(".", "plugins", "RoyalAuth", "userdata", name + ".yml"));
|
||||
|
||||
if (dataSource.isAuthAvailable(name) || !file.exists()) {
|
||||
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());
|
||||
data.saveAuth(auth);
|
||||
}
|
||||
FileConfiguration configuration = YamlConfiguration.loadConfiguration(file);
|
||||
PlayerAuth auth = PlayerAuth.builder()
|
||||
.name(name)
|
||||
.password(configuration.getString(PASSWORD_PATH), null)
|
||||
.lastLogin(configuration.getLong(LAST_LOGIN_PATH))
|
||||
.realName(player.getName())
|
||||
.build();
|
||||
|
||||
dataSource.saveAuth(auth);
|
||||
} catch (Exception e) {
|
||||
ConsoleLogger.logException("Error while trying to import " + o.getName() + " RoyalAuth data", e);
|
||||
ConsoleLogger.logException("Error while trying to import " + player.getName() + " RoyalAuth data", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,22 +0,0 @@
|
||||
package fr.xephi.authme.converter;
|
||||
|
||||
import fr.xephi.authme.settings.CustomConfiguration;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
class RoyalAuthYamlReader extends CustomConfiguration {
|
||||
|
||||
public RoyalAuthYamlReader(File file) {
|
||||
super(file);
|
||||
load();
|
||||
save();
|
||||
}
|
||||
|
||||
public long getLastLogin() {
|
||||
return getLong("timestamps.quit");
|
||||
}
|
||||
|
||||
public String getHash() {
|
||||
return getString("login.password");
|
||||
}
|
||||
}
|
@ -1,94 +0,0 @@
|
||||
package fr.xephi.authme.settings;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
|
||||
/**
|
||||
*/
|
||||
public abstract class CustomConfiguration extends YamlConfiguration {
|
||||
|
||||
private final File configFile;
|
||||
|
||||
/**
|
||||
* Constructor for CustomConfiguration.
|
||||
*
|
||||
* @param file the config file
|
||||
*/
|
||||
public CustomConfiguration(File file) {
|
||||
this.configFile = file;
|
||||
load();
|
||||
}
|
||||
|
||||
public void load() {
|
||||
try {
|
||||
super.load(configFile);
|
||||
} catch (FileNotFoundException e) {
|
||||
ConsoleLogger.showError("Could not find " + configFile.getName() + ", creating new one...");
|
||||
reLoad();
|
||||
} catch (IOException e) {
|
||||
ConsoleLogger.showError("Could not load " + configFile.getName());
|
||||
} catch (InvalidConfigurationException e) {
|
||||
ConsoleLogger.showError(configFile.getName() + " is no valid configuration file");
|
||||
}
|
||||
}
|
||||
|
||||
public boolean reLoad() {
|
||||
boolean out = true;
|
||||
if (!configFile.exists()) {
|
||||
out = loadResource(configFile);
|
||||
}
|
||||
if (out)
|
||||
load();
|
||||
return out;
|
||||
}
|
||||
|
||||
public void save() {
|
||||
try {
|
||||
super.save(configFile);
|
||||
} catch (IOException ex) {
|
||||
ConsoleLogger.showError("Could not save config to " + configFile.getName());
|
||||
}
|
||||
}
|
||||
|
||||
public File getConfigFile() {
|
||||
return configFile;
|
||||
}
|
||||
|
||||
private boolean loadResource(File file) {
|
||||
if (!file.exists()) {
|
||||
try {
|
||||
if (!file.getParentFile().exists() && !file.getParentFile().mkdirs()) {
|
||||
return false;
|
||||
}
|
||||
int i = file.getPath().indexOf("AuthMe");
|
||||
if (i > -1) {
|
||||
String path = file.getPath().substring(i + 6).replace('\\', '/');
|
||||
InputStream is = AuthMe.class.getResourceAsStream(path);
|
||||
Files.copy(is, file.toPath(), StandardCopyOption.REPLACE_EXISTING);
|
||||
return true;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
ConsoleLogger.logException("Failed to load config from JAR", e);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean containsAll(String... paths) {
|
||||
for (String path : paths) {
|
||||
if (!contains(path)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
@ -5,7 +5,6 @@ import fr.xephi.authme.settings.domain.Property;
|
||||
import fr.xephi.authme.settings.domain.PropertyType;
|
||||
import fr.xephi.authme.settings.domain.SettingsClass;
|
||||
import fr.xephi.authme.settings.propertymap.PropertyMap;
|
||||
import fr.xephi.authme.util.WrapperMock;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.List;
|
||||
@ -57,7 +56,6 @@ public final class TestConfiguration implements SettingsClass {
|
||||
* @return The generated property map
|
||||
*/
|
||||
public static PropertyMap generatePropertyMap() {
|
||||
WrapperMock.createInstance();
|
||||
PropertyMap propertyMap = new PropertyMap();
|
||||
for (Field field : TestConfiguration.class.getDeclaredFields()) {
|
||||
Object fieldValue = ReflectionTestUtils.getFieldValue(TestConfiguration.class, null, field.getName());
|
||||
|
Loading…
Reference in New Issue
Block a user