Avoid requesting invalid names from Mojang (old UUID conversion code) (#1092)

This commit is contained in:
Adam 2020-12-09 03:31:38 -05:00 committed by GitHub
parent d5c5e4983e
commit de7a1372f0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -16,7 +16,9 @@ import java.net.URL;
import java.nio.ByteBuffer;
import java.util.HashMap;
import java.util.List;
import java.util.Objects;
import java.util.UUID;
import java.util.regex.Pattern;
class UUIDFetcher
{
@ -95,9 +97,23 @@ class UUIDFetcher
}
}
names.removeIf(Objects::isNull);
//for online mode, call Mojang to resolve the rest
if (GriefPrevention.instance.getServer().getOnlineMode())
{
Pattern validNamePattern = Pattern.compile("^\\w+$");
// Don't bother requesting UUIDs for invalid names from Mojang.
names.removeIf(name ->
{
if (name.length() >= 3 && name.length() <= 16 && validNamePattern.matcher(name).find())
return false;
GriefPrevention.AddLogEntry(String.format("Cannot convert invalid name: %s", name));
return true;
});
GriefPrevention.AddLogEntry("Calling Mojang to get UUIDs for remaining unresolved players (this is the slowest step)...");
for (int i = 0; i * PROFILES_PER_REQUEST < names.size(); i++)