I was wondering what the best way is to go about setting the time to 23000 when the time is over 13000. I am going to set my server up to have 3 days and 2 nights that people have to then survive. Any help is appreciated. Mainly I want to know if I need to use an event listener, and I want to know which one even when no one is online.
You could use a Timer and schedule it for every 50 milliseconds. Inside of the TimerTask's run method, make a check Code: if(getServer().getWorld("world").getTime() > 13000) getServer().getWorld("world").setTime(23000); Once I get back to my computer I'll post any other code it you need it.
Than Thanks for the reply, but what kind of event can I listen for in order to check time frequently like every 50 ticks?
Thanks Stud I will look into it. Do we know of any source code I can look at for this? Maybe a lottery plugin source?
Well if you don't want to use a Scheduler (which you should), you just make a timer like this: Code:Java Timer t;TimeCheckTimer tim;public void onEnable(){ t = new Timer(); tim = new TimeCheckTimer(); t.schedule(tim, 50, 50);} public void onDisable(){ if(t != null) t.cancel(); // Make sure this is here to stop the thread} public class TimeCheckTimer extends TimerTask { public void run(){ if(getServer().getWorld("world").getTime() > 13000) getServer().getWorld("world").setTime(23000); }
Thanks guys I got it working! Code:java public class Basic extends JavaPlugin{ @Override public void onEnable(){ Bukkit.getServer().getScheduler().scheduleAsyncRepeatingTask(this, new TimeTrack(), 0, 200L); } @Override public void onDisable(){ }} Code:java class TimeTrack implements Runnable { public void run() { long time = Bukkit.getServer().getWorld("dev").getTime(); if( time > 13000 && time < 23000 ) { //World name is dev, 13000 is the time Sun sets Bukkit.getServer().getWorld("dev").setTime(23000);// 23000 is the time Sun Rises } }} My Final Code: Code:java public class 3Days2Nights extends JavaPlugin{ @Override public void onEnable(){ Bukkit.getServer().getScheduler().scheduleAsyncRepeatingTask(this, new TimeTrack(), 0, 100L); } @Override public void onDisable(){ }} Code:java class TimeTrack implements Runnable { int dayCount = 1; public void run() { long time = Bukkit.getServer().getWorld("dev").getTime(); Bukkit.getServer().broadcastMessage(""+dayCount); Bukkit.getServer().broadcastMessage(""+time); switch (dayCount){ case 1: //Day 1 if( time > 23000 && time < 24000 ) { Bukkit.getServer().broadcastMessage(ChatColor.GREEN + "The First Day"); dayCount ++; } break; case 2: //Day 2 if( time > 12000 && time < 23000 ) { Bukkit.getServer().getWorld("dev").setTime(23900); Bukkit.getServer().broadcastMessage(ChatColor.YELLOW + "Hump Day"); dayCount ++; } break; case 3: //Day 3 if( time > 12000 && time < 23900 ) { Bukkit.getServer().getWorld("dev").setTime(23900); Bukkit.getServer().broadcastMessage(ChatColor.GOLD+ "The Last Day"); dayCount ++; } break; case 4: //Day 4 if(time > 14000 && time < 23900) { Bukkit.getServer().broadcastMessage(ChatColor.BLUE + "The First Night"); dayCount ++; } break; case 5: //Day 5 if( time > 20000) { Bukkit.getServer().getWorld("dev").setTime(14000); Bukkit.getServer().broadcastMessage(ChatColor.DARK_PURPLE + "The Final Night"); dayCount = 1; } break; } }} EDIT by Moderator: merged posts, please use the edit button instead of double posting.
I am adding different difficulties for each dayCount Now First Day: Peaceful Hump Day: Easy Final Day: Easy First Night: Normal Final Night: Hard I love learning this stuff!