Skip to content

Commit

Permalink
improve entity spawned check handling
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Sep 17, 2019
1 parent a310732 commit e25527e
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
Expand Up @@ -1019,8 +1019,12 @@ else if (entity == null) {

}

public boolean isSpawnedOrValidForTag() {
return entity != null && (isValidForTag() || rememberedEntities.containsKey(entity.getUniqueId()));
}

public boolean isSpawned() {
return entity != null && isValidForTag();
return entity != null && entity.isValid();
}

public boolean isValid() {
Expand Down Expand Up @@ -1173,7 +1177,7 @@ public String debuggable() {
if (isPlayer()) {
return getDenizenPlayer().debuggable();
}
if (isSpawned() || rememberedEntities.containsKey(entity.getUniqueId())) {
if (isSpawnedOrValidForTag()) {
return "e@ " + entity.getUniqueId().toString() + "<GR>(" + entity.getType().name() + "/" + entity.getName() + ")";
}
}
Expand Down Expand Up @@ -1205,7 +1209,7 @@ public String identify() {
// if (isSaved(this))
// return "e@" + getSaved(this);

else if (isSpawned() || rememberedEntities.containsKey(entity.getUniqueId())) {
else if (isSpawnedOrValidForTag()) {
return "e@" + entity.getUniqueId().toString();
}
}
Expand Down Expand Up @@ -1762,7 +1766,7 @@ else if (mtr.angle == BlockFace.EAST) {
public ObjectTag run(Attribute attribute, ObjectTag object) {
if (((EntityTag) object).isLivingEntity() && attribute.hasContext(1) && EntityTag.matches(attribute.getContext(1))) {
EntityTag toEntity = EntityTag.valueOf(attribute.getContext(1));
if (toEntity != null && toEntity.isSpawned()) {
if (toEntity != null && toEntity.isSpawnedOrValidForTag()) {
return new ElementTag(((EntityTag) object).getLivingEntity().hasLineOfSight(toEntity.getBukkitEntity())).getObjectAttribute(attribute.fulfill(1));
}
}
Expand Down Expand Up @@ -2787,7 +2791,7 @@ public static void registerSpawnedOnlyTag(String name, TagRunnable.ObjectForm ru
TagRunnable.ObjectForm newRunnable = new TagRunnable.ObjectForm() {
@Override
public ObjectTag run(Attribute attribute, ObjectTag object) {
if (!((EntityTag) object).isSpawned()) {
if (!((EntityTag) object).isSpawnedOrValidForTag()) {
if (!attribute.hasAlternative()) {
com.denizenscript.denizen.utilities.debugging.Debug.echoError("Entity is not spawned, but tag '" + attribute.getAttributeWithoutContext(1) + "' requires the entity be spawned, for entity: " + object.debuggable());
}
Expand Down
Expand Up @@ -1753,7 +1753,7 @@ public ObjectTag run(Attribute attribute, ObjectTag object) {
float yaw = 0f;
if (EntityTag.matches(context)) {
EntityTag ent = EntityTag.valueOf(context);
if (ent.isSpawned()) {
if (ent.isSpawnedOrValidForTag()) {
pitch = ent.getBukkitEntity().getLocation().getPitch();
yaw = ent.getBukkitEntity().getLocation().getYaw();
}
Expand Down
Expand Up @@ -3141,7 +3141,7 @@ public void adjust(Mechanism mechanism) {
String[] split = mechanism.getValue().asString().split("[\\|" + ListTag.internal_escape + "]", 2);
if (split.length > 0 && new ElementTag(split[0]).matchesType(EntityTag.class)) {
EntityTag entity = mechanism.valueAsType(EntityTag.class);
if (!entity.isSpawned()) {
if (!entity.isSpawnedOrValidForTag()) {
Debug.echoError("Can't hide the unspawned entity '" + split[0] + "'!");
}
else if (split.length > 1 && new ElementTag(split[1]).isBoolean()) {
Expand Down
Expand Up @@ -1531,7 +1531,7 @@ else if (attribute.startsWith("source")) {
else if (attribute.startsWith("entity_is_spawned")
&& attribute.hasContext(1)) {
EntityTag ent = EntityTag.valueOf(attribute.getContext(1), new BukkitTagContext(null, null, false, null, false, null));
event.setReplaced(new ElementTag((ent != null && ent.isUnique() && ent.isSpawned()) ? "true" : "false")
event.setReplaced(new ElementTag((ent != null && ent.isUnique() && ent.isSpawnedOrValidForTag()) ? "true" : "false")
.getAttribute(attribute.fulfill(1)));
}

Expand Down

0 comments on commit e25527e

Please sign in to comment.