Added 'utils.unwatchFile()' function to fix #117
This commit is contained in:
parent
3c7d3a2bb4
commit
2e4516bf69
3 changed files with 37 additions and 2 deletions
|
@ -70,6 +70,7 @@ Walter Higgins
|
||||||
* [utils.find() function](#utilsfind-function)
|
* [utils.find() function](#utilsfind-function)
|
||||||
* [utils.serverAddress() function](#utilsserveraddress-function)
|
* [utils.serverAddress() function](#utilsserveraddress-function)
|
||||||
* [utils.watchFile() function](#utilswatchfile-function)
|
* [utils.watchFile() function](#utilswatchfile-function)
|
||||||
|
* [utils.unwatchFile() function](#utilsunwatchfile-function)
|
||||||
* [Drone Plugin](#drone-plugin)
|
* [Drone Plugin](#drone-plugin)
|
||||||
* [TLDNR; (Just read this if you're impatient)](#tldnr-just-read-this-if-youre-impatient)
|
* [TLDNR; (Just read this if you're impatient)](#tldnr-just-read-this-if-youre-impatient)
|
||||||
* [Constructing a Drone Object](#constructing-a-drone-object)
|
* [Constructing a Drone Object](#constructing-a-drone-object)
|
||||||
|
@ -1368,6 +1369,16 @@ utils.watchFile( 'test.txt', function( file ) {
|
||||||
console.log( file + ' has changed');
|
console.log( file + ' has changed');
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
### utils.unwatchFile() function
|
||||||
|
|
||||||
|
Removes a file from the watch list.
|
||||||
|
|
||||||
|
#### Example
|
||||||
|
```javascript
|
||||||
|
var utils = require('utils');
|
||||||
|
utils.unwatchFile( 'test.txt');
|
||||||
|
```
|
||||||
|
|
||||||
## Drone Plugin
|
## Drone Plugin
|
||||||
|
|
||||||
The Drone is a convenience class for building. It can be used for...
|
The Drone is a convenience class for building. It can be used for...
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
var File = java.io.File;
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
## Utilities Module
|
## Utilities Module
|
||||||
|
|
||||||
|
@ -440,7 +441,7 @@ var jsFiles = utils.find('./', function(dir,name){
|
||||||
exports.find = function( dir , filter ) {
|
exports.find = function( dir , filter ) {
|
||||||
var result = [];
|
var result = [];
|
||||||
var recurse = function( dir, store ) {
|
var recurse = function( dir, store ) {
|
||||||
var files, dirfile = new java.io.File( dir );
|
var files, dirfile = new File( dir );
|
||||||
|
|
||||||
if ( typeof filter == 'undefined' ) {
|
if ( typeof filter == 'undefined' ) {
|
||||||
files = dirfile.list();
|
files = dirfile.list();
|
||||||
|
@ -514,7 +515,6 @@ utils.watchFile( 'test.txt', function( file ) {
|
||||||
***/
|
***/
|
||||||
var filesWatched = {};
|
var filesWatched = {};
|
||||||
exports.watchFile = function( file, callback ) {
|
exports.watchFile = function( file, callback ) {
|
||||||
var File = java.io.File;
|
|
||||||
if ( typeof file == 'string' ) {
|
if ( typeof file == 'string' ) {
|
||||||
file = new File(file);
|
file = new File(file);
|
||||||
}
|
}
|
||||||
|
@ -523,6 +523,25 @@ exports.watchFile = function( file, callback ) {
|
||||||
lastModified: file.lastModified()
|
lastModified: file.lastModified()
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
/************************************************************************
|
||||||
|
### utils.unwatchFile() function
|
||||||
|
|
||||||
|
Removes a file from the watch list.
|
||||||
|
|
||||||
|
#### Example
|
||||||
|
```javascript
|
||||||
|
var utils = require('utils');
|
||||||
|
utils.unwatchFile( 'test.txt');
|
||||||
|
```
|
||||||
|
|
||||||
|
***/
|
||||||
|
exports.unwatchFile = function( file, callback ) {
|
||||||
|
if ( typeof file == 'string' ) {
|
||||||
|
file = new File(file);
|
||||||
|
}
|
||||||
|
delete filesWatched[file.canonicalPath];
|
||||||
|
};
|
||||||
|
|
||||||
function fileWatcher() {
|
function fileWatcher() {
|
||||||
for (var file in filesWatched) {
|
for (var file in filesWatched) {
|
||||||
var fileObject = new File(file);
|
var fileObject = new File(file);
|
||||||
|
|
|
@ -3,6 +3,7 @@ var utils = require('utils'),
|
||||||
logger = __plugin.logger,
|
logger = __plugin.logger,
|
||||||
foreach = utils.foreach,
|
foreach = utils.foreach,
|
||||||
watchFile = utils.watchFile,
|
watchFile = utils.watchFile,
|
||||||
|
unwatchFile = utils.unwatchFile,
|
||||||
playersDir = __dirname + '/../../players/',
|
playersDir = __dirname + '/../../players/',
|
||||||
serverAddress = utils.serverAddress();
|
serverAddress = utils.serverAddress();
|
||||||
|
|
||||||
|
@ -100,6 +101,10 @@ function revokeScripting ( player ) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
var playerName = '' + player.name;
|
||||||
|
playerName = playerName.replace(/[^a-zA-Z0-9_\-]/g,'');
|
||||||
|
var playerDir = new File( playersDir + playerName );
|
||||||
|
unwatchFile( playerDir );
|
||||||
}
|
}
|
||||||
|
|
||||||
function grantScripting( player ) {
|
function grantScripting( player ) {
|
||||||
|
|
Reference in a new issue