Added error reporting in in-game console

This commit is contained in:
walterhiggins 2012-12-29 07:41:09 +00:00
parent ea5e2c4bb9
commit b092aa9f87

View file

@ -1,6 +1,7 @@
package net.minecraft.src; package net.minecraft.src;
import java.util.List; import java.util.List;
import java.util.Stack;
import java.io.*; import java.io.*;
import javax.swing.JFileChooser; import javax.swing.JFileChooser;
import net.minecraft.server.MinecraftServer; import net.minecraft.server.MinecraftServer;
@ -143,6 +144,7 @@ public class CommandScript extends CommandBase {
} }
return; return;
} }
public static void load(Context cx, Scriptable thisObj, public static void load(Context cx, Scriptable thisObj,
Object[] args, Function funObj) Object[] args, Function funObj)
{ {
@ -166,31 +168,43 @@ public class CommandScript extends CommandBase {
in = new FileReader(scriptFile); in = new FileReader(scriptFile);
} }
catch (FileNotFoundException ex) { catch (FileNotFoundException ex) {
notifyAdmins(CommandScript.sender, "Error - File not found " + args[0], args);
Context.reportError("Couldn't open file \"" + scriptFile + "\"."); Context.reportError("Couldn't open file \"" + scriptFile + "\".");
return; return;
} }
filename = scriptFile.getAbsolutePath(); filename = scriptFile.getAbsolutePath();
((ScriptableObject)thisObj).defineProperty("$SCRIPT",scriptFile.getAbsolutePath(),ScriptableObject.DONTENUM); String filedir = scriptFile.getParentFile().getAbsolutePath();
((ScriptableObject)thisObj).defineProperty("$SCRIPT_DIR",scriptFile.getParentFile().getAbsolutePath(),ScriptableObject.DONTENUM); //
// setup the special script-context-only variables
//
((ScriptableObject)thisObj).defineProperty("$SCRIPT",filename,ScriptableObject.DONTENUM);
((ScriptableObject)thisObj).defineProperty("$SCRIPT_DIR",filedir,ScriptableObject.DONTENUM);
try { try {
// Here we evalute the entire contents of the file as // Here we evalute the entire contents of the file as
// a script. Text is printed only if the print() function // a script. Text is printed only if the print() function
// is called. // is called.
notifyAdmins(CommandScript.sender, "Loading " + filename, args);
cx.evaluateReader(thisObj, in, filename, 1, null); cx.evaluateReader(thisObj, in, filename, 1, null);
notifyAdmins(CommandScript.sender, "Successfully loaded " + filename, args);
} }
catch (WrappedException we) { catch (WrappedException we) {
System.err.println(we.getWrappedException().toString()); String wes = we.getWrappedException().toString();
notifyAdmins(CommandScript.sender, "Error loading " + filename + ": " + wes, args);
System.err.println(wes);
we.printStackTrace(); we.printStackTrace();
} }
catch (EvaluatorException ee) { catch (EvaluatorException ee) {
System.err.println("js: " + ee.getMessage()); System.err.println("js: " + ee.getMessage());
notifyAdmins(CommandScript.sender, "Error loading " + filename + ": " + ee.getMessage(), args);
} }
catch (JavaScriptException jse) { catch (JavaScriptException jse) {
System.err.println("js: " + jse.getMessage()); System.err.println("js: " + jse.getMessage());
notifyAdmins(CommandScript.sender, "Error loading " + filename + ": " + jse.getMessage(), args);
} }
catch (IOException ioe) { catch (IOException ioe) {
System.err.println(ioe.toString()); System.err.println(ioe.toString());
notifyAdmins(CommandScript.sender, "Error loading " + filename + ": " + ioe.getMessage(), args);
} }
finally { finally {
try { try {