mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2025-04-27 08:59:45 +00:00
Allow usermap to support legacy users, and restore ability to create user on first access, as well as server join.
This commit is contained in:
parent
e8ace54036
commit
3dbf69f163
1 changed files with 38 additions and 8 deletions
|
@ -131,12 +131,29 @@ public class UserMap extends CacheLoader<UUID, User> implements IConf
|
||||||
final String sanitizedName = StringUtil.sanitizeFileName(name);
|
final String sanitizedName = StringUtil.sanitizeFileName(name);
|
||||||
if (names.containsKey(sanitizedName))
|
if (names.containsKey(sanitizedName))
|
||||||
{
|
{
|
||||||
ess.getLogger().info("Trying to grab user via string, found matching key.");
|
|
||||||
final UUID uuid = names.get(sanitizedName);
|
final UUID uuid = names.get(sanitizedName);
|
||||||
return users.get(uuid);
|
return users.get(uuid);
|
||||||
}
|
}
|
||||||
ess.getLogger().info("Trying to grab user via string, failed, returning null.");
|
|
||||||
return null; // TODO: THIS IS PROBABLY NOT RIGHT
|
for (Player player : ess.getServer().getOnlinePlayers())
|
||||||
|
{
|
||||||
|
String sanitizedPlayer = StringUtil.sanitizeFileName(player.getName());
|
||||||
|
if (sanitizedPlayer.equalsIgnoreCase(sanitizedName))
|
||||||
|
{
|
||||||
|
User user = new User(player, ess);
|
||||||
|
trackUUID(user.getBase().getUniqueId(), user.getName());
|
||||||
|
return new User(player, ess);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
final File userFile = getUserFileFromString(sanitizedName);
|
||||||
|
if (userFile.exists())
|
||||||
|
{
|
||||||
|
User user = new User(new OfflinePlayer(sanitizedName, ess.getServer()), ess);
|
||||||
|
trackUUID(user.getBase().getUniqueId(), user.getName());
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
catch (ExecutionException ex)
|
catch (ExecutionException ex)
|
||||||
{
|
{
|
||||||
|
@ -166,8 +183,12 @@ public class UserMap extends CacheLoader<UUID, User> implements IConf
|
||||||
|
|
||||||
public void trackUUID(final UUID uuid, final String name)
|
public void trackUUID(final UUID uuid, final String name)
|
||||||
{
|
{
|
||||||
names.put(StringUtil.sanitizeFileName(name), uuid);
|
if (uuid != null)
|
||||||
writeUUIDMap();
|
{
|
||||||
|
names.put(StringUtil.sanitizeFileName(name), uuid);
|
||||||
|
keys.add(uuid);
|
||||||
|
writeUUIDMap();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void writeUUIDMap()
|
public void writeUUIDMap()
|
||||||
|
@ -221,8 +242,11 @@ public class UserMap extends CacheLoader<UUID, User> implements IConf
|
||||||
public void removeUser(final String name)
|
public void removeUser(final String name)
|
||||||
{
|
{
|
||||||
UUID uuid = names.get(name);
|
UUID uuid = names.get(name);
|
||||||
keys.remove(uuid);
|
if (uuid != null)
|
||||||
users.invalidate(uuid);
|
{
|
||||||
|
keys.remove(uuid);
|
||||||
|
users.invalidate(uuid);
|
||||||
|
}
|
||||||
names.remove(name);
|
names.remove(name);
|
||||||
names.remove(StringUtil.sanitizeFileName(name));
|
names.remove(StringUtil.sanitizeFileName(name));
|
||||||
}
|
}
|
||||||
|
@ -242,4 +266,10 @@ public class UserMap extends CacheLoader<UUID, User> implements IConf
|
||||||
final File userFolder = new File(ess.getDataFolder(), "userdata");
|
final File userFolder = new File(ess.getDataFolder(), "userdata");
|
||||||
return new File(userFolder, uuid.toString() + ".yml");
|
return new File(userFolder, uuid.toString() + ".yml");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public File getUserFileFromString(final String name)
|
||||||
|
{
|
||||||
|
final File userFolder = new File(ess.getDataFolder(), "userdata");
|
||||||
|
return new File(userFolder, StringUtil.sanitizeFileName(name) + ".yml");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue