Merge pull request #236 from vorburger/SomeMinorCleanUp
Thanks for this @vorburger . I'm interested in how you used blockly with ScriptCraft - is there source code for that integration anywhere?
This commit is contained in:
commit
754dd687e1
7 changed files with 71 additions and 36 deletions
11
.classpath
Normal file
11
.classpath
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<classpath>
|
||||||
|
<classpathentry kind="src" path="src/docs/java"/>
|
||||||
|
<classpathentry kind="src" path="src/main/java/bukkit"/>
|
||||||
|
<classpathentry kind="src" path="src/main/java/canary"/>
|
||||||
|
<classpathentry kind="src" path="src/main/java/webserver"/>
|
||||||
|
<classpathentry kind="lib" path="lib/bukkit-1.7.10-R0.1-SNAPSHOT.jar"/>
|
||||||
|
<classpathentry kind="lib" path="lib/canarymod.jar"/>
|
||||||
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||||
|
<classpathentry kind="output" path="target"/>
|
||||||
|
</classpath>
|
17
.project
Normal file
17
.project
Normal 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>
|
1
lib/.gitignore
vendored
Normal file
1
lib/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
/canarymod.jar
|
|
@ -1,6 +1,5 @@
|
||||||
import javax.script.*;
|
import javax.script.*;
|
||||||
import java.io.FileReader;
|
import java.io.FileReader;
|
||||||
import net.canarymod.api.Server;
|
|
||||||
import net.canarymod.api.inventory.ItemType;
|
import net.canarymod.api.inventory.ItemType;
|
||||||
|
|
||||||
public class jscript
|
public class jscript
|
||||||
|
|
|
@ -21,42 +21,43 @@ public class ScriptCraftPlugin extends JavaPlugin implements Listener
|
||||||
//protected Map<CommandSender,ScriptCraftEvaluator> playerContexts = new HashMap<CommandSender,ScriptCraftEvaluator>();
|
//protected Map<CommandSender,ScriptCraftEvaluator> playerContexts = new HashMap<CommandSender,ScriptCraftEvaluator>();
|
||||||
private String NO_JAVASCRIPT_MESSAGE = "No JavaScript Engine available. ScriptCraft will not work without Javascript.";
|
private String NO_JAVASCRIPT_MESSAGE = "No JavaScript Engine available. ScriptCraft will not work without Javascript.";
|
||||||
protected ScriptEngine engine = null;
|
protected ScriptEngine engine = null;
|
||||||
@Override
|
|
||||||
public void onEnable()
|
@Override public void onEnable()
|
||||||
{
|
{
|
||||||
Thread currentThread = Thread.currentThread();
|
Thread currentThread = Thread.currentThread();
|
||||||
ClassLoader previousClassLoader = currentThread.getContextClassLoader();
|
ClassLoader previousClassLoader = currentThread.getContextClassLoader();
|
||||||
currentThread.setContextClassLoader(getClassLoader());
|
currentThread.setContextClassLoader(getClassLoader());
|
||||||
try{
|
try {
|
||||||
ScriptEngineManager factory = new ScriptEngineManager();
|
ScriptEngineManager factory = new ScriptEngineManager();
|
||||||
this.engine = factory.getEngineByName("JavaScript");
|
this.engine = factory.getEngineByName("JavaScript");
|
||||||
if (this.engine == null){
|
if (this.engine == null) {
|
||||||
this.getLogger().severe(NO_JAVASCRIPT_MESSAGE);
|
this.getLogger().severe(NO_JAVASCRIPT_MESSAGE);
|
||||||
} else {
|
} else {
|
||||||
Invocable inv = (Invocable)this.engine;
|
Invocable inv = (Invocable) this.engine;
|
||||||
this.engine.eval(new InputStreamReader(this.getResource("boot.js")));
|
this.engine.eval(new InputStreamReader(this.getResource("boot.js")));
|
||||||
inv.invokeFunction("__scboot", this, engine);
|
inv.invokeFunction("__scboot", this, engine);
|
||||||
}
|
}
|
||||||
}catch(Exception e){
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
this.getLogger().severe(e.getMessage());
|
this.getLogger().severe(e.getMessage());
|
||||||
}finally{
|
} finally {
|
||||||
currentThread.setContextClassLoader(previousClassLoader);
|
currentThread.setContextClassLoader(previousClassLoader);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> onTabComplete(CommandSender sender, Command cmd,
|
public List<String> onTabComplete(CommandSender sender, Command cmd,
|
||||||
String alias,
|
String alias,
|
||||||
String[] args)
|
String[] args)
|
||||||
{
|
{
|
||||||
List<String> result = new ArrayList<String>();
|
List<String> result = new ArrayList<String>();
|
||||||
if (this.engine == null){
|
if (this.engine == null) {
|
||||||
this.getLogger().severe(NO_JAVASCRIPT_MESSAGE);
|
this.getLogger().severe(NO_JAVASCRIPT_MESSAGE);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
Invocable inv = (Invocable)this.engine;
|
Invocable inv = (Invocable)this.engine;
|
||||||
inv.invokeFunction("__onTabComplete", result, sender, cmd, alias, args);
|
inv.invokeFunction("__onTabComplete", result, sender, cmd, alias, args);
|
||||||
}catch (Exception e){
|
} catch (Exception e) {
|
||||||
sender.sendMessage(e.getMessage());
|
sender.sendMessage(e.getMessage());
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -66,15 +67,14 @@ public class ScriptCraftPlugin extends JavaPlugin implements Listener
|
||||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
|
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
|
||||||
{
|
{
|
||||||
boolean result = false;
|
boolean result = false;
|
||||||
String javascriptCode = "";
|
|
||||||
Object jsResult = null;
|
Object jsResult = null;
|
||||||
if (this.engine == null){
|
if (this.engine == null) {
|
||||||
this.getLogger().severe(NO_JAVASCRIPT_MESSAGE);
|
this.getLogger().severe(NO_JAVASCRIPT_MESSAGE);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
jsResult = ((Invocable)this.engine).invokeFunction("__onCommand", sender, cmd, label, args);
|
jsResult = ((Invocable)this.engine).invokeFunction("__onCommand", sender, cmd, label, args);
|
||||||
}catch (Exception se){
|
} catch (Exception se) {
|
||||||
this.getLogger().severe(se.toString());
|
this.getLogger().severe(se.toString());
|
||||||
se.printStackTrace();
|
se.printStackTrace();
|
||||||
sender.sendMessage(se.getMessage());
|
sender.sendMessage(se.getMessage());
|
||||||
|
|
|
@ -16,12 +16,8 @@ import net.canarymod.commandsys.Command;
|
||||||
import net.canarymod.commandsys.TabComplete;
|
import net.canarymod.commandsys.TabComplete;
|
||||||
import net.canarymod.chat.MessageReceiver;
|
import net.canarymod.chat.MessageReceiver;
|
||||||
import net.canarymod.Canary;
|
import net.canarymod.Canary;
|
||||||
import net.canarymod.api.inventory.recipes.CraftingRecipe;
|
|
||||||
import net.canarymod.api.inventory.recipes.RecipeRow;
|
|
||||||
import net.canarymod.api.inventory.Item;
|
|
||||||
// event help stuff
|
// event help stuff
|
||||||
import net.canarymod.hook.Dispatcher;
|
import net.canarymod.hook.Dispatcher;
|
||||||
import net.canarymod.plugin.PluginListener;
|
|
||||||
import net.canarymod.hook.Hook;
|
import net.canarymod.hook.Hook;
|
||||||
|
|
||||||
public class ScriptCraftPlugin extends Plugin implements PluginListener, CommandListener
|
public class ScriptCraftPlugin extends Plugin implements PluginListener, CommandListener
|
||||||
|
@ -31,6 +27,7 @@ public class ScriptCraftPlugin extends Plugin implements PluginListener, Command
|
||||||
private String NO_JAVASCRIPT_MESSAGE = "No JavaScript Engine available. " +
|
private String NO_JAVASCRIPT_MESSAGE = "No JavaScript Engine available. " +
|
||||||
"ScriptCraft will not work without Javascript.";
|
"ScriptCraft will not work without Javascript.";
|
||||||
protected ScriptEngine engine = null;
|
protected ScriptEngine engine = null;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void disable(){
|
public void disable(){
|
||||||
try {
|
try {
|
||||||
|
@ -39,6 +36,7 @@ public class ScriptCraftPlugin extends Plugin implements PluginListener, Command
|
||||||
this.getLogman().error(e.getMessage());
|
this.getLogman().error(e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean enable()
|
public boolean enable()
|
||||||
{
|
{
|
||||||
|
@ -62,11 +60,15 @@ public class ScriptCraftPlugin extends Plugin implements PluginListener, Command
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
this.getLogman().error(e.getMessage());
|
this.getLogman().error(e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static interface IDispatcher {
|
public static interface IDispatcher {
|
||||||
public void execute(PluginListener listener, Hook hook);
|
public void execute(PluginListener listener, Hook hook);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Dispatcher getDispatcher(final IDispatcher impl){
|
public Dispatcher getDispatcher(final IDispatcher impl){
|
||||||
return new Dispatcher(){
|
return new Dispatcher(){
|
||||||
public void execute(PluginListener listener, Hook hook){
|
public void execute(PluginListener listener, Hook hook){
|
||||||
|
@ -74,6 +76,7 @@ public class ScriptCraftPlugin extends Plugin implements PluginListener, Command
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
static class ScriptCraftTask extends ServerTask {
|
static class ScriptCraftTask extends ServerTask {
|
||||||
private Runnable runnable = null;
|
private Runnable runnable = null;
|
||||||
public ScriptCraftTask(Runnable runnable, TaskOwner owner, long delay, boolean continuous){
|
public ScriptCraftTask(Runnable runnable, TaskOwner owner, long delay, boolean continuous){
|
||||||
|
@ -91,8 +94,6 @@ public class ScriptCraftPlugin extends Plugin implements PluginListener, Command
|
||||||
}
|
}
|
||||||
|
|
||||||
private void executeCommand( MessageReceiver sender, String[] args) {
|
private void executeCommand( MessageReceiver sender, String[] args) {
|
||||||
boolean result = false;
|
|
||||||
String javascriptCode = "";
|
|
||||||
Object jsResult = null;
|
Object jsResult = null;
|
||||||
if (this.engine == null){
|
if (this.engine == null){
|
||||||
this.getLogman().error(NO_JAVASCRIPT_MESSAGE);
|
this.getLogman().error(NO_JAVASCRIPT_MESSAGE);
|
||||||
|
@ -110,6 +111,7 @@ public class ScriptCraftPlugin extends Plugin implements PluginListener, Command
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Command(
|
@Command(
|
||||||
aliases = { "js" },
|
aliases = { "js" },
|
||||||
description = "Execute Javascript code",
|
description = "Execute Javascript code",
|
||||||
|
@ -119,6 +121,7 @@ public class ScriptCraftPlugin extends Plugin implements PluginListener, Command
|
||||||
|
|
||||||
executeCommand(sender, args);
|
executeCommand(sender, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
groupmod permission add visitors canary.jsp
|
groupmod permission add visitors canary.jsp
|
||||||
groupmod permission add visitors canary.command.jsp
|
groupmod permission add visitors canary.command.jsp
|
||||||
|
@ -148,10 +151,12 @@ public class ScriptCraftPlugin extends Plugin implements PluginListener, Command
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@TabComplete (commands = { "js" })
|
@TabComplete (commands = { "js" })
|
||||||
public List<String> jsComplete(MessageReceiver sender, String[] args){
|
public List<String> jsComplete(MessageReceiver sender, String[] args){
|
||||||
return complete(sender, args, "js");
|
return complete(sender, args, "js");
|
||||||
}
|
}
|
||||||
|
|
||||||
@TabComplete (commands = { "jsp" })
|
@TabComplete (commands = { "jsp" })
|
||||||
public List<String> jspComplete(MessageReceiver sender, String[] args){
|
public List<String> jspComplete(MessageReceiver sender, String[] args){
|
||||||
return complete(sender, args, "jsp");
|
return complete(sender, args, "jsp");
|
||||||
|
|
2
src/main/js/lib/.gitignore
vendored
Normal file
2
src/main/js/lib/.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
/events-helper-bukkit.js
|
||||||
|
/events-helper-canary.js
|
Reference in a new issue