From 0cd59d7e86b2b20cd167f372c747a093dd850751 Mon Sep 17 00:00:00 2001 From: Alex 'mcmonkey' Goodwin Date: Tue, 13 Apr 2021 18:51:40 -0700 Subject: [PATCH] EntityTag.has_equipped --- .../denizen/objects/EntityTag.java | 30 +++++++++++++++++-- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/plugin/src/main/java/com/denizenscript/denizen/objects/EntityTag.java b/plugin/src/main/java/com/denizenscript/denizen/objects/EntityTag.java index e244eef22e..81afe61d42 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/objects/EntityTag.java +++ b/plugin/src/main/java/com/denizenscript/denizen/objects/EntityTag.java @@ -2368,7 +2368,7 @@ else if (object.getBukkitEntity() instanceof Hanging) { // Returns whether the entity is currently disguised, either globally (if no context input given), or to the specified player. // Relates to <@link command disguise>. // --> - registerTag("is_disguised", (attribute, object) -> { + registerSpawnedOnlyTag("is_disguised", (attribute, object) -> { HashMap map = DisguiseCommand.disguises.get(object.getUUID()); if (map == null) { return new ElementTag(false); @@ -2394,7 +2394,7 @@ else if (object.getBukkitEntity() instanceof Hanging) { // Returns the entity type the entity is disguised as, either globally (if no context input given), or to the specified player. // Relates to <@link command disguise>. // --> - registerTag("disguised_type", (attribute, object) -> { + registerSpawnedOnlyTag("disguised_type", (attribute, object) -> { HashMap map = DisguiseCommand.disguises.get(object.getUUID()); if (map == null) { return null; @@ -2428,7 +2428,7 @@ else if (object.getBukkitEntity() instanceof Hanging) { // Returns the fake entity used to disguise the entity in other's views, either globally (if no context input given), or to the specified player. // Relates to <@link command disguise>. // --> - registerTag("disguise_to_others", (attribute, object) -> { + registerSpawnedOnlyTag("disguise_to_others", (attribute, object) -> { HashMap map = DisguiseCommand.disguises.get(object.getUUID()); if (map == null) { return null; @@ -2491,6 +2491,30 @@ else if (object.getBukkitEntity() instanceof Hanging) { } return new ElementTag(BukkitScriptEvent.tryEntity(object, attribute.getContext(1))); }); + + // <--[tag] + // @attribute ]> + // @returns ElementTag(Boolean) + // @group element checking + // @description + // Returns whether the entity has any armor equipment item that matches the given item matcher, using the system behind <@link language Advanced Script Event Matching>. + // For example, has_equipped[diamond_*] will return true if the entity is wearing at least one piece of diamond armor. + // --> + registerSpawnedOnlyTag("has_equipped", (attribute, object) -> { + if (!attribute.hasContext(1)) { + return null; + } + if (!object.isLivingEntity()) { + return null; + } + String matcher = attribute.getContext(1); + for (ItemStack item : object.getLivingEntity().getEquipment().getArmorContents()) { + if (BukkitScriptEvent.tryItem(new ItemTag(item), matcher)) { + return new ElementTag(true); + } + } + return new ElementTag(false); + }); } public static ObjectTagProcessor tagProcessor = new ObjectTagProcessor<>();