Skip to content

Commit

Permalink
add 'mob' and 'animal' entity matchers
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Aug 15, 2020
1 parent 61ddc6a commit 9136231
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
Expand Up @@ -43,7 +43,8 @@ public abstract class BukkitScriptEvent extends ScriptEvent {
// "<entity>", "<projectile>", "<vehicle>", etc. are examples of where an EntityTag will be expected.
// You can generally specify any potentially relevant entity type, such as "creeper" under "<entity>", or "arrow" for "<projectile>",
// but you can also specify "entity" (catch-all), "player" (real players, NOT player-type NPCs), "npc" (Citizens NPC),
// "vehicle" (minecarts, boats, horses, etc), "fish" (cod, pufferfish, etc), "projectile" (arrow, trident, etc), "hanging" (painting, item_frame, etc), "monster".
// "vehicle" (minecarts, boats, horses, etc), "fish" (cod, pufferfish, etc), "projectile" (arrow, trident, etc), "hanging" (painting, item_frame, etc),
// "monster" (creepers, zombies, etc), "animals" (pigs, cows, etc), "mob" (creepers, pigs, etc).
//
// "<item>" or similar expects of course an ItemTag.
// You can use any valid item material type like "stick", or the name of an item script, or "item" as a catch-all, or "potion" for any potion item.
Expand Down Expand Up @@ -104,7 +105,7 @@ public boolean couldMatchInventory(String text) {
return genericCouldMatchChecks(text, this::couldMatchInventory);
}

public static HashSet<String> specialEntityMatchables = new HashSet<>(Arrays.asList("player", "entity", "npc", "vehicle", "fish", "projectile", "hanging", "monster"));
public static HashSet<String> specialEntityMatchables = new HashSet<>(Arrays.asList("player", "entity", "npc", "vehicle", "fish", "projectile", "hanging", "monster", "mob", "animal"));

public boolean couldMatchEntity(String text) {
if (specialEntityMatchables.contains(text)) {
Expand Down Expand Up @@ -759,6 +760,12 @@ else if (comparedto.equals("hanging")) {
else if (comparedto.equals("monster")) {
return bEntity instanceof Monster;
}
else if (comparedto.equals("mob")) {
return bEntity instanceof Mob;
}
else if (comparedto.equals("animal")) {
return bEntity instanceof Animals;
}
MatchHelper matcher = createMatcher(comparedto);
if (entity.getEntityScript() != null && matcher.doesMatch(entity.getEntityScript())) {
return true;
Expand Down
Expand Up @@ -2260,9 +2260,9 @@ else if (object.getBukkitEntity() instanceof Hanging) {
registerTag("is_mob", (attribute, object) -> {
if (object.entity == null && object.entity_type != null) {
EntityType type = object.entity_type.getBukkitEntityType();
return new ElementTag(type != EntityType.PLAYER && LivingEntity.class.isAssignableFrom(type.getEntityClass()));
return new ElementTag(Mob.class.isAssignableFrom(type.getEntityClass()));
}
return new ElementTag(!object.isPlayer() && !object.isNPC() && object.isLivingEntity());
return new ElementTag(!object.isNPC() && object.getBukkitEntity() instanceof Mob);
});

// <--[tag]
Expand Down

0 comments on commit 9136231

Please sign in to comment.