Further changes to achieve compat with Nashorn java 8

This commit is contained in:
walterhiggins 2014-01-13 23:01:17 +00:00
parent 93fb626276
commit 3a6cb1057d
7 changed files with 22 additions and 17 deletions

View file

@ -105,7 +105,7 @@ Walter Higgins
<pathelement path="src/docs/java"/> <pathelement path="src/docs/java"/>
</classpath> </classpath>
<arg value="src/docs/javascript/generateTOC.js"/> <arg value="src/docs/javascript/generateTOC.js"/>
<arg value="src/docs/templates/ypgpm.mdt"/> <arg value="src/docs/templates/ypgpm.md"/>
</java> </java>
</target> </target>
@ -113,10 +113,9 @@ Walter Higgins
<target name="construct-ypgpm" depends="gen-toc-ypgpm,init"> <target name="construct-ypgpm" depends="gen-toc-ypgpm,init">
<concat destfile="docs/YoungPersonsGuideToProgrammingMinecraft.md"> <concat destfile="docs/YoungPersonsGuideToProgrammingMinecraft.md">
<header filtering="no" trimleading="yes"># The Young Person's Guide to Programming in Minecraft <header filtering="no" trimleading="yes"># The Young Person's Guide to Programming in Minecraft
</header> </header>
<fileset file="${dist}/toc-ypgpm.md" /> <fileset file="${dist}/toc-ypgpm.md" />
<fileset file="src/docs/templates/ypgpm.mdt" /> <fileset file="src/docs/templates/ypgpm.md" />
</concat> </concat>
</target> </target>

View file

@ -1,5 +1,4 @@
# The Young Person's Guide to Programming in Minecraft # The Young Person's Guide to Programming in Minecraft
## Table of Contents ## Table of Contents
* [Introduction](#introduction) * [Introduction](#introduction)
* [Installation](#installation) * [Installation](#installation)

View file

@ -3,7 +3,12 @@
*/ */
var err = java.lang.System.err; var err = java.lang.System.err;
args = args.slice(1); args = Array.prototype.slice.call(args,1);
if (typeof importPackage == 'undefined'){
// load compatibility script
load('nashorn:mozilla_compat.js');
}
var dir = args[0]; var dir = args[0];
var foreach = function(array, func){ var foreach = function(array, func){
for (var i =0; i < array.length; i++){ for (var i =0; i < array.length; i++){
@ -142,7 +147,7 @@ for (var i = 0;i < contents.length; i++){
writeComment = false; writeComment = false;
} }
if (writeComment){ if (writeComment){
println(contents[i]); java.lang.System.out.println(contents[i]);
} }
} }

View file

@ -1,4 +1,4 @@
args = args.slice(1); args = Array.prototype.slice.call(args,1);
// wph 20140105 trim not availabe in String on Mac OS. // wph 20140105 trim not availabe in String on Mac OS.
if (typeof String.prototype.trim == 'undefined'){ if (typeof String.prototype.trim == 'undefined'){
@ -33,18 +33,18 @@ var createLink = function(text){
anchors[result] = 1; anchors[result] = 1;
return result; return result;
}; };
println('## Table of Contents'); java.lang.System.out.println('## Table of Contents');
for (var i = 0; i < contents.length; i++){ for (var i = 0; i < contents.length; i++){
line = contents[i]; line = contents[i];
if (line.match(/^##\s+/)){ if (line.match(/^##\s+/)){
var h2 = line.match(/^##\s+(.*)/)[1].trim(); var h2 = line.match(/^##\s+(.*)/)[1].trim();
var link = createLink(h2); var link = createLink(h2);
println (' * [' + h2 + '](#' + link + ')'); java.lang.System.out.println (' * [' + h2 + '](#' + link + ')');
} }
if (line.match(/^###\s+/)){ if (line.match(/^###\s+/)){
var h3 = line.match(/^###\s+(.*)/)[1].trim(); var h3 = line.match(/^###\s+(.*)/)[1].trim();
var link = createLink(h3); var link = createLink(h3);
println (' * [' + h3 + '](#' + link + ')'); java.lang.System.out.println (' * [' + h3 + '](#' + link + ')');
} }
} }

View file

@ -22,10 +22,9 @@ var executeCmd = function(args, player){
if (!intercepted) if (!intercepted)
console.warn('Command %s is not recognised',name); console.warn('Command %s is not recognised',name);
}else{ }else{
func = cmd.callback;
var result = null; var result = null;
try { try {
result = func(args.slice(1),player); result = cmd.callback(args.slice(1),player);
}catch (e){ }catch (e){
console.error("Error while trying to execute command: " + JSON.stringify(args)); console.error("Error while trying to execute command: " + JSON.stringify(args));
throw e; throw e;

View file

@ -37,9 +37,10 @@ location. For example...
create a firework at the given location create a firework at the given location
*/ */
var firework = function(location){ var firework = function(location){
importPackage(org.bukkit.entity); var Color = org.bukkit.Color;
importPackage(org.bukkit); var FireworkEffect = org.bukkit.FireworkEffect;
var EntityType = org.bukkit.entity.EntityType;
var randInt = function(n){ var randInt = function(n){
return Math.floor(Math.random() * n); return Math.floor(Math.random() * n);
}; };

View file

@ -29,8 +29,10 @@ exports.Game_NumberGuess = {
sb('players set ' + sender.name + ' NumberGuess ' + guesses); sb('players set ' + sender.name + ' NumberGuess ' + guesses);
sb('objectives setdisplay sidebar NumberGuess'); sb('objectives setdisplay sidebar NumberGuess');
importPackage(org.bukkit.conversations); var Prompt = org.bukkit.conversations.Prompt;
var ConversationFactory = org.bukkit.conversations.ConversationFactory;
var ConversationPrefix = org.bukkit.conversations.ConversationPrefix;
var number = Math.ceil(Math.random() * 10); var number = Math.ceil(Math.random() * 10);
var prompt = new Prompt() var prompt = new Prompt()