Skip to content

Commit

Permalink
improve entitytag identify and describe
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Dec 27, 2020
1 parent 43388bc commit 28b52c4
Showing 1 changed file with 43 additions and 16 deletions.
Expand Up @@ -32,6 +32,7 @@
import com.denizenscript.denizencore.tags.Attribute;
import com.denizenscript.denizencore.tags.TagContext;
import com.denizenscript.denizencore.utilities.CoreUtilities;
import com.denizenscript.denizencore.utilities.text.StringHolder;
import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.npc.ai.NPCHolder;
Expand Down Expand Up @@ -977,13 +978,26 @@ else if (isSpawnedOrValidForTag()) {
return "e@ " + entity.getUniqueId().toString() + "<GR>(" + entity.getType().name() + "/" + entity.getName() + ")";
}
}
if (entityScript != null) {
return "e@" + entityScript;
return identify();
}

@Override
public String savable() {
if (npc != null) {
return npc.savable();
}
if (entity_type != null) {
if (entity == null) {
return identify();
}
return "null";
if (isPlayer()) {
return getDenizenPlayer().savable();
}
else if (isFake) {
return "e@fake:" + entity.getUniqueId().toString();
}
else {
return "e@" + entity.getUniqueId().toString();
}
}

@Override
Expand All @@ -1003,22 +1017,25 @@ else if (isSpawnedOrValidForTag()) {
}
}
if (entityScript != null) {
return "e@" + entityScript;
return "e@" + entityScript + getWaitingMechanismsString();
}
if (entity_type != null) {
StringBuilder properties = new StringBuilder();
for (Mechanism mechanism : mechanisms) {
properties.append(mechanism.getName()).append("=").append(PropertyParser.escapePropertyValue(mechanism.getValue().asString())).append(";");
}
String propertyOutput = "";
if (properties.length() > 0) {
propertyOutput = "[" + properties.substring(0, properties.length() - 1) + "]";
}
return "e@" + entity_type.getLowercaseName() + propertyOutput;
return "e@" + entity_type.getLowercaseName() + getWaitingMechanismsString();
}
return "null";
}

public String getWaitingMechanismsString() {
StringBuilder properties = new StringBuilder();
for (Mechanism mechanism : mechanisms) {
properties.append(mechanism.getName()).append("=").append(PropertyParser.escapePropertyValue(mechanism.getValue().asString())).append(";");
}
if (properties.length() > 0) {
return "[" + properties.substring(0, properties.length() - 1) + "]";
}
return "";
}

@Override
public String identifySimple() {
if (npc != null && npc.isValid()) {
Expand Down Expand Up @@ -2351,13 +2368,23 @@ else if (object.getBukkitEntity() instanceof Hanging) {

// <--[tag]
// @attribute <EntityTag.describe>
// @returns ElementTag
// @returns EntityTag
// @group properties
// @description
// Returns the entity's full description, including all properties.
// -->
registerTag("describe", (attribute, object) -> {
return new ElementTag(object.describe());
ArrayList<Mechanism> waitingMechs;
if (object.isSpawnedOrValidForTag()) {
waitingMechs = new ArrayList<>();
for (Map.Entry<StringHolder, ObjectTag> property : PropertyParser.getPropertiesMap(object).map.entrySet()) {
waitingMechs.add(new Mechanism(new ElementTag(property.getKey().str), new ElementTag(property.getValue().toString())));
}
}
else {
waitingMechs = new ArrayList<>(object.getWaitingMechanisms());
}
return new EntityTag(object.entity_type, waitingMechs);
});

// <--[tag]
Expand Down

0 comments on commit 28b52c4

Please sign in to comment.