Added RealTime Day
This commit is contained in:
@@ -14,6 +14,9 @@ import java.net.URL;
|
|||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.GregorianCalendar;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
@@ -89,6 +92,7 @@ public class AnuraCore extends JavaPlugin implements PluginMessageListener {
|
|||||||
this.getConfig().addDefault("disable-mushroom-spread", false);
|
this.getConfig().addDefault("disable-mushroom-spread", false);
|
||||||
this.getConfig().addDefault("on-join-to-spawn", false);
|
this.getConfig().addDefault("on-join-to-spawn", false);
|
||||||
this.getConfig().addDefault("golf", false);
|
this.getConfig().addDefault("golf", false);
|
||||||
|
this.getConfig().addDefault("realtime-day", false);
|
||||||
this.getConfig().options().copyDefaults(true);
|
this.getConfig().options().copyDefaults(true);
|
||||||
this.getConfig().options().header("Config File of the Anura Core-Plugin:");
|
this.getConfig().options().header("Config File of the Anura Core-Plugin:");
|
||||||
sql.queryUpdate("DELETE FROM coreServers WHERE name = '"+this.getConfig().getString("server-name")+"'");
|
sql.queryUpdate("DELETE FROM coreServers WHERE name = '"+this.getConfig().getString("server-name")+"'");
|
||||||
@@ -231,6 +235,22 @@ public class AnuraCore extends JavaPlugin implements PluginMessageListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}, 600, 600);
|
}, 600, 600);
|
||||||
|
if (this.getConfig().getBoolean("realtime-day")) {
|
||||||
|
for (World world : Bukkit.getWorlds()) {
|
||||||
|
world.setGameRuleValue("doDaylightCycle", "false");
|
||||||
|
world.setTime(0);
|
||||||
|
}
|
||||||
|
Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
Integer[] time = getSystemTime();
|
||||||
|
int TTime = convertTime(time[0], time[1]);
|
||||||
|
setWorldTime(TTime);
|
||||||
|
System.out.println("World Time synchronized");
|
||||||
|
}
|
||||||
|
}, 0, (20 * 60 * 10));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -1222,4 +1242,36 @@ public class AnuraCore extends JavaPlugin implements PluginMessageListener {
|
|||||||
public Features getFeatures() {
|
public Features getFeatures() {
|
||||||
return features;
|
return features;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Integer[] getSystemTime() {
|
||||||
|
Date date = new Date();
|
||||||
|
Calendar calendar = GregorianCalendar.getInstance();
|
||||||
|
calendar.setTime(date);
|
||||||
|
int hour = calendar.get(Calendar.HOUR_OF_DAY);
|
||||||
|
int minute = calendar.get(Calendar.MINUTE);
|
||||||
|
Integer[] time = new Integer[]{hour, minute};
|
||||||
|
return time;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setWorldTime(Integer ticks) {
|
||||||
|
for (World world : Bukkit.getWorlds()) {
|
||||||
|
world.setGameRuleValue("doDaylightCycle", "false");
|
||||||
|
world.setTime(ticks);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private int convertTime(Integer hour, Integer minute) {
|
||||||
|
int TMinute = (int) (83 * (round(minute, 5)) / 5);
|
||||||
|
int THour;
|
||||||
|
if (hour >= 6) {
|
||||||
|
THour = (hour - 6) * 1000;
|
||||||
|
} else {
|
||||||
|
THour = ((hour + 24) - 6) * 1000;
|
||||||
|
}
|
||||||
|
return THour + TMinute;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static double round(double num, int multipleOf) {
|
||||||
|
return Math.floor((num + (double) multipleOf / 2) / multipleOf) * multipleOf;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user