diff --git a/src/main/java/org/maxgamer/quickshop/Listeners/PlayerListener.java b/src/main/java/org/maxgamer/quickshop/Listeners/PlayerListener.java index 927f3bbdb..143eb7a2a 100644 --- a/src/main/java/org/maxgamer/quickshop/Listeners/PlayerListener.java +++ b/src/main/java/org/maxgamer/quickshop/Listeners/PlayerListener.java @@ -18,6 +18,7 @@ import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.util.BlockIterator; +import org.maxgamer.quickshop.Economy.Economy; import org.maxgamer.quickshop.QuickShop; import org.maxgamer.quickshop.Shop.Info; import org.maxgamer.quickshop.Shop.Shop; @@ -85,16 +86,30 @@ public class PlayerListener implements Listener { // Text menu MsgUtil.sendShopInfo(p, shop); shop.setSignText(); + Economy eco = plugin.getEconomy(); + double price = shop.getPrice(); + double money = plugin.getEconomy().getBalance(p.getUniqueId()); if (shop.isSelling()) { - double price = shop.getPrice(); - double money = plugin.getEconomy().getBalance(p.getUniqueId()); int itemAmount = Math.min(Util.countSpace(p.getInventory(), shop.getItem()), (int) Math.floor(money / price)); if (!shop.isUnlimited()) { itemAmount = Math.min(itemAmount, shop.getRemainingStock()); } p.sendMessage(MsgUtil.getMessage("how-many-buy", p, "" + itemAmount)); } else { + double ownerBalance = eco.getBalance(shop.getOwner()); int items = Util.countItems(p.getInventory(), shop.getItem()); + int ownerCanAfford = (int) (ownerBalance / shop.getPrice()); + if (!shop.isUnlimited()) { + // Amount check player amount and shop empty slot + items = Math.min(items, shop.getRemainingSpace()); + // Amount check player selling item total cost and the shop owner's balance + items = Math.min(items, (int) ownerCanAfford); + } + else if (plugin.getConfig().getBoolean("shop.pay-unlimited-shop-owners")) { + // even if the shop is unlimited, the config option pay-unlimited-shop-owners is set to true, + // the unlimited shop owner should have enough money. + items = Math.min(items, (int) ownerCanAfford); + } p.sendMessage(MsgUtil.getMessage("how-many-sell", p, "" + items)); } // Add the new action