From 3f528f44a12916a161c649688bf790e81f4de44b Mon Sep 17 00:00:00 2001 From: Jikoo Date: Fri, 21 Apr 2023 13:14:33 -0400 Subject: [PATCH 1/3] Resolve UUID strings when matching players --- .../ryanhamshire/GriefPrevention/GriefPrevention.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/java/me/ryanhamshire/GriefPrevention/GriefPrevention.java b/src/main/java/me/ryanhamshire/GriefPrevention/GriefPrevention.java index 47acaf428..3aeb867de 100644 --- a/src/main/java/me/ryanhamshire/GriefPrevention/GriefPrevention.java +++ b/src/main/java/me/ryanhamshire/GriefPrevention/GriefPrevention.java @@ -3189,7 +3189,16 @@ public OfflinePlayer resolvePlayerByName(String name) } if (bestMatchID == null) { - return null; + try + { + // Try to parse UUID from string. + bestMatchID = UUID.fromString(name); + } + catch (IllegalArgumentException ignored) + { + // Not a valid UUID string either. + return null; + } } return this.getServer().getOfflinePlayer(bestMatchID); From 2f5d794178e95cfaf81b83ab5400fddd13f41ecb Mon Sep 17 00:00:00 2001 From: Jikoo Date: Fri, 21 Apr 2023 13:33:19 -0400 Subject: [PATCH 2/3] Remove redundant resolution --- .../GriefPrevention/GriefPrevention.java | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/src/main/java/me/ryanhamshire/GriefPrevention/GriefPrevention.java b/src/main/java/me/ryanhamshire/GriefPrevention/GriefPrevention.java index 3aeb867de..43f529a53 100644 --- a/src/main/java/me/ryanhamshire/GriefPrevention/GriefPrevention.java +++ b/src/main/java/me/ryanhamshire/GriefPrevention/GriefPrevention.java @@ -2338,17 +2338,7 @@ else if (cmd.getName().equalsIgnoreCase("adjustbonusclaimblocks")) } //otherwise, find the specified player - OfflinePlayer targetPlayer; - try - { - UUID playerID = UUID.fromString(args[0]); - targetPlayer = this.getServer().getOfflinePlayer(playerID); - - } - catch (IllegalArgumentException e) - { - targetPlayer = this.resolvePlayerByName(args[0]); - } + OfflinePlayer targetPlayer = this.resolvePlayerByName(args[0]); if (targetPlayer == null) { From 476c48cde80ae45497ff5fc51826698ec8065f3e Mon Sep 17 00:00:00 2001 From: Jikoo Date: Fri, 21 Apr 2023 13:33:50 -0400 Subject: [PATCH 3/3] Add guards to /givepet --- .../java/me/ryanhamshire/GriefPrevention/GriefPrevention.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/me/ryanhamshire/GriefPrevention/GriefPrevention.java b/src/main/java/me/ryanhamshire/GriefPrevention/GriefPrevention.java index 43f529a53..4f7e10faa 100644 --- a/src/main/java/me/ryanhamshire/GriefPrevention/GriefPrevention.java +++ b/src/main/java/me/ryanhamshire/GriefPrevention/GriefPrevention.java @@ -2681,7 +2681,9 @@ else if (cmd.getName().equalsIgnoreCase("givepet") && player != null) //find the specified player OfflinePlayer targetPlayer = this.resolvePlayerByName(args[0]); - if (targetPlayer == null) + if (targetPlayer == null + || !targetPlayer.isOnline() && !targetPlayer.hasPlayedBefore() + || targetPlayer.getName() == null) { GriefPrevention.sendMessage(player, TextMode.Err, Messages.PlayerNotFound2); return true;