From 8aa919f83412c6f38c3482e09d8d60d94ec34dda Mon Sep 17 00:00:00 2001 From: t00thpick1 Date: Sat, 5 Jan 2019 19:21:15 -0500 Subject: [PATCH] should fix inspecting offline players (cherry picked from commit ad715f51c6b8b87e3a78c18c7daaf4cdf7c10a8e) --- .../nossr50/database/SQLDatabaseManager.java | 38 ++++++++++++++++--- 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/database/SQLDatabaseManager.java b/src/main/java/com/gmail/nossr50/database/SQLDatabaseManager.java index aaa08e184..f76f2b79c 100644 --- a/src/main/java/com/gmail/nossr50/database/SQLDatabaseManager.java +++ b/src/main/java/com/gmail/nossr50/database/SQLDatabaseManager.java @@ -1393,25 +1393,51 @@ public final class SQLDatabaseManager implements DatabaseManager { } private int getUserID(final Connection connection, final String playerName, final UUID uuid) { - if (uuid != null && cachedUserIDs.containsKey(uuid)) { + if (uuid == null) + return getUserIDByName(connection, playerName); + + if (cachedUserIDs.containsKey(uuid)) return cachedUserIDs.get(uuid); - } ResultSet resultSet = null; PreparedStatement statement = null; try { statement = connection.prepareStatement("SELECT id, user FROM " + tablePrefix + "users WHERE uuid = ? OR (uuid IS NULL AND user = ?)"); - statement.setString(1, uuid == null ? null : uuid.toString()); + statement.setString(1, uuid.toString()); statement.setString(2, playerName); resultSet = statement.executeQuery(); if (resultSet.next()) { int id = resultSet.getInt("id"); - if (uuid != null) { - cachedUserIDs.put(uuid, id); - } + cachedUserIDs.put(uuid, id); + + return id; + } + } + catch (SQLException ex) { + printErrors(ex); + } + finally { + tryClose(resultSet); + tryClose(statement); + } + + return -1; + } + + private int getUserIDByName(final Connection connection, final String playerName) { + ResultSet resultSet = null; + PreparedStatement statement = null; + + try { + statement = connection.prepareStatement("SELECT id, user FROM " + tablePrefix + "users WHERE user = ?"); + statement.setString(1, playerName); + resultSet = statement.executeQuery(); + + if (resultSet.next()) { + int id = resultSet.getInt("id"); return id; }