From 66397c8d98436035df1207c55845ad1e5394f2c6 Mon Sep 17 00:00:00 2001 From: Bill Date: Mon, 21 Mar 2022 12:31:05 -0400 Subject: [PATCH] Fix the busted inventory fragments --- .../commands/EmptyInventoryCommand.java | 1 - .../inventory/RequestInventoryItemsEvent.java | 17 ++++++++++------- .../inventory/InventoryItemsComposer.java | 14 +++++++------- 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/eu/habbo/habbohotel/commands/EmptyInventoryCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/EmptyInventoryCommand.java index 779dd3e5..a7a205a8 100644 --- a/src/main/java/com/eu/habbo/habbohotel/commands/EmptyInventoryCommand.java +++ b/src/main/java/com/eu/habbo/habbohotel/commands/EmptyInventoryCommand.java @@ -42,7 +42,6 @@ public class EmptyInventoryCommand extends Command { Emulator.getThreading().run(new QueryDeleteHabboItems(items)); habbo.getClient().sendResponse(new InventoryRefreshComposer()); - habbo.getClient().sendResponse(new InventoryItemsComposer(0, 1, gameClient.getHabbo().getInventory().getItemsComponent().getItems())); gameClient.getHabbo().whisper(Emulator.getTexts().getValue("commands.succes.cmd_empty.cleared").replace("%username%", habbo.getHabboInfo().getUsername()), RoomChatMessageBubbles.ALERT); } else { diff --git a/src/main/java/com/eu/habbo/messages/incoming/inventory/RequestInventoryItemsEvent.java b/src/main/java/com/eu/habbo/messages/incoming/inventory/RequestInventoryItemsEvent.java index 2b9641cb..f5047b72 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/inventory/RequestInventoryItemsEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/inventory/RequestInventoryItemsEvent.java @@ -17,20 +17,23 @@ public class RequestInventoryItemsEvent extends MessageHandler { @Override public void handle() throws Exception { int totalItems = this.client.getHabbo().getInventory().getItemsComponent().getItems().size(); - int pages = (int) Math.ceil((double) totalItems / 1000.0); + int totalFragments = (int) Math.ceil((double) totalItems / 1000.0); - if (pages == 0) { - pages = 1; + if (totalFragments == 0) { + totalFragments = 1; } synchronized (this.client.getHabbo().getInventory().getItemsComponent().getItems()) { TIntObjectMap items = new TIntObjectHashMap<>(); TIntObjectIterator iterator = this.client.getHabbo().getInventory().getItemsComponent().getItems().iterator(); + int count = 0; - int page = 0; + int fragmentNumber = 0; + for (int i = this.client.getHabbo().getInventory().getItemsComponent().getItems().size(); i-- > 0; ) { + if (count == 0) { - page++; + fragmentNumber++; } try { @@ -43,13 +46,13 @@ public class RequestInventoryItemsEvent extends MessageHandler { } if (count == 1000) { - this.client.sendResponse(new InventoryItemsComposer(page, pages, items)); + this.client.sendResponse(new InventoryItemsComposer(fragmentNumber, totalFragments, items)); count = 0; items.clear(); } } - this.client.sendResponse(new InventoryItemsComposer(page, pages, items)); + if(count > 0 && items.size() > 0) this.client.sendResponse(new InventoryItemsComposer(fragmentNumber, totalFragments, items)); } } } diff --git a/src/main/java/com/eu/habbo/messages/outgoing/inventory/InventoryItemsComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/inventory/InventoryItemsComposer.java index 258ce1a9..a8a24ed0 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/inventory/InventoryItemsComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/inventory/InventoryItemsComposer.java @@ -14,13 +14,13 @@ import org.slf4j.LoggerFactory; public class InventoryItemsComposer extends MessageComposer implements TIntObjectProcedure { private static final Logger LOGGER = LoggerFactory.getLogger(InventoryItemsComposer.class); - private final int page; - private final int out; + private final int fragmentNumber; + private final int totalFragments; private final TIntObjectMap items; - public InventoryItemsComposer(int page, int out, TIntObjectMap items) { - this.page = page; - this.out = out; + public InventoryItemsComposer(int fragmentNumber, int totalFragments, TIntObjectMap items) { + this.fragmentNumber = fragmentNumber; + this.totalFragments = totalFragments; this.items = items; } @@ -28,8 +28,8 @@ public class InventoryItemsComposer extends MessageComposer implements TIntObjec protected ServerMessage composeInternal() { try { this.response.init(Outgoing.InventoryItemsComposer); - this.response.appendInt(this.out); - this.response.appendInt(this.page - 1); + this.response.appendInt(this.totalFragments); + this.response.appendInt(this.fragmentNumber - 1); this.response.appendInt(this.items.size()); this.items.forEachEntry(this);