1919import java .util .stream .Collectors ;
2020
2121import net .brcdev .shopgui .ShopGuiPlugin ;
22+ import net .mackenziemolloy .shopguiplus .sellgui .objects .ShopItemPriceValue ;
2223import net .mackenziemolloy .shopguiplus .sellgui .utility .sirblobman .HexColorUtility ;
2324import org .apache .commons .lang3 .text .WordUtils ;
2425import org .bukkit .Bukkit ;
@@ -403,7 +404,10 @@ private void setItemDamage(ItemStack item, int damage) {
403404 private void onGuiClose (Player player , InventoryCloseEvent event , Set <Integer > ignoredSlotSet ) {
404405 int minorVersion = VersionUtility .getMinorVersion ();
405406 CommentedConfiguration configuration = this .plugin .getConfiguration ();
406-
407+
408+ // ItemStack is a stack size of 0, Integer is Price
409+ Map <ItemStack , ShopItemPriceValue > itemStackSellPriceCache = new HashMap <>();
410+
407411 Map <ItemStack , Map <Short , Integer >> soldMap2 = new HashMap <>();
408412 Map <EconomyType , Double > moneyMap = new EnumMap <>(EconomyType .class );
409413
@@ -415,28 +419,35 @@ private void onGuiClose(Player player, InventoryCloseEvent event, Set<Integer> i
415419 Inventory inventory = event .getInventory ();
416420 for (int a = 0 ; a < inventory .getSize (); a ++) {
417421 ItemStack i = inventory .getItem (a );
422+
418423 if (i == null ) continue ;
419424
420425 if (ignoredSlotSet .contains (a )) {
421426 continue ;
422427 }
423-
428+
429+ ItemStack singleItem = new ItemStack (i );
430+ singleItem .setAmount (1 );
431+
424432 itemsPlacedInGui = true ;
425- if (ShopHandler .getItemSellPrice (i , player ) > 0 ) {
433+
434+ if (itemStackSellPriceCache .getOrDefault (singleItem , new ShopItemPriceValue (null , 0.0 )).getSellPrice () > 0 || ShopHandler .getItemSellPrice (i , player ) > 0 ) {
426435 itemAmount += i .getAmount ();
427436
428437 @ Deprecated
429438 short materialDamage = i .getDurability ();
430439 int amount = i .getAmount ();
431440
432- double itemSellPrice = ShopHandler .getItemSellPrice (i , player );
441+ double itemSellPrice = itemStackSellPriceCache . containsKey ( singleItem ) ? ( itemStackSellPriceCache . get ( singleItem ). getSellPrice () * amount ) : ShopHandler .getItemSellPrice (i , player );
433442
434443 totalPrice = totalPrice + itemSellPrice ;
435444
436445 EconomyType itemEconomyType = ShopHandler .getEconomyType (i );
437446
438447 ItemStack SingleItemStack = new ItemStack (i );
439448 SingleItemStack .setAmount (1 );
449+
450+ itemStackSellPriceCache .putIfAbsent (SingleItemStack , new ShopItemPriceValue (itemEconomyType , itemSellPrice /amount ));
440451
441452 Map <Short , Integer > totalSold = soldMap2 .getOrDefault (SingleItemStack , new HashMap <>());
442453 int totalSoldCount = totalSold .getOrDefault (materialDamage , 0 );
0 commit comments