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 4ce44f74ab..a31fef84f7 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/objects/EntityTag.java +++ b/plugin/src/main/java/com/denizenscript/denizen/objects/EntityTag.java @@ -100,6 +100,7 @@ public class EntityTag implements ObjectTag, Adjustable, EntityFormObject, Flagg // "projectile" plaintext: matches for any projectile type (arrow, trident, fish hook, snowball, etc). // "hanging" plaintext: matches for any hanging type (painting, item_frame, etc). // "monster" plaintext: matches for any monster type (creepers, zombies, etc). + // "enemy" plaintext: matches for any hostile entities (zombies, shulkers, ect). // "animal" plaintext: matches for any animal type (pigs, cows, etc). // "mob" plaintext: matches for any mob type (creepers, pigs, etc). // "living" plaintext: matches for any living type (players, pigs, creepers, etc). @@ -610,6 +611,13 @@ public boolean isMonsterType() { return getBukkitEntity() instanceof Monster; } + public boolean isEnemyType() { + if (getBukkitEntity() == null && entity_type != null) { + return Enemy.class.isAssignableFrom(entity_type.getBukkitEntityType().getEntityClass()); + } + return getBukkitEntity() instanceof Enemy; + } + public boolean isMobType() { if (getBukkitEntity() == null && entity_type != null) { return Mob.class.isAssignableFrom(entity_type.getBukkitEntityType().getEntityClass()); @@ -2372,6 +2380,20 @@ else if (object.getBukkitEntity() instanceof Hanging hanging) { return new ElementTag(object.isMonsterType()); }); + if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_19)) { + + // <--[tag] + // @attribute + // @returns ElementTag(Boolean) + // @group data + // @description + // Returns whether the entity type is an enemy. See <@link url https://hub.spigotmc.org/javadocs/spigot/org/bukkit/entity/Enemy.html> + // --> + tagProcessor.registerTag(ElementTag.class, "is_enemy", (attribute, object) -> { + return new ElementTag(object.isEnemyType()); + }); + } + // <--[tag] // @attribute // @returns ElementTag(Boolean) @@ -4587,6 +4609,8 @@ public final boolean trySpecialEntityMatcher(String text, boolean isNPC) { return isMobType(); case "animal": return isAnimalType(); + case "enemy": + return isEnemyType(); } return false; }