Attempt to parse input as UUID in loop commands (#2606)

Related: #2424
This commit is contained in:
md678685 2019-12-23 13:06:15 +00:00 committed by GitHub
parent 15bb978dab
commit a1a0d34940
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 1 deletions

View File

@ -4,6 +4,7 @@ import com.earth2me.essentials.ChargeException;
import com.earth2me.essentials.CommandSource;
import com.earth2me.essentials.User;
import com.earth2me.essentials.utils.FormatUtil;
import com.earth2me.essentials.utils.StringUtil;
import net.ess3.api.MaxMoneyException;
import org.bukkit.Server;
import org.bukkit.entity.Player;
@ -23,7 +24,11 @@ public abstract class EssentialsLoopCommand extends EssentialsCommand {
throw new PlayerNotFoundException();
}
if (matchWildcards && searchTerm.contentEquals("**")) {
final UUID uuid = StringUtil.toUUID(searchTerm);
if (uuid != null) {
final User matchedUser = ess.getUser(uuid);
updatePlayer(server, sender, matchedUser, commandArgs);
} else if (matchWildcards && searchTerm.contentEquals("**")) {
for (UUID sUser : ess.getUserMap().getAllUniqueUsers()) {
final User matchedUser = ess.getUser(sUser);
updatePlayer(server, sender, matchedUser, commandArgs);

View File

@ -2,6 +2,7 @@ package com.earth2me.essentials.utils;
import java.util.Collection;
import java.util.Locale;
import java.util.UUID;
import java.util.regex.Pattern;
@ -73,6 +74,14 @@ public class StringUtil {
return buf.toString();
}
public static UUID toUUID(String input) {
try {
return UUID.fromString(input);
} catch (IllegalArgumentException ignored) {}
return null;
}
private StringUtil() {
}
}