Skip to content

Commit

Permalink
Return raw null as much as possible
Browse files Browse the repository at this point in the history
yay for fallbacks
  • Loading branch information
mcmonkey4eva committed Nov 2, 2014
1 parent f69a4a7 commit ca5fc40
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 67 deletions.
54 changes: 27 additions & 27 deletions src/main/java/net/aufdemrand/denizen/objects/Element.java
Expand Up @@ -95,7 +95,7 @@ public static boolean matches(String string) {
public static dObject HandleNull(String tag, dObject object, String type) {
if (object == null) {
dB.echoError("'" + tag + "' is an invalid " + type + "!");
return Element.NULL;
return Element.NULL; // TODO: Raw null
}
return object;
}
Expand Down Expand Up @@ -844,7 +844,7 @@ else if (element.toLowerCase().contains(contains.toLowerCase()))
String regex = attribute.getContext(1);
Matcher m = Pattern.compile(regex).matcher(element);
if (!m.matches()) {
return Element.NULL.getAttribute(attribute.fulfill(2));
return null;
}
int group = new Element(attribute.getContext(2)).asInt();
if (group < 0)
Expand Down Expand Up @@ -991,7 +991,7 @@ else if (element.toLowerCase().contains(contains.toLowerCase()))
&& attribute.hasContext(1)) {
int index = attribute.getIntContext(1) - 1;
if (index < 0 || index >= element.length())
return Element.NULL.getAttribute(attribute.fulfill(1));
return null;
else
return new Element(String.valueOf(element.charAt(index)))
.getAttribute(attribute.fulfill(1));
Expand Down Expand Up @@ -1211,7 +1211,7 @@ else if (element.toLowerCase().contains(contains.toLowerCase()))
FormatScriptContainer format = ScriptRegistry.getScriptContainer(attribute.getContext(1));
if (format == null) {
dB.echoError("Could not find format script matching '" + attribute.getContext(1) + "'");
return Element.NULL.getAttribute(attribute.fulfill(1));
return null;
}
else {
return new Element(format.getFormattedText(element,
Expand Down Expand Up @@ -1405,7 +1405,7 @@ else if (element.toLowerCase().contains(contains.toLowerCase()))
if (attribute.startsWith("abs")) {
if (!isDouble()) {
dB.echoError("Element '" + element + "' is not a valid decimal number!");
return Element.NULL.getAttribute(attribute.fulfill(1));
return null;
}
return new Element(Math.abs(asDouble()))
.getAttribute(attribute.fulfill(1));
Expand All @@ -1422,7 +1422,7 @@ else if (element.toLowerCase().contains(contains.toLowerCase()))
&& attribute.hasContext(1)) {
if (!isDouble()) {
dB.echoError("Element '" + element + "' is not a valid number!");
return Element.NULL.getAttribute(attribute.fulfill(1));
return null;
}
return new Element(asLong() + aH.getLongFrom(attribute.getContext(1)))
.getAttribute(attribute.fulfill(1));
Expand All @@ -1439,7 +1439,7 @@ else if (element.toLowerCase().contains(contains.toLowerCase()))
&& attribute.hasContext(1)) {
if (!isDouble()) {
dB.echoError("Element '" + element + "' is not a valid decimal number!");
return Element.NULL.getAttribute(attribute.fulfill(1));
return null;
}
return new Element(asLong() / aH.getLongFrom(attribute.getContext(1)))
.getAttribute(attribute.fulfill(1));
Expand All @@ -1456,7 +1456,7 @@ else if (element.toLowerCase().contains(contains.toLowerCase()))
&& attribute.hasContext(1)) {
if (!isDouble()) {
dB.echoError("Element '" + element + "' is not a valid decimal number!");
return Element.NULL.getAttribute(attribute.fulfill(1));
return null;
}
return new Element(asLong() * aH.getLongFrom(attribute.getContext(1)))
.getAttribute(attribute.fulfill(1));
Expand All @@ -1473,7 +1473,7 @@ else if (element.toLowerCase().contains(contains.toLowerCase()))
&& attribute.hasContext(1)) {
if (!isDouble()) {
dB.echoError("Element '" + element + "' is not a valid decimal number!");
return Element.NULL.getAttribute(attribute.fulfill(1));
return null;
}
return new Element(asLong() - aH.getLongFrom(attribute.getContext(1)))
.getAttribute(attribute.fulfill(1));
Expand All @@ -1490,7 +1490,7 @@ else if (element.toLowerCase().contains(contains.toLowerCase()))
&& attribute.hasContext(1)) {
if (!isDouble()) {
dB.echoError("Element '" + element + "' is not a valid decimal number!");
return Element.NULL.getAttribute(attribute.fulfill(1));
return null;
}
return new Element(asBigDecimal().add(getBD(attribute.getContext(1))).toString())
.getAttribute(attribute.fulfill(1));
Expand All @@ -1507,7 +1507,7 @@ else if (element.toLowerCase().contains(contains.toLowerCase()))
&& attribute.hasContext(1)) {
if (!isDouble()) {
dB.echoError("Element '" + element + "' is not a valid decimal number!");
return Element.NULL.getAttribute(attribute.fulfill(1));
return null;
}
try {
return new Element(asBigDecimal().divide(getBD(attribute.getContext(1))).toString())
Expand All @@ -1530,7 +1530,7 @@ else if (element.toLowerCase().contains(contains.toLowerCase()))
&& attribute.hasContext(1)) {
if (!isDouble()) {
dB.echoError("Element '" + element + "' is not a valid decimal number!");
return Element.NULL.getAttribute(attribute.fulfill(1));
return null;
}
return new Element(asDouble() % aH.getDoubleFrom(attribute.getContext(1)))
.getAttribute(attribute.fulfill(1));
Expand All @@ -1547,7 +1547,7 @@ else if (element.toLowerCase().contains(contains.toLowerCase()))
&& attribute.hasContext(1)) {
if (!isDouble()) {
dB.echoError("Element '" + element + "' is not a valid decimal number!");
return Element.NULL.getAttribute(attribute.fulfill(1));
return null;
}
try {
return new Element(asBigDecimal().multiply(getBD(attribute.getContext(1))).toString())
Expand All @@ -1570,7 +1570,7 @@ else if (element.toLowerCase().contains(contains.toLowerCase()))
&& attribute.hasContext(1)) {
if (!isDouble()) {
dB.echoError("Element '" + element + "' is not a valid decimal number!");
return Element.NULL.getAttribute(attribute.fulfill(1));
return null;
}
return new Element(asBigDecimal().subtract(getBD(attribute.getContext(1))).toString())
.getAttribute(attribute.fulfill(1));
Expand All @@ -1586,7 +1586,7 @@ else if (element.toLowerCase().contains(contains.toLowerCase()))
if (attribute.startsWith("sqrt")) {
if (!isDouble()) {
dB.echoError("Element '" + element + "' is not a valid decimal number!");
return Element.NULL.getAttribute(attribute.fulfill(1));
return null;
}
return new Element(Math.sqrt(asDouble()))
.getAttribute(attribute.fulfill(1));
Expand All @@ -1609,7 +1609,7 @@ else if (element.toLowerCase().contains(contains.toLowerCase()))
&& attribute.hasContext(1)) {
if (!isDouble()) {
dB.echoError("Element '" + element + "' is not a valid decimal number!");
return Element.NULL.getAttribute(attribute.fulfill(1));
return null;
}
return new Element(Math.pow(asDouble(), aH.getDoubleFrom(attribute.getContext(1))))
.getAttribute(attribute.fulfill(1));
Expand All @@ -1631,7 +1631,7 @@ else if (element.toLowerCase().contains(contains.toLowerCase()))
if (attribute.startsWith("asin")) {
if (!isDouble()) {
dB.echoError("Element '" + element + "' is not a valid decimal number!");
return Element.NULL.getAttribute(attribute.fulfill(1));
return null;
}
return new Element(Math.asin(asDouble()))
.getAttribute(attribute.fulfill(1));
Expand All @@ -1647,7 +1647,7 @@ else if (element.toLowerCase().contains(contains.toLowerCase()))
if (attribute.startsWith("acos")) {
if (!isDouble()) {
dB.echoError("Element '" + element + "' is not a valid decimal number!");
return Element.NULL.getAttribute(attribute.fulfill(1));
return null;
}
return new Element(Math.acos(asDouble()))
.getAttribute(attribute.fulfill(1));
Expand All @@ -1663,7 +1663,7 @@ else if (element.toLowerCase().contains(contains.toLowerCase()))
if (attribute.startsWith("atan")) {
if (!isDouble()) {
dB.echoError("Element '" + element + "' is not a valid decimal number!");
return Element.NULL.getAttribute(attribute.fulfill(1));
return null;
}
return new Element(Math.atan(asDouble()))
.getAttribute(attribute.fulfill(1));
Expand All @@ -1679,7 +1679,7 @@ else if (element.toLowerCase().contains(contains.toLowerCase()))
if (attribute.startsWith("cos")) {
if (!isDouble()) {
dB.echoError("Element '" + element + "' is not a valid decimal number!");
return Element.NULL.getAttribute(attribute.fulfill(1));
return null;
}
return new Element(Math.cos(asDouble()))
.getAttribute(attribute.fulfill(1));
Expand All @@ -1695,7 +1695,7 @@ else if (element.toLowerCase().contains(contains.toLowerCase()))
if (attribute.startsWith("sin")) {
if (!isDouble()) {
dB.echoError("Element '" + element + "' is not a valid decimal number!");
return Element.NULL.getAttribute(attribute.fulfill(1));
return null;
}
return new Element(Math.sin(asDouble()))
.getAttribute(attribute.fulfill(1));
Expand All @@ -1711,7 +1711,7 @@ else if (element.toLowerCase().contains(contains.toLowerCase()))
if (attribute.startsWith("tan")) {
if (!isDouble()) {
dB.echoError("Element '" + element + "' is not a valid decimal number!");
return Element.NULL.getAttribute(attribute.fulfill(1));
return null;
}
return new Element(Math.tan(asDouble()))
.getAttribute(attribute.fulfill(1));
Expand All @@ -1727,7 +1727,7 @@ else if (element.toLowerCase().contains(contains.toLowerCase()))
if (attribute.startsWith("to_degrees")) {
if (!isDouble()) {
dB.echoError("Element '" + element + "' is not a valid decimal number!");
return Element.NULL.getAttribute(attribute.fulfill(1));
return null;
}
return new Element(Math.toDegrees(asDouble()))
.getAttribute(attribute.fulfill(1));
Expand All @@ -1743,7 +1743,7 @@ else if (element.toLowerCase().contains(contains.toLowerCase()))
if (attribute.startsWith("to_radians")) {
if (!isDouble()) {
dB.echoError("Element '" + element + "' is not a valid decimal number!");
return Element.NULL.getAttribute(attribute.fulfill(1));
return null;
}
return new Element(Math.toRadians(asDouble()))
.getAttribute(attribute.fulfill(1));
Expand All @@ -1759,7 +1759,7 @@ else if (element.toLowerCase().contains(contains.toLowerCase()))
if (attribute.startsWith("round_up")) {
if (!isDouble()) {
dB.echoError("Element '" + element + "' is not a valid decimal number!");
return Element.NULL.getAttribute(attribute.fulfill(1));
return null;
}
return new Element((int)Math.ceil(asDouble()))
.getAttribute(attribute.fulfill(1));
Expand All @@ -1775,7 +1775,7 @@ else if (element.toLowerCase().contains(contains.toLowerCase()))
if (attribute.startsWith("round_down")) {
if (!isDouble()) {
dB.echoError("Element '" + element + "' is not a valid decimal number!");
return Element.NULL.getAttribute(attribute.fulfill(1));
return null;
}
return new Element((int)Math.floor(asDouble()))
.getAttribute(attribute.fulfill(1));
Expand All @@ -1791,7 +1791,7 @@ else if (element.toLowerCase().contains(contains.toLowerCase()))
if (attribute.startsWith("round")) {
if (!isDouble()) {
dB.echoError("Element '" + element + "' is not a valid decimal number!");
return Element.NULL.getAttribute(attribute.fulfill(1));
return null;
}
return new Element((int)Math.round(asDouble()))
.getAttribute(attribute.fulfill(1));
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/net/aufdemrand/denizen/objects/dEntity.java
Expand Up @@ -1083,7 +1083,7 @@ public String getAttribute(Attribute attribute) {
return new Element(identify()).getAttribute(attribute);
}
dB.echoError("dEntity has returned null.");
return Element.NULL.getAttribute(attribute);
return null;
}

/////////////////////
Expand Down Expand Up @@ -1249,7 +1249,7 @@ public String getAttribute(Attribute attribute) {
// -->
if (attribute.startsWith("custom_name")) {
if (!isLivingEntity() || getLivingEntity().getCustomName() == null)
return Element.NULL.getAttribute(attribute.fulfill(1));
return null;
return new Element(getLivingEntity().getCustomName()).getAttribute(attribute.fulfill(1));
}

Expand All @@ -1262,7 +1262,7 @@ public String getAttribute(Attribute attribute) {
// -->
if (attribute.startsWith("custom_name.visible")) {
if (!isLivingEntity())
return Element.NULL.getAttribute(attribute.fulfill(2));
return null;
return new Element(getLivingEntity().isCustomNameVisible())
.getAttribute(attribute.fulfill(2));
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/net/aufdemrand/denizen/objects/dInventory.java
Expand Up @@ -1346,7 +1346,7 @@ public String getAttribute(Attribute attribute) {
if (location != null)
return location.getAttribute(attribute.fulfill(1));
else
return Element.NULL.getAttribute(attribute.fulfill(1));
return null;
}

// <--[tag]
Expand Down Expand Up @@ -1417,7 +1417,7 @@ public String getAttribute(Attribute attribute) {
if (attribute.startsWith("equipment")) {
dList equipment = getEquipment();
if (equipment == null)
return Element.NULL.getAttribute(attribute.fulfill(1));
return null;
else
return equipment.getAttribute(attribute.fulfill(1));
}
Expand Down Expand Up @@ -1452,7 +1452,7 @@ public String getAttribute(Attribute attribute) {
if (craftingInventory.getResult() != null)
return new dItem(craftingInventory.getResult()).getAttribute(attribute.fulfill(1));
else
return Element.NULL.getAttribute(attribute.fulfill(1));
return null;
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/main/java/net/aufdemrand/denizen/objects/dList.java
Expand Up @@ -368,7 +368,7 @@ public String getAttribute(Attribute attribute) {
}

if (index < 0)
return Element.NULL.getAttribute(attribute);
return null;

dList sub_list = new dList();

Expand Down Expand Up @@ -591,7 +591,7 @@ else if (get(n).startsWith("e@") || get(n).startsWith("n@")) {
}
else {
dB.echoError("The tag li@list.insert[...] requires an at[#] tag follow it!");
return Element.NULL.getAttribute(attribute);
return null;
}
}

Expand Down Expand Up @@ -862,7 +862,7 @@ else if (get(n).startsWith("e@") || get(n).startsWith("n@")) {
// -->
if (attribute.startsWith("first")) {
if (size() == 0)
return Element.NULL.getAttribute(attribute.fulfill(1));
return null;
else
return new Element(get(0)).getAttribute(attribute.fulfill(1));
}
Expand All @@ -878,7 +878,7 @@ else if (get(n).startsWith("e@") || get(n).startsWith("n@")) {
// -->
if (attribute.startsWith("last")) {
if (size() == 0)
return Element.NULL.getAttribute(attribute.fulfill(1));
return null;
else
return new Element(get(size() - 1)).getAttribute(attribute.fulfill(1));
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/aufdemrand/denizen/objects/dLocation.java
Expand Up @@ -713,7 +713,7 @@ else if (yaw < 315)
if (attribute.hasContext(1))
materials = dList.valueOf(attribute.getContext(1)).filter(dMaterial.class);
// Avoid NPE from invalid materials
if (materials == null) return Element.NULL.getAttribute(attribute.fulfill(2));
if (materials == null) return null;

// dB.log(materials + " " + radius + " ");
attribute.fulfill(2);
Expand Down Expand Up @@ -761,7 +761,7 @@ else if (attribute.startsWith("surface_blocks")
if (attribute.hasContext(1))
materials = dList.valueOf(attribute.getContext(1)).filter(dMaterial.class);
// Avoid NPE from invalid materials
if (materials == null) return Element.NULL.getAttribute(attribute.fulfill(2));
if (materials == null) return null;

attribute.fulfill(2);
Location loc = getBlock().getLocation().add(0.5f, 0.5f, 0.5f);
Expand Down

0 comments on commit ca5fc40

Please sign in to comment.