This commit is contained in:
walterhiggins 2013-01-07 23:48:43 +00:00
parent a26829eec7
commit 4a434dfdd2
24 changed files with 96 additions and 0 deletions

11
bukkit-plugin/.classpath Normal file
View file

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="lib" path="/home/walter/bukkit/target/bukkit-1.4.6-R0.4-SNAPSHOT.jar" sourcepath="/home/walter/bukkit/src/main/java">
<attributes>
<attribute name="javadoc_location" value="http://jd.bukkit.org/apidocs/"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="bin"/>
</classpath>

17
bukkit-plugin/.project Normal file
View file

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>ScriptCraft</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

9
bukkit-plugin/plugin.yml Normal file
View file

@ -0,0 +1,9 @@
name: ScriptCraftPlugin
main: net.walterhiggins.scriptcraft.ScriptCraftPlugin
version: 0.01
commands:
js:
description: Evaluate javascript.
usage: /<command> Javascript code
permission: ScriptCraftPlugin.js
permission-message: You don't have <permission>

View file

@ -0,0 +1,59 @@
package net.walterhiggins.scriptcraft;
import java.io.File;
import java.io.FileReader;
import javax.script.*;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.command.*;
public class ScriptCraftPlugin extends JavaPlugin
{
// right now all ops share the same JS context/scope
// need to look at possibly having context/scope per operator
//protected Map<CommandSender,ScriptCraftEvaluator> playerContexts = new HashMap<CommandSender,ScriptCraftEvaluator>();
protected ScriptEngine engine = null;
@Override
public void onEnable(){
if (this.engine == null){
try{
ScriptEngineManager factory = new ScriptEngineManager();
File boot = new File("js-plugins2/core/_scriptcraft.js");
this.engine = factory.getEngineByName("JavaScript");
this.engine.put("__engine",engine);
this.engine.put("__plugin",this);
this.engine.put("__script",boot.getCanonicalPath().replaceAll("\\\\","/"));
this.engine.eval(new FileReader(boot));
}catch(Exception e){
e.printStackTrace();
}
}
}
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
{
if(cmd.getName().equalsIgnoreCase("js"))
{
this.engine.put("__self",sender);
String javascriptCode = "";
for (int i = 0;i < args.length; i++){
javascriptCode = javascriptCode + args[i] + " ";
}
try{
Object result = this.engine.eval(javascriptCode);
if (result != null)
sender.sendMessage(result.toString());
return true;
}catch (Exception e){
sender.sendMessage(e.getMessage());
e.printStackTrace();
}
return true;
}
return false;
}
}