1 |
package dk.thoerup.bukkit.hoeruputils; |
2 |
|
3 |
import java.util.List; |
4 |
|
5 |
import org.bukkit.ChatColor; |
6 |
import org.bukkit.Server; |
7 |
import org.bukkit.World; |
8 |
import org.bukkit.command.Command; |
9 |
import org.bukkit.command.CommandExecutor; |
10 |
import org.bukkit.command.CommandSender; |
11 |
import org.bukkit.plugin.Plugin; |
12 |
|
13 |
import dk.thoerup.bukkit.hoeruputils.utils.MessageBroadcaster; |
14 |
|
15 |
public class EternalDayCommand implements CommandExecutor { |
16 |
|
17 |
|
18 |
int taskId = -1; |
19 |
|
20 |
List<World> worlds; |
21 |
Server server; |
22 |
Plugin plugin; |
23 |
|
24 |
public EternalDayCommand(Plugin plugin) { |
25 |
|
26 |
this.plugin = plugin; |
27 |
server = plugin.getServer(); |
28 |
worlds = server.getWorlds(); |
29 |
} |
30 |
|
31 |
@Override |
32 |
public boolean onCommand(final CommandSender sender, Command command, String label, String[] args) { |
33 |
//debug |
34 |
System.out.println("world count " + worlds.size()); |
35 |
for (World world : worlds) { |
36 |
System.out.println(" >" + world.getName() + " : " + world.getTime() ); |
37 |
} |
38 |
|
39 |
if (taskId == -1) { |
40 |
taskId = server.getScheduler().scheduleSyncRepeatingTask(plugin, new EternalDayRunner(), 2*20, 60*20); |
41 |
server.broadcastMessage(ChatColor.YELLOW + "Eternal day is enabled - have a nice long day"); |
42 |
} else { |
43 |
server.getScheduler().cancelTask(taskId); |
44 |
taskId = -1; |
45 |
server.broadcastMessage(ChatColor.YELLOW + "Eternal day is disabled - watch out for zombies"); |
46 |
} |
47 |
|
48 |
|
49 |
return true; |
50 |
} |
51 |
|
52 |
class EternalDayRunner implements Runnable { |
53 |
|
54 |
// 1000=1 hour, 0 is 06:00 so 12000 is 18:00 |
55 |
@Override |
56 |
public void run() { |
57 |
for(World world : worlds) { |
58 |
if (world.getTime() > 12000) { |
59 |
world.setTime(0); |
60 |
server.getScheduler().scheduleSyncDelayedTask(plugin, new MessageBroadcaster(server, ChatColor.YELLOW + "Eternalday has extended the period of light once again!")); |
61 |
} |
62 |
} |
63 |
} |
64 |
|
65 |
} |
66 |
|
67 |
} |