diff --git a/src/main/java/ca/tweetzy/auctionhouse/api/auction/category/ItemCategory.java b/src/main/java/ca/tweetzy/auctionhouse/api/auction/category/ItemCategory.java index c06356f..95c1593 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/api/auction/category/ItemCategory.java +++ b/src/main/java/ca/tweetzy/auctionhouse/api/auction/category/ItemCategory.java @@ -1,7 +1,11 @@ package ca.tweetzy.auctionhouse.api.auction.category; +import ca.tweetzy.auctionhouse.api.AuctionAPI; import ca.tweetzy.auctionhouse.api.sync.Identifiable; import ca.tweetzy.flight.comp.enums.CompMaterial; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.enchantments.Enchantment; import org.bukkit.inventory.ItemStack; import java.util.HashSet; @@ -22,4 +26,164 @@ public interface ItemCategory extends Identifiable { List getConditions(); List getMaterialList(); + + default boolean doesItemMatch(final ItemStack itemStack) { + if (itemStack == null || itemStack.getType() == CompMaterial.AIR.parseMaterial() || itemStack.getAmount() == 0) return false; + boolean matches = false; + + final String itemName = AuctionAPI.getInstance().getItemName(itemStack); + final Material material = itemStack.getType(); + final String materialName = material.name(); + + + // check the material list + if (!getMaterialList().isEmpty()) { + for (CompMaterial compMaterial : getMaterialList()) { + if (compMaterial.parseMaterial() == itemStack.getType()) { + matches = true; + break; + } + } + } + + // check generic field conditions + if (!getFieldConditions().isEmpty()) { + for (CategoryFieldCondition fieldCondition : getFieldConditions()) { + switch (fieldCondition) { + case IS_EDIBLE: + if (material.isEdible() || material == Material.CAKE) + matches = true; + break; + case IS_BLOCK: + if (material.isBlock()) + matches = true; + break; + case IS_ARMOR: + if (materialName.endsWith("_HELMET") || materialName.endsWith("_CHESTPLATE") || materialName.endsWith("_LEGGINGS") || materialName.endsWith("_BOOTS")) + matches = true; + break; + case IS_TOOL: + if (materialName.endsWith("_AXE") || materialName.endsWith("_PICKAXE") || materialName.endsWith("_HOE") || materialName.endsWith("SHOVEL")) + matches = true; + break; + case IS_POTION: + if (material == CompMaterial.BREWING_STAND.parseMaterial() + || material == CompMaterial.CAULDRON.parseMaterial() + || material == CompMaterial.BLAZE_POWDER.parseMaterial() + || material == CompMaterial.POTION.parseMaterial() + || material == CompMaterial.NETHER_WART.parseMaterial() + || material == CompMaterial.REDSTONE.parseMaterial() + || material == CompMaterial.GLOWSTONE_DUST.parseMaterial() + || material == CompMaterial.FERMENTED_SPIDER_EYE.parseMaterial() + || material == CompMaterial.GUNPOWDER.parseMaterial() + || material.name().contains("DRAGONS_BREATH") || material.name().contains("DRAGON_BREATH") + || material == CompMaterial.GLISTERING_MELON_SLICE.parseMaterial() + || material == CompMaterial.MAGMA_CREAM.parseMaterial() + || material == CompMaterial.GHAST_TEAR.parseMaterial() + || material == CompMaterial.SUGAR.parseMaterial() + || material == CompMaterial.GOLDEN_CARROT.parseMaterial() + || material == CompMaterial.PUFFERFISH.parseMaterial() + || material == CompMaterial.RABBIT_FOOT.parseMaterial() + || material == CompMaterial.PHANTOM_MEMBRANE.parseMaterial() + || material == CompMaterial.SPIDER_EYE.parseMaterial() + || material == CompMaterial.SPLASH_POTION.parseMaterial()) + matches = true; + break; + case IS_WEAPON: + if (materialName.endsWith("_SWORD") || materialName.equals("BOW") || materialName.equals("TRIDENT") || materialName.equals("CROSSBOW")) + matches = true; + break; + case IS_ENCHANT: + if (material == CompMaterial.ENCHANTED_BOOK.parseMaterial()) + matches = true; + break; + } + } + } + + // check comparison conditions + if (!getConditions().isEmpty()) { + for (CategoryCondition condition : getConditions()) { + final CategoryConditionType conditionType = condition.getType(); + final CategoryStringComparison stringComparison = condition.getComparisonType(); + final String value = condition.getValue(); + + switch (stringComparison) { + case STARTS_WITH: + switch (conditionType) { + case MATERIAL: + if (materialName.startsWith(value)) matches = true; + break; + case NAME: + if (itemName.startsWith(value)) matches = true; + break; + case LORE: + // this repeats so extract probs + if (itemStack.getItemMeta() != null && itemStack.getItemMeta().getLore() != null) { + for (String line : itemStack.getItemMeta().getLore()) { + if (ChatColor.stripColor(line).startsWith(value)) { + matches = true; + break; + } + } + } + break; + } + break; + case ENDS_WITH: + switch (conditionType) { + case MATERIAL: + if (materialName.endsWith(value)) matches = true; + break; + case NAME: + if (itemName.endsWith(value)) matches = true; + break; + case LORE: + if (itemStack.getItemMeta() != null && itemStack.getItemMeta().getLore() != null) { + for (String line : itemStack.getItemMeta().getLore()) { + if (ChatColor.stripColor(line).endsWith(value)) { + matches = true; + break; + } + } + } + break; + } + break; + case CONTAINS: + switch (conditionType) { + case MATERIAL: + if (AuctionAPI.getInstance().match(value, materialName)) matches = true; + break; + case NAME: + if (AuctionAPI.getInstance().match(value, itemName)) matches = true; + break; + case LORE: + if (AuctionAPI.getInstance().matchSearch(value, AuctionAPI.getInstance().getItemLore(itemStack))) matches = true; + break; + case ENCHANTMENT: + // TODO CHECK FOR ENCHANTMENTS + break; + } + break; + case EQUALS: + break; + } + } + } + + return matches; + } } + + +// if (item == null) return false; +// ItemStack stack = item.getItem(); +// if (stack == null) return false; +// +// 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, item.getOwnerName()) +// || AuctionAPI.getInstance().matchSearch(phrase, AuctionAPI.getInstance().getItemLore(stack)) +// || AuctionAPI.getInstance().matchSearch(phrase, AuctionAPI.getInstance().getItemEnchantments(stack)); \ No newline at end of file diff --git a/src/main/java/ca/tweetzy/auctionhouse/impl/AuctionAPI.java b/src/main/java/ca/tweetzy/auctionhouse/impl/AuctionAPI.java index eec7a1e..548058b 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/impl/AuctionAPI.java +++ b/src/main/java/ca/tweetzy/auctionhouse/impl/AuctionAPI.java @@ -62,6 +62,8 @@ public final class AuctionAPI implements AuctionHouseAPI { decimalFormat.setDecimalFormatSymbols(symbols); } + currencyFormatter.setGroupingUsed(Settings.CURRENCY_USE_GROUPING.getBoolean()); + String formatted = currencyFormatter.format(number); if (Settings.CURRENCY_STRIP_ENDING_ZEROES.getBoolean()) { diff --git a/src/main/java/ca/tweetzy/auctionhouse/model/manager/CategoryManager.java b/src/main/java/ca/tweetzy/auctionhouse/model/manager/CategoryManager.java index 157b5c6..557b46f 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/model/manager/CategoryManager.java +++ b/src/main/java/ca/tweetzy/auctionhouse/model/manager/CategoryManager.java @@ -1,17 +1,17 @@ package ca.tweetzy.auctionhouse.model.manager; import ca.tweetzy.auctionhouse.AuctionHouse; -import ca.tweetzy.auctionhouse.api.auction.category.CategoryFieldCondition; -import ca.tweetzy.auctionhouse.api.auction.category.ItemCategory; +import ca.tweetzy.auctionhouse.api.auction.category.*; import ca.tweetzy.auctionhouse.api.manager.KeyValueManager; +import ca.tweetzy.auctionhouse.impl.category.AuctionCategoryCondition; import ca.tweetzy.auctionhouse.impl.category.AuctionItemCategory; +import ca.tweetzy.flight.comp.enums.CompMaterial; import ca.tweetzy.flight.utils.ChatUtil; -import ca.tweetzy.flight.utils.Common; import ca.tweetzy.flight.utils.QuickItem; +import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.YamlConfiguration; import java.io.File; -import java.util.stream.Collectors; public final class CategoryManager extends KeyValueManager { @@ -51,6 +51,16 @@ public final class CategoryManager extends KeyValueManager if (ymlFile.contains("name") && ymlFile.isString("name")) category.setName(ymlFile.getString("name", ChatUtil.capitalizeFully(categoryId))); + // material list + if (ymlFile.contains("materials") && ymlFile.isList("materials")) { + ymlFile.getStringList("materials").forEach(material -> { + final CompMaterial matchedMaterial = CompMaterial.matchCompMaterial(material).orElse(null); + if (matchedMaterial == null) return; + + category.getMaterialList().add(matchedMaterial); + }); + } + // field conditions if (ymlFile.contains("field-conditions") && ymlFile.isList("field-conditions")) { ymlFile.getStringList("field-conditions").forEach(condition -> { @@ -60,21 +70,60 @@ public final class CategoryManager extends KeyValueManager final CategoryFieldCondition fieldCondition = Enum.valueOf(CategoryFieldCondition.class, formattedCondition); category.getFieldConditions().add(fieldCondition); - } catch (IllegalArgumentException ignored) {} + } catch (IllegalArgumentException ignored) { + } }); } if (ymlFile.contains("attribute-conditions") && ymlFile.isConfigurationSection("attribute-conditions")) { - } + // grab the attrib node + final ConfigurationSection attributeConditionsNode = ymlFile.getConfigurationSection("attribute-conditions"); - AuctionHouse.getInstance().getLogger().info(String.format( - "Category: %s, icon: %s, name: %s, Field Conditions: %s", - categoryId, - category.getIcon().getType().name(), - category.getName(), - category.getFieldConditions().stream().map(Enum::name).collect(Collectors.joining(", ")) - )); + if (attributeConditionsNode != null) { + // loop through each of the first layer children since those are the condition type -> CategoryConditionType + attributeConditionsNode.getKeys(false).forEach(attributeNode -> { + + try { + // if the children name doesn't match any enumeration value skip + final String formattedAttribute = attributeNode.toUpperCase(); + final CategoryConditionType categoryCondition = Enum.valueOf(CategoryConditionType.class, formattedAttribute); + + // grab the children node then check their children to see the comparisons + final ConfigurationSection conditionNode = attributeConditionsNode.getConfigurationSection(attributeNode); + if (conditionNode != null) { + + conditionNode.getKeys(false).forEach(comparisonTypes -> { + final CategoryStringComparison stringComparison = Enum.valueOf(CategoryStringComparison.class, comparisonTypes.toUpperCase()); + + final String valuePath = String.format("attribute-conditions.%s.%s", categoryCondition.name(), stringComparison.name()); + if (!ymlFile.isSet(valuePath)) return; + + // add the values now + if (ymlFile.isList(valuePath)) { + + ymlFile.getStringList(valuePath).forEach(value -> category.getConditions().add(new AuctionCategoryCondition( + categoryCondition, + stringComparison, + value + ))); + + } else if (ymlFile.isString(valuePath)) { + category.getConditions().add(new AuctionCategoryCondition( + categoryCondition, + stringComparison, + ymlFile.getString(valuePath) + )); + } + }); + + } + + } catch (IllegalArgumentException ignored) { + } + }); + } + } } } } diff --git a/src/main/java/ca/tweetzy/auctionhouse/settings/Settings.java b/src/main/java/ca/tweetzy/auctionhouse/settings/Settings.java index 0ee5c7c..56deb23 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/settings/Settings.java +++ b/src/main/java/ca/tweetzy/auctionhouse/settings/Settings.java @@ -52,6 +52,7 @@ public class Settings { public static final ConfigSetting CURRENCY_HIDE_VAULT_SYMBOL = new ConfigSetting(config, "economy.currency.hide vault symbol", false, "Should the specified vault symbol be hidden?"); public static final ConfigSetting CURRENCY_STRIP_ENDING_ZEROES = new ConfigSetting(config, "economy.currency.strip ending zeroes", false, "If the number ends with 00, should it be stripped. EX 123.00 becomes 123"); public static final ConfigSetting CURRENCY_TIGHT_CURRENCY_SYMBOL = new ConfigSetting(config, "economy.currency.tight currency symbol", false, "If true, the space between the currency symbol and number will be removed"); + public static final ConfigSetting CURRENCY_USE_GROUPING = new ConfigSetting(config, "economy.currency.use grouping", true, "If false, number grouping will be disabled. Ex. 123,456.78 becomes 123456.78"); public static final ConfigSetting CMD_ALIAS_MAIN = new ConfigSetting(config, "command aliases.main", Arrays.asList("ah", "auctions", "auctionhouses", "ahgui", "auctiongui"), "Command aliases for the main command"); public static final ConfigSetting CMD_ALIAS_SUB_ACTIVE = new ConfigSetting(config, "command aliases.subcommands.active", Collections.singletonList("active"), "Command aliases for the active command"); diff --git a/src/main/resources/categories/food.yml b/src/main/resources/categories/food.yml new file mode 100644 index 0000000..1fbd32d --- /dev/null +++ b/src/main/resources/categories/food.yml @@ -0,0 +1,4 @@ +attribute-conditions: + NAME: + EQUALS: + - \ No newline at end of file