fix(items): persist clothing grants before redeem

Redeeming clothing furniture now inserts the wardrobe grant before removing/deleting the voucher furniture. If the DB insert fails, the item remains in the room and the in-memory wardrobe is not updated.

Tests: mvn -Dtest=RedeemClothingContractTest test; mvn -DskipTests package
This commit is contained in:
simoleo89
2026-06-14 20:39:51 +02:00
parent 82c6f3f9ff
commit 39c6e24097
2 changed files with 44 additions and 8 deletions
@@ -36,6 +36,10 @@ public class RedeemClothingEvent extends MessageHandler {
if (clothing != null) {
if (!this.client.getHabbo().getInventory().getWardrobeComponent().getClothing().contains(clothing.id)) {
if (!this.grantClothing(clothing.id)) {
return;
}
item.setRoomId(0);
RoomTile tile = this.client.getHabbo().getHabboInfo().getCurrentRoom().getLayout().getTile(item.getX(), item.getY());
this.client.getHabbo().getHabboInfo().getCurrentRoom().removeHabboItem(item);
@@ -44,14 +48,6 @@ public class RedeemClothingEvent extends MessageHandler {
this.client.getHabbo().getHabboInfo().getCurrentRoom().sendComposer(new RemoveFloorItemComposer(item, true).compose());
Emulator.getThreading().run(new QueryDeleteHabboItem(item.getId()));
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("INSERT INTO users_clothing (user_id, clothing_id) VALUES (?, ?)")) {
statement.setInt(1, this.client.getHabbo().getHabboInfo().getId());
statement.setInt(2, clothing.id);
statement.execute();
} catch (SQLException e) {
LOGGER.error("Caught SQL exception", e);
}
this.client.getHabbo().getInventory().getWardrobeComponent().getClothing().add(clothing.id);
this.client.getHabbo().getInventory().getWardrobeComponent().getClothingSets().addAll(clothing.setId);
this.client.sendResponse(new UserClothesComposer(this.client.getHabbo()));
@@ -67,4 +63,15 @@ public class RedeemClothingEvent extends MessageHandler {
}
}
}
private boolean grantClothing(int clothingId) {
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("INSERT INTO users_clothing (user_id, clothing_id) VALUES (?, ?)")) {
statement.setInt(1, this.client.getHabbo().getHabboInfo().getId());
statement.setInt(2, clothingId);
return statement.executeUpdate() > 0;
} catch (SQLException e) {
LOGGER.error("Caught SQL exception", e);
return false;
}
}
}