Only utilize usercache lookup for seen command

This commit is contained in:
vemacs 2015-12-01 17:32:53 -07:00
parent bc4737562d
commit ad93d15197
2 changed files with 17 additions and 18 deletions

View File

@ -69,20 +69,10 @@ public class UserMap extends CacheLoader<String, User> implements IConf {
public User getUser(final String name) { public User getUser(final String name) {
try { try {
User offlineUser = null;
final String sanitizedName = StringUtil.safeString(name); final String sanitizedName = StringUtil.safeString(name);
if (names.containsKey(sanitizedName)) { if (names.containsKey(sanitizedName)) {
final UUID uuid = names.get(sanitizedName); final UUID uuid = names.get(sanitizedName);
offlineUser = getUser(uuid); return getUser(uuid);
} else {
UUID bukkitUuid = getIdFromBukkit(sanitizedName);
if (bukkitUuid != null) {
names.put(sanitizedName, bukkitUuid);
offlineUser = getUser(bukkitUuid);
}
}
if (offlineUser != null) {
return offlineUser;
} }
final File userFile = getUserFileFromString(sanitizedName); final File userFile = getUserFileFromString(sanitizedName);
@ -227,8 +217,11 @@ public class UserMap extends CacheLoader<String, User> implements IConf {
private final Pattern validUserPattern = Pattern.compile("^[a-zA-Z0-9_]{2,16}$"); private final Pattern validUserPattern = Pattern.compile("^[a-zA-Z0-9_]{2,16}$");
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
private UUID getIdFromBukkit(String name) { public User getUserFromBukkit(String name) {
ess.getLogger().warning("Using potentially blocking Bukkit UUID lookup for: " + name); name = StringUtil.safeString(name);
if (ess.getSettings().isDebug()) {
ess.getLogger().warning("Using potentially blocking Bukkit UUID lookup for: " + name);
}
// Don't attempt to look up entirely invalid usernames // Don't attempt to look up entirely invalid usernames
if (name == null || !validUserPattern.matcher(name).matches()) { if (name == null || !validUserPattern.matcher(name).matches()) {
return null; return null;
@ -247,7 +240,8 @@ public class UserMap extends CacheLoader<String, User> implements IConf {
if (UUID.nameUUIDFromBytes(("OfflinePlayer:" + name).getBytes(Charsets.UTF_8)).equals(uuid)) { if (UUID.nameUUIDFromBytes(("OfflinePlayer:" + name).getBytes(Charsets.UTF_8)).equals(uuid)) {
return null; return null;
} else { } else {
return uuid; names.put(name, uuid);
return getUser(uuid);
} }
} }
} }

View File

@ -51,10 +51,15 @@ public class Commandseen extends EssentialsCommand {
sender.sendMessage(tl("whoisBanned", showBan ? BanLookup.getBanEntry(ess, args[0]).getReason() : tl("true"))); sender.sendMessage(tl("whoisBanned", showBan ? BanLookup.getBanEntry(ess, args[0]).getReason() : tl("true")));
return; return;
} else { } else {
try { User userFromBukkit = ess.getUserMap().getUserFromBukkit(args[0]);
player = getPlayer(server, sender, args, 0); if (userFromBukkit != null) {
} catch (NoSuchFieldException e) { player = userFromBukkit;
throw new PlayerNotFoundException(); } else {
try {
player = getPlayer(server, sender, args, 0);
} catch (NoSuchFieldException e) {
throw new PlayerNotFoundException();
}
} }
} }
} }