Skip to content

Commit

Permalink
EntityTag cleanup, better Fake entity debug format
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Oct 22, 2020
1 parent 8541fc8 commit 06732f6
Showing 1 changed file with 9 additions and 47 deletions.
Expand Up @@ -186,9 +186,7 @@ public static EntityTag valueOf(String string, TagContext context) {
}
// Choose a random entity type if "RANDOM" is used
if (string.equalsIgnoreCase("RANDOM")) {

EntityType randomType = null;

// When selecting a random entity type, ignore invalid or inappropriate ones
while (randomType == null ||
randomType.name().matches("^(COMPLEX_PART|DROPPED_ITEM|ENDER_CRYSTAL" +
Expand All @@ -197,7 +195,6 @@ public static EntityTag valueOf(String string, TagContext context) {

randomType = EntityType.values()[CoreUtilities.getRandom().nextInt(EntityType.values().length)];
}

return new EntityTag(randomType, "RANDOM");
}
if (string.startsWith("e@fake:")) {
Expand Down Expand Up @@ -229,8 +226,7 @@ public static EntityTag valueOf(String string, TagContext context) {
}
}
else {
Debug.echoError("NPC '" + string
+ "' does not exist!");
Debug.echoError("NPC '" + string + "' does not exist!");
}
}
// Player entity
Expand Down Expand Up @@ -980,7 +976,10 @@ public String debuggable() {
if (isPlayer()) {
return getDenizenPlayer().debuggable();
}
if (isSpawnedOrValidForTag()) {
else if (isFake) {
return "e@FAKE: " + entity.getUniqueId().toString() + "<GR>(FAKE-" + entity.getType().name() + "/" + entity.getName() + ")";
}
else if (isSpawnedOrValidForTag()) {
return "e@ " + entity.getUniqueId().toString() + "<GR>(" + entity.getType().name() + "/" + entity.getName() + ")";
}
}
Expand All @@ -995,40 +994,24 @@ public String debuggable() {

@Override
public String identify() {

// Check if entity is an NPC
if (npc != null) {
return npc.identify();
}

// Check if entity is a Player or is spawned
if (entity != null) {
if (isPlayer()) {
return getDenizenPlayer().identify();
}

// TODO:
// Check if entity is a 'notable entity'
// if (isSaved(this))
// return "e@" + getSaved(this);

else if (isSpawnedOrValidForTag()) {
return "e@" + entity.getUniqueId().toString();
}

else if (isFake) {
return "e@fake:" + entity.getUniqueId().toString();
}
else if (isSpawnedOrValidForTag()) {
return "e@" + entity.getUniqueId().toString();
}
}

// Try to identify as an entity script
if (entityScript != null) {
return "e@" + entityScript;
}

// Check if an entity_type is available
if (entity_type != null) {
// Build the pseudo-property-string, if any
StringBuilder properties = new StringBuilder();
for (Mechanism mechanism : mechanisms) {
properties.append(mechanism.getName()).append("=").append(PropertyParser.escapePropertyValue(mechanism.getValue().asString())).append(";");
Expand All @@ -1039,47 +1022,26 @@ else if (isFake) {
}
return "e@" + entity_type.getLowercaseName() + propertyOutput;
}

return "null";
}

@Override
public String identifySimple() {

// Check if entity is an NPC
if (npc != null && npc.isValid()) {
return "n@" + npc.getId();
}

if (isPlayer()) {
return "p@" + getPlayer().getName();
}

// Try to identify as an entity script
if (entityScript != null) {
return "e@" + entityScript;
}

// Check if an entity_type is available
if (entity_type != null) {
return "e@" + entity_type.getLowercaseName();
}

return "null";
}

public String identifyType() {
if (isCitizensNPC()) {
return "npc";
}
else if (isPlayer()) {
return "player";
}
else {
return "e@" + entity_type.getName();
}
}

public String identifySimpleType() {
if (isCitizensNPC()) {
return "npc";
Expand All @@ -1100,7 +1062,7 @@ public String toString() {
@Override
public boolean isUnique() {
return isPlayer() || isCitizensNPC() || isSpawned() || isLivingEntity()
|| (entity != null && rememberedEntities.containsKey(entity.getUniqueId())); // || isSaved()
|| (entity != null && rememberedEntities.containsKey(entity.getUniqueId())) || isFake; // || isSaved()
}

public boolean matchesEntity(String ent) {
Expand Down

0 comments on commit 06732f6

Please sign in to comment.