PandacraftUtils/src/net/mc_pandacraft/java/plugin/pandacraftutils/modules/SpawnTimeManager.java

52 lines
1.0 KiB
Java
Raw Normal View History

package net.mc_pandacraft.java.plugin.pandacraftutils.modules;
2014-11-22 17:18:10 +01:00
import java.util.Calendar;
import java.util.Date;
import net.mc_pandacraft.java.plugin.pandacraftutils.PandacraftUtils;
import org.bukkit.scheduler.BukkitRunnable;
public class SpawnTimeManager extends BukkitRunnable {
private PandacraftUtils plugin = PandacraftUtils.getInstance();
2014-11-22 17:18:10 +01:00
int timeTick = 0;
private String initial_map_name = "spawn";
public SpawnTimeManager() {
2014-11-22 17:18:10 +01:00
run();
plugin.getServer().getScheduler().runTaskTimer(plugin, this, 1L, 2L);
}
@Override
public void run() {
Calendar calendar = Calendar.getInstance();
calendar.setTime(new Date());
int hours = calendar.get(Calendar.HOUR_OF_DAY);
int minutes = calendar.get(Calendar.MINUTE);
int seconds = calendar.get(Calendar.SECOND);
timeTick = ((hours * 3600 + minutes * 60 + seconds) * 10 / 36) - 6000;
if (timeTick < 0)
timeTick += 24000;
try
{
plugin.getServer().getWorld(initial_map_name).setFullTime(timeTick);
}
catch (NullPointerException e) {}
}
}