This commit is contained in:
TomyLobo
2011-11-23 02:29:48 +01:00
parent 1a57f6e95d
commit 7e13b60a51
161 changed files with 1433 additions and 1412 deletions

View File

@ -45,14 +45,14 @@ import com.sk89q.worldedit.patterns.Pattern;
public class CraftScriptContext extends CraftScriptEnvironment {
private List<EditSession> editSessions = new ArrayList<EditSession>();
private String[] args;
public CraftScriptContext(WorldEdit controller,
ServerInterface server, LocalConfiguration config,
LocalSession session, LocalPlayer player, String[] args) {
super(controller, server, config, session, player);
this.args = args;
}
/**
* Get an edit session. Every subsequent call returns a new edit session.
* Usually you only need to use one edit session.
@ -67,7 +67,7 @@ public class CraftScriptContext extends CraftScriptEnvironment {
editSessions.add(editSession);
return editSession;
}
/**
* Get the player.
*
@ -76,7 +76,7 @@ public class CraftScriptContext extends CraftScriptEnvironment {
public LocalPlayer getPlayer() {
return player;
}
/**
* Get the player's session.
*
@ -85,7 +85,7 @@ public class CraftScriptContext extends CraftScriptEnvironment {
public LocalSession getSession() {
return session;
}
/**
* Get the configuration for WorldEdit.
*
@ -94,7 +94,7 @@ public class CraftScriptContext extends CraftScriptEnvironment {
public LocalConfiguration getConfiguration() {
return config;
}
/**
* Get a list of edit sessions that have been created.
*
@ -103,7 +103,7 @@ public class CraftScriptContext extends CraftScriptEnvironment {
public List<EditSession> getEditSessions() {
return Collections.unmodifiableList(editSessions);
}
/**
* Print a regular message to the user.
*
@ -112,7 +112,7 @@ public class CraftScriptContext extends CraftScriptEnvironment {
public void print(String msg) {
player.print(msg);
}
/**
* Print an error message to the user.
*
@ -121,7 +121,7 @@ public class CraftScriptContext extends CraftScriptEnvironment {
public void error(String msg) {
player.printError(msg);
}
/**
* Print an raw message to the user.
*
@ -172,7 +172,7 @@ public class CraftScriptContext extends CraftScriptEnvironment {
throws UnknownItemException, DisallowedItemException {
return controller.getBlock(player, id, false);
}
/**
* Get a list of blocks as a set. This returns a Pattern.
*
@ -199,7 +199,7 @@ public class CraftScriptContext extends CraftScriptEnvironment {
throws UnknownItemException, DisallowedItemException {
return controller.getBlockIDs(player, list, allBlocksAllowed);
}
/**
* Gets the path to a file. This method will check to see if the filename
* has valid characters and has an extension. It also prevents directory
@ -218,7 +218,7 @@ public class CraftScriptContext extends CraftScriptEnvironment {
File dir = controller.getWorkingDirectoryFile(folder);
return controller.getSafeOpenFile(player, dir, filename, null, null);
}
/**
* Gets the path to a file for opening. This method will check to see if the
* filename has valid characters and has an extension. It also prevents
@ -241,7 +241,7 @@ public class CraftScriptContext extends CraftScriptEnvironment {
File dir = controller.getWorkingDirectoryFile(folder);
return controller.getSafeOpenFile(player, dir, filename, defaultExt, exts);
}
/**
* Gets the path to a file for saving. This method will check to see if the
* filename has valid characters and has an extension. It also prevents

View File

@ -24,7 +24,9 @@ import javax.script.ScriptException;
public interface CraftScriptEngine {
public void setTimeLimit(int milliseconds);
public int getTimeLimit();
public Object evaluate(String script, String filename, Map<String, Object> args)
throws ScriptException, Throwable;
}

View File

@ -31,7 +31,7 @@ public abstract class CraftScriptEnvironment {
protected LocalConfiguration config;
protected LocalSession session;
protected ServerInterface server;
public CraftScriptEnvironment(WorldEdit controller, ServerInterface server,
LocalConfiguration config, LocalSession session, LocalPlayer player) {
this.controller = controller;

View File

@ -23,11 +23,11 @@ import org.mozilla.javascript.*;
public class RhinoContextFactory extends ContextFactory {
protected int timeLimit;
public RhinoContextFactory(int timeLimit) {
this.timeLimit = timeLimit;
}
@Override
protected Context makeContext() {
RhinoContext cx = new RhinoContext(this);
@ -37,9 +37,9 @@ public class RhinoContextFactory extends ContextFactory {
@Override
protected void observeInstructionCount(Context cx, int instructionCount) {
RhinoContext mcx = (RhinoContext)cx;
RhinoContext mcx = (RhinoContext) cx;
long currentTime = System.currentTimeMillis();
if (currentTime - mcx.startTime > timeLimit) {
throw new Error("Script timed out (" + timeLimit + "ms)");
}
@ -48,7 +48,7 @@ public class RhinoContextFactory extends ContextFactory {
@Override
protected Object doTopCall(Callable callable, Context cx, Scriptable scope,
Scriptable thisObj, Object[] args) {
RhinoContext mcx = (RhinoContext)cx;
RhinoContext mcx = (RhinoContext) cx;
mcx.startTime = System.currentTimeMillis();
return super.doTopCall(callable, cx, scope, thisObj, args);
@ -56,9 +56,9 @@ public class RhinoContextFactory extends ContextFactory {
private static class RhinoContext extends Context {
long startTime;
public RhinoContext(ContextFactory factory) {
super(factory);
}
}
}
}

View File

@ -41,7 +41,7 @@ public class RhinoCraftScriptEngine implements CraftScriptEngine {
Context cx = factory.enterContext();
ScriptableObject scriptable = new ImporterTopLevel(cx);
Scriptable scope = cx.initStandardObjects(scriptable);
for (Map.Entry<String, Object> entry : args.entrySet()) {
ScriptableObject.putProperty(scope, entry.getKey(),
Context.javaToJS(entry.getValue(), scope));
@ -57,20 +57,20 @@ public class RhinoCraftScriptEngine implements CraftScriptEngine {
throw ((WrappedException) e).getCause();
}
}
String msg;
int line = (line = e.lineNumber()) == 0 ? -1 : line;
if (e instanceof JavaScriptException) {
msg = String.valueOf(((JavaScriptException) e).getValue());
} else {
msg = e.getMessage();
}
ScriptException scriptException =
new ScriptException(msg, e.sourceName(), line);
new ScriptException(msg, e.sourceName(), line);
scriptException.initCause(e);
throw scriptException;
} finally {
Context.exit();

View File

@ -39,28 +39,28 @@ public class RhinoScriptEngine extends AbstractScriptEngine {
public Object eval(String script, ScriptContext context)
throws ScriptException {
Scriptable scope = setupScope(cx, context);
String filename = (filename = (String) get(ScriptEngine.FILENAME)) == null
? "<unknown>" : filename;
try {
return cx.evaluateString(scope, script, filename, 1, null);
} catch (RhinoException e) {
String msg;
int line = (line = e.lineNumber()) == 0 ? -1 : line;
if (e instanceof JavaScriptException) {
msg = String.valueOf(((JavaScriptException) e).getValue());
} else {
msg = e.getMessage();
}
ScriptException scriptException =
new ScriptException(msg, e.sourceName(), line);
new ScriptException(msg, e.sourceName(), line);
scriptException.initCause(e);
throw scriptException;
} finally {
Context.exit();
@ -69,28 +69,28 @@ public class RhinoScriptEngine extends AbstractScriptEngine {
public Object eval(Reader reader, ScriptContext context)
throws ScriptException {
Scriptable scope = setupScope(cx, context);
String filename = (filename = (String) get(ScriptEngine.FILENAME)) == null
? "<unknown>" : filename;
try {
return cx.evaluateReader(scope, reader, filename, 1, null);
} catch (RhinoException e) {
String msg;
int line = (line = e.lineNumber()) == 0 ? -1 : line;
if (e instanceof JavaScriptException) {
msg = String.valueOf(((JavaScriptException) e).getValue());
} else {
msg = e.getMessage();
}
ScriptException scriptException =
new ScriptException(msg, e.sourceName(), line);
new ScriptException(msg, e.sourceName(), line);
scriptException.initCause(e);
throw scriptException;
} catch (IOException e) {
throw new ScriptException(e);
@ -106,7 +106,7 @@ public class RhinoScriptEngine extends AbstractScriptEngine {
return new RhinoScriptEngineFactory();
}
}
private Scriptable setupScope(Context cx, ScriptContext context) {
ScriptableObject scriptable = new ImporterTopLevel(cx);
Scriptable scope = cx.initStandardObjects(scriptable);

View File

@ -72,22 +72,22 @@ public class RhinoScriptEngineFactory implements ScriptEngineFactory {
return "1.8";
}
public String getMethodCallSyntax(String obj, String m, String ... args) {
public String getMethodCallSyntax(String obj, String m, String... args) {
StringBuilder s = new StringBuilder();
s.append(obj);
s.append(".");
s.append(m);
s.append("(");
for (int i = 0; i < args.length; ++i) {
s.append(args[i]);
if (i < args.length - 1) {
s.append(",");
}
}
s.append(")");
return s.toString();
}
@ -123,7 +123,7 @@ public class RhinoScriptEngineFactory implements ScriptEngineFactory {
}
}
public String getProgram(String ... statements) {
public String getProgram(String... statements) {
StringBuilder s = new StringBuilder();
for (String stmt : statements) {
s.append(stmt);