keepcalm / BukkitForge

The world's first __opensource__ coremod. Also a port of the Bukkit server API to MinecraftForge.
http://www.minecraftforge.net/forum/index.php/topic,3254.0.html
103 stars 60 forks source link

getTime() always returns null (Update: Found another bug!) #405

Open recon88 opened 11 years ago

recon88 commented 11 years ago

Somehow getTime() is always returning null. Is there a workaround for this? I just wrote a quick plugin which I really want to use but It's not possible. (It works with Craftbukkit)

long time = Bukkit.getServer().getWorld("world").getTime();
2013-01-30 05:39:46 [WARNUNG] [BukkitForge] Task #6 for DayCounter v1.0 generated an exception
java.lang.NullPointerException
    at com.recon.DayCounter.TimeTrack.run(DayWatcher.java:11)
    at keepcalm.mods.bukkit.bukkitAPI.scheduler.B4VTask.run(B4VTask.java:53)
    at keepcalm.mods.bukkit.bukkitAPI.scheduler.B4VScheduler.mainThreadHeartbeat(B4VScheduler.java:347)
    at keepcalm.mods.bukkit.forgeHandler.SchedulerTickHandler.tickStart(SchedulerTickHandler.java:38)
    at cpw.mods.fml.common.SingleIntervalHandler.tickStart(SingleIntervalHandler.java:16)
    at cpw.mods.fml.common.FMLCommonHandler.tickStart(FMLCommonHandler.java:119)
    at cpw.mods.fml.common.FMLCommonHandler.onPreServerTick(FMLCommonHandler.java:287)
    at net.minecraft.server.MinecraftServer.q(MinecraftServer.java:588)
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:497)
    at fy.run(SourceFile:849)
gravypod commented 11 years ago

This is not get time returning null, this is the world being null. The main dimension isn't called "world", it is "overworld". You should use Bukkit.getServer().getWorld(0) to get the main world

recon88 commented 11 years ago

Oh wow... How did I miss that? Thanks!

recon88 commented 11 years ago

Sorry had to reopen. Just figured out that there is a bug in getTime(). It doesn't reset every 24000 ticks as it should. It keeps running and running... getTime() was at 58000+ during my tests so there is definitly something wrong.

I did the same test with the original Craftbukkit: http://i.imgur.com/yW8LBc8.png It resets after 24000 ticks.

http://jd.bukkit.org/doxygen/dd/daa/interfaceorg_1_1bukkit_1_1World.html#a5c7497b274e17d78c7688adf1ba9c98d

jesusthekiller commented 11 years ago

Just modulo it with 24000 for now:

Time % 24000 will equal real time, even after repair :)

recon88 commented 11 years ago

That's what I did now for my own uses. But that's no real fix since this my plugin will go public.

recon88 commented 11 years ago

Also getFullTime() does not work as it should. Try to use "/set time" and it will not change the full time as it does in bukkit.

recon88 commented 11 years ago

Still sitting on that problem ...

gravypod commented 11 years ago

I'v got Spoons on the case! Should be fixed soon!