Merge branch 'master' into 'dev'

COUNT() always return something, statement found would be always true.

See merge request morningstar/Arcturus-Community!440
This commit is contained in:
ArpyAge 2021-09-02 00:32:33 +00:00
commit b2f5c5fe71

View File

@ -55,16 +55,18 @@ public class GiveBadge extends RCONMessage<GiveBadge.GiveBadgeJSON> {
} 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 {