From e76c2de94a44aeca33aeea662e6beaf3821a8f16 Mon Sep 17 00:00:00 2001 From: Raizer Date: Thu, 2 Sep 2021 00:32:33 +0000 Subject: [PATCH] COUNT() always return something, statement found would be always true. --- .../java/com/eu/habbo/messages/rcon/GiveBadge.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/eu/habbo/messages/rcon/GiveBadge.java b/src/main/java/com/eu/habbo/messages/rcon/GiveBadge.java index 98d63c33..4cb93feb 100644 --- a/src/main/java/com/eu/habbo/messages/rcon/GiveBadge.java +++ b/src/main/java/com/eu/habbo/messages/rcon/GiveBadge.java @@ -55,16 +55,18 @@ public class GiveBadge extends RCONMessage { } else { try (Connection connection = Emulator.getDatabase().getDataSource().getConnection()) { for (String badgeCode : json.badge.split(";")) { - boolean found; + int numberOfRows = 0; try (PreparedStatement statement = connection.prepareStatement("SELECT COUNT(slot_id) FROM users_badges INNER JOIN users ON users.id = user_id WHERE users.id = ? AND badge_code = ? LIMIT 1")) { statement.setInt(1, json.user_id); statement.setString(2, badgeCode); try (ResultSet set = statement.executeQuery()) { - found = set.next(); + if (set.next()){ + numberOfRows = set.getInt(1); + } } } - if (found) { + if (numberOfRows != 0) { this.status = RCONMessage.STATUS_ERROR; this.message += Emulator.getTexts().getValue("commands.error.cmd_badge.already_owns").replace("%user%", username).replace("%badge%", badgeCode) + "\r"; } else { @@ -92,4 +94,4 @@ public class GiveBadge extends RCONMessage { public String badge; } -} \ No newline at end of file +}