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