Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down Expand Up @@ -610,6 +611,13 @@ public boolean isMonsterType() {
return getBukkitEntity() instanceof Monster;
}

public boolean isEnemyType() {
Comment thread
tal5 marked this conversation as resolved.
if (getBukkitEntity() == null && entity_type != null) {
return Enemy.class.isAssignableFrom(entity_type.getBukkitEntityType().getEntityClass());
}
return getBukkitEntity() instanceof Enemy;
Comment thread
tal5 marked this conversation as resolved.
}

public boolean isMobType() {
if (getBukkitEntity() == null && entity_type != null) {
return Mob.class.isAssignableFrom(entity_type.getBukkitEntityType().getEntityClass());
Expand Down Expand Up @@ -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 <EntityTag.is_enemy>
// @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>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure the link is necessary, unless you're referencing entities that Spigot defines as "enemies"?

// -->
tagProcessor.registerTag(ElementTag.class, "is_enemy", (attribute, object) -> {
return new ElementTag(object.isEnemyType());
});
}

// <--[tag]
// @attribute <EntityTag.is_mob>
// @returns ElementTag(Boolean)
Expand Down Expand Up @@ -4587,6 +4609,8 @@ public final boolean trySpecialEntityMatcher(String text, boolean isNPC) {
return isMobType();
case "animal":
return isAnimalType();
case "enemy":
return isEnemyType();
Comment on lines +4612 to +4613

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs documentation (the "matchers" section in the EntityTag meta)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did so, though I worry it's a little confusing. Monster is a subset of Enemy but they mostly sound like the same thing, and I'm not sure how to document it more clearly without just giving a list of entities included or excluded

}
return false;
}
Expand Down