lib24time
Overview
Important: This is just a library for using with other plugins. I you're searching for a plugin which let's you get/set the time in a 24 h format have a look at RealTimeSet
This library was splitted out from SignClock because I want to make plugins (ideas welcome) which should use a 24 h time format. This is what this library is for. Feel free to use it in your own plugins!
How to use
Import
To use it in your plugin make lib24time a dependecy of it and import the library in the class files like this:
import com.V10lator.lib24time.lib24time
Check Version
Then, its highly recommended to make a versions check in onEnable() like this:
if(!lib24time.isInitialized()) { info2log("ERROR: lib24time not ready!"); pm.disablePlugin(this); return; } if(lib24time.getVersion() < 0.7D) { info2log("ERROR: lib24time >= 0.7 needed (" + lib24time.getVersion() + " found)"); pm.disablePlugin(this); return; }
As you can see all is handled statically. Don't try to start an instance of the lib!
Get the Time
To get the time in your plugin you'll need a listener for the TimeChangeEvent, it could look like that:
import org.bukkit.World; import org.bukkit.event.Event; import org.bukkit.event.Listener; import com.V10lator.lib24time.lib24time; import com.V10lator.lib24time.event.TimeChangeEvent; class TimeEventCustomListener implements Listener { public void timeChange(TimeChangeEvent event) { World world = event.getWorld(); String now = event.getNewTime(); ... } }
to get the old time you can use event.getOldTime(); - You can also cancel the event (event.setCancelled(true);).
There's also the function getTime(World world) in the library but it's recommended to use the event instead (if possible).
Get the Daytime
For the daytime there's the DaytimeChangedEvent or getDaytime(World world). It's recommended to prefer the event over the function here, too.
Set the Time
To set the time you can use the function setTime(String time).
...
There are more functions like formatting a minecraft timecode to a 24h time (code2time(long timecode)) in the library and if you think something is missing feel free to request it for a feature version.
Features:
- Get and set the in-game time in 24 h format (hh:mm).
- Get and set times from a timecode.
- Calculate the remaining time till a given time.
- Adjust the sun.