Skip to content

Commit

Permalink
Fixed boolean logic parsing.
Browse files Browse the repository at this point in the history
  • Loading branch information
winsock committed Feb 10, 2015
1 parent 7b35a16 commit fa8095c
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions src/main/java/mods/quiddity/redux/ReduxCommandBlockTileEntity.java
Expand Up @@ -23,6 +23,8 @@
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.common.eventhandler.Event;

import java.text.NumberFormat;
import java.text.ParsePosition;
import java.util.*;
import java.util.regex.MatchResult;
import java.util.regex.Matcher;
Expand Down Expand Up @@ -329,15 +331,25 @@ public void receiveEvent(Event event) {
if (parsedCommand.startsWith("/stopscript")) {
String[] split = parsedCommand.split(" ");
if (split.length == 2) {
boolean stopScript = Boolean.valueOf(split[1]);
boolean stopScript;
if (isNumeric(split[1])) {
stopScript = Integer.parseInt(split[1]) != 0;
} else {
stopScript = split[1].equalsIgnoreCase("true");
}
if (stopScript)
break;
}
continue;
} else if (parsedCommand.startsWith("/stopdefault")) {
String[] split = parsedCommand.split(" ");
if (split.length == 2) {
boolean stopEvent = Boolean.valueOf(split[1]);
boolean stopEvent;
if (isNumeric(split[1])) {
stopEvent = Integer.parseInt(split[1]) != 0;
} else {
stopEvent = split[1].equalsIgnoreCase("true");
}
if (event != null && event.isCancelable())
event.setCanceled(stopEvent);
}
Expand All @@ -347,7 +359,13 @@ public void receiveEvent(Event event) {
if (split.length == 3) {
try {
int skip = Integer.parseInt(split[1]);
if (Boolean.parseBoolean(split[2]) && skip > 0)
boolean test;
if (isNumeric(split[2])) {
test = Integer.parseInt(split[2]) != 0;
} else {
test = split[2].equalsIgnoreCase("true");
}
if (test && skip > 0)
skipCount = skip;
} catch (NumberFormatException ignored) {}
}
Expand All @@ -361,4 +379,11 @@ public void receiveEvent(Event event) {
}
}
}

protected static boolean isNumeric(String str) {
NumberFormat formatter = NumberFormat.getInstance();
ParsePosition pos = new ParsePosition(0);
formatter.parse(str, pos);
return str.length() == pos.getIndex();
}
}

0 comments on commit fa8095c

Please sign in to comment.