Skip to content

Commit

Permalink
Fix console spam when holding item not in shop
Browse files Browse the repository at this point in the history
Fix the console being spammed with "Shop not found" errors when holding a item not present in the shop.
  • Loading branch information
noahbclarkson committed Sep 21, 2022
1 parent d9ff9ce commit 72a66e2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
13 changes: 13 additions & 0 deletions src/main/java/unprotesting/com/github/data/ShopUtil.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package unprotesting.com.github.data;

import lombok.experimental.UtilityClass;

import java.util.Arrays;

import org.bukkit.OfflinePlayer;
import unprotesting.com.github.config.Config;

Expand Down Expand Up @@ -33,6 +36,16 @@ public String[] getShopNames() {
return shopNameCache;
}

/**
* Whether the item is in the shop.
*
* @param item The item to check.
* @return Whether the item is in the shop.
*/
public boolean isInShop(String item) {
return Arrays.asList(getSectionNames()).contains(item.toLowerCase());
}

/**
* Get the list of possible section names.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ private void checkInventory(Player player) {

for (Enchantment enchantment : item.getEnchantments().keySet()) {
String name = enchantment.getKey().getKey().toLowerCase();

if (!ShopUtil.isInShop(name)) {
continue;
}

Shop shop = getShop(name);
updateCf(name, shop, uuid);
}
Expand All @@ -64,11 +69,12 @@ private void checkInventory(Player player) {
private void runUpdate(ItemStack item, @NotNull Player player) {

String name = item.getType().toString().toLowerCase();
Shop shop = getShop(name);

if (shop == null) {
if (!ShopUtil.isInShop(name)) {
return;
}

Shop shop = getShop(name);

UUID uuid = player.getUniqueId();
updateCf(name, shop, uuid);
Expand Down

0 comments on commit 72a66e2

Please sign in to comment.