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