From 9dad818fda720388c33818f2f7fd099bc8283bfe Mon Sep 17 00:00:00 2001 From: Snaiker Date: Fri, 15 Apr 2022 01:19:50 +0100 Subject: [PATCH 1/2] Removed old code --- .../habbohotel/commands/TakeBadgeCommand.java | 4 +++- .../users/inventory/BadgesComponent.java | 18 +----------------- 2 files changed, 4 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/eu/habbo/habbohotel/commands/TakeBadgeCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/TakeBadgeCommand.java index 8241d517..a1097852 100644 --- a/src/main/java/com/eu/habbo/habbohotel/commands/TakeBadgeCommand.java +++ b/src/main/java/com/eu/habbo/habbohotel/commands/TakeBadgeCommand.java @@ -5,6 +5,8 @@ import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.rooms.RoomChatMessageBubbles; import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.habbohotel.users.HabboBadge; +import com.eu.habbo.habbohotel.users.HabboInfo; +import com.eu.habbo.habbohotel.users.HabboManager; import com.eu.habbo.habbohotel.users.inventory.BadgesComponent; import com.eu.habbo.messages.outgoing.inventory.InventoryBadgesComposer; import com.eu.habbo.messages.outgoing.users.UserBadgesComposer; @@ -46,7 +48,7 @@ public class TakeBadgeCommand extends Command { gameClient.getHabbo().whisper(Emulator.getTexts().getValue("commands.succes.cmd_take_badge"), RoomChatMessageBubbles.ALERT); - BadgesComponent.deleteBadge(username, badge); + BadgesComponent.deleteBadge(habbo != null ? habbo.getHabboInfo().getId() : HabboManager.getOfflineHabboInfo(username).getId(), badge); } return true; diff --git a/src/main/java/com/eu/habbo/habbohotel/users/inventory/BadgesComponent.java b/src/main/java/com/eu/habbo/habbohotel/users/inventory/BadgesComponent.java index 02573ff4..49f30136 100644 --- a/src/main/java/com/eu/habbo/habbohotel/users/inventory/BadgesComponent.java +++ b/src/main/java/com/eu/habbo/habbohotel/users/inventory/BadgesComponent.java @@ -46,7 +46,7 @@ public class BadgesComponent { } if (delete) { - deleteBadge(habbo.getHabboInfo().getUsername(), badge.getCode()); + deleteBadge(habbo.getHabboInfo().getId(), badge.getCode()); continue; } } @@ -94,22 +94,6 @@ public class BadgesComponent { return badge; } - @Deprecated - public static void deleteBadge(String username, HabboBadge badge) { - deleteBadge(username, badge.getCode()); - } - - @Deprecated - public static void deleteBadge(String username, String badge) { - try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("DELETE users_badges FROM users_badges INNER JOIN users ON users_badges.user_id = users.id WHERE users.username LIKE ? AND badge_code LIKE ?")) { - statement.setString(1, username); - statement.setString(2, badge); - statement.execute(); - } catch (SQLException e) { - LOGGER.error("Caught SQL exception", e); - } - } - public static void deleteBadge(int userId, String badge) { try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("DELETE users_badges FROM users_badges WHERE user_id = ? AND badge_code LIKE ?")) { statement.setInt(1, userId); From 2a6e81ef05ce5fe5061d09242ee4b39c9d957e0a Mon Sep 17 00:00:00 2001 From: Snaiker Date: Fri, 15 Apr 2022 01:29:06 +0100 Subject: [PATCH 2/2] Check if the offline user exists --- .../habbohotel/commands/TakeBadgeCommand.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/eu/habbo/habbohotel/commands/TakeBadgeCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/TakeBadgeCommand.java index a1097852..2afe3bb3 100644 --- a/src/main/java/com/eu/habbo/habbohotel/commands/TakeBadgeCommand.java +++ b/src/main/java/com/eu/habbo/habbohotel/commands/TakeBadgeCommand.java @@ -46,9 +46,21 @@ public class TakeBadgeCommand extends Command { } } - gameClient.getHabbo().whisper(Emulator.getTexts().getValue("commands.succes.cmd_take_badge"), RoomChatMessageBubbles.ALERT); + int userId = 0; - BadgesComponent.deleteBadge(habbo != null ? habbo.getHabboInfo().getId() : HabboManager.getOfflineHabboInfo(username).getId(), badge); + if (habbo != null) + userId = habbo.getHabboInfo().getId(); + else { + HabboInfo habboInfo = HabboManager.getOfflineHabboInfo(username); + if (habboInfo != null) + userId = habboInfo.getId(); + } + + if (userId > 0) { + gameClient.getHabbo().whisper(Emulator.getTexts().getValue("commands.succes.cmd_take_badge"), RoomChatMessageBubbles.ALERT); + + BadgesComponent.deleteBadge(userId, badge); + } } return true;