diff --git a/src/main/java/de/epiceric/shopchest/command/ShopCommandExecutor.java b/src/main/java/de/epiceric/shopchest/command/ShopCommandExecutor.java index 4983c54..9e9ac79 100644 --- a/src/main/java/de/epiceric/shopchest/command/ShopCommandExecutor.java +++ b/src/main/java/de/epiceric/shopchest/command/ShopCommandExecutor.java @@ -2,7 +2,10 @@ package de.epiceric.shopchest.command; import java.util.ArrayList; import java.util.Collection; +import java.util.HashSet; import java.util.List; +import java.util.Set; +import java.util.UUID; import java.util.concurrent.CompletableFuture; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReference; @@ -537,6 +540,7 @@ class ShopCommandExecutor implements CommandExecutor { AtomicInteger count = new AtomicInteger(); AtomicReference buyPrice = new AtomicReference<>(0d); AtomicReference sellPrice = new AtomicReference<>(0d); + Set sellers = new HashSet<>(); plugin.getShopUtils().getShops().forEach(shop -> { if (!shop.hasItem()) { @@ -545,13 +549,22 @@ class ShopCommandExecutor implements CommandExecutor { if (!Utils.isItemSimilar(shop.getProduct().getItemStack(), item)) { return; } + if (shop.getShopType().equals(ShopType.ADMIN)) { + return; + } + sellers.add(shop.getVendor().getUniqueId()); count.getAndIncrement(); buyPrice.updateAndGet(v -> v + shop.getBuyPrice()); sellPrice.updateAndGet(v -> v + shop.getSellPrice()); }); - p.sendMessage(LanguageUtils.getMessage(Message.VALUE_OF_ITEM, new Replacement(Placeholder.AMOUNT, count.get()), new Replacement(Placeholder.BUY_PRICE, buyPrice.get()), new Replacement(Placeholder.SELL_PRICE, sellPrice.get()))); + if (count.get() == 0) { + p.sendMessage(LanguageUtils.getMessage(Message.VALUE_NO_SHOPS)); + return; + } + + p.sendMessage(LanguageUtils.getMessage(Message.VALUE_OF_ITEM, new Replacement(Placeholder.AMOUNT, sellers.size()), new Replacement(Placeholder.BUY_PRICE, buyPrice.get() / (double)count.get()), new Replacement(Placeholder.SELL_PRICE, sellPrice.get() / (double)count.get()))); } private boolean changeConfig(CommandSender sender, String[] args) { diff --git a/src/main/java/de/epiceric/shopchest/language/LanguageUtils.java b/src/main/java/de/epiceric/shopchest/language/LanguageUtils.java index 877bb83..383315a 100644 --- a/src/main/java/de/epiceric/shopchest/language/LanguageUtils.java +++ b/src/main/java/de/epiceric/shopchest/language/LanguageUtils.java @@ -2592,7 +2592,8 @@ public class LanguageUtils { messages.add(new LocalizedMessage(Message.CHANGED_CONFIG_SET, langConfig.getString("message.config.set", "&6Changed &a%PROPERTY% &6to &a%VALUE%&6."))); messages.add(new LocalizedMessage(Message.CHANGED_CONFIG_REMOVED, langConfig.getString("message.config.removed", "&6Removed &a%VALUE% &6from &a%PROPERTY%&6."))); messages.add(new LocalizedMessage(Message.CHANGED_CONFIG_ADDED, langConfig.getString("message.config.added", "&6Added &a%VALUE% &6to &a%PROPERTY%&6."))); - messages.add(new LocalizedMessage(Message.VALUE_OF_ITEM, langConfig.getString("message.valueOfItem", "&6This item is sold in &a%COUNT% &6shops for an average price of &a%SELL-PRICE%&6, and bought for &a%BUY-PRICE%."))); + messages.add(new LocalizedMessage(Message.VALUE_OF_ITEM, langConfig.getString("message.valueOfItem", "&6This item is sold by &a%COUNT% &6players for an average price of &a%SELL-PRICE%&6, and bought for &a%BUY-PRICE%."))); + messages.add(new LocalizedMessage(Message.VALUE_NO_SHOPS, langConfig.getString("message.valueNoShops", "&cNo shops are currently selling this item."))); } /** diff --git a/src/main/java/de/epiceric/shopchest/language/Message.java b/src/main/java/de/epiceric/shopchest/language/Message.java index 842b96c..fd6bcfc 100644 --- a/src/main/java/de/epiceric/shopchest/language/Message.java +++ b/src/main/java/de/epiceric/shopchest/language/Message.java @@ -97,5 +97,6 @@ public enum Message { CHANGED_CONFIG_SET, CHANGED_CONFIG_REMOVED, CHANGED_CONFIG_ADDED, - VALUE_OF_ITEM + VALUE_OF_ITEM, + VALUE_NO_SHOPS }