Skip to content

Commit

Permalink
warn on invalid use of entity flags
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Jul 30, 2015
1 parent aed4f41 commit ccdd013
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
Expand Up @@ -168,10 +168,10 @@ else if (name.equals("cause")) {
return cause;
}
else if (name.equals("damager") && damager != null) {
return damager;
return damager.getDenizenObject();
}
else if (name.equals("projectile") && projectile != null) {
return projectile;
return projectile.getDenizenObject();
}
else if (name.startsWith("damage_")) {
for (EntityDamageEvent.DamageModifier dm : EntityDamageEvent.DamageModifier.values()) {
Expand Down
36 changes: 26 additions & 10 deletions src/main/java/net/aufdemrand/denizen/objects/dEntity.java
Expand Up @@ -1404,8 +1404,16 @@ public String getAttribute(Attribute attribute) {
// -->
if (attribute.startsWith("has_flag")) {
String flag_name;
if (attribute.hasContext(1)) flag_name = attribute.getContext(1);
else return null;
if (attribute.hasContext(1)) {
flag_name = attribute.getContext(1);
}
else {
return null;
}
if (isPlayer() || isCitizensNPC()) {
dB.echoError("Reading flag for PLAYER or NPC as if it were an ENTITY!");
return null;
}
return new Element(FlagManager.entityHasFlag(this, flag_name)).getAttribute(attribute.fulfill(1));
}

Expand All @@ -1417,19 +1425,27 @@ public String getAttribute(Attribute attribute) {
// -->
if (attribute.startsWith("flag")) {
String flag_name;
if (attribute.hasContext(1)) flag_name = attribute.getContext(1);
else return null;
if (attribute.hasContext(1)) {
flag_name = attribute.getContext(1);
}
else {
return null;
}
if (isPlayer() || isCitizensNPC()) {
dB.echoError("Reading flag for PLAYER or NPC as if it were an ENTITY!");
return null;
}
if (attribute.getAttribute(2).equalsIgnoreCase("is_expired")
|| attribute.startsWith("isexpired"))
|| attribute.startsWith("isexpired")) {
return new Element(!FlagManager.entityHasFlag(this, flag_name))
.getAttribute(attribute.fulfill(2));
if (attribute.getAttribute(2).equalsIgnoreCase("size") && !FlagManager.entityHasFlag(this, flag_name))
}
if (attribute.getAttribute(2).equalsIgnoreCase("size") && !FlagManager.entityHasFlag(this, flag_name)) {
return new Element(0).getAttribute(attribute.fulfill(2));
}
if (FlagManager.entityHasFlag(this, flag_name)) {
FlagManager.Flag flag = DenizenAPI.getCurrentInstance().flagManager()
.getEntityFlag(this, flag_name);
return new dList(flag.toString(), true, flag.values())
.getAttribute(attribute.fulfill(1));
FlagManager.Flag flag = DenizenAPI.getCurrentInstance().flagManager().getEntityFlag(this, flag_name);
return new dList(flag.toString(), true, flag.values()).getAttribute(attribute.fulfill(1));
}
return new Element(identify()).getAttribute(attribute);
}
Expand Down

0 comments on commit ccdd013

Please sign in to comment.