From d54e69aa7772b56a3c0d1b4865dfd1565d3d4b93 Mon Sep 17 00:00:00 2001 From: jho5245 Date: Sun, 17 Nov 2019 18:28:37 +0900 Subject: [PATCH] Also changed output when clicking the shop Former-commit-id: 76192a6e577decc2ca592044c354f171507fab17 [formerly bc9ddf3c976c6d692c946c6498ca84c519388040] Former-commit-id: 8654537fc61cef7b8aa382bf32908f87c62aedd5 --- .../quickshop/Listeners/PlayerListener.java | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) 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