Skip to content

Commit

Permalink
initial if rewrite helper fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Feb 21, 2015
1 parent a1b6759 commit 213414a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 12 deletions.
@@ -1,7 +1,9 @@
package net.aufdemrand.denizen.scripts.commands;

import net.aufdemrand.denizen.scripts.commands.core.*;
import net.aufdemrand.denizencore.scripts.commands.core.*;
import net.aufdemrand.denizencore.scripts.commands.core.ForeachCommand;
import net.aufdemrand.denizencore.scripts.commands.core.DetermineCommand;
import net.aufdemrand.denizencore.scripts.commands.core.DefineCommand;
import net.aufdemrand.denizen.scripts.commands.entity.*;
import net.aufdemrand.denizen.scripts.commands.item.*;
import net.aufdemrand.denizen.scripts.commands.npc.*;
Expand Down
Expand Up @@ -2,6 +2,8 @@

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;

import net.aufdemrand.denizencore.exceptions.CommandExecutionException;
import net.aufdemrand.denizencore.exceptions.InvalidArgumentsException;
import net.aufdemrand.denizencore.objects.Element;
Expand Down Expand Up @@ -57,13 +59,13 @@ public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {

int possibilities = 0;
ScriptQueue queue = scriptEntry.getResidingQueue();
ArrayList<ScriptEntry> bracedCommands = null;
List<ScriptEntry> bracedCommands = null;

if (!scriptEntry.hasObject("braces")) {
possibilities = scriptEntry.getElement("possibilities").asInt();
}
else {
bracedCommands = ((LinkedHashMap<String, ArrayList<ScriptEntry>>) scriptEntry.getObject("braces")).get("RANDOM");
bracedCommands = ((List<BracedData>) scriptEntry.getObject("braces")).get(0).value;
possibilities = bracedCommands.size();
}

Expand Down
Expand Up @@ -136,13 +136,13 @@ else if (next != null && next.asBoolean()) {
else if (callback != null && callback.asBoolean()) {
if (scriptEntry.getOwner() != null && (scriptEntry.getOwner().getCommandName().equalsIgnoreCase("repeat") ||
scriptEntry.getOwner().getBracedSet() == null || scriptEntry.getOwner().getBracedSet().size() == 0 ||
scriptEntry.getBracedSet().get("REPEAT").get(scriptEntry.getBracedSet().get("REPEAT").size() - 1) != scriptEntry)) {
scriptEntry.getBracedSet().get(0).value.get(scriptEntry.getBracedSet().get(0).value.size() - 1) != scriptEntry)) {
RepeatData data = (RepeatData)scriptEntry.getOwner().getData();
data.index++;
if (data.index <= data.target) {
dB.echoDebug(scriptEntry, DebugElement.Header, "Repeat loop " + data.index);
scriptEntry.getResidingQueue().addDefinition("value", String.valueOf(data.index));
ArrayList<ScriptEntry> bracedCommands = BracedCommand.getBracedCommands(scriptEntry.getOwner()).get("REPEAT");
List<ScriptEntry> bracedCommands = BracedCommand.getBracedCommands(scriptEntry.getOwner()).get(0).value;
ScriptEntry callbackEntry = null;
try {
callbackEntry = new ScriptEntry("REPEAT", new String[] { "\0CALLBACK" },
Expand All @@ -169,8 +169,8 @@ else if (callback != null && callback.asBoolean()) {
else {

// Get objects
ArrayList<ScriptEntry> bracedCommandsList =
((LinkedHashMap<String, ArrayList<ScriptEntry>>) scriptEntry.getObject("braces")).get("REPEAT");
List<ScriptEntry> bracedCommandsList =
((List<BracedData>) scriptEntry.getObject("braces")).get(0).value;

if (bracedCommandsList == null || bracedCommandsList.isEmpty()) {
dB.echoError("Empty braces!");
Expand Down
Expand Up @@ -144,7 +144,7 @@ else if (next != null && next.asBoolean()) {
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)) {
scriptEntry.getBracedSet().get(0).value.get(scriptEntry.getBracedSet().get(0).value.size() - 1) != scriptEntry)) {
WhileData data = (WhileData)scriptEntry.getOwner().getData();
data.index++;
if (System.currentTimeMillis() - data.LastChecked < 50) {
Expand All @@ -160,7 +160,7 @@ else if (callback != null && callback.asBoolean()) {
if (TagManager.tag(data.value, new BukkitTagContext(scriptEntry, false)).equalsIgnoreCase("true")) {
dB.echoDebug(scriptEntry, DebugElement.Header, "While loop " + data.index);
scriptEntry.getResidingQueue().addDefinition("loop_index", String.valueOf(data.index));
ArrayList<ScriptEntry> bracedCommands = BracedCommand.getBracedCommands(scriptEntry.getOwner()).get("WHILE");
List<ScriptEntry> bracedCommands = BracedCommand.getBracedCommands(scriptEntry.getOwner()).get(0).value;
ScriptEntry callbackEntry = null;
try {
callbackEntry = new ScriptEntry("WHILE", new String[] { "\0CALLBACK" },
Expand Down Expand Up @@ -188,8 +188,8 @@ else if (callback != null && callback.asBoolean()) {

// Get objects
Element value = scriptEntry.getElement("value");
ArrayList<ScriptEntry> bracedCommandsList =
((LinkedHashMap<String, ArrayList<ScriptEntry>>) scriptEntry.getObject("braces")).get("WHILE");
List<ScriptEntry> bracedCommandsList =
((List<BracedData>) scriptEntry.getObject("braces")).get(0).value;

if (bracedCommandsList == null || bracedCommandsList.isEmpty()) {
dB.echoError(scriptEntry.getResidingQueue(), "Empty braces!");
Expand All @@ -199,7 +199,7 @@ else if (callback != null && callback.asBoolean()) {
// Report to dB
dB.report(scriptEntry, getName(), value.debug());

if (!TagManager.tag(value.asString(), new BukkitTagContext(scriptEntry, false)).equalsIgnoreCase("true")) {
if (!TagManager.tag(value.asString(), scriptEntry.entryData.getTagContext()).equalsIgnoreCase("true")) {
return;
}

Expand Down

0 comments on commit 213414a

Please sign in to comment.