From a1a0d34940336d80ed39ef19aec50f8278c3f440 Mon Sep 17 00:00:00 2001 From: md678685 <1917406+md678685@users.noreply.github.com> Date: Mon, 23 Dec 2019 13:06:15 +0000 Subject: [PATCH] Attempt to parse input as UUID in loop commands (#2606) Related: #2424 --- .../essentials/commands/EssentialsLoopCommand.java | 7 ++++++- .../src/com/earth2me/essentials/utils/StringUtil.java | 9 +++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/Essentials/src/com/earth2me/essentials/commands/EssentialsLoopCommand.java b/Essentials/src/com/earth2me/essentials/commands/EssentialsLoopCommand.java index fffe3b86e..19620c902 100644 --- a/Essentials/src/com/earth2me/essentials/commands/EssentialsLoopCommand.java +++ b/Essentials/src/com/earth2me/essentials/commands/EssentialsLoopCommand.java @@ -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); diff --git a/Essentials/src/com/earth2me/essentials/utils/StringUtil.java b/Essentials/src/com/earth2me/essentials/utils/StringUtil.java index 4f1ee1f6f..9db7cf055 100644 --- a/Essentials/src/com/earth2me/essentials/utils/StringUtil.java +++ b/Essentials/src/com/earth2me/essentials/utils/StringUtil.java @@ -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() { } }