From 62a1006f027c24c8a6aa421bbf22c717188bbe8c Mon Sep 17 00:00:00 2001 From: Camotoy <20743703+Camotoy@users.noreply.github.com> Date: Sun, 5 Dec 2021 14:03:15 -0500 Subject: [PATCH] Better handling of usernames with periods (#1543) Fixes #1360 --- .../GriefPrevention/GriefPrevention.java | 34 +++++++++++-------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/src/main/java/me/ryanhamshire/GriefPrevention/GriefPrevention.java b/src/main/java/me/ryanhamshire/GriefPrevention/GriefPrevention.java index 5e34d08..6bb6480 100644 --- a/src/main/java/me/ryanhamshire/GriefPrevention/GriefPrevention.java +++ b/src/main/java/me/ryanhamshire/GriefPrevention/GriefPrevention.java @@ -1526,12 +1526,6 @@ public class GriefPrevention extends JavaPlugin //determine which claim the player is standing in Claim claim = this.dataStore.getClaimAt(player.getLocation(), true /*ignore height*/, null); - //bracket any permissions - if (args[0].contains(".") && !args[0].startsWith("[") && !args[0].endsWith("]")) - { - args[0] = "[" + args[0] + "]"; - } - //determine whether a single player or clearing permissions entirely boolean clearPermissions = false; OfflinePlayer otherPlayer = null; @@ -1555,8 +1549,16 @@ public class GriefPrevention extends JavaPlugin otherPlayer = this.resolvePlayerByName(args[0]); if (!clearPermissions && otherPlayer == null && !args[0].equals("public")) { - GriefPrevention.sendMessage(player, TextMode.Err, Messages.PlayerNotFound2); - return true; + //bracket any permissions - at this point it must be a permission without brackets + if (args[0].contains(".")) + { + args[0] = "[" + args[0] + "]"; + } + else + { + GriefPrevention.sendMessage(player, TextMode.Err, Messages.PlayerNotFound2); + return true; + } } //correct to proper casing @@ -2949,20 +2951,22 @@ public class GriefPrevention extends JavaPlugin return; } } - else if (recipientName.contains(".")) - { - permission = recipientName; - } else { otherPlayer = this.resolvePlayerByName(recipientName); - if (otherPlayer == null && !recipientName.equals("public") && !recipientName.equals("all")) + boolean isPermissionFormat = recipientName.contains("."); + if (otherPlayer == null && !recipientName.equals("public") && !recipientName.equals("all") && !isPermissionFormat) { GriefPrevention.sendMessage(player, TextMode.Err, Messages.PlayerNotFound2); return; } - if (otherPlayer != null) + if (otherPlayer == null && isPermissionFormat) + { + //player does not exist and argument has a period so this is a permission instead + permission = recipientName; + } + else if (otherPlayer != null) { recipientName = otherPlayer.getName(); recipientID = otherPlayer.getUniqueId(); @@ -3029,6 +3033,8 @@ public class GriefPrevention extends JavaPlugin if (permission != null) { identifierToAdd = "[" + permission + "]"; + //replace recipientName as well so the success message clearly signals a permission + recipientName = identifierToAdd; } else if (recipientID != null) {