2014-04-13 05:53:11 +00:00
|
|
|
package com.earth2me.essentials;
|
|
|
|
|
2014-04-26 22:49:38 +00:00
|
|
|
import com.google.common.base.Charsets;
|
2014-04-13 05:53:11 +00:00
|
|
|
import com.google.common.io.Files;
|
|
|
|
import java.io.File;
|
|
|
|
import java.io.IOException;
|
2014-04-26 22:49:38 +00:00
|
|
|
import java.util.Locale;
|
2014-04-13 05:53:11 +00:00
|
|
|
import java.util.UUID;
|
|
|
|
import java.util.logging.Level;
|
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
|
|
|
|
|
|
|
|
public class EssentialsUserConf extends EssentialsConf
|
|
|
|
{
|
2014-06-07 14:45:57 +00:00
|
|
|
public final String username;
|
|
|
|
public final UUID uuid;
|
2014-04-13 05:53:11 +00:00
|
|
|
|
|
|
|
public EssentialsUserConf(final String username, final UUID uuid, final File configFile)
|
|
|
|
{
|
|
|
|
super(configFile);
|
|
|
|
this.username = username;
|
|
|
|
this.uuid = uuid;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean legacyFileExists()
|
|
|
|
{
|
2014-04-26 22:49:38 +00:00
|
|
|
final File file = new File(configFile.getParentFile(), username + ".yml");
|
2014-04-13 05:53:11 +00:00
|
|
|
return file.exists();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void convertLegacyFile()
|
|
|
|
{
|
2014-04-26 22:49:38 +00:00
|
|
|
final File file = new File(configFile.getParentFile(), username + ".yml");
|
2014-04-13 05:53:11 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
Files.move(file, new File(configFile.getParentFile(), uuid + ".yml"));
|
|
|
|
}
|
|
|
|
catch (IOException ex)
|
|
|
|
{
|
|
|
|
Bukkit.getLogger().log(Level.WARNING, "Failed to migrate user: " + username, ex);
|
|
|
|
}
|
|
|
|
|
|
|
|
setProperty("lastAccountName", username);
|
|
|
|
}
|
2014-04-26 22:49:38 +00:00
|
|
|
|
|
|
|
private File getAltFile()
|
|
|
|
{
|
|
|
|
final UUID fn = UUID.nameUUIDFromBytes(("OfflinePlayer:" + username.toLowerCase(Locale.ENGLISH)).getBytes(Charsets.UTF_8));
|
|
|
|
return new File(configFile.getParentFile(), fn.toString() + ".yml");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean altFileExists()
|
|
|
|
{
|
|
|
|
if (username.equals(username.toLowerCase()))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return getAltFile().exists();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void convertAltFile()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
Files.move(getAltFile(), new File(configFile.getParentFile(), uuid + ".yml"));
|
|
|
|
}
|
|
|
|
catch (IOException ex)
|
|
|
|
{
|
|
|
|
Bukkit.getLogger().log(Level.WARNING, "Failed to migrate user: " + username, ex);
|
|
|
|
}
|
|
|
|
}
|
2014-04-13 05:53:11 +00:00
|
|
|
}
|