From 9fed59cf637c02bc81e7ded1df00cfad2fce8914 Mon Sep 17 00:00:00 2001 From: sk89q Date: Sun, 30 Jan 2011 15:10:48 -0800 Subject: [PATCH] Added compiling information, removed dependency on internal Sun components. --- README.md | 36 ++++++++ src/com/sk89q/worldedit/WorldEdit.java | 8 +- .../scripting/SunRhinoContextFactory.java | 61 ------------- .../scripting/SunRhinoCraftScriptEngine.java | 90 ------------------- 4 files changed, 38 insertions(+), 157 deletions(-) create mode 100644 README.md delete mode 100644 src/com/sk89q/worldedit/scripting/SunRhinoContextFactory.java delete mode 100644 src/com/sk89q/worldedit/scripting/SunRhinoCraftScriptEngine.java diff --git a/README.md b/README.md new file mode 100644 index 000000000..7eef97ed1 --- /dev/null +++ b/README.md @@ -0,0 +1,36 @@ +WorldEdit +========= + +WorldEdit is a voxel and block manipulation library for Minecraft. It is +primarily a library but bindings to Bukkit (included) and SPC (external) +are available. + +Compiling +--------- + +Some dependencies are required: + +- TrueZip (http://java.net/projects/truezip) provides snapshot reading +- Bukkit (http://bukkit.org/) is a SMP plugin API +- Rhino (http://www.mozilla.org/rhino/) provides a JavaScript engine +- GroupUsers (http://forums.bukkit.org/threads/639/) provides an + permission system for Bukkit +- Permissions (http://forums.bukkit.org/threads/1403/) provides an + permission system for Bukkit + +For links to downloads, check out +http://wiki.sk89q.com/wiki/WorldEdit/Development + +To compile a .jar, use the Ant build file with the 'jar' target. + + ant jar + +Contributing +------------ + +We happily accept contributions. The best way to do this is to fork +WorldEdit on GitHub, add your changes, and then submit a pull request. We'll +look at it, make comments, and merge it into WorldEdit if everything +works out. + +Your submissions have to be licensed under the GNU General Public License v3. \ No newline at end of file diff --git a/src/com/sk89q/worldedit/WorldEdit.java b/src/com/sk89q/worldedit/WorldEdit.java index 20fd2094a..fe7dc6879 100644 --- a/src/com/sk89q/worldedit/WorldEdit.java +++ b/src/com/sk89q/worldedit/WorldEdit.java @@ -860,12 +860,8 @@ public class WorldEdit { try { engine = new RhinoCraftScriptEngine(); } catch (NoClassDefFoundError e) { - try { - engine = new SunRhinoCraftScriptEngine(); - } catch (NoClassDefFoundError e2) { - player.printError("Failed to find an installed script engine."); - return; - } + player.printError("Please install a scripting engine."); + return; } engine.setTimeLimit(config.scriptTimeout); diff --git a/src/com/sk89q/worldedit/scripting/SunRhinoContextFactory.java b/src/com/sk89q/worldedit/scripting/SunRhinoContextFactory.java deleted file mode 100644 index aad0fa2ae..000000000 --- a/src/com/sk89q/worldedit/scripting/SunRhinoContextFactory.java +++ /dev/null @@ -1,61 +0,0 @@ -// $Id$ -/* - * WorldEdit - * Copyright (C) 2010 sk89q - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.sk89q.worldedit.scripting; - -import sun.org.mozilla.javascript.internal.*; - -public class SunRhinoContextFactory extends ContextFactory { - protected int timeLimit; - - public SunRhinoContextFactory(int timeLimit) { - this.timeLimit = timeLimit; - } - - protected Context makeContext() { - RhinoContext cx = new RhinoContext(this); - cx.setInstructionObserverThreshold(10000); - return cx; - } - - protected void observeInstructionCount(Context cx, int instructionCount) { - RhinoContext mcx = (RhinoContext)cx; - long currentTime = System.currentTimeMillis(); - - if (currentTime - mcx.startTime > timeLimit) { - throw new Error("Script timed out (" + timeLimit + "ms)"); - } - } - - protected Object doTopCall(Callable callable, Context cx, Scriptable scope, - Scriptable thisObj, Object[] args) { - RhinoContext mcx = (RhinoContext)cx; - mcx.startTime = System.currentTimeMillis(); - - return super.doTopCall(callable, cx, scope, thisObj, args); - } - - private static class RhinoContext extends Context { - long startTime; - - public RhinoContext(ContextFactory factory) { - super(); - } - } -} \ No newline at end of file diff --git a/src/com/sk89q/worldedit/scripting/SunRhinoCraftScriptEngine.java b/src/com/sk89q/worldedit/scripting/SunRhinoCraftScriptEngine.java deleted file mode 100644 index 4706b69e4..000000000 --- a/src/com/sk89q/worldedit/scripting/SunRhinoCraftScriptEngine.java +++ /dev/null @@ -1,90 +0,0 @@ -// $Id$ -/* - * WorldEdit - * Copyright (C) 2010 sk89q - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . -*/ - -package com.sk89q.worldedit.scripting; - -import java.util.Map; -import javax.script.ScriptException; -import com.sk89q.worldedit.WorldEdit; -import com.sk89q.worldedit.WorldEditException; -import sun.org.mozilla.javascript.internal.*; - -public class SunRhinoCraftScriptEngine implements CraftScriptEngine { - private int timeLimit; - - @Override - public void setTimeLimit(int milliseconds) { - timeLimit = milliseconds; - } - - @Override - public int getTimeLimit() { - return timeLimit; - } - - @Override - public Object evaluate(final String script, final String filename, - final Map args) - throws ScriptException, Throwable { - SunRhinoContextFactory factory = new SunRhinoContextFactory(timeLimit); - factory.initApplicationClassLoader(WorldEdit.class.getClassLoader()); - - try { - return factory.call(new ContextAction() { - public Object run(Context cx) { - Scriptable topLevel = new ImporterTopLevel(cx); - Scriptable scope = cx.initStandardObjects(); - topLevel.setParentScope(scope); - - for (Map.Entry entry : args.entrySet()) { - ScriptableObject.putProperty(scope, entry.getKey(), - Context.javaToJS(entry.getValue(), scope)); - } - - return cx.evaluateString(topLevel, script, filename, 1, null); - } - }); - } catch (Error e) { - throw new ScriptException(e.getMessage()); - } catch (RhinoException e) { - if (e instanceof WrappedException) { - Throwable cause = ((WrappedException)e).getCause(); - if (cause instanceof WorldEditException) { - 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); - scriptException.initCause(e); - - throw scriptException; - } - } - -}