You've already forked Arcturus-Morningstar-Extended
mirror of
https://github.com/duckietm/Arcturus-Morningstar-Extended.git
synced 2026-06-20 07:26:18 +00:00
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:
+15
-8
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user