Added 'use strict' to lib modules. Added legacy directory check
This commit is contained in:
parent
8a65765f08
commit
4803f3027a
12 changed files with 95 additions and 33 deletions
|
@ -49,14 +49,14 @@ module.exports instead of exports.
|
|||
## Module Loading
|
||||
|
||||
When the ScriptCraft Java plugin is first installed, a new
|
||||
subdirectory is created in the craftbukkit directory. If your
|
||||
subdirectory is created in the craftbukkit/plugins directory. If your
|
||||
craftbukkit directory is called 'craftbukkit' then the new
|
||||
subdirectories will be ...
|
||||
|
||||
* craftbukkit/scriptcraft/
|
||||
* craftbukkit/scriptcraft/plugins
|
||||
* craftbukkit/scriptcraft/modules
|
||||
* craftbukkit/scriptcraft/lib
|
||||
* craftbukkit/plugins/scriptcraft/
|
||||
* craftbukkit/plugins/scriptcraft/plugins
|
||||
* craftbukkit/plugins/scriptcraft/modules
|
||||
* craftbukkit/plugins/scriptcraft/lib
|
||||
|
||||
... The `plugins`, `modules` and `lib` directories each serve a different purpose.
|
||||
|
||||
|
@ -317,7 +317,7 @@ See chat/color.js for an example of a simple plugin - one which lets
|
|||
players choose a default chat color. See also [Anatomy of a
|
||||
ScriptCraft Plugin][anatomy].
|
||||
|
||||
[anatomy]: http://walterhiggins.net/blog/ScriptCraft-1-Month-later
|
||||
[anatomy]: ./Anatomy-of-a-Plugin.md
|
||||
|
||||
### command() function
|
||||
|
||||
|
@ -330,8 +330,18 @@ plugin author) safely expose javascript functions for use by players.
|
|||
|
||||
#### Parameters
|
||||
|
||||
* commandName : The name to give your command - the command will be invoked like this by players `/jsp commandName`
|
||||
* commandFunction: The javascript function which will be invoked when the command is invoked by a player.
|
||||
* commandName : The name to give your command - the command will
|
||||
be invoked like this by players `/jsp commandName`
|
||||
* commandFunction: The javascript function which will be invoked when
|
||||
the command is invoked by a player. The callback function in turn
|
||||
takes 2 parameters...
|
||||
|
||||
* params : An Array of type String - the list of parameters
|
||||
passed to the command.
|
||||
* sender : The [CommandSender][bukcs] object that invoked the
|
||||
command (this is usually a Player object but can be a Block
|
||||
([BlockCommandSender][bukbcs]).
|
||||
|
||||
* options (Array - optional) : An array of command options/parameters
|
||||
which the player can supply (It's useful to supply an array so that
|
||||
Tab-Completion works for the `/jsp ` commands.
|
||||
|
@ -393,7 +403,9 @@ A scriptcraft implementation of clearInterval().
|
|||
|
||||
### refresh() function
|
||||
|
||||
The refresh() function will ...
|
||||
The refresh() function can be used to only reload the ScriptCraft
|
||||
plugin (it's like the `reload` command except it only reloads
|
||||
ScriptCraft). The refresh() function will ...
|
||||
|
||||
1. Disable the ScriptCraft plugin.
|
||||
2. Unload all event listeners associated with the ScriptCraft plugin.
|
||||
|
@ -411,6 +423,10 @@ parameter. The callback will be called when the ScriptCraft plugin is
|
|||
unloaded (usually as a result of a a `reload` command or server
|
||||
shutdown).
|
||||
|
||||
This function provides a way for ScriptCraft modules to do any
|
||||
required cleanup/housekeeping just prior to the ScriptCraft Plugin
|
||||
unloading.
|
||||
|
||||
## require - Node.js-style module loading in ScriptCraft
|
||||
|
||||
Node.js is a server-side javascript environment with an excellent
|
||||
|
|
|
@ -480,11 +480,11 @@ Once you've installed Notepad++, Launch it, create a new file and type the follo
|
|||
}
|
||||
|
||||
... then save the file in a new directory
|
||||
`craftbukkit/scriptcraft/plugins/{your_name}` (replace {your_name} with your
|
||||
own name) and call the file `greet.js` (be sure to change the file-type
|
||||
option to '*.* All Files' when saving or NotePad++ will add a '.txt'
|
||||
extension to the filename. Now switch back to the Minecraft game and
|
||||
type...
|
||||
`craftbukkit/plugins/scriptcraft/plugins/{your_name}` (replace
|
||||
{your_name} with your own name) and call the file `greet.js` (be sure
|
||||
to change the file-type option to '*.* All Files' when saving or
|
||||
NotePad++ will add a '.txt' extension to the filename. Now switch back
|
||||
to the Minecraft game and type...
|
||||
|
||||
/js refresh()
|
||||
|
||||
|
@ -501,10 +501,10 @@ loaded. Try it out by typing this command...
|
|||
minecraft username. Congratulations - You've just written your very
|
||||
first Minecraft Mod! With ScriptCraft installed, writing Minecraft
|
||||
Mods is as simple as writing a new javascript function and saving it
|
||||
in a file in the craftbukkit/scriptcraft/plugins directory. This
|
||||
function will now be avaible every time you launch minecraft. This is
|
||||
a deliberately trivial minecraft mod but the principles are the same
|
||||
when creating more complex mods.
|
||||
in a file in the craftbukkit/plugins/scriptcraft/plugins
|
||||
directory. This function will now be avaible every time you launch
|
||||
minecraft. This is a deliberately trivial minecraft mod but the
|
||||
principles are the same when creating more complex mods.
|
||||
|
||||
The `exports` variable is a special variable you can use in your mod
|
||||
to provide functions, objects and variables for others to use. If you
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
'use strict';
|
||||
/*
|
||||
command management - allow for non-ops to execute approved javascript code.
|
||||
*/
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
'use strict';
|
||||
/*************************************************************************
|
||||
## console global variable
|
||||
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
'use strict';
|
||||
/************************************************************************
|
||||
## events Module
|
||||
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
'use strict';
|
||||
var console = require('./console');
|
||||
var File = java.io.File;
|
||||
var FileWriter = java.io.FileWriter;
|
||||
|
|
|
@ -260,3 +260,4 @@ When resolving module names to file paths, ScriptCraft uses the following rules.
|
|||
};
|
||||
return _requireClosure(new java.io.File(rootDir));
|
||||
})
|
||||
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
'use strict';
|
||||
/************************************************************************
|
||||
# ScriptCraft API Reference
|
||||
|
||||
|
@ -50,14 +51,14 @@ module.exports instead of exports.
|
|||
## Module Loading
|
||||
|
||||
When the ScriptCraft Java plugin is first installed, a new
|
||||
subdirectory is created in the craftbukkit directory. If your
|
||||
subdirectory is created in the craftbukkit/plugins directory. If your
|
||||
craftbukkit directory is called 'craftbukkit' then the new
|
||||
subdirectories will be ...
|
||||
|
||||
* craftbukkit/scriptcraft/
|
||||
* craftbukkit/scriptcraft/plugins
|
||||
* craftbukkit/scriptcraft/modules
|
||||
* craftbukkit/scriptcraft/lib
|
||||
* craftbukkit/plugins/scriptcraft/
|
||||
* craftbukkit/plugins/scriptcraft/plugins
|
||||
* craftbukkit/plugins/scriptcraft/modules
|
||||
* craftbukkit/plugins/scriptcraft/lib
|
||||
|
||||
... The `plugins`, `modules` and `lib` directories each serve a different purpose.
|
||||
|
||||
|
@ -318,7 +319,7 @@ See chat/color.js for an example of a simple plugin - one which lets
|
|||
players choose a default chat color. See also [Anatomy of a
|
||||
ScriptCraft Plugin][anatomy].
|
||||
|
||||
[anatomy]: http://walterhiggins.net/blog/ScriptCraft-1-Month-later
|
||||
[anatomy]: ./Anatomy-of-a-Plugin.md
|
||||
|
||||
### command() function
|
||||
|
||||
|
@ -331,8 +332,18 @@ plugin author) safely expose javascript functions for use by players.
|
|||
|
||||
#### Parameters
|
||||
|
||||
* commandName : The name to give your command - the command will be invoked like this by players `/jsp commandName`
|
||||
* commandFunction: The javascript function which will be invoked when the command is invoked by a player.
|
||||
* commandName : The name to give your command - the command will
|
||||
be invoked like this by players `/jsp commandName`
|
||||
* commandFunction: The javascript function which will be invoked when
|
||||
the command is invoked by a player. The callback function in turn
|
||||
takes 2 parameters...
|
||||
|
||||
* params : An Array of type String - the list of parameters
|
||||
passed to the command.
|
||||
* sender : The [CommandSender][bukcs] object that invoked the
|
||||
command (this is usually a Player object but can be a Block
|
||||
([BlockCommandSender][bukbcs]).
|
||||
|
||||
* options (Array - optional) : An array of command options/parameters
|
||||
which the player can supply (It's useful to supply an array so that
|
||||
Tab-Completion works for the `/jsp ` commands.
|
||||
|
@ -394,7 +405,9 @@ A scriptcraft implementation of clearInterval().
|
|||
|
||||
### refresh() function
|
||||
|
||||
The refresh() function will ...
|
||||
The refresh() function can be used to only reload the ScriptCraft
|
||||
plugin (it's like the `reload` command except it only reloads
|
||||
ScriptCraft). The refresh() function will ...
|
||||
|
||||
1. Disable the ScriptCraft plugin.
|
||||
2. Unload all event listeners associated with the ScriptCraft plugin.
|
||||
|
@ -412,6 +425,10 @@ parameter. The callback will be called when the ScriptCraft plugin is
|
|||
unloaded (usually as a result of a a `reload` command or server
|
||||
shutdown).
|
||||
|
||||
This function provides a way for ScriptCraft modules to do any
|
||||
required cleanup/housekeeping just prior to the ScriptCraft Plugin
|
||||
unloading.
|
||||
|
||||
***/
|
||||
|
||||
/*
|
||||
|
@ -437,8 +454,8 @@ function __onEnable (__engine, __plugin, __script)
|
|||
return "" + file.getCanonicalPath().replaceAll("\\\\","/");
|
||||
};
|
||||
|
||||
var parentFileObj = __script.parentFile;
|
||||
var jsPluginsRootDir = parentFileObj.parentFile;
|
||||
var libDir = __script.parentFile; // lib (assumes scriptcraft.js is in craftbukkit/plugins/scriptcraft/lib directory
|
||||
var jsPluginsRootDir = libDir.parentFile; // scriptcraft
|
||||
var jsPluginsRootDirName = _canonize(jsPluginsRootDir);
|
||||
|
||||
var _loaded = {};
|
||||
|
@ -466,11 +483,13 @@ function __onEnable (__engine, __plugin, __script)
|
|||
var reader = new FileReader(file);
|
||||
var br = new BufferedReader(reader);
|
||||
var code = "";
|
||||
var wrappedCode;
|
||||
try{
|
||||
while ((r = br.readLine()) !== null)
|
||||
code += r + "\n";
|
||||
|
||||
result = __engine.eval("(" + code + ")");
|
||||
wrappedCode = "(" + code + ")";
|
||||
result = __engine.eval(wrappedCode);
|
||||
// issue #103 avoid side-effects of || operator on Mac Rhino
|
||||
_loaded[canonizedFilename] = result ;
|
||||
if (!_loaded[canonizedFilename])
|
||||
|
@ -619,4 +638,23 @@ function __onEnable (__engine, __plugin, __script)
|
|||
}
|
||||
return result;
|
||||
};
|
||||
/*
|
||||
wph 20140102 - warn if legacy 'craftbukkit/js-plugins' or 'craftbukkit/scriptcraft' directories are present
|
||||
*/
|
||||
var cbPluginsDir = jsPluginsRootDir.parentFile;
|
||||
var cbDir = new File(cbPluginsDir.canonicalPath).parentFile;
|
||||
var legacyDirs = [
|
||||
new File(cbDir, 'js-plugins'),
|
||||
new File(cbDir, 'scriptcraft')
|
||||
];
|
||||
var legacyExists = false;
|
||||
for (var i = 0; i < legacyDirs.length; i++){
|
||||
if (legacyDirs[i].exists() && legacyDirs[i].isDirectory()){
|
||||
legacyExists = true;
|
||||
console.warn('Legacy ScriptCraft directory ' + legacyDirs[i].canonicalPath + ' was found. This directory is no longer used.');
|
||||
}
|
||||
}
|
||||
if (legacyExists){
|
||||
console.info('Please note that the working directory for ' + __plugin + ' is ' + jsPluginsRootDir.canonicalPath);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
'use strict';
|
||||
var _commands = require('command').commands;
|
||||
/*
|
||||
Tab completion for the /jsp commmand
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
'use strict';
|
||||
var tabCompleteJSP = require('tabcomplete-jsp');
|
||||
/*
|
||||
Tab Completion of the /js and /jsp commands
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
'use strict';
|
||||
/************************************************************************
|
||||
String class extensions
|
||||
-----------------------
|
||||
|
@ -61,7 +62,6 @@ var formattingCodes = {
|
|||
italic: c.ITALIC,
|
||||
lightpurple: c.LIGHT_PURPLE,
|
||||
indigo: c.BLUE,
|
||||
green: c.GREEN,
|
||||
red: c.RED,
|
||||
pink: c.LIGHT_PURPLE,
|
||||
yellow: c.YELLOW,
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
'use strict';
|
||||
/************************************************************************
|
||||
## Utilities Module
|
||||
|
||||
|
|
Reference in a new issue