Closed foosratt closed 7 years ago
Update: I have also implemented a fix for the list numbering. It now prints out 1-10 on baltop and then 11-10 on page 2 etc. ThIs fix is implemented in BalanaceTopCommand.java. All the fixes mentioned here and above are compiled and are running on pizzagamers.com if you wish to see them working.
public void onCommand(CommandSender sender, String[] args) throws CommandException { if (args.length > 1) { throw new TooManyArgumentsException(); }
int offset = 0;
if (args.length == 1) {
int page = Integer.parseInt(args[0]);
if (page > 1) {
page = page - 1;
//System.out.println("Page = " + page);
try {
offset = 10 * Math.abs(page);
} catch (NumberFormatException e) {
MessageUtils.sendMessage(sender, "%s is not a valid number.");
return;
}
}
}
Map<OfflinePlayer, Double> topBalances = saneEconomy.getEconomyManager().getTopPlayerBalances(10, offset);
AtomicInteger index = new AtomicInteger(offset + 1); /* I know it's stupid, but you can't do some_int++ from within the lambda. */
MessageUtils.sendMessage(sender, "Top %d players (page %s):", topBalances.size(), args.length == 1 ? args[0] : "1");
topBalances.forEach((player, balance) -> MessageUtils.sendMessage(sender, "[%02d] %s - %s", index.getAndIncrement(), player.getName(), SaneEconomy.getInstance().getEconomyManager().getCurrency().formatAmount(balance)));
}
Please submit a pull request, then I will merge it.
I can push it direct or have to make a fork? Not supper familiar with github.
Fork, clone the fork, edit the fork, push to the fork, then open a PR from the fork to the original.
OK I will work on getting that done this weekend
Fixed in 0.9.2 because you took too long :P
Sorry crazy weekend with the family. Have 2 kids will do that to you :). I hope at least the code snippets I provided helped.
Here is the fix for this in MapUtil.java
You never increment the counter i if it is less than the offset.
You check if newMap.size() > amount I have fixed this to be >= which prints out 10 now instead of 11.
I have tested the code below on our pizzagamers.com test server. I will compile and move the fix I have to pizzagamers.com soon. Next fix needs to be the list output so as to show a continued list number as opposed to always starting at 0
public static <K, V> Map<K, V> takeFromMap(Map<K, V> map, int amount, int offset) { Map<K, V> newMap = new LinkedHashMap<>();