Added: Delete Items
This commit is contained in:
parent
4610904002
commit
2a3a73e08a
@ -35,6 +35,7 @@ import com.eu.habbo.messages.incoming.helper.RequestTalentTrackEvent;
|
||||
import com.eu.habbo.messages.incoming.hotelview.*;
|
||||
import com.eu.habbo.messages.incoming.inventory.RequestInventoryBadgesEvent;
|
||||
import com.eu.habbo.messages.incoming.inventory.RequestInventoryBotsEvent;
|
||||
import com.eu.habbo.messages.incoming.inventory.RequestInventoryItemsDelete;
|
||||
import com.eu.habbo.messages.incoming.inventory.RequestInventoryItemsEvent;
|
||||
import com.eu.habbo.messages.incoming.inventory.RequestInventoryPetsEvent;
|
||||
import com.eu.habbo.messages.incoming.modtool.*;
|
||||
@ -366,6 +367,7 @@ public class PacketManager {
|
||||
private void registerInventory() throws Exception {
|
||||
this.registerHandler(Incoming.RequestInventoryBadgesEvent, RequestInventoryBadgesEvent.class);
|
||||
this.registerHandler(Incoming.RequestInventoryBotsEvent, RequestInventoryBotsEvent.class);
|
||||
this.registerHandler(Incoming.RequestInventoryItemsDelete, RequestInventoryItemsDelete.class);
|
||||
this.registerHandler(Incoming.RequestInventoryItemsEvent, RequestInventoryItemsEvent.class);
|
||||
this.registerHandler(Incoming.HotelViewInventoryEvent, RequestInventoryItemsEvent.class);
|
||||
this.registerHandler(Incoming.RequestInventoryPetsEvent, RequestInventoryPetsEvent.class);
|
||||
|
@ -139,6 +139,7 @@ public class Incoming {
|
||||
public static final int RequestAchievementsEvent = 219;
|
||||
public static final int GuildChangeColorsEvent = 1764;
|
||||
public static final int RequestInventoryBadgesEvent = 2769;
|
||||
public static final int RequestInventoryItemsDelete = 10018;
|
||||
public static final int HotelViewInventoryEvent = 3500;
|
||||
public static final int RequestPetBreedsEvent = 1756;
|
||||
public static final int GuildChangeBadgeEvent = 1991;
|
||||
|
@ -0,0 +1,58 @@
|
||||
package com.eu.habbo.messages.incoming.inventory;
|
||||
|
||||
import com.eu.habbo.Emulator;
|
||||
import com.eu.habbo.habbohotel.items.Item;
|
||||
import com.eu.habbo.habbohotel.users.Habbo;
|
||||
import com.eu.habbo.habbohotel.users.HabboItem;
|
||||
import com.eu.habbo.messages.incoming.MessageHandler;
|
||||
import com.eu.habbo.messages.outgoing.inventory.InventoryRefreshComposer;
|
||||
import com.eu.habbo.messages.outgoing.inventory.RemoveHabboItemComposer;
|
||||
import com.eu.habbo.threading.runnables.QueryDeleteHabboItems;
|
||||
import gnu.trove.iterator.hash.TObjectHashIterator;
|
||||
import gnu.trove.map.hash.TIntObjectHashMap;
|
||||
|
||||
public class RequestInventoryItemsDelete extends MessageHandler {
|
||||
public int getRatelimit() {
|
||||
return 500;
|
||||
}
|
||||
|
||||
public void handle() {
|
||||
int itemId = this.packet.readInt();
|
||||
int amount = this.packet.readInt();
|
||||
HabboItem habboItem = this.client.getHabbo().getInventory().getItemsComponent().getHabboItem(itemId);
|
||||
if (habboItem == null)
|
||||
return;
|
||||
Item item = habboItem.getBaseItem();
|
||||
if (item == null)
|
||||
return;
|
||||
if (!hasFurnitureInInventory(this.client.getHabbo(), item, Math.abs(amount)))
|
||||
return;
|
||||
final Habbo habbo = this.client.getHabbo();
|
||||
if (habbo == null)
|
||||
return;
|
||||
TIntObjectHashMap<HabboItem> toRemove = new TIntObjectHashMap();
|
||||
for (int i = 0; i < Math.abs(amount); i++) {
|
||||
HabboItem habboInventoryItem = habbo.getInventory().getItemsComponent().getAndRemoveHabboItem(item);
|
||||
if (habboInventoryItem != null)
|
||||
toRemove.put(habboInventoryItem.getId(), habboInventoryItem);
|
||||
}
|
||||
toRemove.forEachValue(object -> {
|
||||
habbo.getClient().sendResponse(new RemoveHabboItemComposer(object.getGiftAdjustedId()));
|
||||
return true;
|
||||
});
|
||||
habbo.getClient().sendResponse(new InventoryRefreshComposer());
|
||||
Emulator.getThreading().run(new QueryDeleteHabboItems(toRemove));
|
||||
}
|
||||
|
||||
private boolean hasFurnitureInInventory(Habbo habbo, Item item, Integer amount) {
|
||||
int count = 0;
|
||||
for (TObjectHashIterator<HabboItem> tObjectHashIterator = habbo.getInventory().getItemsComponent().getItemsAsValueCollection().iterator(); tObjectHashIterator.hasNext(); ) {
|
||||
HabboItem habboItem = tObjectHashIterator.next();
|
||||
if (habboItem.getBaseItem().getId() == item.getId())
|
||||
count++;
|
||||
}
|
||||
if (count < amount)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user