From 1251c4a3c190811a7bb8519ffff8a684775d783a Mon Sep 17 00:00:00 2001 From: mcmonkey4eva Date: Fri, 15 Nov 2013 21:40:44 -0800 Subject: [PATCH] Fix 'matches integer' comparable Integers and doubles are different: Keep them separate (Until mathematical comparison)! Before this fix, 'if 3 matches integer' would fail because it reads '3' as '3.0' --- .../scripts/commands/core/Comparable.java | 26 ++++++++++++++----- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/src/main/java/net/aufdemrand/denizen/scripts/commands/core/Comparable.java b/src/main/java/net/aufdemrand/denizen/scripts/commands/core/Comparable.java index 2d810f222e..6042f6d310 100644 --- a/src/main/java/net/aufdemrand/denizen/scripts/commands/core/Comparable.java +++ b/src/main/java/net/aufdemrand/denizen/scripts/commands/core/Comparable.java @@ -71,7 +71,9 @@ public void setOperator(Operator operator) { public void setComparable(String arg) { // If a Number - if (aH.matchesDouble(arg) || aH.matchesInteger(arg)) + if (aH.matchesInteger(arg)) + comparable = aH.getIntegerFrom(arg); + else if (aH.matchesDouble(arg)) comparable = aH.getDoubleFrom(arg); // If a Boolean @@ -100,8 +102,10 @@ public void setComparedto(String arg) { comparedto = arg; // Comparable is a Number, return Double - else if (comparable instanceof Double) { - if (aH.matchesDouble(arg) || aH.matchesInteger(arg)) + else if (comparable instanceof Double || comparable instanceof Integer) { + if (aH.matchesInteger(arg)) + comparedto = aH.getIntegerFrom(arg); + else if (aH.matchesDouble(arg)) comparedto = aH.getDoubleFrom(arg); else { dB.log(ChatColor.YELLOW + "WARNING! " + ChatColor.WHITE + "Cannot compare NUMBER(" @@ -144,8 +148,8 @@ else if (comparable instanceof dList) { compare_as_list(); } - else if (comparable instanceof Double) { - if (comparedto instanceof Double) { + else if (comparable instanceof Double || comparable instanceof Integer) { + if (comparedto instanceof Double || comparedto instanceof Integer) { compare_as_numbers(); } } @@ -169,8 +173,16 @@ private void compare_as_numbers() { outcome = false; - Double comparable = (Double) this.comparable; - Double comparedto = (Double) this.comparedto; + Double comparable; + if (this.comparable instanceof Double) + comparable = (Double) this.comparable; + else + comparable = ((Integer) this.comparable).doubleValue(); + Double comparedto; + if (this.comparedto instanceof Double) + comparedto = (Double) this.comparedto; + else + comparedto = ((Integer) this.comparedto).doubleValue(); switch(operator) {