mirror of
https://github.com/ProjectSWGCore/Holocore.git
synced 2026-01-17 00:06:00 -05:00
Added Jython library and added Scripts class for executing Jython scripts
This commit is contained in:
@@ -4,5 +4,6 @@
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/Engine3"/>
|
||||
<classpathentry kind="lib" path="lib/jdbc-postgresql.jar"/>
|
||||
<classpathentry kind="lib" path="lib/jython-standalone-2.5.4-rc1.jar"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
|
||||
BIN
lib/jython-standalone-2.5.4-rc1.jar
Normal file
BIN
lib/jython-standalone-2.5.4-rc1.jar
Normal file
Binary file not shown.
61
src/resources/utilities/Scripts.java
Normal file
61
src/resources/utilities/Scripts.java
Normal file
@@ -0,0 +1,61 @@
|
||||
package resources.utilities;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.python.core.Py;
|
||||
import org.python.util.PythonInterpreter;
|
||||
|
||||
public final class Scripts {
|
||||
private static final String SCRIPTS_PATH = "scripts/";
|
||||
|
||||
// TODO: Variable arguments?
|
||||
|
||||
public static void execute(String script, String method) {
|
||||
if (!scriptExists(script))
|
||||
return;
|
||||
|
||||
PythonInterpreter interp = new PythonInterpreter();
|
||||
interp.execfile(SCRIPTS_PATH + script);
|
||||
interp.get(method).__call__();
|
||||
}
|
||||
|
||||
public static void execute(String script, String method, Object arg1) {
|
||||
if (!scriptExists(script))
|
||||
return;
|
||||
|
||||
PythonInterpreter interp = new PythonInterpreter();
|
||||
interp.execfile(SCRIPTS_PATH + script);
|
||||
interp.get(method).__call__(Py.java2py(arg1));
|
||||
}
|
||||
|
||||
public static void execute(String script, String method, Object arg1, Object arg2) {
|
||||
if (!scriptExists(script))
|
||||
return;
|
||||
|
||||
PythonInterpreter interp = new PythonInterpreter();
|
||||
interp.execfile(SCRIPTS_PATH + script);
|
||||
interp.get(method).__call__(Py.java2py(arg1), Py.java2py(arg2));
|
||||
}
|
||||
|
||||
public static void execute(String script, String method, Object arg1, Object arg2, Object arg3) {
|
||||
if (!scriptExists(script))
|
||||
return;
|
||||
|
||||
PythonInterpreter interp = new PythonInterpreter();
|
||||
interp.execfile(SCRIPTS_PATH + script);
|
||||
interp.get(method).__call__(Py.java2py(arg1), Py.java2py(arg2), Py.java2py(arg3));
|
||||
}
|
||||
|
||||
public static void execute(String script, String method, Object arg1, Object arg2, Object arg3, Object arg4) {
|
||||
if (!scriptExists(script))
|
||||
return;
|
||||
|
||||
PythonInterpreter interp = new PythonInterpreter();
|
||||
interp.execfile(SCRIPTS_PATH + script);
|
||||
interp.get(method).__call__(Py.java2py(arg1), Py.java2py(arg2), Py.java2py(arg3), Py.java2py(arg4));
|
||||
}
|
||||
|
||||
private static boolean scriptExists(String file) {
|
||||
return new File(file).exists();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user