/[projects]/miscJava/bukkit-minecraft-plugins/HoerupUtils/src/dk/thoerup/bukkit/hoeruputils/EternalDayCommand.java
ViewVC logotype

Annotation of /miscJava/bukkit-minecraft-plugins/HoerupUtils/src/dk/thoerup/bukkit/hoeruputils/EternalDayCommand.java

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.20