This plugin will convert standard time to metric time.
As with my Ship Time plugin, this is a rewrite of a program I wrote in college many years ago in Turbo Pascal 3.0.
Back in high school (mumble-mumble years ago), I devised a system of metric time where the day was divided into 10 hours, each hour divided into 100 minutes, and each minute divided into 100 seconds.
I wrote a Pascal program in college to implement my metric time system.
This was before the Internet was a thing, so I didn't know that some companies and countries already toyed with metric time standards and had come up with systems very similar to mine.
To get the current time, issue /METRICTIME . To convert standard time to metric time, issue /METRICTIME hh:mm:ss .
To install this plugin, copy the plugin JAR file to your server's plugins folder.
Code (Text):
package FredashaySpigotMetricTime;
/* This plugin will convert standard time to metric time.
*
* As with my Ship Time plugin, this is a rewrite of a program I wrote in college many years
* ago in Turbo Pascal 3.0.
*
* Back in high school (mumble-mumble years ago), I devised a system of metric time where
* the day was divided into 10 hours, each hour divided into 100 minutes, and each minute
* divided into 100 seconds.
*
* Majoring in math and computer science in college, I wrote a Pascal program to implement my
* metric time system.
*
* This was before the Internet was a thing, so I didn't know that some companies and
* countries already toyed with metric time standards and had come up with
* systems very similar to mine.
*
* To get the current time, issue /METRICTIME . To convert standard time to metric time,
* issue /METRICTIME hh:mm:ss .
*/
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.logging.Logger;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.plugin.java.JavaPlugin;
public class MyPlugin extends JavaPlugin implements Listener, CommandExecutor {
private static Logger logger = null;
private static String EOL = System.getProperty("line.separator");
@Override
public void onEnable() {
getServer().getPluginManager().registerEvents(this,this);
logger = Logger.getLogger("Minecraft");
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (label.equalsIgnoreCase("metrictime")) {
if (sender instanceof Player) {
Player player = (Player) sender;
logger.info ("[MetricTime] Player '" + player.getName() + "' invoked /METRICTIME . ");
if (args.length > 0) {
if ((args[0].equalsIgnoreCase("help")) || (args[0].equalsIgnoreCase("about")) || (args[0].equalsIgnoreCase("?"))) {
player.sendMessage("<MetricTime> This plugin will convert standard time to metric time. " + EOL +
"As with my Ship Time plugin, this is a rewrite of a program I wrote in college many years ago in Turbo Pascal 3.0. " + EOL +
"Back in high school (mumble-mumble years ago), I devised a system of metric time where the day was divided into 10 hours, each hour divided into 100 minutes, and each minute divided into 100 seconds. " + EOL +
"Majoring in math and computer science in college, I wrote a Pascal program to implement my metric time system. " + EOL +
"This was before the Internet was a thing, so I didn't know that some companies and countries already toyed with metric time standards and had come up with systems very similar to mine. " + EOL +
"To get the current time, issue /METRICTIME . To convert standard time to metric time, issue /METRICTIME hh:mm:ss . " + EOL +
"Thank you for using Fredashay's MetricTime plugin! ");
}
else {
long userTime = 0;
SimpleDateFormat sdfTime = new SimpleDateFormat("HH:mm:ss");
boolean valid = true;
try {
userTime = sdfTime.parse(args[0]).getTime();
logger.info ("[MetricTime] Standard time entered is " + prettyTime(userTime) + ". ");
}
catch (ParseException oops) {
valid = false;
player.sendMessage("<MetricTime> Silly player! '" + args[0] + "' is not a valid standard time. ");
}
if (valid) {
Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(userTime);
int hour = cal.get(Calendar.HOUR_OF_DAY);
int minute = cal.get(Calendar.MINUTE);
int second = cal.get(Calendar.SECOND);
logger.info ("[MetricTime] Hour=" + hour + " Minute=" + minute + " Second=" + second);
int secondsNow = second + (minute * 60) + (hour * 3600);
logger.info ("[MetricTime] Standard seconds=" + secondsNow);
double blah = secondsNow;
double blahBlah = blah * 1.15740; //740740;
int metricSeconds = (int) blahBlah;
logger.info ("[MetricTime] Metric seconds=" + metricSeconds);
int metricMinutes = metricSeconds / 100;
int metricHours = metricMinutes / 100;
metricSeconds = metricSeconds - (metricMinutes * 100);
metricMinutes = metricMinutes - (metricHours * 100);
logger.info ("[MetricTime] Metric time entered is " + metricHours + ":" + metricMinutes + ":" + metricSeconds + ". ");
player.sendMessage("<MetricTime> Standard time entered is " + prettyTime(userTime) + ". Converted to metric time is " + metricHours + ":" + metricMinutes + ":" + metricSeconds + ". Thank you for using Fredashay's MetricTime plugin! ");
}
}
}
else {
long timeNow = System.currentTimeMillis();
logger.info ("[MetricTime] Standard time now is " + prettyTime(timeNow) + ". ");
Calendar cal = Calendar.getInstance();
int hour = cal.get(Calendar.HOUR_OF_DAY);
int minute = cal.get(Calendar.MINUTE);
int second = cal.get(Calendar.SECOND);
logger.info ("[MetricTime] Hour=" + hour + " Minute=" + minute + " Second=" + second);
int secondsNow = second + (minute * 60) + (hour * 3600);
logger.info ("[MetricTime] Standard seconds since midnight=" + secondsNow);
double blah = secondsNow;
double blahBlah = blah * 1.15740; //740740;
int metricSeconds = (int) blahBlah;
logger.info ("[MetricTime] Metric seconds since midnight=" + metricSeconds);
int metricMinutes = metricSeconds / 100;
int metricHours = metricMinutes / 100;
metricSeconds = metricSeconds - (metricMinutes * 100);
metricMinutes = metricMinutes - (metricHours * 100);
logger.info ("[MetricTime] Metric time now is " + metricHours + ":" + metricMinutes + ":" + metricSeconds + ". ");
player.sendMessage("<MetricTime> Standard time now is " + prettyTime(timeNow) + ". Metric time now is " + metricHours + ":" + metricMinutes + ":" + metricSeconds + ". Thank you for using Fredashay's MetricTime plugin! ");
}
}
else {
sender.sendMessage("[MetricTime] Say what? ");
}
return(true);
}
return(false);
}
private String prettyTime(Long time) {
SimpleDateFormat sdfTime = new SimpleDateFormat("HH:mm:ss");
return (sdfTime.format(time));
}
}