From 738641c38bd06886b63002ef163fd6a6ebaeb405 Mon Sep 17 00:00:00 2001 From: TechnicallyCoded Date: Wed, 8 Jun 2022 17:53:44 +0200 Subject: [PATCH] Added support for malformed UUIDs (missing the dashes) --- .../inventoryrollback/RestoreSubCmd.java | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/nuclyon/technicallycoded/inventoryrollback/commands/inventoryrollback/RestoreSubCmd.java b/src/main/java/com/nuclyon/technicallycoded/inventoryrollback/commands/inventoryrollback/RestoreSubCmd.java index e13e7e9..d5e7e23 100644 --- a/src/main/java/com/nuclyon/technicallycoded/inventoryrollback/commands/inventoryrollback/RestoreSubCmd.java +++ b/src/main/java/com/nuclyon/technicallycoded/inventoryrollback/commands/inventoryrollback/RestoreSubCmd.java @@ -48,10 +48,27 @@ private void openBackupMenu(CommandSender sender, Player staff, String[] args) { } else if(args.length == 2) { OfflinePlayer rollbackPlayer; + String uuidStr = args[1]; + // Handle input of UUID - if (args[1].length() == 36) { + if (uuidStr.length() == 36 || args[1].length() == 32) { + + // Handle malformed UUID + if (args[1].length() == 32) { + String oldUuidStr = uuidStr; + uuidStr = oldUuidStr.substring(0, 8); + uuidStr += "-"; + uuidStr += oldUuidStr.substring(8, 12); + uuidStr += "-"; + uuidStr += oldUuidStr.substring(12, 16); + uuidStr += "-"; + uuidStr += oldUuidStr.substring(16, 20); + uuidStr += "-"; + uuidStr += oldUuidStr.substring(20); + } + try { - rollbackPlayer = Bukkit.getOfflinePlayer(UUID.fromString(args[1])); + rollbackPlayer = Bukkit.getOfflinePlayer(UUID.fromString(uuidStr)); } catch (IllegalArgumentException e) { sender.sendMessage(MessageData.getPluginPrefix() + MessageData.getError()); return;