Fix various NPC account lookup issues (#4188)

This commit is contained in:
Josh Roy 2021-06-01 15:47:39 -04:00 committed by GitHub
parent f8f1facf43
commit fbb3a9a0a4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 23 additions and 2 deletions

View File

@ -11,7 +11,7 @@ import java.util.UUID;
import java.util.logging.Level; import java.util.logging.Level;
public class EssentialsUserConf extends EssentialsConf { public class EssentialsUserConf extends EssentialsConf {
public final String username; public String username;
public final UUID uuid; public final UUID uuid;
public EssentialsUserConf(final String username, final UUID uuid, final File configFile) { public EssentialsUserConf(final String username, final UUID uuid, final File configFile) {
@ -20,6 +20,10 @@ public class EssentialsUserConf extends EssentialsConf {
this.uuid = uuid; this.uuid = uuid;
} }
public void setUsername(String username) {
this.username = username;
}
@Override @Override
public boolean legacyFileExists() { public boolean legacyFileExists() {
final File file = new File(configFile.getParentFile(), username + ".yml"); final File file = new File(configFile.getParentFile(), username + ".yml");

View File

@ -2,6 +2,7 @@ package com.earth2me.essentials;
import com.earth2me.essentials.utils.NumberUtil; import com.earth2me.essentials.utils.NumberUtil;
import com.earth2me.essentials.utils.StringUtil; import com.earth2me.essentials.utils.StringUtil;
import com.google.common.base.Charsets;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import net.ess3.api.IEssentials; import net.ess3.api.IEssentials;
import net.ess3.api.InvalidWorldException; import net.ess3.api.InvalidWorldException;
@ -90,6 +91,10 @@ public abstract class UserData extends PlayerExtension implements IConf {
config = new EssentialsUserConf(base.getName(), base.getUniqueId(), new File(folder, filename + ".yml")); config = new EssentialsUserConf(base.getName(), base.getUniqueId(), new File(folder, filename + ".yml"));
reloadConfig(); reloadConfig();
if (config.username == null) {
config.setUsername(getLastAccountName());
}
} }
public final void reset() { public final void reset() {
@ -97,6 +102,10 @@ public abstract class UserData extends PlayerExtension implements IConf {
config.getFile().delete(); config.getFile().delete();
if (config.username != null) { if (config.username != null) {
ess.getUserMap().removeUser(config.username); ess.getUserMap().removeUser(config.username);
if (isNPC()) {
final String uuid = UUID.nameUUIDFromBytes(("NPC:" + config.username).getBytes(Charsets.UTF_8)).toString();
ess.getUserMap().removeUserUUID(uuid);
}
} }
} }

View File

@ -219,6 +219,10 @@ public class UserMap extends CacheLoader<String, User> implements IConf {
names.remove(StringUtil.safeString(name)); names.remove(StringUtil.safeString(name));
} }
public void removeUserUUID(final String uuid) {
users.invalidate(uuid);
}
public Set<UUID> getAllUniqueUsers() { public Set<UUID> getAllUniqueUsers() {
return Collections.unmodifiableSet(keys); return Collections.unmodifiableSet(keys);
} }

View File

@ -95,6 +95,10 @@ public class Economy {
} }
} }
if (user == null) {
user = getUserByUUID(UUID.nameUUIDFromBytes(("NPC:" + name).getBytes(Charsets.UTF_8)));
}
return user; return user;
} }

View File

@ -660,7 +660,7 @@ public class FakeServer implements Server {
case "testPlayer2": case "testPlayer2":
return UUID.fromString("2c9ebe1a-9098-43fd-bc0c-a369b76817ba"); return UUID.fromString("2c9ebe1a-9098-43fd-bc0c-a369b76817ba");
case "npc1": case "npc1":
return null; return UUID.fromString("f4a37409-5c40-3b2c-9cd6-57d3c5abdc76");
} }
throw new UnsupportedOperationException("Not supported yet."); throw new UnsupportedOperationException("Not supported yet.");
} }