extract item pre-listing requirements into meetsListingRequirements

Took 4 minutes
This commit is contained in:
Kiran Hart 2023-01-02 13:37:56 -05:00
parent 70c1cbd682
commit 2258672bf1
No known key found for this signature in database
GPG Key ID: 5F36C7BC79D3EBC3

View File

@ -64,6 +64,7 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
/**
* The current file has been created by Kiran Hart
@ -808,4 +809,44 @@ public class AuctionAPI {
return player.getName();
}
public boolean meetsListingRequirements(Player player, ItemStack itemStack) {
boolean meets = true;
if (Settings.MAKE_BLOCKED_ITEMS_A_WHITELIST.getBoolean()) {
if (!Settings.BLOCKED_ITEMS.getStringList().contains(itemStack.getType().name())) {
AuctionHouse.getInstance().getLocale().getMessage("general.blockeditem").processPlaceholder("item", itemStack.getType().name()).sendPrefixedMessage(player);
return false;
}
} else {
if (Settings.BLOCKED_ITEMS.getStringList().contains(itemStack.getType().name())) {
AuctionHouse.getInstance().getLocale().getMessage("general.blockeditem").processPlaceholder("item", itemStack.getType().name()).sendPrefixedMessage(player);
return false;
}
}
String itemName = ChatColor.stripColor(getItemName(itemStack).toLowerCase());
List<String> itemLore = getItemLore(itemStack).stream().map(line -> ChatColor.stripColor(line.toLowerCase())).collect(Collectors.toList());
// Check for blocked names and lore
for (String s : Settings.BLOCKED_ITEM_NAMES.getStringList()) {
if (match(s, itemName)) {
AuctionHouse.getInstance().getLocale().getMessage("general.blockedname").sendPrefixedMessage(player);
meets = false;
}
}
if (!itemLore.isEmpty() && meets) {
for (String s : Settings.BLOCKED_ITEM_LORES.getStringList()) {
for (String line : itemLore) {
if (match(s, line)) {
AuctionHouse.getInstance().getLocale().getMessage("general.blockedlore").sendPrefixedMessage(player);
meets = false;
}
}
}
}
return meets;
}
}