Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -64,22 +65,24 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
}
}

RepairCounter inventory = sumInventory(craft);
Pair<RepairCounter, Integer> result = sumInventory(craft);
RepairCounter inventory = result.getLeft();

List<RepairBlob> 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())
Expand All @@ -105,8 +108,9 @@ private Component buildLine(@NotNull RepairBlob key, double count) {
}

@NotNull
private RepairCounter sumInventory(@NotNull Craft craft) {
private Pair<RepairCounter, Integer> 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());
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading