Make UUID detection in DomainInputResolver reusable.

This commit is contained in:
sk89q 2014-08-14 21:23:26 -07:00
parent 501a7aa77a
commit e43ce420a3

View File

@ -99,10 +99,11 @@ public DefaultDomain call() throws UnresolvedNamesException {
if (m.matches()) {
domain.addGroup(m.group(1));
} else {
try {
UUID uuid = parseUUID(s);
if (uuid != null) {
// Try to add any UUIDs given
domain.addPlayer(UUID.fromString(UUIDs.addDashes(s.replaceAll("^uuid:", ""))));
} catch (IllegalArgumentException e) {
} else {
switch (locatorPolicy) {
case NAME_ONLY:
domain.addPlayer(s);
@ -157,4 +158,21 @@ public DefaultDomain apply(@Nullable DefaultDomain domain) {
}
};
}
/**
* Try to parse a UUID locator from input.
*
* @param input the input
* @return a UUID or {@code null} if the input is not a UUID
*/
@Nullable
public static UUID parseUUID(String input) {
checkNotNull(input);
try {
return UUID.fromString(UUIDs.addDashes(input.replaceAll("^uuid:", "")));
} catch (IllegalArgumentException e) {
return null;
}
}
}