Skip to content

Commit

Permalink
Add <l@location.raw> tag which will return a version of a dLocation t…
Browse files Browse the repository at this point in the history
…hat will not identify as a notable location.
  • Loading branch information
davidcernat committed Nov 1, 2013
1 parent fe12f14 commit ecfacb1
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 10 deletions.
1 change: 0 additions & 1 deletion src/main/java/net/aufdemrand/denizen/objects/dEntity.java
Expand Up @@ -284,7 +284,6 @@ public dEntity(NPC npc) {
// INSTANCE FIELDS/METHODS
/////////////////


private Entity entity = null;
private EntityType entity_type = null;
private String data1 = null;
Expand Down
51 changes: 42 additions & 9 deletions src/main/java/net/aufdemrand/denizen/objects/dLocation.java
Expand Up @@ -209,6 +209,11 @@ public static boolean matches(String string) {
return m.matches();
}


/////////////////////
// CONSTRUCTORS
//////////////////

/**
* Turns a Bukkit Location into a Location, which has some helpful methods
* for working with dScript.
Expand Down Expand Up @@ -242,6 +247,19 @@ public dLocation(World world, double x, double y, double z, float yaw, float pit
super(world, x, y, z, pitch, yaw);
}


/////////////////////
// INSTANCE FIELDS/METHODS
/////////////////

// A boolean that determines whether this location will identify
// as a notable or not
private boolean raw = false;

private void setRaw(boolean state) {
this.raw = state;
}

@Override
public void setPitch(float pitch) {
super.setPitch(pitch);
Expand Down Expand Up @@ -297,7 +315,7 @@ public boolean isUnique() {

@Override
public String identify() {
if (isSaved(this))
if (!raw && isSaved(this))
return getSaved(this);
else return identifyRaw();
}
Expand All @@ -320,14 +338,6 @@ public String toString() {
public String getAttribute(Attribute attribute) {
if (attribute == null) return null;

// <--[tag]
// @attribute <l@location.get_chunk>
// @returns dChunk
// @description
// returns the chunk that this location belongs to.
// -->
if (attribute.startsWith("get_chunk"))
return new dChunk(this).getAttribute(attribute.fulfill(1));

/////////////////////
// BLOCK ATTRIBUTES
Expand Down Expand Up @@ -811,6 +821,29 @@ public int compare(dEntity ent1, dEntity ent2) {
+ "', Z '" + getZ()
+ "', in world '" + getWorld().getName() + "'").getAttribute(attribute.fulfill(1));

// <--[tag]
// @attribute <l@location.get_chunk>
// @returns dChunk
// @description
// returns the chunk that this location belongs to.
// -->
if (attribute.startsWith("get_chunk") ||
attribute.startsWith("chunk"))
return new dChunk(this).getAttribute(attribute.fulfill(1));

// <--[tag]
// @attribute <l@location.raw>
// @returns dLocation
// @description
// returns the raw representation of this location,
// ignoring any notables it might match.
// -->
if (attribute.startsWith("raw")) {
dLocation rawLocation = new dLocation(this);
rawLocation.setRaw(true);
return rawLocation.getAttribute(attribute.fulfill(1));
}

// <--[tag]
// @attribute <l@location.world>
// @returns dWorld
Expand Down

0 comments on commit ecfacb1

Please sign in to comment.