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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1243 - (hide annotations) (download)
Wed Mar 23 21:47:26 2011 UTC (13 years, 2 months ago) by torben
Original Path: miscJava/bukkit-minecraft-plugins/HoerupUtils/src/dk/thoerup/bukkit/hoeruputils/EternalDayCommand.java
File size: 1530 byte(s)
Move messagebroadcaster to it's own file and make eternaldaycommand broadcast a message when it resets time
1 torben 1242 package dk.thoerup.bukkit.hoeruputils;
2    
3     import org.bukkit.ChatColor;
4     import org.bukkit.Server;
5     import org.bukkit.World;
6     import org.bukkit.command.Command;
7     import org.bukkit.command.CommandExecutor;
8     import org.bukkit.command.CommandSender;
9     import org.bukkit.plugin.Plugin;
10    
11 torben 1243 import dk.thoerup.bukkit.hoeruputils.utils.MessageBroadcaster;
12    
13 torben 1242 public class EternalDayCommand implements CommandExecutor {
14    
15    
16     int taskId = -1;
17    
18     World world;
19     Server server;
20     Plugin plugin;
21    
22     public EternalDayCommand(Plugin plugin) {
23    
24     this.plugin = plugin;
25     server = plugin.getServer();
26     world = server.getWorlds().get(0);
27     }
28    
29     @Override
30     public boolean onCommand(final CommandSender sender, Command command, String label, String[] args) {
31    
32    
33     if (taskId == -1) {
34     taskId = server.getScheduler().scheduleSyncRepeatingTask(plugin, new EternalDayRunner(), 2*20, 60*20);
35     server.broadcastMessage(ChatColor.YELLOW + "Eternal day is enabled - have a nice long day");
36     } else {
37     server.getScheduler().cancelTask(taskId);
38     taskId = -1;
39     server.broadcastMessage(ChatColor.YELLOW + "Eternal day is disabled - watch out for zombies");
40     }
41    
42    
43     return true;
44     }
45    
46     class EternalDayRunner implements Runnable {
47    
48     // 1000=1 hour, 0 is 06:00 so 12000 is 18:00
49     @Override
50     public void run() {
51     if (world.getTime() > 12000) {
52     world.setTime(0);
53 torben 1243 server.getScheduler().scheduleSyncDelayedTask(plugin, new MessageBroadcaster(server, ChatColor.YELLOW + "Eternalday has extended the period of light once again!"));
54 torben 1242 }
55     }
56    
57     }
58    
59     }

  ViewVC Help
Powered by ViewVC 1.1.20