Fixing the at() function so it works for canarymod

This commit is contained in:
walterhiggins 2015-01-24 00:07:58 +00:00
parent 1fabb59eb5
commit 9f80f240a9

View file

@ -450,27 +450,27 @@ utils.at( '19:00', function() {
``` ```
***/ ***/
exports.at = function( time24hr, callback, worlds ) { exports.at = function( time24hr, callback, pWorlds ) {
var forever = function(){ return true; }; var forever = function(){ return true; };
var timeParts = time24hr.split( ':' ); var timeParts = time24hr.split( ':' );
var hrs = ( (timeParts[0] * 1000) + 18000 ) % 24000; var timeMins = (timeParts[0] * 60) + (timeParts[1] * 1);
var mins; if ( typeof pWorlds == 'undefined' ) {
if ( timeParts.length > 1 ) { pWorlds = worlds();
mins = ( timeParts[1] / 60 ) * 1000;
}
var timeMc = hrs + mins;
if ( typeof worlds == 'undefined' ) {
worlds = server.worlds;
} }
var calledToday = false;
_nicely( function() { _nicely( function() {
_foreach( worlds, function ( world ) { _foreach( pWorlds, function ( world ) {
var time = getTime(world); var time = getTime24(world);
var diff = timeMc - time; var diff = time - timeMins;
if ( diff > 0 && diff < 100 ) { if (diff > 0 && diff < 5 && !calledToday){
callback(); callback();
calledToday = true;
}
if (diff < 0){
calledToday = false;
} }
}); });
}, forever, null, 100 ); }, forever, null, 1000 );
}; };
/************************************************************************* /*************************************************************************
### utils.time( world ) function ### utils.time( world ) function
@ -817,13 +817,15 @@ function toArray( ){
} }
exports.array = toArray; exports.array = toArray;
function canaryWorlds(){ function worlds(){
return toArray( server.worldManager.allWorlds ); if (__plugin.canary){
return toArray(server.worldManager.allWorlds);
}
if (__plugin.bukkit){
return toArray(server.worlds);
}
} }
function bukkitWorlds(){ exports.worlds = worlds;
return toArray( server.worlds );
}
exports.worlds = __plugin.canary ? canaryWorlds : bukkitWorlds;
/************************************************************************* /*************************************************************************
### utils.players() function ### utils.players() function