Merge pull request #180 from simoleo89/fix/items-ownership-and-charges

fix(items): harden ownership and redeem lifecycle
This commit is contained in:
DuckieTM
2026-06-15 07:21:09 +02:00
committed by GitHub
8 changed files with 162 additions and 13 deletions
@@ -179,9 +179,13 @@ public class BotManager {
}
public void pickUpBot(Bot bot, Habbo habbo) {
HabboInfo receiverInfo = habbo == null ? Emulator.getGameEnvironment().getHabboManager().getHabboInfo(bot.getOwnerId()) : habbo.getHabboInfo();
if (bot != null) {
HabboInfo receiverInfo = resolvePickupReceiver(bot, habbo);
Room botRoom = bot.getRoom();
if (receiverInfo == null || botRoom == null) {
return;
}
BotPickUpEvent pickedUpEvent = new BotPickUpEvent(bot, habbo);
Emulator.getPluginManager().fireEvent(pickedUpEvent);
@@ -198,8 +202,8 @@ public class BotManager {
return;
}
bot.onPickUp(habbo, receiverInfo.getCurrentRoom());
receiverInfo.getCurrentRoom().removeBot(bot);
bot.onPickUp(habbo, botRoom);
botRoom.removeBot(bot);
bot.stopFollowingHabbo();
bot.setOwnerId(receiverInfo.getId());
bot.setOwnerName(receiverInfo.getUsername());
@@ -215,6 +219,14 @@ public class BotManager {
}
}
private HabboInfo resolvePickupReceiver(Bot bot, Habbo picker) {
if (picker != null && bot.getOwnerId() == picker.getHabboInfo().getId()) {
return picker.getHabboInfo();
}
return Emulator.getGameEnvironment().getHabboManager().getHabboInfo(bot.getOwnerId());
}
public Bot loadBot(ResultSet set) {
try {
String type = set.getString("type");
@@ -3,6 +3,7 @@ package com.eu.habbo.habbohotel.items.interactions;
import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.gameclients.GameClient;
import com.eu.habbo.habbohotel.items.Item;
import com.eu.habbo.habbohotel.permissions.Permission;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomLayout;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
@@ -133,12 +134,18 @@ public class InteractionRentableSpace extends HabboItem {
if (habbo.getHabboStats().isRentingSpace())
return;
if (habbo.getHabboInfo().getCredits() < this.rentCost())
int cost = this.rentCost();
boolean hasInfiniteCredits = habbo.hasPermission(Permission.ACC_INFINITE_CREDITS);
if (!hasInfiniteCredits && habbo.getHabboInfo().getCredits() < cost)
return;
if (habbo.getHabboStats().getClubExpireTimestamp() < Emulator.getIntUnixTimestamp())
return;
if (!hasInfiniteCredits) {
habbo.giveCredits(-cost);
}
this.setRenterId(habbo.getHabboInfo().getId());
this.setRenterName(habbo.getHabboInfo().getUsername());
this.setEndTimestamp(Emulator.getIntUnixTimestamp() + (7 * 86400));
@@ -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;
}
}
}
@@ -103,6 +103,10 @@ public class ToggleFloorItemEvent extends MessageHandler {
// Do not move to onClick(). Wired could trigger it.
if (item instanceof InteractionMonsterPlantSeed) {
if (item.getUserId() != this.client.getHabbo().getHabboInfo().getId()) {
return;
}
Emulator.getThreading().run(new QueryDeleteHabboItem(item.getId()));
boolean isRare = item.getBaseItem().getName().contains("rare");