From 9a81456f9c5074e2bbecd4d890d6b876a25bedaf Mon Sep 17 00:00:00 2001 From: DaniFoldi Date: Thu, 16 Dec 2021 23:28:41 +0100 Subject: [PATCH] Fix some more bugs --- .../shopchest/command/ShopCommandExecutor.java | 9 ++++++--- .../listeners/ShopInteractListener.java | 16 ++++++++-------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/main/java/de/epiceric/shopchest/command/ShopCommandExecutor.java b/src/main/java/de/epiceric/shopchest/command/ShopCommandExecutor.java index eb80885..24787e1 100644 --- a/src/main/java/de/epiceric/shopchest/command/ShopCommandExecutor.java +++ b/src/main/java/de/epiceric/shopchest/command/ShopCommandExecutor.java @@ -547,6 +547,9 @@ class ShopCommandExecutor implements CommandExecutor { if (!shop.hasItem()) { return; } + if (sellers.contains(shop.getVendor().getUniqueId())) { + return; + } if (!Utils.isItemSimilar(shop.getProduct().getItemStack(), item)) { return; } @@ -556,11 +559,11 @@ class ShopCommandExecutor implements CommandExecutor { sellers.add(shop.getVendor().getUniqueId()); if (shop.getBuyPrice() != 0) { - buyPrice.updateAndGet(v -> v + shop.getBuyPrice()); + buyPrice.updateAndGet(v -> v + shop.getBuyPrice() / shop.getProduct().getAmount()); buyCount.getAndIncrement(); } if (shop.getSellPrice() != 0) { - sellPrice.updateAndGet(v -> v + shop.getSellPrice()); + sellPrice.updateAndGet(v -> v + shop.getSellPrice() / shop.getProduct().getAmount()); sellCount.getAndIncrement(); } }); @@ -573,7 +576,7 @@ class ShopCommandExecutor implements CommandExecutor { if (sellCount.get() == 0) { p.sendMessage(LanguageUtils.getMessage(Message.VALUE_NO_SHOPS_SELL)); } else { - p.sendMessage(LanguageUtils.getMessage(Message.VALUE_OF_ITEM_SELL, new Replacement(Placeholder.AMOUNT, sellers.size()), new Replacement(Placeholder.SELL_PRICE, sellPrice.get() / (double) buyCount.get()))); + p.sendMessage(LanguageUtils.getMessage(Message.VALUE_OF_ITEM_SELL, new Replacement(Placeholder.AMOUNT, sellers.size()), new Replacement(Placeholder.SELL_PRICE, sellPrice.get() / (double) sellCount.get()))); } } diff --git a/src/main/java/de/epiceric/shopchest/listeners/ShopInteractListener.java b/src/main/java/de/epiceric/shopchest/listeners/ShopInteractListener.java index 02b6064..6c2a50f 100644 --- a/src/main/java/de/epiceric/shopchest/listeners/ShopInteractListener.java +++ b/src/main/java/de/epiceric/shopchest/listeners/ShopInteractListener.java @@ -830,7 +830,7 @@ public class ShopInteractListener implements Listener { EconomyResponse r = econ.withdrawPlayer(executor, worldName, newPrice); if (r.transactionSuccess()) { - EconomyResponse r2 = (shop.getShopType() != ShopType.ADMIN) ? econ.depositPlayer(shop.getVendor(), worldName, newPrice * (100 - tax)) : null; + EconomyResponse r2 = (shop.getShopType() != ShopType.ADMIN) ? econ.depositPlayer(shop.getVendor(), worldName, newPrice * (100d - tax) / 100d) : null; if (r2 != null) { if (r2.transactionSuccess()) { @@ -842,7 +842,7 @@ public class ShopInteractListener implements Listener { if (event.isCancelled()) { econ.depositPlayer(executor, worldName, newPrice); - econ.withdrawPlayer(shop.getVendor(), worldName, newPrice * (100 - tax)); + econ.withdrawPlayer(shop.getVendor(), worldName, newPrice * (100d - tax) / 100d); plugin.debug("Buy event cancelled (#" + shop.getID() + ")"); return; } @@ -887,7 +887,7 @@ public class ShopInteractListener implements Listener { plugin.debug("Economy transaction failed (r2): " + r2.errorMessage + " (#" + shop.getID() + ")"); executor.sendMessage(LanguageUtils.getMessage(Message.ERROR_OCCURRED, new Replacement(Placeholder.ERROR, r2.errorMessage))); econ.withdrawPlayer(shop.getVendor(), worldName, newPrice); - econ.depositPlayer(executor, worldName, newPrice * (100 - tax)); + econ.depositPlayer(executor, worldName, newPrice * (100d - tax) / 100d); }); } } else { @@ -897,7 +897,7 @@ public class ShopInteractListener implements Listener { Bukkit.getPluginManager().callEvent(event); if (event.isCancelled()) { - econ.depositPlayer(executor, worldName, newPrice * (100 - tax)); + econ.depositPlayer(executor, worldName, newPrice * (100d - tax) / 100d); plugin.debug("Buy event cancelled (#" + shop.getID() + ")"); return; } @@ -1021,7 +1021,7 @@ public class ShopInteractListener implements Listener { int finalNewAmount = newAmount; CompletableFuture.runAsync(() -> { - EconomyResponse r = econ.depositPlayer(executor, worldName, newPrice * (100 - tax)); + EconomyResponse r = econ.depositPlayer(executor, worldName, newPrice * (100d - tax) / 100d); if (r.transactionSuccess()) { EconomyResponse r2 = (shop.getShopType() != ShopType.ADMIN) ? econ.withdrawPlayer(shop.getVendor(), worldName, newPrice) : null; @@ -1034,7 +1034,7 @@ public class ShopInteractListener implements Listener { if (event.isCancelled()) { CompletableFuture.runAsync(() -> { - econ.withdrawPlayer(executor, worldName, newPrice * (100 - tax)); + econ.withdrawPlayer(executor, worldName, newPrice * (100d - tax) / 100d); econ.depositPlayer(shop.getVendor(), worldName, newPrice); plugin.debug("Sell event cancelled (#" + shop.getID() + ")"); }); @@ -1080,7 +1080,7 @@ public class ShopInteractListener implements Listener { CompletableFuture.runAsync(() -> { plugin.debug("Economy transaction failed (r2): " + r2.errorMessage + " (#" + shop.getID() + ")"); executor.sendMessage(LanguageUtils.getMessage(Message.ERROR_OCCURRED, new Replacement(Placeholder.ERROR, r2.errorMessage))); - econ.withdrawPlayer(executor, worldName, newPrice * (100 - tax)); + econ.withdrawPlayer(executor, worldName, newPrice * (100d - tax) / 100d); econ.depositPlayer(shop.getVendor(), worldName, newPrice); }); } @@ -1091,7 +1091,7 @@ public class ShopInteractListener implements Listener { if (event.isCancelled()) { CompletableFuture.runAsync(() -> { - econ.withdrawPlayer(executor, worldName, newPrice * (100 - tax)); + econ.withdrawPlayer(executor, worldName, newPrice * (100d - tax) / 100d); plugin.debug("Sell event cancelled (#" + shop.getID() + ")"); }); return;