Skip to content

Commit

Permalink
health_data slight cleanup, and event entity match opti
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Dec 23, 2020
1 parent c2bc3fd commit e3ddf11
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 31 deletions.
Expand Up @@ -732,35 +732,37 @@ public boolean tryEntity(EntityTag entity, String comparedto) {
}
Entity bEntity = entity.getBukkitEntity();
comparedto = CoreUtilities.toLowerCase(comparedto);
if (comparedto.equals("entity")) {
return true;
}
else if (comparedto.equals("npc")) {
return entity.isCitizensNPC();
}
else if (comparedto.equals("player")) {
return entity.isPlayer();
}
else if (comparedto.equals("vehicle")) {
return bEntity instanceof Vehicle;
}
else if (comparedto.equals("fish")) {
return bEntity instanceof Fish;
}
else if (comparedto.equals("projectile")) {
return bEntity instanceof Projectile;
}
else if (comparedto.equals("hanging")) {
return bEntity instanceof 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;
if (specialEntityMatchables.contains(comparedto)) {
if (comparedto.equals("entity")) {
return true;
}
else if (comparedto.equals("npc")) {
return entity.isCitizensNPC();
}
else if (comparedto.equals("player")) {
return entity.isPlayer();
}
else if (comparedto.equals("vehicle")) {
return bEntity instanceof Vehicle;
}
else if (comparedto.equals("fish")) {
return bEntity instanceof Fish;
}
else if (comparedto.equals("projectile")) {
return bEntity instanceof Projectile;
}
else if (comparedto.equals("hanging")) {
return bEntity instanceof 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())) {
Expand Down
Expand Up @@ -30,7 +30,7 @@ public static EntityHealth getFrom(ObjectTag entity) {
}

public static final String[] handledTags = new String[] {
"health", "formatted_health", "health_max", "health_percentage"
"health", "formatted_health", "health_max", "health_percentage", "health_data"
};

public static final String[] handledMechs = new String[] {
Expand All @@ -45,7 +45,7 @@ private EntityHealth(EntityTag ent) {

@Override
public String getPropertyString() {
return entity.getLivingEntity().getHealth() + "/" + entity.getLivingEntity().getMaxHealth();
return CoreUtilities.doubleToString(entity.getLivingEntity().getHealth()) + "/" + CoreUtilities.doubleToString(entity.getLivingEntity().getMaxHealth());
}

@Override
Expand Down Expand Up @@ -142,6 +142,19 @@ public ObjectTag getObjectAttribute(Attribute attribute) {
.getObjectAttribute(attribute.fulfill(2));
}

// <--[tag]
// @attribute <EntityTag.health_data>
// @returns ElementTag)
// @mechanism EntityTag.health
// @group attributes
// @description
// Returns the current health data of the entity, in the format of current/max.
// -->
if (attribute.startsWith("health_data")) {
return new ElementTag(getPropertyString())
.getObjectAttribute(attribute.fulfill(1));
}

// <--[tag]
// @attribute <EntityTag.health>
// @returns ElementTag(Decimal)
Expand Down

0 comments on commit e3ddf11

Please sign in to comment.