Minor fixes for craftscripts in Forge

Dieser Commit ist enthalten in:
Kenzie Togami 2019-07-10 18:55:09 -07:00
Ursprung 5a14693aa9
Commit 5277f99bf2
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 5D200B325E157A81
6 geänderte Dateien mit 46 neuen und 289 gelöschten Zeilen

Datei anzeigen

@ -15,7 +15,7 @@ configurations.all {
dependencies { dependencies {
"compile"(project(":worldedit-libs:core")) "compile"(project(":worldedit-libs:core"))
"compile"("de.schlichtherle:truezip:6.8.3") "compile"("de.schlichtherle:truezip:6.8.3")
"compile"("org.mozilla:rhino:1.7R5") "compile"("org.mozilla:rhino:1.7.11")
"compile"("org.yaml:snakeyaml:1.9") "compile"("org.yaml:snakeyaml:1.9")
"compile"("com.google.guava:guava:21.0") "compile"("com.google.guava:guava:21.0")
"compile"("com.google.code.findbugs:jsr305:1.3.9") "compile"("com.google.code.findbugs:jsr305:1.3.9")

Datei anzeigen

@ -0,0 +1,41 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser 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 Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.scripting;
import org.mozilla.javascript.ClassShutter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Hides Minecraft's obfuscated & de-obfuscated names from scripts.
*/
class MinecraftHidingClassShutter implements ClassShutter {
private static final Logger LOGGER = LoggerFactory.getLogger(MinecraftHidingClassShutter.class);
@Override
public boolean visibleToScripts(String fullClassName) {
if (!fullClassName.contains(".")) {
// Default package -- probably Minecraft
return false;
}
return !fullClassName.startsWith("net.minecraft");
}
}

Datei anzeigen

@ -50,6 +50,7 @@ public class RhinoCraftScriptEngine implements CraftScriptEngine {
throws ScriptException, Throwable { throws ScriptException, Throwable {
RhinoContextFactory factory = new RhinoContextFactory(timeLimit); RhinoContextFactory factory = new RhinoContextFactory(timeLimit);
Context cx = factory.enterContext(); Context cx = factory.enterContext();
cx.setClassShutter(new MinecraftHidingClassShutter());
ScriptableObject scriptable = new ImporterTopLevel(cx); ScriptableObject scriptable = new ImporterTopLevel(cx);
Scriptable scope = cx.initStandardObjects(scriptable); Scriptable scope = cx.initStandardObjects(scriptable);

Datei anzeigen

@ -1,134 +0,0 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser 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 Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.scripting.java;
import com.sk89q.worldedit.scripting.RhinoContextFactory;
import org.mozilla.javascript.Context;
import org.mozilla.javascript.ImporterTopLevel;
import org.mozilla.javascript.JavaScriptException;
import org.mozilla.javascript.RhinoException;
import org.mozilla.javascript.Scriptable;
import org.mozilla.javascript.ScriptableObject;
import java.io.IOException;
import java.io.Reader;
import javax.script.AbstractScriptEngine;
import javax.script.Bindings;
import javax.script.ScriptContext;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineFactory;
import javax.script.ScriptException;
import javax.script.SimpleBindings;
public class RhinoScriptEngine extends AbstractScriptEngine {
private ScriptEngineFactory factory;
private Context cx;
public RhinoScriptEngine() {
RhinoContextFactory factory = new RhinoContextFactory(3000);
factory.enterContext();
}
@Override
public Bindings createBindings() {
return new SimpleBindings();
}
@Override
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);
scriptException.initCause(e);
throw scriptException;
} finally {
Context.exit();
}
}
@Override
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);
scriptException.initCause(e);
throw scriptException;
} catch (IOException e) {
throw new ScriptException(e);
} finally {
Context.exit();
}
}
@Override
public ScriptEngineFactory getFactory() {
if (factory != null) {
return factory;
} else {
return new RhinoScriptEngineFactory();
}
}
private Scriptable setupScope(Context cx, ScriptContext context) {
ScriptableObject scriptable = new ImporterTopLevel(cx);
Scriptable scope = cx.initStandardObjects(scriptable);
//ScriptableObject.putProperty(scope, "argv", Context.javaToJS(args, scope));
return scope;
}
}

Datei anzeigen

@ -1,153 +0,0 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser 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 Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.scripting.java;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineFactory;
public class RhinoScriptEngineFactory implements ScriptEngineFactory {
private static List<String> names;
private static List<String> mimeTypes;
private static List<String> extensions;
static {
names = new ArrayList<>(5);
names.add("ECMAScript");
names.add("ecmascript");
names.add("JavaScript");
names.add("javascript");
names.add("js");
names = Collections.unmodifiableList(names);
mimeTypes = new ArrayList<>(4);
mimeTypes.add("application/ecmascript");
mimeTypes.add("text/ecmascript");
mimeTypes.add("application/javascript");
mimeTypes.add("text/javascript");
mimeTypes = Collections.unmodifiableList(mimeTypes);
extensions = new ArrayList<>(2);
extensions.add("emcascript");
extensions.add("js");
extensions = Collections.unmodifiableList(extensions);
}
@Override
public String getEngineName() {
return "Rhino JavaScript Engine (SK)";
}
@Override
public String getEngineVersion() {
return "unknown";
}
@Override
public List<String> getExtensions() {
return extensions;
}
@Override
public String getLanguageName() {
return "EMCAScript";
}
@Override
public String getLanguageVersion() {
return "1.8";
}
@Override
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();
}
@Override
public List<String> getMimeTypes() {
return mimeTypes;
}
@Override
public List<String> getNames() {
return names;
}
@Override
public String getOutputStatement(String str) {
return "print(" + str.replace("\\", "\\\\")
.replace("\"", "\\\\\"")
.replace(";", "\\\\;") + ")";
}
@Override
public Object getParameter(String key) {
switch (key) {
case ScriptEngine.ENGINE:
return getEngineName();
case ScriptEngine.ENGINE_VERSION:
return getEngineVersion();
case ScriptEngine.NAME:
return getEngineName();
case ScriptEngine.LANGUAGE:
return getLanguageName();
case ScriptEngine.LANGUAGE_VERSION:
return getLanguageVersion();
case "THREADING":
return "MULTITHREADED";
default:
throw new IllegalArgumentException("Invalid key");
}
}
@Override
public String getProgram(String... statements) {
StringBuilder s = new StringBuilder();
for (String stmt : statements) {
s.append(stmt);
s.append(";");
}
return s.toString();
}
@Override
public ScriptEngine getScriptEngine() {
return new RhinoScriptEngine();
}
}

Datei anzeigen

@ -91,7 +91,9 @@ tasks.named<ShadowJar>("shadowJar") {
include(dependency("org.apache.logging.log4j:log4j-slf4j-impl")) include(dependency("org.apache.logging.log4j:log4j-slf4j-impl"))
include(dependency("de.schlichtherle:truezip")) include(dependency("de.schlichtherle:truezip"))
include(dependency("org.mozilla:rhino")) include(dependency("org.mozilla:rhino"))
}
minimize {
exclude(dependency("org.mozilla:rhino"))
} }
} }