Updated
|
Cba to show pictures and stuff, just do a trade or open the price checker, and offer stuff over the integer max value..
It overflows becoming negative, and so on, this fixes it pretty much completely.
Still has a chance to overflow with a long, but common, 9 quintillion?
In the ItemContainer class, replace your #getTotalValue method with this one;
Code:/** * Gets the total wealth of this container's items as a string. * @return */ public String getTotalValue() { int totalValue = 0; for(Item item : getValidItems()) { final long itemValues = item.getDefinition().getValue(); if (itemValues + itemValues >= Integer.MAX_VALUE || itemValues + itemValues <= -1) return "Too High!"; if (totalValue + itemValues >= Integer.MAX_VALUE || totalValue + itemValues <= -1) return "Too High!"; if (itemValues * item.getAmount() >= Integer.MAX_VALUE || itemValues * item.getAmount() <= -1) return "Too High!"; else totalValue += item.getDefinition().getValue() * item.getAmount(); } return Misc.format(totalValue); }
Updated
Thanks for the share.
Thanks for this
« Previous Thread | Next Thread » |
Thread Information |
Users Browsing this ThreadThere are currently 1 users browsing this thread. (0 members and 1 guests) |