Skip to content

Commit

Permalink
fix paging
Browse files Browse the repository at this point in the history
  • Loading branch information
Ilya246 committed May 11, 2024
1 parent 41778d0 commit 6a33e1c
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/crawler_arena/CrawlerArenaMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -663,24 +663,26 @@ public void registerClientCommands(CommandHandler handler){
}
}
IntSeq sortedUnitCosts = unitCosts.values().toArray();
int maxPage = (sortedUnitCosts.size - 1) / (unitsRows * page) + 1;
int maxPage = (sortedUnitCosts.size - 1) / unitsRows + 1;
if(1 > page || page > maxPage){
Bundle.bundled(player, "exceptions.invalid-amount");
return;
}
sortedUnitCosts.sort();
if(page < maxPage){
sortedUnitCosts.removeRange(unitsRows * page, sortedUnitCosts.size - 1);
}
if(page > 1){
sortedUnitCosts.removeRange(0, unitsRows * (page - 1) - 1);
}
sortedUnitCosts.removeRange(unitsRows * page, sortedUnitCosts.size - 1);
ObjectIntMap<UnitType> unitCostsCopy = new ObjectIntMap<>();
unitCostsCopy.putAll(unitCosts);
int i = 1;
StringBuilder upgrades = new StringBuilder(Bundle.format("commands.upgrades.header", Bundle.findLocale(player)));
upgrades.append(Bundle.format("commands.upgrades.header", Bundle.findLocale(player), page, maxPage)).append("/n");
upgrades.append(Bundle.format("commands.upgrades.page", Bundle.findLocale(player), page, maxPage)).append("\n");
sortedUnitCosts.each((cost) -> {
UnitType type = unitCostsCopy.findKey(cost);
upgrades.append("[gold] - [accent]").append(type.name).append(" [lightgray](").append(cost).append("/n");
upgrades.append("[gold] - [accent]").append(type.name).append(" [lightgray](").append(cost).append(")\n");
unitCostsCopy.remove(type);
});
player.sendMessage(upgrades.toString());
Expand Down

0 comments on commit 6a33e1c

Please sign in to comment.