Skip to content

Commit

Permalink
Shut the InteractScriptHelper up
Browse files Browse the repository at this point in the history
Don't debug if the owner told you to not debug!
  • Loading branch information
mcmonkey4eva committed Nov 2, 2014
1 parent 97538c3 commit bef84bc
Showing 1 changed file with 49 additions and 23 deletions.
Expand Up @@ -3,7 +3,9 @@
import net.aufdemrand.denizen.objects.dNPC;
import net.aufdemrand.denizen.objects.dPlayer;
import net.aufdemrand.denizen.scripts.ScriptRegistry;
import net.aufdemrand.denizen.scripts.containers.ScriptContainer;
import net.aufdemrand.denizen.scripts.triggers.AbstractTrigger;
import net.aufdemrand.denizen.tags.TagManager;
import net.aufdemrand.denizen.utilities.DenizenAPI;
import net.aufdemrand.denizen.utilities.debugging.dB;
import org.bukkit.ChatColor;
Expand Down Expand Up @@ -46,7 +48,8 @@ public static InteractScriptContainer getInteractScript(dNPC npc, dPlayer player
if (assignedScripts.isEmpty()) return null;

// Alert the dBugger -- trying to find a good interact script!
dB.log(dB.DebugElement.Header, "Getting interact script: n@" + npc.getName() + "/p@" + player.getName());
if (dB.shouldDebug(assignmentScript))
dB.log(dB.DebugElement.Header, "Getting interact script: n@" + npc.getName() + "/p@" + player.getName());

//
// Get scripts that meet requirements and add them to interactableScripts.
Expand Down Expand Up @@ -89,30 +92,35 @@ public static InteractScriptContainer getInteractScript(dNPC npc, dPlayer player
if (interactScript != null) {
// Check requirements of the script
if (interactScript.checkBaseRequirements(player, npc)) {
dB.echoApproval("'" + entry + "' meets requirements.");
if (dB.shouldDebug(interactScript))
dB.echoApproval("'" + entry + "' meets requirements.");

// Meets requirements, but we need to check cool down, too.
if (interactScript.checkCooldown(player))
interactableScripts.add(new PriorityPair(priority, entry.split(" ", 2)[1]));
else
dB.log(ChatColor.GOLD + " ...but, isn't cooled down, yet! Skipping.");
else {
if (dB.shouldDebug(interactScript))
dB.log(ChatColor.GOLD + " ...but, isn't cooled down, yet! Skipping.");
}

} else {
// Does not meet requirements, alert the console!
dB.log("'" + entry + "' does not meet requirements.");
if (dB.shouldDebug(interactScript))
dB.log("'" + entry + "' does not meet requirements.");
}

} else {
// Alert the console
dB.log("'" + entry + "' is not a valid Interact Script. Is there a duplicate script by this name?");
dB.echoError("'" + entry + "' is not a valid Interact Script. Is there a duplicate script by this name?");
}
} catch (Exception e) {
// Had a problem checking requirements, most likely a Legacy Requirement with bad syntax. Alert the console!
dB.echoError(ChatColor.RED + "'" + entry + "' has a bad requirement, skipping.");
dB.echoError(e);
}

dB.log(dB.DebugElement.Spacer, null);
if (dB.shouldDebug(assignmentScript))
dB.log(dB.DebugElement.Spacer, null);
// Next entry!
}

Expand All @@ -123,16 +131,22 @@ public static InteractScriptContainer getInteractScript(dNPC npc, dPlayer player
// If list has only one entry, this is it!
if (interactableScripts.size() == 1) {
String script = interactableScripts.get(0).getName();
dB.echoApproval("Highest scoring script is " + script + ".");
dB.log("Current step for this script is: " + getCurrentStep(player, script));
dB.log(dB.DebugElement.Footer, "");
return ScriptRegistry.getScriptContainer(script.replace("^", ""));
InteractScriptContainer interactScript = ScriptRegistry.getScriptContainer(script.replace("^", ""));
if (dB.shouldDebug(interactScript))
dB.echoApproval("Highest scoring script is " + script + ".");
if (dB.shouldDebug(assignmentScript))
dB.log("Current step for this script is: " + getCurrentStep(player, script));
if (dB.shouldDebug(interactScript))
dB.log(dB.DebugElement.Footer, "");
return interactScript;
}

// Or, if list is empty.. no scripts meet requirements!
else if (interactableScripts.isEmpty()) {
dB.log(ChatColor.YELLOW + "+> " + ChatColor.WHITE + "No scripts meet requirements!");
dB.log(dB.DebugElement.Footer, "");
if (dB.shouldDebug(assignmentScript))
dB.log(ChatColor.YELLOW + "+> " + ChatColor.WHITE + "No scripts meet requirements!");
if (dB.shouldDebug(assignmentScript))
dB.log(dB.DebugElement.Footer, "");
return null;
}

Expand All @@ -145,7 +159,8 @@ else if (interactableScripts.isEmpty()) {
InteractScriptContainer interactScript = ScriptRegistry
.getScriptContainer(interactableScripts.get(a).name.replace("^", ""));

dB.log("Checking script '" + interactableScripts.get(a).getName() + "'.");
if (dB.shouldDebug(interactScript))
dB.log("Checking script '" + interactableScripts.get(a).getName() + "'.");

// Check for 'Overlay' assignment mode.
// If specified as an 'Overlay', the criteria for matching requires the
Expand All @@ -155,22 +170,33 @@ else if (interactableScripts.isEmpty()) {
// This is an Overlay Assignment, check for the appropriate Trigger Script...
// If Trigger exists, cool, this is our script.
if (interactScript.containsTriggerInStep(getCurrentStep(player, interactScript.getName()), trigger)) {
dB.log("...found trigger!");
dB.echoApproval("Highest scoring script is " + interactScript.getName() + ".");
dB.log("Current step for this script is: " + getCurrentStep(player, interactScript.getName()));
dB.log(dB.DebugElement.Footer, "");
if (dB.shouldDebug(interactScript))
dB.log("...found trigger!");
if (dB.shouldDebug(interactScript))
dB.echoApproval("Highest scoring script is " + interactScript.getName() + ".");
if (dB.shouldDebug(interactScript))
dB.log("Current step for this script is: " + getCurrentStep(player, interactScript.getName()));
if (dB.shouldDebug(interactScript))
dB.log(dB.DebugElement.Footer, "");
return interactScript;
}

else dB.log("...no trigger on this overlay assignment. Skipping.");
else {
if (dB.shouldDebug(interactScript))
dB.log("...no trigger on this overlay assignment. Skipping.");
}
}

// Not an Overlay Assignment, so return this script, which is the highest scoring.
else {
dB.log("...script is good!");
dB.echoApproval("Highest scoring script is " + interactScript.getName() + ".");
dB.log("Current step for this script is: " + getCurrentStep(player, interactScript.getName()));
dB.log(dB.DebugElement.Footer, "");
if (dB.shouldDebug(interactScript))
dB.log("...script is good!");
if (dB.shouldDebug(interactScript))
dB.echoApproval("Highest scoring script is " + interactScript.getName() + ".");
if (dB.shouldDebug(interactScript))
dB.log("Current step for this script is: " + getCurrentStep(player, interactScript.getName()));
if (dB.shouldDebug(interactScript))
dB.log(dB.DebugElement.Footer, "");
return interactScript;
}
}
Expand Down

0 comments on commit bef84bc

Please sign in to comment.