From 5a82f0afa7464a819e95d9acda92cb513de330e2 Mon Sep 17 00:00:00 2001 From: walterhiggins Date: Thu, 19 Feb 2015 20:24:20 +0000 Subject: [PATCH] fix issue #214 --- docs/API-Reference.md | 3 +++ src/main/js/modules/utils/utils.js | 24 ++++++++++++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/docs/API-Reference.md b/docs/API-Reference.md index 6840cb8..2c51379 100644 --- a/docs/API-Reference.md +++ b/docs/API-Reference.md @@ -5295,6 +5295,9 @@ Returns the timeofday for the given world using 24 hour notation. (number of min See http://minecraft.gamepedia.com/Day-night_cycle#Conversions +#### Parameters + + * world : the name of the world or world object for which you want to get time ### utils.find() function The utils.find() function will return a list of all files starting at diff --git a/src/main/js/modules/utils/utils.js b/src/main/js/modules/utils/utils.js index e8148e5..b7a36f4 100644 --- a/src/main/js/modules/utils/utils.js +++ b/src/main/js/modules/utils/utils.js @@ -76,13 +76,27 @@ Returns a World object matching the given name ***/ function _world( worldName ){ if (__plugin.canary){ + if (worldName instanceof Packages.net.canarymod.api.world.World){ + return worldName; + } + var worldMgr = Canary.server.worldManager; try { - return Canary.server.worldManager.getWorld( worldName, true ); + if (worldName === undefined){ + var worldNames = worldMgr.getLoadedWorldsNames(); + worldName = worldNames[0]; + } + return worldMgr.getWorld( worldName, true ); } catch (error) { console.error( 'utils.world() failed to load ' + worldName + ',Error:' + error ); } } if (__plugin.bukkit){ + if (worldName instanceof org.bukkit.World){ + return worldName; + } + if (worldName === undefined){ + return bkBukkit.getWorlds().get(0); + } return bkBukkit.getWorld( worldName ); } return null; @@ -427,6 +441,8 @@ See http://minecraft.gamepedia.com/Day-night_cycle#Conversions ***/ function getTime(world){ + world = _world(world); + if (__plugin.bukkit){ return world.time; } @@ -450,8 +466,12 @@ Returns the timeofday for the given world using 24 hour notation. (number of min See http://minecraft.gamepedia.com/Day-night_cycle#Conversions +#### Parameters + + * world : the name of the world or world object for which you want to get time ***/ -function getTime24(world){ +function getTime24( world ){ + world = _world(world); // accept world name or object or undeifned var mcTime = getTime(world); var mins = Math.floor( ( (mcTime + 6000) % 24000) / 16.6667 ); return mins;