Skip to content

Commit

Permalink
entity matcher compat with unspawned ents
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Dec 23, 2021
1 parent bdc0f76 commit 37c96bc
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 18 deletions.
Expand Up @@ -1167,7 +1167,7 @@ public static boolean tryEntity(EntityTag entity, String comparedto) {
case "player":
return entity.isPlayer();
case "living":
return bEntity instanceof LivingEntity;
return entity.isLivingEntityType();
case "vehicle":
return bEntity instanceof Vehicle;
case "fish":
Expand All @@ -1177,11 +1177,11 @@ public static boolean tryEntity(EntityTag entity, String comparedto) {
case "hanging":
return bEntity instanceof Hanging;
case "monster":
return bEntity instanceof Monster;
return entity.isMonsterType();
case "mob":
return bEntity instanceof Mob;
return entity.isMobType();
case "animal":
return bEntity instanceof Animals;
return entity.isAnimalType();
}
}
if (comparedto.contains(":")) {
Expand Down
Expand Up @@ -553,7 +553,35 @@ public LivingEntity getLivingEntity() {
}

public boolean isLivingEntity() {
return (entity instanceof LivingEntity);
return entity instanceof LivingEntity;
}

public boolean isLivingEntityType() {
if (getBukkitEntity() == null && entity_type != null) {
return entity_type.getBukkitEntityType().isAlive();
}
return entity instanceof LivingEntity;
}

public boolean isMonsterType() {
if (getBukkitEntity() == null && entity_type != null) {
return Monster.class.isAssignableFrom(entity_type.getBukkitEntityType().getEntityClass());
}
return getBukkitEntity() instanceof Monster;
}

public boolean isMobType() {
if (getBukkitEntity() == null && entity_type != null) {
return Mob.class.isAssignableFrom(entity_type.getBukkitEntityType().getEntityClass());
}
return getBukkitEntity() instanceof Mob;
}

public boolean isAnimalType() {
if (getBukkitEntity() == null && entity_type != null) {
return Animals.class.isAssignableFrom(entity_type.getBukkitEntityType().getEntityClass());
}
return getBukkitEntity() instanceof Animals;
}

public boolean hasInventory() {
Expand Down Expand Up @@ -2274,10 +2302,7 @@ else if (object.getBukkitEntity() instanceof Hanging) {
// Not to be confused with the idea of being alive - see <@link tag EntityTag.is_spawned>.
// -->
tagProcessor.registerTag(ElementTag.class, "is_living", (attribute, object) -> {
if (object.getBukkitEntity() == null && object.entity_type != null) {
return new ElementTag(object.entity_type.getBukkitEntityType().isAlive());
}
return new ElementTag(object.isLivingEntity());
return new ElementTag(object.isLivingEntityType());
});

// <--[tag]
Expand All @@ -2288,10 +2313,7 @@ else if (object.getBukkitEntity() instanceof Hanging) {
// Returns whether the entity type is a hostile monster.
// -->
tagProcessor.registerTag(ElementTag.class, "is_monster", (attribute, object) -> {
if (object.getBukkitEntity() == null && object.entity_type != null) {
return new ElementTag(Monster.class.isAssignableFrom(object.entity_type.getBukkitEntityType().getEntityClass()));
}
return new ElementTag(object.getBukkitEntity() instanceof Monster);
return new ElementTag(object.isMonsterType());
});

// <--[tag]
Expand All @@ -2302,11 +2324,7 @@ else if (object.getBukkitEntity() instanceof Hanging) {
// Returns whether the entity type is a mob (Not a player or NPC).
// -->
tagProcessor.registerTag(ElementTag.class, "is_mob", (attribute, object) -> {
if (object.getBukkitEntity() == null && object.entity_type != null) {
EntityType type = object.entity_type.getBukkitEntityType();
return new ElementTag(Mob.class.isAssignableFrom(type.getEntityClass()));
}
return new ElementTag(!object.isNPC() && object.getBukkitEntity() instanceof Mob);
return new ElementTag(object.isMobType());
});

// <--[tag]
Expand Down

0 comments on commit 37c96bc

Please sign in to comment.