Skip to content

Commit

Permalink
Can't just return 'null' anymore since the implementation of 'is' att…
Browse files Browse the repository at this point in the history
…ributes on Element.
  • Loading branch information
aufdemrand committed Nov 10, 2013
1 parent 4e20f25 commit 5ea2cd3
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 32 deletions.
1 change: 1 addition & 0 deletions src/main/java/net/aufdemrand/denizen/objects/Element.java
Expand Up @@ -46,6 +46,7 @@ public class Element implements dObject {
public final static Element TRUE = new Element(Boolean.TRUE);
public final static Element FALSE = new Element(Boolean.FALSE);
public final static Element SERVER = new Element("server");
public final static Element NULL = new Element("null");

final static Pattern VALUE_PATTERN =
Pattern.compile("el@val(?:ue)?\\[([^\\[\\]]+)\\].*",
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/aufdemrand/denizen/objects/dEntity.java
Expand Up @@ -976,7 +976,7 @@ public String getAttribute(Attribute attribute) {

if (entity == null) {
dB.echoError("dEntity has returned null.");
return "null";
return Element.NULL.getAttribute(attribute);
}

/////////////////////
Expand Down
43 changes: 22 additions & 21 deletions src/main/java/net/aufdemrand/denizen/objects/dNPC.java
Expand Up @@ -389,7 +389,7 @@ && getCitizen().getTrait(Anchors.class).getAnchor(attribute.getContext(1)) != nu
if (attribute.startsWith("has_flag")) {
String flag_name;
if (attribute.hasContext(1)) flag_name = attribute.getContext(1);
else return "null";
else return Element.NULL.getAttribute(attribute.fulfill(1));
return new Element(FlagManager.npcHasFlag(this, flag_name)).getAttribute(attribute.fulfill(1));
}

Expand All @@ -402,7 +402,7 @@ && getCitizen().getTrait(Anchors.class).getAnchor(attribute.getContext(1)) != nu
if (attribute.startsWith("flag")) {
String flag_name;
if (attribute.hasContext(1)) flag_name = attribute.getContext(1);
else return "null";
else return Element.NULL.getAttribute(attribute.fulfill(1));
attribute.fulfill(1);
if (attribute.startsWith("is_expired")
|| attribute.startsWith("isexpired"))
Expand All @@ -414,7 +414,7 @@ && getCitizen().getTrait(Anchors.class).getAnchor(attribute.getContext(1)) != nu
return new dList(DenizenAPI.getCurrentInstance().flagManager()
.getNPCFlag(getId(), flag_name))
.getAttribute(attribute);
else return "null";
else return Element.NULL.getAttribute(attribute);
}

// <--[tag]
Expand All @@ -432,7 +432,7 @@ && getCitizen().getTrait(ConstantsTrait.class).getConstant(attribute.getContext(
.getConstant(attribute.getContext(1))).getAttribute(attribute.fulfill(1));
}
else {
return "null";
return Element.NULL.getAttribute(attribute.fulfill(1));
}
}
}
Expand Down Expand Up @@ -486,7 +486,7 @@ && getCitizen().getTrait(ConstantsTrait.class).getConstant(attribute.getContext(
if (attribute.startsWith("location.previous_location"))
return (NPCTags.previousLocations.containsKey(getId())
? NPCTags.previousLocations.get(getId()).getAttribute(attribute.fulfill(2))
: "null");
: Element.NULL.getAttribute(attribute.fulfill(2)));

// <--[tag]
// @attribute <n@npc.script>
Expand All @@ -497,7 +497,7 @@ && getCitizen().getTrait(ConstantsTrait.class).getConstant(attribute.getContext(
if (attribute.startsWith("script")) {
NPC citizen = getCitizen();
if (!citizen.hasTrait(AssignmentTrait.class) || !citizen.getTrait(AssignmentTrait.class).hasAssignment()) {
return "null";
return Element.NULL.getAttribute(attribute.fulfill(1));
}
else {
return new Element(citizen.getTrait(AssignmentTrait.class).getAssignment().getName())
Expand Down Expand Up @@ -583,7 +583,7 @@ && getCitizen().getTrait(ConstantsTrait.class).getConstant(attribute.getContext(
if (attribute.startsWith("navigator.target_location"))
return (getNavigator().getTargetAsLocation() != null
? new dLocation(getNavigator().getTargetAsLocation()).getAttribute(attribute.fulfill(2))
: "null");
: Element.NULL.getAttribute(attribute.fulfill(2)));

// <--[tag]
// @attribute <n@npc.navigator.is_fighting>
Expand All @@ -602,7 +602,8 @@ && getCitizen().getTrait(ConstantsTrait.class).getConstant(attribute.getContext(
// returns the entity type of the target.
// -->
if (attribute.startsWith("navigator.target_type"))
return new Element(getNavigator().getTargetType() == null ? "null": getNavigator().getTargetType().toString())
return new Element(getNavigator().getTargetType() == null ? Element.NULL.getAttribute(attribute.fulfill(2))
: getNavigator().getTargetType().toString())
.getAttribute(attribute.fulfill(2));

// <--[tag]
Expand All @@ -614,7 +615,7 @@ && getCitizen().getTrait(ConstantsTrait.class).getConstant(attribute.getContext(
if (attribute.startsWith("navigator.target_entity"))
return (getNavigator().getEntityTarget() != null && getNavigator().getEntityTarget().getTarget() != null
? new dEntity(getNavigator().getEntityTarget().getTarget()).getAttribute(attribute.fulfill(2))
: "null");
: Element.NULL.getAttribute(attribute.fulfill(2)));

return (getEntity() != null
? new dEntity(getCitizen()).getAttribute(attribute)
Expand All @@ -627,18 +628,18 @@ public void adjust(Mechanism mechanism, Element value) {


// TODO:
// getAssignmentTrait().setAssignment();
// getAssignmentTrait().removeAssignment();
//
// getNicknameTrait().setNickname();
// getNicknameTrait().removeNickname();
//
// getCitizen().setBukkitEntityType();
// getCitizen().setName();
// getCitizen().spawn();
// getCitizen().despawn();
// getCitizen().setProtected();
// getCitizen().getTrait(LookClose.class).lookClose();
// getAssignmentTrait().setAssignment();
// getAssignmentTrait().removeAssignment();
//
// getNicknameTrait().setNickname();
// getNicknameTrait().removeNickname();
//
// getCitizen().setBukkitEntityType();
// getCitizen().setName();
// getCitizen().spawn();
// getCitizen().despawn();
// getCitizen().setProtected();
// getCitizen().getTrait(LookClose.class).lookClose();

}
}
38 changes: 28 additions & 10 deletions src/main/java/net/aufdemrand/denizen/objects/dPlayer.java
Expand Up @@ -207,9 +207,11 @@ public String toString() {

@Override
public String getAttribute(Attribute attribute) {
if (attribute == null) return "null";
if (attribute == null)
return "null";

if (player_name == null) return "null";
if (player_name == null)
return Element.NULL.getAttribute(attribute);

/////////////////////
// OFFLINE ATTRIBUTES
Expand Down Expand Up @@ -291,8 +293,10 @@ public String getAttribute(Attribute attribute) {
if (attribute.hasContext(1) && aH.matchesInteger(attribute.getContext(1)))
x = attribute.getIntContext(1);
// No playerchathistory? Return null.
if (!PlayerTags.playerChatHistory.containsKey(player_name)) return "null";
else return new Element(PlayerTags.playerChatHistory.get(player_name).get(x - 1))
if (!PlayerTags.playerChatHistory.containsKey(player_name))
return Element.NULL.getAttribute(attribute.fulfill(1));
else
return new Element(PlayerTags.playerChatHistory.get(player_name).get(x - 1))
.getAttribute(attribute.fulfill(1));
}

Expand All @@ -305,7 +309,7 @@ else return new Element(PlayerTags.playerChatHistory.get(player_name).get(x - 1)
if (attribute.startsWith("flag")) {
String flag_name;
if (attribute.hasContext(1)) flag_name = attribute.getContext(1);
else return "null";
else return Element.NULL.getAttribute(attribute.fulfill(1));
attribute.fulfill(1);
if (attribute.startsWith("is_expired")
|| attribute.startsWith("isexpired"))
Expand All @@ -317,7 +321,7 @@ else return new Element(PlayerTags.playerChatHistory.get(player_name).get(x - 1)
return new dList(DenizenAPI.getCurrentInstance().flagManager()
.getPlayerFlag(getName(), flag_name))
.getAttribute(attribute);
else return "null";
else return Element.NULL.getAttribute(attribute.fulfill(1));
}

// <--[tag]
Expand All @@ -329,11 +333,25 @@ else return new Element(PlayerTags.playerChatHistory.get(player_name).get(x - 1)
if (attribute.startsWith("has_flag")) {
String flag_name;
if (attribute.hasContext(1)) flag_name = attribute.getContext(1);
else return "null";
else return Element.NULL.getAttribute(attribute.fulfill(1));
return new Element(FlagManager.playerHasFlag(this, flag_name)).getAttribute(attribute.fulfill(1));
}


if (attribute.startsWith("current_step")) {
String outcome = "null";
if (attribute.hasContext(1)) {
try {
outcome = DenizenAPI.getCurrentInstance().getSaves().getString("Players." + getName() + ".Scripts."
+ dScript.valueOf(attribute.getContext(1)).getName() + ".Current Step");
} catch (Exception e) {
outcome = "null";
}
}
return new Element(outcome).getAttribute(attribute.fulfill(1));
}


/////////////////////
// ECONOMY ATTRIBUTES
/////////////////
Expand Down Expand Up @@ -375,7 +393,7 @@ else return new Element(PlayerTags.playerChatHistory.get(player_name).get(x - 1)

} else {
dB.echoError("No economy loaded! Have you installed Vault and a compatible economy plugin?");
return null;
return Element.NULL.getAttribute(attribute.fulfill(1));
}
}

Expand Down Expand Up @@ -573,7 +591,7 @@ else if (attribute.startsWith("list.offline")) {
if (getPlayerEntity().hasMetadata("selected"))
return getSelectedNPC()
.getAttribute(attribute.fulfill(1));
else return "null";
else return Element.NULL.getAttribute(attribute.fulfill(1));
}


Expand Down Expand Up @@ -726,7 +744,7 @@ else if (attribute.getAttribute(2).startsWith("world"))
|| attribute.startsWith("in_group")) {
if (Depends.permissions == null) {
dB.echoError("No permission system loaded! Have you installed Vault and a compatible permissions plugin?");
return "null";
return Element.NULL.getAttribute(attribute.fulfill(1));
}

String group = attribute.getContext(1);
Expand Down

0 comments on commit 5ea2cd3

Please sign in to comment.