From caf90292e04381cd30e1c18888ff67c920d98589 Mon Sep 17 00:00:00 2001 From: Alex 'mcmonkey' Goodwin Date: Sat, 23 Oct 2021 04:16:09 -0700 Subject: [PATCH] material_flagged --- .../denizen/events/BukkitScriptEvent.java | 93 +++++++++++-------- 1 file changed, 52 insertions(+), 41 deletions(-) diff --git a/plugin/src/main/java/com/denizenscript/denizen/events/BukkitScriptEvent.java b/plugin/src/main/java/com/denizenscript/denizen/events/BukkitScriptEvent.java index 0c5f2955d1..fd67dfcf3c 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/events/BukkitScriptEvent.java +++ b/plugin/src/main/java/com/denizenscript/denizen/events/BukkitScriptEvent.java @@ -46,14 +46,15 @@ public abstract class BukkitScriptEvent extends ScriptEvent { // // "" usually indicates that a MaterialTag will be matched against. // This means you can specify any valid block material name, like "stone" or "air". - // You can also use "vanilla_tagged:". + // You can also use "vanilla_tagged:" or "material_flagged:". // You can also use "block" or "material" as catch-alls. // // "" or similar expects of course an ItemTag. // You can use any valid item material type like "stick", or the name of an item script, or "item" as a catch-all, or "potion" for any potion item. // Items can also be used with an "item_flagged" secondary prefix, so for an event that has "with:", you can also do "with:item_flagged:". // For item matchers that aren't switches, this works similarly, like "on player consumes item_flagged:myflag:" (note that this is not a switch). - // You can also use "vanilla_tagged:" to check vanilla tags, or "item_enchanted:" to check enchantments. + // You can also use "vanilla_tagged:" to check vanilla tags, or "material_flagged:" to check material flags (not item flags), + // or "item_enchanted:" to check enchantments. // You can also use "raw_exact:" to do an exact raw item data comparison (almost always a bad idea to use). // // "", "", "", etc. are examples of where an EntityTag will be expected. @@ -951,43 +952,48 @@ public static boolean tryItem(ItemTag item, String comparedto) { } String rawComparedTo = comparedto; comparedto = CoreUtilities.toLowerCase(comparedto); - if (comparedto.startsWith("item_flagged:")) { - for (String flag : CoreUtilities.split(rawComparedTo.substring("item_flagged:".length()), '|')) { - if (!item.getFlagTracker().hasFlag(flag)) { - return false; + if (comparedto.contains(":")) { + if (comparedto.startsWith("item_flagged:")) { + for (String flag : CoreUtilities.split(rawComparedTo.substring("item_flagged:".length()), '|')) { + if (!item.getFlagTracker().hasFlag(flag)) { + return false; + } } + return true; } - return true; - } - if (comparedto.startsWith("item_enchanted:")) { - String enchMatcher = comparedto.substring("item_enchanted:".length()); - if (!item.getItemMeta().hasEnchants()) { + else if (comparedto.startsWith("item_enchanted:")) { + String enchMatcher = comparedto.substring("item_enchanted:".length()); + if (!item.getItemMeta().hasEnchants()) { + return false; + } + for (Enchantment enchant : item.getItemMeta().getEnchants().keySet()) { + if (runGenericCheck(enchMatcher, enchant.getKey().getKey())) { + return true; + } + } return false; } - for (Enchantment enchant : item.getItemMeta().getEnchants().keySet()) { - if (runGenericCheck(enchMatcher, enchant.getKey().getKey())) { - return true; - } + else if (comparedto.startsWith("raw_exact:")) { + ItemTag compareItem = ItemTag.valueOf(rawComparedTo.substring("raw_exact:".length()), CoreUtilities.errorButNoDebugContext); + return compareItem != null && compareItem.matchesRawExact(item); } - return false; - } - if (comparedto.startsWith("raw_exact:")) { - ItemTag compareItem = ItemTag.valueOf(rawComparedTo.substring("raw_exact:".length()), CoreUtilities.errorButNoDebugContext); - return compareItem != null && compareItem.matchesRawExact(item); - } - if (comparedto.startsWith("vanilla_tagged:")) { - String tagCheck = comparedto.substring("vanilla_tagged:".length()); - HashSet tags = VanillaTagHelper.tagsByMaterial.get(item.getItemStack().getType()); - if (tags == null) { + else if (comparedto.startsWith("vanilla_tagged:")) { + String tagCheck = comparedto.substring("vanilla_tagged:".length()); + HashSet tags = VanillaTagHelper.tagsByMaterial.get(item.getItemStack().getType()); + if (tags == null) { + return false; + } + MatchHelper matcher = createMatcher(tagCheck); + for (String tag : tags) { + if (matcher.doesMatch(tag)) { + return true; + } + } return false; } - MatchHelper matcher = createMatcher(tagCheck); - for (String tag : tags) { - if (matcher.doesMatch(tag)) { - return true; - } + else if (comparedto.startsWith("material_flagged:")) { + return item.getMaterial().getFlagTracker().hasFlag(comparedto.substring("material_flagged:".length())); } - return false; } if (comparedto.equals("item")) { return true; @@ -1021,19 +1027,24 @@ public static boolean tryMaterial(Material mat, String comparedto) { if (comparedto.equals("block") || comparedto.equals("material")) { return true; } - if (comparedto.startsWith("vanilla_tagged:")) { - String tagCheck = comparedto.substring("vanilla_tagged:".length()); - HashSet tags = VanillaTagHelper.tagsByMaterial.get(mat); - if (tags == null) { + if (comparedto.contains(":")) { + if (comparedto.startsWith("vanilla_tagged:")) { + String tagCheck = comparedto.substring("vanilla_tagged:".length()); + HashSet tags = VanillaTagHelper.tagsByMaterial.get(mat); + if (tags == null) { + return false; + } + MatchHelper matcher = createMatcher(tagCheck); + for (String tag : tags) { + if (matcher.doesMatch(tag)) { + return true; + } + } return false; } - MatchHelper matcher = createMatcher(tagCheck); - for (String tag : tags) { - if (matcher.doesMatch(tag)) { - return true; - } + else if (comparedto.startsWith("material_flagged:")) { + return new MaterialTag(mat).getFlagTracker().hasFlag(comparedto.substring("material_flagged:".length())); } - return false; } MaterialTag quickOf = MaterialTag.quickOfNamed(comparedto); if (quickOf != null) {