From d42054968d76f9b46d215d5df5dbf974e39906e2 Mon Sep 17 00:00:00 2001 From: Kiran Hart Date: Thu, 3 Aug 2023 20:15:09 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=8E=20revert=20match=20regex=20for=20s?= =?UTF-8?q?earching?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Took 6 minutes --- .../ca/tweetzy/auctionhouse/api/AuctionAPI.java | 15 +++++++++++++++ .../auctionhouse/api/hook/UltraEconomyHook.java | 8 ++++---- .../auctionhouse/guis/GUIAuctionHouse.java | 12 ++++++------ 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/src/main/java/ca/tweetzy/auctionhouse/api/AuctionAPI.java b/src/main/java/ca/tweetzy/auctionhouse/api/AuctionAPI.java index dd5cc3b..1e558ff 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/api/AuctionAPI.java +++ b/src/main/java/ca/tweetzy/auctionhouse/api/AuctionAPI.java @@ -321,6 +321,21 @@ public class AuctionAPI { return matcher.find(); } + public boolean matchSearch(String pattern, String sentence) { + Pattern patt = Pattern.compile(ChatColor.stripColor(pattern), Pattern.CASE_INSENSITIVE); + Matcher matcher = patt.matcher(sentence); + return matcher.find(); + } + + public boolean matchSearch(String pattern, List lines) { + for (String line : lines) { + if (matchSearch(pattern, line)) { + return true; + } + } + return false; + } + /** * @param pattern is the keyword that you're currently searching for * @param lines is the lines being checked for the keyword diff --git a/src/main/java/ca/tweetzy/auctionhouse/api/hook/UltraEconomyHook.java b/src/main/java/ca/tweetzy/auctionhouse/api/hook/UltraEconomyHook.java index a4b4bdd..5775f7b 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/api/hook/UltraEconomyHook.java +++ b/src/main/java/ca/tweetzy/auctionhouse/api/hook/UltraEconomyHook.java @@ -53,7 +53,7 @@ public final class UltraEconomyHook extends Economy { } if (!ultraEconomyCurrencyName[0].equalsIgnoreCase("UltraEconomy")) return; - this.currency = UltraEconomy.getAPI().getCurrencies().name(ultraEconomyCurrencyName[1]).orElse(null); + this.currency = UltraEconomy.getInstance().getCurrencies().name(ultraEconomyCurrencyName[1]).orElse(null); if (this.currency == null) { throw new UltraEconomyCurrencyException("AuctionHouse could not find the currency: " + ultraEconomyCurrencyName[0]); @@ -62,7 +62,7 @@ public final class UltraEconomyHook extends Economy { @Override public double getBalance(OfflinePlayer player) { - final Account account = UltraEconomy.getAPI().getAccounts().uuid(player.getUniqueId()).orElse(null); + final Account account = UltraEconomy.getInstance().getAccounts().uuid(player.getUniqueId()).orElse(null); return account == null ? 0 : account.getBalance(this.currency).getSum(); } @@ -73,7 +73,7 @@ public final class UltraEconomyHook extends Economy { @Override public boolean withdrawBalance(OfflinePlayer player, double cost) { - final Account account = UltraEconomy.getAPI().getAccounts().uuid(player.getUniqueId()).orElse(null); + final Account account = UltraEconomy.getInstance().getAccounts().uuid(player.getUniqueId()).orElse(null); if (account == null) return false; account.removeBalance(this.currency, cost); @@ -82,7 +82,7 @@ public final class UltraEconomyHook extends Economy { @Override public boolean deposit(OfflinePlayer player, double amount) { - final Account account = UltraEconomy.getAPI().getAccounts().uuid(player.getUniqueId()).orElse(null); + final Account account = UltraEconomy.getInstance().getAccounts().uuid(player.getUniqueId()).orElse(null); if (account == null) return false; account.addBalance(this.currency, amount); diff --git a/src/main/java/ca/tweetzy/auctionhouse/guis/GUIAuctionHouse.java b/src/main/java/ca/tweetzy/auctionhouse/guis/GUIAuctionHouse.java index c4b4021..40f7806 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/guis/GUIAuctionHouse.java +++ b/src/main/java/ca/tweetzy/auctionhouse/guis/GUIAuctionHouse.java @@ -196,12 +196,12 @@ public class GUIAuctionHouse extends AbstractPlaceholderGui { private boolean checkSearchCriteria(String phrase, AuctionedItem item) { ItemStack stack = item.getItem(); - return AuctionAPI.getInstance().match(phrase, AuctionAPI.getInstance().getItemName(stack)) || - AuctionAPI.getInstance().match(phrase, item.getCategory().getTranslatedType()) || - AuctionAPI.getInstance().match(phrase, stack.getType().name()) || - AuctionAPI.getInstance().match(phrase, Bukkit.getOfflinePlayer(item.getOwner()).getName()) || - AuctionAPI.getInstance().match(phrase, AuctionAPI.getInstance().getItemLore(stack)) || - AuctionAPI.getInstance().match(phrase, AuctionAPI.getInstance().getItemEnchantments(stack)); + return AuctionAPI.getInstance().matchSearch(phrase, AuctionAPI.getInstance().getItemName(stack)) || + AuctionAPI.getInstance().matchSearch(phrase, item.getCategory().getTranslatedType()) || + AuctionAPI.getInstance().matchSearch(phrase, stack.getType().name()) || + AuctionAPI.getInstance().matchSearch(phrase, Bukkit.getOfflinePlayer(item.getOwner()).getName()) || + AuctionAPI.getInstance().matchSearch(phrase, AuctionAPI.getInstance().getItemLore(stack)) || + AuctionAPI.getInstance().matchSearch(phrase, AuctionAPI.getInstance().getItemEnchantments(stack)); } /*