Skip to content

Commit

Permalink
Reorganize Element
Browse files Browse the repository at this point in the history
(To fix a bug. Gotta be careful with tiny tag names like 'sub'!)
  • Loading branch information
mcmonkey4eva committed Sep 15, 2013
1 parent 30687b6 commit c5caf34
Showing 1 changed file with 89 additions and 90 deletions.
179 changes: 89 additions & 90 deletions src/main/java/net/aufdemrand/denizen/objects/Element.java
Expand Up @@ -342,7 +342,7 @@ public String getAttribute(Attribute attribute) {
return new Element(prefix)
.getAttribute(attribute.fulfill(1));


/////////////////////
// INITIALIZATION ATTRIBUTES
/////////////////
Expand All @@ -358,7 +358,7 @@ public String getAttribute(Attribute attribute) {
return new Element(Double.valueOf(attribute.getContext(1)))
.getAttribute(attribute.fulfill(1));
}

// <--[tag]
// @attribute <element.int[<#>]>
// @returns Element(Integer)
Expand All @@ -371,93 +371,6 @@ public String getAttribute(Attribute attribute) {
return new Element(Math.round(Double.valueOf(attribute.getContext(1))))
.getAttribute(attribute.fulfill(1));
}


/////////////////////
// MATH ATTRIBUTES
/////////////////

// <--[tag]
// @attribute <element.abs>
// @returns Element(Number)
// @description
// Returns the absolute value of the element.
// -->
if (attribute.startsWith("abs")) {
return new Element(Math.abs(asDouble()))
.getAttribute(attribute.fulfill(1));
}

// <--[tag]
// @attribute <element.add[<#>]>
// @returns Element(Number)
// @description
// Returns the element plus a number.
// -->
if (attribute.startsWith("add")
&& attribute.hasContext(1)) {
return new Element(asDouble() + aH.getDoubleFrom(attribute.getContext(1)))
.getAttribute(attribute.fulfill(1));
}

// <--[tag]
// @attribute <element.div[<#>]>
// @returns Element(Number)
// @description
// Returns the element divided by a number.
// -->
if (attribute.startsWith("div")
&& attribute.hasContext(1)) {
return new Element(asDouble() / aH.getDoubleFrom(attribute.getContext(1)))
.getAttribute(attribute.fulfill(1));
}

// <--[tag]
// @attribute <element.mod[<#>]>
// @returns Element(Number)
// @description
// Returns the remainder of the element divided by a number.
// -->
if (attribute.startsWith("mod")
&& attribute.hasContext(1)) {
return new Element(asDouble() % aH.getDoubleFrom(attribute.getContext(1)))
.getAttribute(attribute.fulfill(1));
}

// <--[tag]
// @attribute <element.mul[<#>]>
// @returns Element(Number)
// @description
// Returns the element multiplied by a number.
// -->
if (attribute.startsWith("mul")
&& attribute.hasContext(1)) {
return new Element(asDouble() * aH.getDoubleFrom(attribute.getContext(1)))
.getAttribute(attribute.fulfill(1));
}

// <--[tag]
// @attribute <element.sqrt>
// @returns Element(Number)
// @description
// Returns the square root of the element.
// -->
if (attribute.startsWith("sqrt")) {
return new Element(Math.sqrt(asDouble()))
.getAttribute(attribute.fulfill(1));
}

// <--[tag]
// @attribute <element.sub[<#>]>
// @returns Element(Number)
// @description
// Returns the element minus a number.
// -->
if (attribute.startsWith("sub")
&& attribute.hasContext(1)) {
return new Element(asDouble() - aH.getDoubleFrom(attribute.getContext(1)))
.getAttribute(attribute.fulfill(1));
}


/////////////////////
Expand Down Expand Up @@ -627,7 +540,6 @@ else if (element.toLowerCase().contains(contains.toLowerCase()))
if (attribute.startsWith("strip_color"))
return new Element(ChatColor.stripColor(element)).getAttribute(attribute.fulfill(1));


// <--[tag]
// @attribute <element.substring[<#>(,<#>)]>
// @returns Element
Expand All @@ -648,6 +560,93 @@ else if (element.toLowerCase().contains(contains.toLowerCase()))
}


/////////////////////
// MATH ATTRIBUTES
/////////////////

// <--[tag]
// @attribute <element.abs>
// @returns Element(Number)
// @description
// Returns the absolute value of the element.
// -->
if (attribute.startsWith("abs")) {
return new Element(Math.abs(asDouble()))
.getAttribute(attribute.fulfill(1));
}

// <--[tag]
// @attribute <element.add[<#>]>
// @returns Element(Number)
// @description
// Returns the element plus a number.
// -->
if (attribute.startsWith("add")
&& attribute.hasContext(1)) {
return new Element(asDouble() + aH.getDoubleFrom(attribute.getContext(1)))
.getAttribute(attribute.fulfill(1));
}

// <--[tag]
// @attribute <element.div[<#>]>
// @returns Element(Number)
// @description
// Returns the element divided by a number.
// -->
if (attribute.startsWith("div")
&& attribute.hasContext(1)) {
return new Element(asDouble() / aH.getDoubleFrom(attribute.getContext(1)))
.getAttribute(attribute.fulfill(1));
}

// <--[tag]
// @attribute <element.mod[<#>]>
// @returns Element(Number)
// @description
// Returns the remainder of the element divided by a number.
// -->
if (attribute.startsWith("mod")
&& attribute.hasContext(1)) {
return new Element(asDouble() % aH.getDoubleFrom(attribute.getContext(1)))
.getAttribute(attribute.fulfill(1));
}

// <--[tag]
// @attribute <element.mul[<#>]>
// @returns Element(Number)
// @description
// Returns the element multiplied by a number.
// -->
if (attribute.startsWith("mul")
&& attribute.hasContext(1)) {
return new Element(asDouble() * aH.getDoubleFrom(attribute.getContext(1)))
.getAttribute(attribute.fulfill(1));
}

// <--[tag]
// @attribute <element.sqrt>
// @returns Element(Number)
// @description
// Returns the square root of the element.
// -->
if (attribute.startsWith("sqrt")) {
return new Element(Math.sqrt(asDouble()))
.getAttribute(attribute.fulfill(1));
}

// <--[tag]
// @attribute <element.sub[<#>]>
// @returns Element(Number)
// @description
// Returns the element minus a number.
// -->
if (attribute.startsWith("sub")
&& attribute.hasContext(1)) {
return new Element(asDouble() - aH.getDoubleFrom(attribute.getContext(1)))
.getAttribute(attribute.fulfill(1));
}


// Unfilled attributes past this point probably means the tag is spelled
// incorrectly. So instead of just passing through what's been resolved
// so far, 'null' shall be returned with an error message.
Expand Down

0 comments on commit c5caf34

Please sign in to comment.