diff --git a/src/main/java/net/countercraft/movecraft/repair/commands/RepairInventoryCommand.java b/src/main/java/net/countercraft/movecraft/repair/commands/RepairInventoryCommand.java index 70ca988..f3e2746 100644 --- a/src/main/java/net/countercraft/movecraft/repair/commands/RepairInventoryCommand.java +++ b/src/main/java/net/countercraft/movecraft/repair/commands/RepairInventoryCommand.java @@ -5,6 +5,7 @@ import net.countercraft.movecraft.util.ChatUtils; import net.countercraft.movecraft.util.ComponentPaginator; +import net.countercraft.movecraft.util.Pair; import net.kyori.adventure.text.Component; import org.bukkit.World; import org.bukkit.block.Block; @@ -64,22 +65,24 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command } } - RepairCounter inventory = sumInventory(craft); + Pair result = sumInventory(craft); + RepairCounter inventory = result.getLeft(); + List keys = new LinkedList<>(inventory.getKeySet()); - keys.sort((key1, key2) -> ((int) (inventory.get(key2) - inventory.get(key1)))); + if (keys.isEmpty()) { + player.sendMessage(ChatUtils.commandPrefix().append(I18nSupport.getInternationalisedComponent("Inventory - Empty Craft"))); + return true; + } + keys.sort((key1, key2) -> ((int) (inventory.get(key2) - inventory.get(key1)))); ComponentPaginator paginator = new ComponentPaginator( I18nSupport.getInternationalisedComponent("Inventory - Inventory Header"), pageNumber -> "/repairinventory " + pageNumber); + paginator.addLine(Component.text(String.format("EMPTY SLOTS: %,d", result.getRight()))); for (RepairBlob key : keys) { paginator.addLine(buildLine(key, inventory.get(key))); } - if (paginator.isEmpty()) { - player.sendMessage(ChatUtils.commandPrefix().append(I18nSupport.getInternationalisedComponent("Inventory - Empty Craft"))); - return true; - } - if (!paginator.isInBounds(page)) { sender.sendMessage(Component.empty() .append(ChatUtils.commandPrefix()) @@ -105,8 +108,9 @@ private Component buildLine(@NotNull RepairBlob key, double count) { } @NotNull - private RepairCounter sumInventory(@NotNull Craft craft) { + private Pair sumInventory(@NotNull Craft craft) { RepairCounter result = new RepairCounter(); + int emptySlots = 0; World world = craft.getWorld(); for (MovecraftLocation location : craft.getHitBox()) { Block block = world.getBlockAt(location.getX(), location.getY(), location.getZ()); @@ -121,12 +125,14 @@ private RepairCounter sumInventory(@NotNull Craft craft) { if (inventory instanceof DoubleChestInventory) continue; // Don't take from double chests for (ItemStack item : inventory.getContents()) { - if (item == null) + if (item == null) { + emptySlots++; continue; + } result.add(RepairBlobManager.get(item.getType()), item.getAmount()); } } - return result; + return new Pair<>(result, emptySlots); } } diff --git a/src/main/resources/localisation/mc-repairlang_en.properties b/src/main/resources/localisation/mc-repairlang_en.properties index 7aa7bec..eb979bd 100644 --- a/src/main/resources/localisation/mc-repairlang_en.properties +++ b/src/main/resources/localisation/mc-repairlang_en.properties @@ -8,7 +8,6 @@ Repair\ -\ Failed\ Craft\ Too\ Damaged=This craft is too damaged and cannot be r Repair\ -\ Need\ more\ of\ material=Need more of material Repair\ -\ Total\ damaged\ blocks=Total damaged blocks Repair\ -\ Percentage\ of\ craft=Percentage of craft -Repair\ -\ Supplies\ needed=SUPPLIES NEEDED Repair\ -\ Seconds\ to\ complete\ repair=Seconds to complete repair Repair\ -\ Money\ to\ complete\ repair=Money to complete repair Repair\ -\ Empty\ Directory=You currently have no saved states.