From 96d6e301dd939723068bb38711d70eeff6c43d3c Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Thu, 17 Jan 2019 11:06:51 +0200 Subject: [PATCH] [#877] Made player pages accessible via UUIDs --- .../plan/utilities/uuid/UUIDUtility.java | 49 ++++++++++++++----- 1 file changed, 36 insertions(+), 13 deletions(-) diff --git a/Plan/common/src/main/java/com/djrapitops/plan/utilities/uuid/UUIDUtility.java b/Plan/common/src/main/java/com/djrapitops/plan/utilities/uuid/UUIDUtility.java index 38738a755..bc14b331d 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/utilities/uuid/UUIDUtility.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/utilities/uuid/UUIDUtility.java @@ -51,23 +51,46 @@ public class UUIDUtility { * @return UUID of the player */ public UUID getUUIDOf(String playerName) { - UUID uuid = null; - UUID uuidOf = dataCache.getUUIDof(playerName); - if (uuidOf != null) { - return uuidOf; + UUID uuid = getUUIDFromString(playerName); + if (uuid != null) { + return uuid; } + + uuid = dataCache.getUUIDof(playerName); + if (uuid != null) { + return uuid; + } + + uuid = getUUIDFromDB(playerName); + if (uuid != null) { + return uuid; + } + + return getUUIDViaUUIDFetcher(playerName); + } + + private UUID getUUIDFromString(String playerName) { try { - uuid = dbSystem.getDatabase().fetch().getUuidOf(playerName); + return UUID.fromString(playerName); + } catch (IllegalArgumentException ignore) { + return null; + } + } + + private UUID getUUIDViaUUIDFetcher(String playerName) { + try { + return UUIDFetcher.getUUIDOf(playerName); + } catch (Exception | NoClassDefFoundError ignored) { + return null; + } + } + + private UUID getUUIDFromDB(String playerName) { + try { + return dbSystem.getDatabase().fetch().getUuidOf(playerName); } catch (DBOpException e) { errorHandler.log(L.ERROR, UUIDUtility.class, e); + return null; } - try { - if (uuid == null) { - uuid = UUIDFetcher.getUUIDOf(playerName); - } - } catch (Exception | NoClassDefFoundError ignored) { - /* Ignored */ - } - return uuid; } }