summaryrefslogtreecommitdiffstats
path: root/Essentials/src/com/earth2me/essentials/EssentialsUserConf.java
blob: cbfba46b18e182d75fb3d4b6cb6f2220b79ad311 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package com.earth2me.essentials;

import com.google.common.base.Charsets;
import com.google.common.io.Files;
import java.io.File;
import java.io.IOException;
import java.util.Locale;
import java.util.UUID;
import java.util.logging.Level;
import org.bukkit.Bukkit;


public class EssentialsUserConf extends EssentialsConf
{
	public final String username;
	public final UUID uuid;

	public EssentialsUserConf(final String username, final UUID uuid, final File configFile)
	{
		super(configFile);
		this.username = username;
		this.uuid = uuid;
	}

	@Override
	public boolean legacyFileExists()
	{
		final File file = new File(configFile.getParentFile(), username + ".yml");
		return file.exists();
	}

	@Override
	public void convertLegacyFile()
	{
		final File file = new File(configFile.getParentFile(), username + ".yml");
		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);
	}

	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);
		}
	}
}