This is an easy API for parsing times (such as 5m2d) into seconds/minutes/hours etc.
API Usage:
The class is located in sh.okx.timeapi.api.TimeAPI. Remember to import the TimeAPI.jar into your project.
TimeAPI has an accuracy of one second, as such it cannot hold something like 1 millisecond but has getter methods to convert its stored seconds to milliseconds.
First, you'd want to create an instance of TimeAPI:
TimeAPI api = new TimeAPI("1s 2m 3h"); // Creates a new instance of TimeAPI with 1 second, 2 minutes, and 3 hours.
or
TimeAPI api = new TimeAPI(seconds);
Then, you can extract information from it (all methods return doubles):
api.getNanoseconds();
api.getMicroseconds();
api.getMilliseconds();
api.getSeconds(); // Would return the amount of total seconds in the TimeAPI instance.
// For example, if you did 'new TimeAPI("5m and 10s");', you'd get 310.
api.getMinutes(); // Same as above, with minutes
api.getHours();
api.getDays();
api.getWeeks();
api.getYears();
api.reparse(String); // Reparses with a new string.
What can be parsed:
For seconds: s, secs, seconds, sec, second
For minutes: m, mins, minutes, min, minute
For hours: h, hr, hrs, hours, hour
For days: d, dy, dys, day, days
For weeks: w, week, weeks
For months: m, mon, mnth, month, months
For years: y, yr, yrs, year, years
Also, if your string contains 'and', spaces or ',' they will get ignored.
The API will throw an IllegalArgumentException if you use input something like 4asdf.
Examples of Usage:
All the following work with TimeAPI
- 5s, 7d, 9weeks and 22 hours
- 89 secs, 1 hour 17 days
- 6d4h3s2m
- 7h 2m
- 1 day and 7h
Commands:
Commands
/timeapi <time> Parses a time using the TimeAPI (gives you seconds, minutes, hours, etc);
/timeapi Information about the plugin
Permissions:
Permissions
permissions:
timeapi.*:
children:
timeapi.parse: true
timeapi.command: true
timeapi.parse:
description: Parse TimeAPI strings
default: op
timeapi.command:
description: TimeAPI Plugin Info
default: trueDO NOT ask for help or request additional things in the reviews. Use the forums.
Similar projects
Plugin →Let Me Despawn
Improves performance by tweaking mob despawn rules. Say bye to pesky unintentional persistent mobs.
25MSueta
JourneyMap
Real-time map used for mapping in-game or your browser as you explore.
14.7MSueta
Emotecraft
Create your own emotes in Minecraft.
7.5MSueta
Simple Tpa
A simple tpa plugin which sends requests
5.4MSueta
Common Network
Forge and Fabric Unified Networking Solution
3.9MSueta
Set Home
A lightweight plugin for players to set their homes.
3.8MSueta