if (stop != null && stop.asBoolean()) {
// Report to dB
dB.report(scriptEntry, getName(), stop.debug());
boolean hasnext = false;
for (int i = 0; i < scriptEntry.getResidingQueue().getQueueSize(); i++) {
ScriptEntry entry = scriptEntry.getResidingQueue().getEntry(i);
List<String> args = entry.getOriginalArguments();
if (entry.getCommandName().equalsIgnoreCase("while") && args.size() > 0 && args.get(0).equalsIgnoreCase("\0CALLBACK")) {
hasnext = true;
break;
}
}
if (hasnext) {
while (scriptEntry.getResidingQueue().getQueueSize() > 0) {
ScriptEntry entry = scriptEntry.getResidingQueue().getEntry(0);
List<String> args = entry.getOriginalArguments();
if (entry.getCommandName().equalsIgnoreCase("while") && args.size() > 0 && args.get(0).equalsIgnoreCase("\0CALLBACK")) {
scriptEntry.getResidingQueue().removeEntry(0);
break;
}
scriptEntry.getResidingQueue().removeEntry(0);
}
}
else {
dB.echoError(scriptEntry.getResidingQueue(), "Cannot stop while: not in one!");
}
return;
}
else if (next != null && next.asBoolean()) {
// Report to dB
dB.report(scriptEntry, getName(), next.debug());
boolean hasnext = false;
for (int i = 0; i < scriptEntry.getResidingQueue().getQueueSize(); i++) {
ScriptEntry entry = scriptEntry.getResidingQueue().getEntry(i);
List<String> args = entry.getOriginalArguments();
if (entry.getCommandName().equalsIgnoreCase("while") && args.size() > 0 && args.get(0).equalsIgnoreCase("\0CALLBACK")) {
hasnext = true;
break;
}
}
if (hasnext) {
while (scriptEntry.getResidingQueue().getQueueSize() > 0) {
ScriptEntry entry = scriptEntry.getResidingQueue().getEntry(0);
List<String> args = entry.getOriginalArguments();
if (entry.getCommandName().equalsIgnoreCase("while") && args.size() > 0 && args.get(0).equalsIgnoreCase("\0CALLBACK")) {
break;
}
scriptEntry.getResidingQueue().removeEntry(0);
}
}
else {
dB.echoError(scriptEntry.getResidingQueue(), "Cannot stop while: not in one!");
}
return;
}
else if (callback != null && callback.asBoolean()) {
if (scriptEntry.getOwner() != null && (scriptEntry.getOwner().getCommandName().equalsIgnoreCase("while") ||
scriptEntry.getOwner().getBracedSet() == null || scriptEntry.getOwner().getBracedSet().size() == 0 ||
scriptEntry.getBracedSet().get("WHILE").get(scriptEntry.getBracedSet().get("WHILE").size() - 1) != scriptEntry)) {
WhileData data = (WhileData)scriptEntry.getOwner().getData();
data.index++;
if (System.currentTimeMillis() - data.LastChecked < 50) {
data.instaTicks++;
int max = Settings.whileMaxLoops();
if (data.instaTicks > max && max != 0)
return;
}
else {
data.instaTicks = 0;
}
data.LastChecked = System.currentTimeMillis();
if (TagManager.tag(((BukkitScriptEntryData)scriptEntry.entryData).getPlayer(), ((BukkitScriptEntryData)scriptEntry.entryData).getNPC(),
data.value, false, scriptEntry).equalsIgnoreCase("true")) {
dB.echoDebug(scriptEntry, dB.DebugElement.Header, "While loop " + data.index);
scriptEntry.getResidingQueue().addDefinition("loop_index", String.valueOf(data.index));
ArrayList<ScriptEntry> bracedCommands = BracedCommand.getBracedCommands(scriptEntry.getOwner()).get("WHILE");
ScriptEntry callbackEntry = null;
try {
callbackEntry = new ScriptEntry("WHILE", new String[] { "\0CALLBACK" },
(scriptEntry.getScript() != null ? scriptEntry.getScript().getContainer(): null));
callbackEntry.copyFrom(scriptEntry);
}
catch (ScriptEntryCreationException e) {
dB.echoError(scriptEntry.getResidingQueue(), e);
}
callbackEntry.setOwner(scriptEntry.getOwner());
bracedCommands.add(callbackEntry);
for (int i = 0; i < bracedCommands.size(); i++) {
bracedCommands.get(i).setInstant(true);
bracedCommands.get(i).addObject("reqId", scriptEntry.getObject("reqId"));
}
scriptEntry.getResidingQueue().injectEntries(bracedCommands, 0);
}
}
else {
dB.echoError(scriptEntry.getResidingQueue(), "While CALLBACK invalid: not a real callback!");
}
}
else {
// Get objects
Element value = scriptEntry.getElement("value");
ArrayList<ScriptEntry> bracedCommandsList =
((LinkedHashMap<String, ArrayList<ScriptEntry>>) scriptEntry.getObject("braces")).get("WHILE");
if (bracedCommandsList == null || bracedCommandsList.isEmpty()) {
dB.echoError(scriptEntry.getResidingQueue(), "Empty braces!");
return;
}
// Report to dB
dB.report(scriptEntry, getName(), value.debug());
if (!TagManager.tag(((BukkitScriptEntryData)scriptEntry.entryData).getPlayer(), ((BukkitScriptEntryData)scriptEntry.entryData).getNPC(),
value.asString(), false, scriptEntry).equalsIgnoreCase("true"))
return;
WhileData datum = new WhileData();
datum.index = 1;
datum.value = value.asString();
datum.LastChecked = System.currentTimeMillis();
datum.instaTicks = 1;
scriptEntry.setData(datum);
ScriptEntry callbackEntry = null;
try {
callbackEntry = new ScriptEntry("WHILE", new String[] { "\0CALLBACK" },
(scriptEntry.getScript() != null ? scriptEntry.getScript().getContainer(): null));
callbackEntry.copyFrom(scriptEntry);
}
catch (ScriptEntryCreationException e) {
dB.echoError(scriptEntry.getResidingQueue(), e);
}
callbackEntry.setOwner(scriptEntry);
bracedCommandsList.add(callbackEntry);
scriptEntry.getResidingQueue().addDefinition("loop_index", "1");
for (int i = 0; i < bracedCommandsList.size(); i++) {
bracedCommandsList.get(i).setInstant(true);
bracedCommandsList.get(i).addObject("reqId", scriptEntry.getObject("reqId"));