mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2025-02-14 13:13:24 +00:00
Don't allow old UUID's to accidentally overwrite current UUID for user mapping.
Add some extra logging and uuid debug.
This commit is contained in:
parent
3887fdd47d
commit
2215b0f53f
5 changed files with 59 additions and 31 deletions
|
@ -646,7 +646,7 @@ public class EssentialsUpgrade
|
||||||
conf.forceSave();
|
conf.forceSave();
|
||||||
config = new EssentialsUserConf(name, uuid, new File(userdir, uuid + ".yml"));
|
config = new EssentialsUserConf(name, uuid, new File(userdir, uuid + ".yml"));
|
||||||
config.convertLegacyFile();
|
config.convertLegacyFile();
|
||||||
ess.getUserMap().trackUUID(uuid, name);
|
ess.getUserMap().trackUUID(uuid, name, false);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
countFails++;
|
countFails++;
|
||||||
|
|
|
@ -841,7 +841,7 @@ public abstract class UserData extends PlayerExtension implements IConf
|
||||||
this.lastAccountName = lastAccountName;
|
this.lastAccountName = lastAccountName;
|
||||||
config.setProperty("lastAccountName", lastAccountName);
|
config.setProperty("lastAccountName", lastAccountName);
|
||||||
config.save();
|
config.save();
|
||||||
ess.getUserMap().trackUUID(getConfigUUID(), lastAccountName);
|
ess.getUserMap().trackUUID(getConfigUUID(), lastAccountName, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setNPC(boolean set)
|
public void setNPC(boolean set)
|
||||||
|
|
|
@ -29,7 +29,7 @@ public class UserMap extends CacheLoader<String, User> implements IConf
|
||||||
private final transient ConcurrentSkipListMap<String, UUID> names = new ConcurrentSkipListMap<String, UUID>();
|
private final transient ConcurrentSkipListMap<String, UUID> names = new ConcurrentSkipListMap<String, UUID>();
|
||||||
private final transient ConcurrentSkipListMap<UUID, ArrayList<String>> history = new ConcurrentSkipListMap<UUID, ArrayList<String>>();
|
private final transient ConcurrentSkipListMap<UUID, ArrayList<String>> history = new ConcurrentSkipListMap<UUID, ArrayList<String>>();
|
||||||
private UUIDMap uuidMap;
|
private UUIDMap uuidMap;
|
||||||
|
|
||||||
public UserMap(final IEssentials ess)
|
public UserMap(final IEssentials ess)
|
||||||
{
|
{
|
||||||
super();
|
super();
|
||||||
|
@ -39,7 +39,7 @@ public class UserMap extends CacheLoader<String, User> implements IConf
|
||||||
//users = CacheBuilder.newBuilder().maximumSize(ess.getSettings().getMaxUserCacheCount()).softValues().removalListener(remListener).build(this);
|
//users = CacheBuilder.newBuilder().maximumSize(ess.getSettings().getMaxUserCacheCount()).softValues().removalListener(remListener).build(this);
|
||||||
users = CacheBuilder.newBuilder().maximumSize(ess.getSettings().getMaxUserCacheCount()).softValues().build(this);
|
users = CacheBuilder.newBuilder().maximumSize(ess.getSettings().getMaxUserCacheCount()).softValues().build(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadAllUsersAsync(final IEssentials ess)
|
private void loadAllUsersAsync(final IEssentials ess)
|
||||||
{
|
{
|
||||||
ess.runTaskAsynchronously(new Runnable()
|
ess.runTaskAsynchronously(new Runnable()
|
||||||
|
@ -77,12 +77,12 @@ public class UserMap extends CacheLoader<String, User> implements IConf
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean userExists(final UUID uuid)
|
public boolean userExists(final UUID uuid)
|
||||||
{
|
{
|
||||||
return keys.contains(uuid);
|
return keys.contains(uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
public User getUser(final String name)
|
public User getUser(final String name)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
@ -93,13 +93,13 @@ public class UserMap extends CacheLoader<String, User> implements IConf
|
||||||
final UUID uuid = names.get(sanitizedName);
|
final UUID uuid = names.get(sanitizedName);
|
||||||
return getUser(uuid);
|
return getUser(uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
final File userFile = getUserFileFromString(sanitizedName);
|
final File userFile = getUserFileFromString(sanitizedName);
|
||||||
if (userFile.exists())
|
if (userFile.exists())
|
||||||
{
|
{
|
||||||
ess.getLogger().info("Importing user " + name + " to usermap.");
|
ess.getLogger().info("Importing user " + name + " to usermap.");
|
||||||
User user = new User(new OfflinePlayer(sanitizedName, ess.getServer()), ess);
|
User user = new User(new OfflinePlayer(sanitizedName, ess.getServer()), ess);
|
||||||
trackUUID(user.getBase().getUniqueId(), user.getName());
|
trackUUID(user.getBase().getUniqueId(), user.getName(), true);
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
@ -109,7 +109,7 @@ public class UserMap extends CacheLoader<String, User> implements IConf
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public User getUser(final UUID uuid)
|
public User getUser(final UUID uuid)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
@ -125,8 +125,8 @@ public class UserMap extends CacheLoader<String, User> implements IConf
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void trackUUID(final UUID uuid, final String name)
|
public void trackUUID(final UUID uuid, final String name, boolean replace)
|
||||||
{
|
{
|
||||||
if (uuid != null)
|
if (uuid != null)
|
||||||
{
|
{
|
||||||
|
@ -134,15 +134,31 @@ public class UserMap extends CacheLoader<String, User> implements IConf
|
||||||
if (name != null && name.length() > 0)
|
if (name != null && name.length() > 0)
|
||||||
{
|
{
|
||||||
final String keyName = StringUtil.safeString(name);
|
final String keyName = StringUtil.safeString(name);
|
||||||
if (!names.containsKey(keyName) || !names.get(keyName).equals(uuid))
|
if (!names.containsKey(keyName))
|
||||||
{
|
{
|
||||||
names.put(keyName, uuid);
|
names.put(keyName, uuid);
|
||||||
uuidMap.writeUUIDMap();
|
uuidMap.writeUUIDMap();
|
||||||
}
|
}
|
||||||
|
else if (!names.get(keyName).equals(uuid))
|
||||||
|
{
|
||||||
|
if (replace)
|
||||||
|
{
|
||||||
|
ess.getLogger().info("Found new UUID for " + name + ". Replacing " + names.get(keyName).toString() + " with " + uuid.toString());
|
||||||
|
names.put(keyName, uuid);
|
||||||
|
uuidMap.writeUUIDMap();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (ess.getSettings().isDebug())
|
||||||
|
{
|
||||||
|
ess.getLogger().info("Found old UUID for " + name + ". Not adding to usermap.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public User load(final String stringUUID) throws Exception
|
public User load(final String stringUUID) throws Exception
|
||||||
{
|
{
|
||||||
|
@ -151,36 +167,36 @@ public class UserMap extends CacheLoader<String, User> implements IConf
|
||||||
if (player != null)
|
if (player != null)
|
||||||
{
|
{
|
||||||
final User user = new User(player, ess);
|
final User user = new User(player, ess);
|
||||||
trackUUID(uuid, user.getName());
|
trackUUID(uuid, user.getName(), true);
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
final File userFile = getUserFileFromID(uuid);
|
final File userFile = getUserFileFromID(uuid);
|
||||||
|
|
||||||
if (userFile.exists())
|
if (userFile.exists())
|
||||||
{
|
{
|
||||||
player = new OfflinePlayer(uuid, ess.getServer());
|
player = new OfflinePlayer(uuid, ess.getServer());
|
||||||
final User user = new User(player, ess);
|
final User user = new User(player, ess);
|
||||||
((OfflinePlayer)player).setName(user.getLastAccountName());
|
((OfflinePlayer)player).setName(user.getLastAccountName());
|
||||||
trackUUID(uuid, user.getName());
|
trackUUID(uuid, user.getName(), false);
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new Exception("User not found!");
|
throw new Exception("User not found!");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void reloadConfig()
|
public void reloadConfig()
|
||||||
{
|
{
|
||||||
getUUIDMap().forceWriteUUIDMap();
|
getUUIDMap().forceWriteUUIDMap();
|
||||||
loadAllUsersAsync(ess);
|
loadAllUsersAsync(ess);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void invalidateAll()
|
public void invalidateAll()
|
||||||
{
|
{
|
||||||
users.invalidateAll();
|
users.invalidateAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeUser(final String name)
|
public void removeUser(final String name)
|
||||||
{
|
{
|
||||||
if (names == null)
|
if (names == null)
|
||||||
|
@ -197,43 +213,43 @@ public class UserMap extends CacheLoader<String, User> implements IConf
|
||||||
names.remove(name);
|
names.remove(name);
|
||||||
names.remove(StringUtil.safeString(name));
|
names.remove(StringUtil.safeString(name));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<UUID> getAllUniqueUsers()
|
public Set<UUID> getAllUniqueUsers()
|
||||||
{
|
{
|
||||||
return Collections.unmodifiableSet(keys.clone());
|
return Collections.unmodifiableSet(keys.clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getUniqueUsers()
|
public int getUniqueUsers()
|
||||||
{
|
{
|
||||||
return keys.size();
|
return keys.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ConcurrentSkipListMap<String, UUID> getNames()
|
protected ConcurrentSkipListMap<String, UUID> getNames()
|
||||||
{
|
{
|
||||||
return names;
|
return names;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ConcurrentSkipListMap<UUID, ArrayList<String>> getHistory()
|
protected ConcurrentSkipListMap<UUID, ArrayList<String>> getHistory()
|
||||||
{
|
{
|
||||||
return history;
|
return history;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> getUserHistory(final UUID uuid)
|
public List<String> getUserHistory(final UUID uuid)
|
||||||
{
|
{
|
||||||
return history.get(uuid);
|
return history.get(uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
public UUIDMap getUUIDMap()
|
public UUIDMap getUUIDMap()
|
||||||
{
|
{
|
||||||
return uuidMap;
|
return uuidMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
private File getUserFileFromID(final UUID uuid)
|
private File getUserFileFromID(final UUID uuid)
|
||||||
{
|
{
|
||||||
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)
|
public File getUserFileFromString(final String name)
|
||||||
{
|
{
|
||||||
final File userFolder = new File(ess.getDataFolder(), "userdata");
|
final File userFolder = new File(ess.getDataFolder(), "userdata");
|
||||||
|
|
|
@ -64,7 +64,7 @@ public class Economy
|
||||||
npcConfig.setProperty("lastAccountName", name);
|
npcConfig.setProperty("lastAccountName", name);
|
||||||
npcConfig.setProperty("money", ess.getSettings().getStartingBalance());
|
npcConfig.setProperty("money", ess.getSettings().getStartingBalance());
|
||||||
npcConfig.forceSave();
|
npcConfig.forceSave();
|
||||||
ess.getUserMap().trackUUID(npcUUID, name);
|
ess.getUserMap().trackUUID(npcUUID, name, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void deleteNPC(String name)
|
private static void deleteNPC(String name)
|
||||||
|
|
|
@ -355,15 +355,27 @@ public class Commandessentials extends EssentialsCommand
|
||||||
{
|
{
|
||||||
if (player.getName().equalsIgnoreCase(name))
|
if (player.getName().equalsIgnoreCase(name))
|
||||||
{
|
{
|
||||||
sender.sendMessage("Online player: " + player.getUniqueId().toString());
|
|
||||||
onlineUUID = player.getUniqueId();
|
onlineUUID = player.getUniqueId();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UUID essUUID = ess.getUserMap().getUser(name).getConfigUUID();
|
||||||
|
|
||||||
org.bukkit.OfflinePlayer player = ess.getServer().getOfflinePlayer(name);
|
org.bukkit.OfflinePlayer player = ess.getServer().getOfflinePlayer(name);
|
||||||
UUID bukkituuid = player.getUniqueId();
|
UUID bukkituuid = player.getUniqueId();
|
||||||
sender.sendMessage("Bukkit Lookup: " + bukkituuid.toString());
|
sender.sendMessage("Bukkit Lookup: " + bukkituuid.toString());
|
||||||
|
|
||||||
|
if (onlineUUID != null && onlineUUID != bukkituuid)
|
||||||
|
{
|
||||||
|
sender.sendMessage("Online player: " + onlineUUID.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (essUUID != null && essUUID != bukkituuid)
|
||||||
|
{
|
||||||
|
sender.sendMessage("Essentials config: " + essUUID.toString());
|
||||||
|
}
|
||||||
|
|
||||||
UUID npcuuid = UUID.nameUUIDFromBytes(("NPC:" + name).getBytes(Charsets.UTF_8));
|
UUID npcuuid = UUID.nameUUIDFromBytes(("NPC:" + name).getBytes(Charsets.UTF_8));
|
||||||
sender.sendMessage("NPC UUID: " + npcuuid.toString());
|
sender.sendMessage("NPC UUID: " + npcuuid.toString());
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue