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 |
1483 |
World world; |
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 |
1483 |
world = server.getWorld("world"); |
29 |
torben |
1242 |
} |
30 |
|
|
|
31 |
|
|
@Override |
32 |
|
|
public boolean onCommand(final CommandSender sender, Command command, String label, String[] args) { |
33 |
torben |
1480 |
|
34 |
torben |
1483 |
if (taskId == -1) { |
35 |
|
|
taskId = server.getScheduler().scheduleSyncRepeatingTask(plugin, new EternalDayRunner(), 2*20, 60*20); |
36 |
|
|
server.broadcastMessage(ChatColor.YELLOW + "Eternal day is enabled - have a nice long day"); |
37 |
|
|
} else { |
38 |
|
|
server.getScheduler().cancelTask(taskId); |
39 |
|
|
taskId = -1; |
40 |
|
|
server.broadcastMessage(ChatColor.YELLOW + "Eternal day is disabled - watch out for zombies"); |
41 |
torben |
1242 |
} |
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 |
torben |
1483 |
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 |
torben |
1242 |
} |
56 |
|
|
|
57 |
|
|
} |
58 |
|
|
|
59 |
|
|
} |