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