1 |
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 |
import dk.thoerup.bukkit.hoeruputils.utils.MessageBroadcaster; |
12 |
|
13 |
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 |
server.getScheduler().scheduleSyncDelayedTask(plugin, new MessageBroadcaster(server, ChatColor.YELLOW + "Eternalday has extended the period of light once again!")); |
54 |
} |
55 |
} |
56 |
|
57 |
} |
58 |
|
59 |
} |