looks nice, well written and thread looks clean and not all thrown together. Good job!
|
Uhm it's my first time I release something on here, Well I know maybe wealth evaluate has been released 10000x times before but I don't think this has been released; anyways here you go
it's something cool to have as well as it's not that hard to make
What you adding
First if you don't have wealth evaluate
Bank class
add this method
Inventory classCode:public long getBankValue() { long value = 0; for (Item bank : player.getBank().getContainerCopy()) { if (bank == null) continue; long amount = bank.getAmount(); value += bank.getDefinitions().getValue() * amount; } return value; }
add this method
Equipment classCode:public long getInventoryValue() { long value = 0; for (Item inventory : player.getInventory().getItems().toArray()) { if (inventory == null) continue; long amount = inventory.getAmount(); value += inventory.getDefinitions().getValue() * amount; } return value; }
add this method as well
Now in player classCode:public long getEquipmentValue(Player player) { long value = 0; for (Item equipment : player.getInventory().getItems().toArray()) { if (equipment == null) continue; long amount = equipment.getAmount(); value += equipment.getDefinitions().getValue() * amount; } return value; }
Add this
Code:public long getTotalWealth() { long bank = getBank().getBankValue(); long inventory = getInventory().getInventoryValue(); long equipment = getEquipment().getEquipmentValue(); long moneypouch = getMoneyPouch().getCoinsAmount(); long total = bank + inventory + equipment + moneypouch; return total; }
Utils class; add this method
Okay now you have added it all; you may let players check the top wealth by using a command ?Code:public static String getFormattedWealth(long amount) { return new DecimalFormat("#,###,###,###").format(amount); }
orCode:if (cmd[0].equalsIgnoreCase("topwealth")) { TopWealth.displayTopWealth(player); return true; }
Post below if you need anyhelp.Code:case "TopWealth": TopWealth.displayTopWealth(player); return true;
Last edited by Oldrspsown; 07-19-2021 at 05:01 PM.
looks nice, well written and thread looks clean and not all thrown together. Good job!
You should use a SortedSet with a comparator instead
When you add a player to it, it determines where in the set the player should be added depending on their total wealth.
EDIT: And you should also take advantage of the Stream#sum method that Java 8 introduced to calculate wealth!
Thank you for the release
Cool release. Nothing special coding wise, but unique and cool. Well done buddy.
P-S
I had a button that displayed your wealth in chat rather than an interface, this may be a bit easier for you rather than multiple methods;
Also i'd save it to a file, rather than just do it via who is online.Code:public long calculateNetworth() { long value = 0; for (int i = 0; i < equipment.getItems().getSize(); i++) { Item item = equipment.getItems().get(i); if (item == null) continue; long price = item.getDefinitions().getValue() * item.getAmount(); value += price; } for (int i = 0; i < inventory.getItems().getSize(); i++) { Item item = inventory.getItems().get(i); if (item == null) continue; long price = item.getDefinitions().getValue() * item.getAmount(); value += price; } // for () { // Item item = coinamount; // if (item == null) // continue; { long price = coinamount; value += price; } for (int i = 0; i < bank.getBankSize(); i++) { Item item = bank.getItem(bank.getRealSlot(i)); long price = item.getDefinitions().getValue() * item.getAmount(); value += price; } return value; }
Looks cool, thanks for release
Good work might use.
thanks
You're welcome, thank you too for the kind words
Thanks, This may also works but I think my way is a bit more accurate. Also it's true you would save it to a file but I just felt Online players will be better because once you exceed the limit of the interface lines no more players will be added or at least the wealth inter will be 24/7 filled with player names which something we don't want to happen.
Oh didn't know about that since I'm used to do it that way, even in other leader boards.. Thank you by the way .
« Previous Thread | Next Thread » |
Thread Information |
Users Browsing this ThreadThere are currently 1 users browsing this thread. (0 members and 1 guests) |