Skip to content

Commit 1729726

Browse files
authored
Sum empty slots (#54)
1 parent 1844067 commit 1729726

2 files changed

Lines changed: 16 additions & 11 deletions

File tree

src/main/java/net/countercraft/movecraft/repair/commands/RepairInventoryCommand.java

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import net.countercraft.movecraft.util.ChatUtils;
77
import net.countercraft.movecraft.util.ComponentPaginator;
8+
import net.countercraft.movecraft.util.Pair;
89
import net.kyori.adventure.text.Component;
910
import org.bukkit.World;
1011
import org.bukkit.block.Block;
@@ -64,22 +65,24 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
6465
}
6566
}
6667

67-
RepairCounter inventory = sumInventory(craft);
68+
Pair<RepairCounter, Integer> result = sumInventory(craft);
69+
RepairCounter inventory = result.getLeft();
70+
6871
List<RepairBlob> keys = new LinkedList<>(inventory.getKeySet());
69-
keys.sort((key1, key2) -> ((int) (inventory.get(key2) - inventory.get(key1))));
72+
if (keys.isEmpty()) {
73+
player.sendMessage(ChatUtils.commandPrefix().append(I18nSupport.getInternationalisedComponent("Inventory - Empty Craft")));
74+
return true;
75+
}
7076

77+
keys.sort((key1, key2) -> ((int) (inventory.get(key2) - inventory.get(key1))));
7178
ComponentPaginator paginator = new ComponentPaginator(
7279
I18nSupport.getInternationalisedComponent("Inventory - Inventory Header"),
7380
pageNumber -> "/repairinventory " + pageNumber);
81+
paginator.addLine(Component.text(String.format("EMPTY SLOTS: %,d", result.getRight())));
7482
for (RepairBlob key : keys) {
7583
paginator.addLine(buildLine(key, inventory.get(key)));
7684
}
7785

78-
if (paginator.isEmpty()) {
79-
player.sendMessage(ChatUtils.commandPrefix().append(I18nSupport.getInternationalisedComponent("Inventory - Empty Craft")));
80-
return true;
81-
}
82-
8386
if (!paginator.isInBounds(page)) {
8487
sender.sendMessage(Component.empty()
8588
.append(ChatUtils.commandPrefix())
@@ -105,8 +108,9 @@ private Component buildLine(@NotNull RepairBlob key, double count) {
105108
}
106109

107110
@NotNull
108-
private RepairCounter sumInventory(@NotNull Craft craft) {
111+
private Pair<RepairCounter, Integer> sumInventory(@NotNull Craft craft) {
109112
RepairCounter result = new RepairCounter();
113+
int emptySlots = 0;
110114
World world = craft.getWorld();
111115
for (MovecraftLocation location : craft.getHitBox()) {
112116
Block block = world.getBlockAt(location.getX(), location.getY(), location.getZ());
@@ -121,12 +125,14 @@ private RepairCounter sumInventory(@NotNull Craft craft) {
121125
if (inventory instanceof DoubleChestInventory)
122126
continue; // Don't take from double chests
123127
for (ItemStack item : inventory.getContents()) {
124-
if (item == null)
128+
if (item == null) {
129+
emptySlots++;
125130
continue;
131+
}
126132

127133
result.add(RepairBlobManager.get(item.getType()), item.getAmount());
128134
}
129135
}
130-
return result;
136+
return new Pair<>(result, emptySlots);
131137
}
132138
}

src/main/resources/localisation/mc-repairlang_en.properties

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ Repair\ -\ Failed\ Craft\ Too\ Damaged=This craft is too damaged and cannot be r
88
Repair\ -\ Need\ more\ of\ material=Need more of material
99
Repair\ -\ Total\ damaged\ blocks=Total damaged blocks
1010
Repair\ -\ Percentage\ of\ craft=Percentage of craft
11-
Repair\ -\ Supplies\ needed=SUPPLIES NEEDED
1211
Repair\ -\ Seconds\ to\ complete\ repair=Seconds to complete repair
1312
Repair\ -\ Money\ to\ complete\ repair=Money to complete repair
1413
Repair\ -\ Empty\ Directory=You currently have no saved states.

0 commit comments

Comments
 (0)