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 @@ -610,6 +610,13 @@ public boolean isMonsterType() {
return getBukkitEntity() instanceof Monster;
}

public boolean isEnemyType() {

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.

Does this need to be a separate method and not part of the tag?

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.

Added to entity matcher to match similar tags

if (getBukkitEntity() == null && entity_type != null) {
return Enemy.class.isAssignableFrom(entity_type.getBukkitEntityType().getEntityClass());
}
return getBukkitEntity() instanceof Enemy;

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.

This line should be all that's required.

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.

the entity_type check allows unspawned entities (eg, <entity[zombie].is_enemy>) to check correctly when getBukkitEntity() is null

}

public boolean isMobType() {
if (getBukkitEntity() == null && entity_type != null) {
return Mob.class.isAssignableFrom(entity_type.getBukkitEntityType().getEntityClass());
Expand Down Expand Up @@ -2372,6 +2379,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 +4608,8 @@ public final boolean trySpecialEntityMatcher(String text, boolean isNPC) {
return isMobType();
case "animal":
return isAnimalType();
case "enemy":
return isEnemyType();
}
return false;
}
Expand Down