Merge remote-tracking branch 'wh/master'

This commit is contained in:
Aaron Mueller 2013-10-15 22:09:33 +02:00
commit 126773fc4c
7 changed files with 195 additions and 26 deletions

View File

@ -1,6 +1,7 @@
<project name="scriptcraft" default="package" basedir=".">
<property file="build.properties"/>
<description>Builds the scriptcraft.jar file - a plugin for bukkit</description>
<description>Builds the scriptcraft.jar file - a plugin for bukkit
</description>
<property name="src" location="src/main/java"/>
<property name="build" location="target/classes"/>
<property name="dist" location="target/" />
@ -21,8 +22,9 @@
<target name="server-setup" depends="init" description="Downloads the latest bukkit dev jar"
unless="minecraft.present">
<mkdir dir="${minecraft.dir}" />
<echo>Retrieving CraftBukkit artifact info</echo>
<echo>Retrieving CraftBukkit artifact info
</echo>
<get src="http://dl.bukkit.org/api/1.0/downloads/projects/CraftBukkit?_accept=application/xml"
dest="${minecraft.dir}/bukkit.xml" />
@ -31,22 +33,22 @@
style="build/bukkit-to-url.xsl"/>
<xmlproperty file="${minecraft.dir}/ant.properties.xml" keeproot="true"/>
<echo>Retrieving CraftBukkit jar</echo>
<echo>Retrieving CraftBukkit jar
</echo>
<get src="${bukkit.url}"
dest="${minecraft.dir}/craftbukkit.jar"
verbose="true"/>
<echo>Creating default ops.txt for your user</echo>
<echo>Creating default ops.txt for your user
</echo>
<echo message="${op.name}" file="${minecraft.dir}/ops.txt" />
<echo>Retrieving Coffeescript compiler</echo>
<mkdir dir="${minecraft.dir}/js-plugins/core" />
<get src="https://raw.github.com/jashkenas/coffee-script/master/extras/coffee-script.js"
dest="${minecraft.dir}/js-plugins/core/_coffeescript.js"/>
</target>
<target name="run" depends="server-setup, package, update-live-cb" description="Starts Bukkit with ScriptCraft">
<echo>Starting Bukkit with ScriptCraft</echo>
<echo>Starting Bukkit with ScriptCraft
</echo>
<java jar="${minecraft.dir}/craftbukkit.jar"
maxmemory="1024m"
fork="true"
@ -69,8 +71,19 @@
</java>
</target>
<target name="zip_js" depends="init">
<zip zipfile="${build}/js-plugins.zip" basedir="./src/main/javascript"/>
<target name="coffeescript_setup" depends="init" description="Gets latest coffeescript compiler">
<echo>Retrieving Coffeescript compiler
</echo>
<mkdir dir="${build}/coffeescript/core" />
<get src="https://raw.github.com/jashkenas/coffee-script/master/extras/coffee-script.js"
dest="${build}/coffeescript/core/_coffeescript.js"/>
</target>
<target name="zip_js" depends="coffeescript_setup">
<zip destfile="${build}/js-plugins.zip">
<zipfileset dir="./src/main/javascript" />
<zipfileset dir="${build}/coffeescript" />
</zip>
</target>
<target name="package" depends="gendocs,zip_js,compile"
@ -79,7 +92,8 @@
<delete file="${build}/plugin.yml" />
<copy file="src/main/resources/plugin.yml" todir="${build}"/>
<replace file="${build}/plugin.yml" value="${bukkit-version}-${DSTAMP}">
<replacetoken>[[version]]</replacetoken>
<replacetoken>[[version]]
</replacetoken>
</replace>
<!-- Put everything in ${build} into the MyProject-${DSTAMP}.jar file -->

View File

@ -209,6 +209,37 @@ The execution of the function object passed to the `ready()` function
is *deferred* until all of the plugins/modules have loaded. That way
you are guaranteed that when the function is invoked, all of the
plugins/modules have been loaded and evaluated and are ready to use.
setTimeout() function
---------------------
This function mimics the setTimeout() function used in browser-based javascript.
However, the function will only accept a function reference, not a string of javascript code.
Where setTimeout() in the browser returns a numeric value which can be subsequently passed to
clearTimeout(), This implementation returns a [BukkitTask][btdoc] object which can be subsequently passed to ScriptCraft's own clearTimeout() implementation.
If Node.js supports setTimeout() then it's probably good for ScriptCraft to support it too.
[btdoc]: http://jd.bukkit.org/beta/apidocs/org/bukkit/scheduler/BukkitTask.html
clearTimeout() function
---------------------
A scriptcraft implementation of clearTimeout().
setInterval() function
---------------------
This function mimics the setInterval() function used in browser-based javascript.
However, the function will only accept a function reference, not a string of javascript code.
Where setInterval() in the browser returns a numeric value which can be subsequently passed to
clearInterval(), This implementation returns a [BukkitTask][btdoc] object which can be subsequently passed to ScriptCraft's own clearInterval() implementation.
If Node.js supports setInterval() then it's probably good for ScriptCraft to support it too.
[btdoc]: http://jd.bukkit.org/beta/apidocs/org/bukkit/scheduler/BukkitTask.html
clearInterval() function
---------------------
A scriptcraft implementation of clearInterval().
Core Module - Special Variables
===============================
@ -1389,10 +1420,11 @@ Example
To warn players when night is approaching...
utils.at( "19:00", function() {
/* it's 7 in the evening so warn all players that night is coming ! */
utils.foreach( server.onlinePlayers, function(player){
player.chat("The night is dark and full of terrors!");
});
}, self.world);
String class extensions

View File

@ -99,10 +99,13 @@ public class ScriptCraftPlugin extends JavaPlugin implements Listener
this.engine.put("__script",boot.getCanonicalPath().replaceAll("\\\\","/"));
reader = new FileReader(boot);
this.engine.eval(reader);
/*
wph 20130811 Need to disable coffeescript support until issues loading and evaluating it are resolved.
See issue #92
// Load the CoffeeScript compiler
File coffeescript = new File(JS_PLUGINS_DIR + "/core/_coffeescript.js");
this.engine.eval(new FileReader(coffeescript));
*/
}catch(Exception e){
e.printStackTrace();
@ -153,10 +156,10 @@ public class ScriptCraftPlugin extends JavaPlugin implements Listener
this.engine.put("__cmdArgs",args);
result = true;
} else if (cmd.getName().equalsIgnoreCase("coffee")) {
for (int i = 0;i < args.length; i++)
for (int i = 0;i < args.length; i++)
javascriptCode += args[i] + " ";
javascriptCode = "eval(CoffeeScript.compile(\""+javascriptCode+"\", {bare: true}))";
result = true;
javascriptCode = "eval(CoffeeScript.compile(\""+javascriptCode+"\", {bare: true}))";
result = true;
}
if (result){

View File

@ -210,7 +210,74 @@ The execution of the function object passed to the `ready()` function
is *deferred* until all of the plugins/modules have loaded. That way
you are guaranteed that when the function is invoked, all of the
plugins/modules have been loaded and evaluated and are ready to use.
***/
var global = this;
/*************************************************************************
setTimeout() function
---------------------
This function mimics the setTimeout() function used in browser-based javascript.
However, the function will only accept a function reference, not a string of javascript code.
Where setTimeout() in the browser returns a numeric value which can be subsequently passed to
clearTimeout(), This implementation returns a [BukkitTask][btdoc] object which can be subsequently passed to ScriptCraft's own clearTimeout() implementation.
If Node.js supports setTimeout() then it's probably good for ScriptCraft to support it too.
[btdoc]: http://jd.bukkit.org/beta/apidocs/org/bukkit/scheduler/BukkitTask.html
***/
global.setTimeout = function( callback, delayInMillis){
//
// javascript programmers familiar with setTimeout know that it expects
// a delay in milliseconds. However, bukkit's scheduler expects a delay in ticks
// (where 1 tick = 1/20th second)
//
var bukkitTask = server.scheduler.runTaskLater(__plugin, callback, delayInMillis/50);
return bukkitTask;
};
/*************************************************************************
clearTimeout() function
---------------------
A scriptcraft implementation of clearTimeout().
***/
global.clearTimeout = function(bukkitTask){
bukkitTask.cancel();
};
/*************************************************************************
setInterval() function
---------------------
This function mimics the setInterval() function used in browser-based javascript.
However, the function will only accept a function reference, not a string of javascript code.
Where setInterval() in the browser returns a numeric value which can be subsequently passed to
clearInterval(), This implementation returns a [BukkitTask][btdoc] object which can be subsequently passed to ScriptCraft's own clearInterval() implementation.
If Node.js supports setInterval() then it's probably good for ScriptCraft to support it too.
[btdoc]: http://jd.bukkit.org/beta/apidocs/org/bukkit/scheduler/BukkitTask.html
***/
global.setInterval = function(callback, intervalInMillis){
var delay = intervalInMillis/ 50;
var bukkitTask = server.scheduler.runTaskTimer(__plugin, callback, delay, delay);
return bukkitTask;
};
/*************************************************************************
clearInterval() function
---------------------
A scriptcraft implementation of clearInterval().
***/
global.clearInterval = function(bukkitTask){
bukkitTask.cancel();
};
/*************************************************************************
Core Module - Special Variables
===============================
There are a couple of special javascript variables available in ScriptCraft...
@ -221,8 +288,6 @@ There are a couple of special javascript variables available in ScriptCraft...
* self - the current player. (Note - this value should not be used in multi-threaded scripts - it's not thread-safe)
***/
var global = this;
var verbose = verbose || false;
/*
wph 20130124 - make self, plugin and server public - these are far more useful now that tab-complete works.
@ -691,6 +756,7 @@ See [issue #69][issue69] for more information.
__plugin.pluginLoader.enablePlugin(__plugin);
};
global.load = _load;
global.save = _save;
global.plugin = _plugin;
@ -698,7 +764,8 @@ See [issue #69][issue69] for more information.
global.command = _command;
global._onTabComplete = __onTabCompleteJS;
global.addUnloadHandler = _addUnloadHandler;
//
// assumes this was loaded from js-plugins/core/
// load all of the plugins.

View File

@ -700,12 +700,15 @@ Used when placing torches so that they face towards the drone.
this.record = false;
var usePlayerCoords = false;
var playerPos = getPlayerPos();
if (typeof x == "undefined"){
if (typeof x == "undefined")
{
var mp = getMousePos();
if (mp){
this.x = mp.x;
this.y = mp.y;
this.z = mp.z;
if (playerPos)
this.dir = _getDirFromRotation(playerPos.yaw);
this.world = mp.world;
}else{
// base it on the player's current location
@ -720,6 +723,7 @@ Used when placing torches so that they face towards the drone.
this.x = playerPos.x;
this.y = playerPos.y;
this.z = playerPos.z;
this.dir = _getDirFromRotation(playerPos.yaw);
this.world = playerPos.world;
}
}else{
@ -746,14 +750,14 @@ Used when placing torches so that they face towards the drone.
}
}
// for debugging
//self.sendMessage("New Drone " + this.toString());
if (usePlayerCoords){
this.fwd(3);
}
this.chkpt('start');
this.record = true;
this.history = [];
// for debugging
// self.sendMessage("New Drone " + this.toString());
return this;
};
//

View File

@ -0,0 +1,48 @@
/*
A basic number-guessing game that uses the Bukkit Conversation API.
*/
ready(function(){
global.GuessTheNumber = function()
{
importPackage(org.bukkit.conversations);
var number = Math.ceil(Math.random() * 10);
var prompt = new Prompt()
{
getPromptText: function(ctx){
var hint = "";
var h = ctx.getSessionData("hint");
if (h){
hint = h;
}
return hint + "Think of a number between 1 and 10";
},
acceptInput: function(ctx, s)
{
s = s.replace(/^[^0-9]+/,""); // strip leading non-numeric characters (e.g. '/' )
s = parseInt(s);
if (s == number){
setTimeout(function(){
ctx.forWhom.sendRawMessage("You guessed Correct!");
},100);
return null;
}else{
if (s < number)
ctx.setSessionData("hint","too low\n");
if (s > number)
ctx.setSessionData("hint","too high\n");
return prompt;
}
},
blocksForInput: function(ctx){ return true; }
};
var cf = new ConversationFactory(__plugin);
var conv = cf.withModality(true)
.withFirstPrompt(prompt)
.withPrefix(new ConversationPrefix(){ getPrefix: function(ctx){ return "[1-10] ";} })
.buildConversation(self);
conv.begin();
};
});

View File

@ -178,10 +178,11 @@ Example
To warn players when night is approaching...
utils.at( "19:00", function() {
/* it's 7 in the evening so warn all players that night is coming ! */
utils.foreach( server.onlinePlayers, function(player){
player.chat("The night is dark and full of terrors!");
});
}, self.world);
***/