From 66201a9062eb4fb023e8af3217df6be6c000aac3 Mon Sep 17 00:00:00 2001 From: Phoenix616 Date: Sat, 27 Mar 2021 18:34:03 +0100 Subject: [PATCH] Directly use Regex group matching to get playername (Fixes #428) --- .../java/com/Acrobot/ChestShop/Signs/ChestShopSign.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/Acrobot/ChestShop/Signs/ChestShopSign.java b/src/main/java/com/Acrobot/ChestShop/Signs/ChestShopSign.java index cc30f4f..ff535df 100644 --- a/src/main/java/com/Acrobot/ChestShop/Signs/ChestShopSign.java +++ b/src/main/java/com/Acrobot/ChestShop/Signs/ChestShopSign.java @@ -20,6 +20,7 @@ import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryHolder; import java.util.Locale; +import java.util.regex.Matcher; import java.util.regex.Pattern; import static com.Acrobot.Breeze.Utils.ImplementationAdapter.getState; @@ -157,12 +158,11 @@ public class ChestShopSign { // Prepare regexp patterns Pattern playernamePattern = Pattern.compile(Properties.VALID_PLAYERNAME_REGEXP); // regexp from config file - Pattern playernameWithIdPattern = Pattern.compile(":[A-Za-z0-9]+$"); // regexp to match ':' and a base62 encoded string - + Matcher playernameWithIdMatcher = Pattern.compile("^(.+):[A-Za-z0-9]+$").matcher(playername); // regexp to match ':' and a base62 encoded string // Check if the playername has an ID. This can happen on duplicate or too long names - if (playernameWithIdPattern.matcher(playername).matches()) { + if (playernameWithIdMatcher.matches()) { // Playername matches the id pattern, so validate everything before the last ':' - playername = playername.substring(0, playername.lastIndexOf(":") - 1); + playername = playernameWithIdMatcher.group(1); } // If the playername doesn't match, this is not a valid sign, so return