Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve UUID strings when matching players #2045

Merged
merged 4 commits into from
May 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions src/main/java/me/ryanhamshire/GriefPrevention/GriefPrevention.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -2691,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;
Expand Down Expand Up @@ -3189,7 +3181,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);
Expand Down