Browse Source

should fix inspecting offline players

(cherry picked from commit ad715f51c6b8b87e3a78c18c7daaf4cdf7c10a8e)
t00thpick1 6 năm trước cách đây
mục cha
commit
8aa919f834

+ 32 - 6
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) {
     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);
             return cachedUserIDs.get(uuid);
-        }
 
 
         ResultSet resultSet = null;
         ResultSet resultSet = null;
         PreparedStatement statement = null;
         PreparedStatement statement = null;
 
 
         try {
         try {
             statement = connection.prepareStatement("SELECT id, user FROM " + tablePrefix + "users WHERE uuid = ? OR (uuid IS NULL AND user = ?)");
             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);
             statement.setString(2, playerName);
             resultSet = statement.executeQuery();
             resultSet = statement.executeQuery();
 
 
             if (resultSet.next()) {
             if (resultSet.next()) {
                 int id = resultSet.getInt("id");
                 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;
                 return id;
             }
             }