Merge remote-tracking branch 'wh/master'
This commit is contained in:
commit
126773fc4c
7 changed files with 195 additions and 26 deletions
38
build.xml
38
build.xml
|
@ -1,6 +1,7 @@
|
||||||
<project name="scriptcraft" default="package" basedir=".">
|
<project name="scriptcraft" default="package" basedir=".">
|
||||||
<property file="build.properties"/>
|
<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="src" location="src/main/java"/>
|
||||||
<property name="build" location="target/classes"/>
|
<property name="build" location="target/classes"/>
|
||||||
<property name="dist" location="target/" />
|
<property name="dist" location="target/" />
|
||||||
|
@ -22,7 +23,8 @@
|
||||||
unless="minecraft.present">
|
unless="minecraft.present">
|
||||||
<mkdir dir="${minecraft.dir}" />
|
<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"
|
<get src="http://dl.bukkit.org/api/1.0/downloads/projects/CraftBukkit?_accept=application/xml"
|
||||||
dest="${minecraft.dir}/bukkit.xml" />
|
dest="${minecraft.dir}/bukkit.xml" />
|
||||||
|
|
||||||
|
@ -31,22 +33,22 @@
|
||||||
style="build/bukkit-to-url.xsl"/>
|
style="build/bukkit-to-url.xsl"/>
|
||||||
<xmlproperty file="${minecraft.dir}/ant.properties.xml" keeproot="true"/>
|
<xmlproperty file="${minecraft.dir}/ant.properties.xml" keeproot="true"/>
|
||||||
|
|
||||||
<echo>Retrieving CraftBukkit jar</echo>
|
<echo>Retrieving CraftBukkit jar
|
||||||
|
</echo>
|
||||||
<get src="${bukkit.url}"
|
<get src="${bukkit.url}"
|
||||||
dest="${minecraft.dir}/craftbukkit.jar"
|
dest="${minecraft.dir}/craftbukkit.jar"
|
||||||
verbose="true"/>
|
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 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>
|
||||||
|
|
||||||
|
|
||||||
<target name="run" depends="server-setup, package, update-live-cb" description="Starts Bukkit with ScriptCraft">
|
<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"
|
<java jar="${minecraft.dir}/craftbukkit.jar"
|
||||||
maxmemory="1024m"
|
maxmemory="1024m"
|
||||||
fork="true"
|
fork="true"
|
||||||
|
@ -69,8 +71,19 @@
|
||||||
</java>
|
</java>
|
||||||
</target>
|
</target>
|
||||||
|
|
||||||
<target name="zip_js" depends="init">
|
<target name="coffeescript_setup" depends="init" description="Gets latest coffeescript compiler">
|
||||||
<zip zipfile="${build}/js-plugins.zip" basedir="./src/main/javascript"/>
|
<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>
|
||||||
|
|
||||||
<target name="package" depends="gendocs,zip_js,compile"
|
<target name="package" depends="gendocs,zip_js,compile"
|
||||||
|
@ -79,7 +92,8 @@
|
||||||
<delete file="${build}/plugin.yml" />
|
<delete file="${build}/plugin.yml" />
|
||||||
<copy file="src/main/resources/plugin.yml" todir="${build}"/>
|
<copy file="src/main/resources/plugin.yml" todir="${build}"/>
|
||||||
<replace file="${build}/plugin.yml" value="${bukkit-version}-${DSTAMP}">
|
<replace file="${build}/plugin.yml" value="${bukkit-version}-${DSTAMP}">
|
||||||
<replacetoken>[[version]]</replacetoken>
|
<replacetoken>[[version]]
|
||||||
|
</replacetoken>
|
||||||
</replace>
|
</replace>
|
||||||
|
|
||||||
<!-- Put everything in ${build} into the MyProject-${DSTAMP}.jar file -->
|
<!-- Put everything in ${build} into the MyProject-${DSTAMP}.jar file -->
|
||||||
|
|
34
docs/api.md
34
docs/api.md
|
@ -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
|
is *deferred* until all of the plugins/modules have loaded. That way
|
||||||
you are guaranteed that when the function is invoked, all of the
|
you are guaranteed that when the function is invoked, all of the
|
||||||
plugins/modules have been loaded and evaluated and are ready to use.
|
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
|
Core Module - Special Variables
|
||||||
===============================
|
===============================
|
||||||
|
@ -1389,10 +1420,11 @@ Example
|
||||||
To warn players when night is approaching...
|
To warn players when night is approaching...
|
||||||
|
|
||||||
utils.at( "19:00", function() {
|
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){
|
utils.foreach( server.onlinePlayers, function(player){
|
||||||
player.chat("The night is dark and full of terrors!");
|
player.chat("The night is dark and full of terrors!");
|
||||||
});
|
});
|
||||||
|
|
||||||
}, self.world);
|
}, self.world);
|
||||||
|
|
||||||
String class extensions
|
String class extensions
|
||||||
|
|
|
@ -99,10 +99,13 @@ public class ScriptCraftPlugin extends JavaPlugin implements Listener
|
||||||
this.engine.put("__script",boot.getCanonicalPath().replaceAll("\\\\","/"));
|
this.engine.put("__script",boot.getCanonicalPath().replaceAll("\\\\","/"));
|
||||||
reader = new FileReader(boot);
|
reader = new FileReader(boot);
|
||||||
this.engine.eval(reader);
|
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
|
// Load the CoffeeScript compiler
|
||||||
File coffeescript = new File(JS_PLUGINS_DIR + "/core/_coffeescript.js");
|
File coffeescript = new File(JS_PLUGINS_DIR + "/core/_coffeescript.js");
|
||||||
this.engine.eval(new FileReader(coffeescript));
|
this.engine.eval(new FileReader(coffeescript));
|
||||||
|
*/
|
||||||
|
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|
|
@ -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
|
is *deferred* until all of the plugins/modules have loaded. That way
|
||||||
you are guaranteed that when the function is invoked, all of the
|
you are guaranteed that when the function is invoked, all of the
|
||||||
plugins/modules have been loaded and evaluated and are ready to use.
|
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
|
Core Module - Special Variables
|
||||||
===============================
|
===============================
|
||||||
There are a couple of special javascript variables available in ScriptCraft...
|
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)
|
* 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;
|
var verbose = verbose || false;
|
||||||
/*
|
/*
|
||||||
wph 20130124 - make self, plugin and server public - these are far more useful now that tab-complete works.
|
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);
|
__plugin.pluginLoader.enablePlugin(__plugin);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
global.load = _load;
|
global.load = _load;
|
||||||
global.save = _save;
|
global.save = _save;
|
||||||
global.plugin = _plugin;
|
global.plugin = _plugin;
|
||||||
|
@ -699,6 +765,7 @@ See [issue #69][issue69] for more information.
|
||||||
global._onTabComplete = __onTabCompleteJS;
|
global._onTabComplete = __onTabCompleteJS;
|
||||||
global.addUnloadHandler = _addUnloadHandler;
|
global.addUnloadHandler = _addUnloadHandler;
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// assumes this was loaded from js-plugins/core/
|
// assumes this was loaded from js-plugins/core/
|
||||||
// load all of the plugins.
|
// load all of the plugins.
|
||||||
|
|
|
@ -700,12 +700,15 @@ Used when placing torches so that they face towards the drone.
|
||||||
this.record = false;
|
this.record = false;
|
||||||
var usePlayerCoords = false;
|
var usePlayerCoords = false;
|
||||||
var playerPos = getPlayerPos();
|
var playerPos = getPlayerPos();
|
||||||
if (typeof x == "undefined"){
|
if (typeof x == "undefined")
|
||||||
|
{
|
||||||
var mp = getMousePos();
|
var mp = getMousePos();
|
||||||
if (mp){
|
if (mp){
|
||||||
this.x = mp.x;
|
this.x = mp.x;
|
||||||
this.y = mp.y;
|
this.y = mp.y;
|
||||||
this.z = mp.z;
|
this.z = mp.z;
|
||||||
|
if (playerPos)
|
||||||
|
this.dir = _getDirFromRotation(playerPos.yaw);
|
||||||
this.world = mp.world;
|
this.world = mp.world;
|
||||||
}else{
|
}else{
|
||||||
// base it on the player's current location
|
// 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.x = playerPos.x;
|
||||||
this.y = playerPos.y;
|
this.y = playerPos.y;
|
||||||
this.z = playerPos.z;
|
this.z = playerPos.z;
|
||||||
|
this.dir = _getDirFromRotation(playerPos.yaw);
|
||||||
this.world = playerPos.world;
|
this.world = playerPos.world;
|
||||||
}
|
}
|
||||||
}else{
|
}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){
|
if (usePlayerCoords){
|
||||||
this.fwd(3);
|
this.fwd(3);
|
||||||
}
|
}
|
||||||
this.chkpt('start');
|
this.chkpt('start');
|
||||||
this.record = true;
|
this.record = true;
|
||||||
this.history = [];
|
this.history = [];
|
||||||
|
// for debugging
|
||||||
|
// self.sendMessage("New Drone " + this.toString());
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
//
|
//
|
||||||
|
|
48
src/main/javascript/minigames/NumberGuess.js
Normal file
48
src/main/javascript/minigames/NumberGuess.js
Normal 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();
|
||||||
|
};
|
||||||
|
});
|
|
@ -178,10 +178,11 @@ Example
|
||||||
To warn players when night is approaching...
|
To warn players when night is approaching...
|
||||||
|
|
||||||
utils.at( "19:00", function() {
|
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){
|
utils.foreach( server.onlinePlayers, function(player){
|
||||||
player.chat("The night is dark and full of terrors!");
|
player.chat("The night is dark and full of terrors!");
|
||||||
});
|
});
|
||||||
|
|
||||||
}, self.world);
|
}, self.world);
|
||||||
|
|
||||||
***/
|
***/
|
||||||
|
|
Reference in a new issue