From a5e15155303165e789632b1d05affa907854afba Mon Sep 17 00:00:00 2001 From: mcmonkey4eva Date: Wed, 6 May 2015 16:47:50 -0700 Subject: [PATCH] element.min, max --- .../denizencore/objects/Element.java | 42 +++++++++++++++++-- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/src/main/java/net/aufdemrand/denizencore/objects/Element.java b/src/main/java/net/aufdemrand/denizencore/objects/Element.java index dc86acaa..82a06fb9 100644 --- a/src/main/java/net/aufdemrand/denizencore/objects/Element.java +++ b/src/main/java/net/aufdemrand/denizencore/objects/Element.java @@ -1299,10 +1299,44 @@ public String getAttribute(Attribute attribute) { } // <--[tag] - // @attribute ]> + // @attribute ]> // @returns Element(Decimal) // @group math // @description + // Returns the higher number: this element or the specified one. + // --> + if (attribute.startsWith("max") + && attribute.hasContext(1)) { + if (!isDouble()) { + dB.echoError("Element '" + element + "' is not a valid number!"); + return null; + } + return new Element(Math.max(asDouble(), new Element(attribute.getContext(1)).asDouble())) + .getAttribute(attribute.fulfill(1)); + } + + // <--[tag] + // @attribute ]> + // @returns Element(Decimal) + // @group math + // @description + // Returns the lower number: this element or the specified one. + // --> + if (attribute.startsWith("min") + && attribute.hasContext(1)) { + if (!isDouble()) { + dB.echoError("Element '" + element + "' is not a valid number!"); + return null; + } + return new Element(Math.min(asDouble(), new Element(attribute.getContext(1)).asDouble())) + .getAttribute(attribute.fulfill(1)); + } + + // <--[tag] + // @attribute ]> + // @returns Element(Number) + // @group math + // @description // Returns the element plus a number, using integer math. // --> if (attribute.startsWith("add_int") @@ -1317,7 +1351,7 @@ public String getAttribute(Attribute attribute) { // <--[tag] // @attribute ]> - // @returns Element(Decimal) + // @returns Element(Number) // @group math // @description // Returns the element divided by a number. @@ -1334,7 +1368,7 @@ public String getAttribute(Attribute attribute) { // <--[tag] // @attribute ]> - // @returns Element(Decimal) + // @returns Element(Number) // @group math // @description // Returns the element multiplied by a number. @@ -1351,7 +1385,7 @@ public String getAttribute(Attribute attribute) { // <--[tag] // @attribute ]> - // @returns Element(Decimal) + // @returns Element(Number) // @group math // @description // Returns the element minus a number.