lib24time

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.

Download

File Name Status Version Downloads Date
lib24time 1.20.2 Updating 1.20.2 Updating Updating
lib24time 1.20.1 Updating 1.20.1 Updating Updating
lib24time 1.20 Updating 1.20 Updating Updating
lib24time 1.19.2 Updating 1.19.2 Updating Updating
lib24time 1.19.1 Updating 1.19.1 Updating Updating
lib24time 1.19 Updating 1.19 Updating Updating
lib24time 1.18 Updating 1.18 Updating Updating
lib24time 1.17.1 Updating 1.17.1 Updating Updating
lib24time Forge Updating Forge Updating Updating
lib24time Fabric Updating Fabric Updating Updating
lib24time
lib24time

Dear youtuber!
Have you a channel youtube and want to bring your Video to quality visitors?
Do you want your video to appear on our website?
Do you want to become partner with us?
Just 3 steps to become our partner:
Step 1: Make video review for mods, addons, plugins, ... which you like
Step 2: Upload this video to youtube and our link to your video description
Step 3: Send the youtube video link via message to http://fb.com/9lifehack or leave a comment in the post. We will add your video in the our post, it will help you have more view.
JOIN to get more youtube view with us!!!!

Related Posts

Smarty Productivity Happiness

9LifeHack.com - make things smart