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 |
public class EternalDayCommand implements CommandExecutor { |
12 |
|
13 |
|
14 |
int taskId = -1; |
15 |
|
16 |
World world; |
17 |
Server server; |
18 |
Plugin plugin; |
19 |
|
20 |
public EternalDayCommand(Plugin plugin) { |
21 |
|
22 |
this.plugin = plugin; |
23 |
server = plugin.getServer(); |
24 |
world = server.getWorlds().get(0); |
25 |
} |
26 |
|
27 |
@Override |
28 |
public boolean onCommand(final CommandSender sender, Command command, String label, String[] args) { |
29 |
|
30 |
|
31 |
if (taskId == -1) { |
32 |
taskId = server.getScheduler().scheduleSyncRepeatingTask(plugin, new EternalDayRunner(), 2*20, 60*20); |
33 |
server.broadcastMessage(ChatColor.YELLOW + "Eternal day is enabled - have a nice long day"); |
34 |
} else { |
35 |
server.getScheduler().cancelTask(taskId); |
36 |
taskId = -1; |
37 |
server.broadcastMessage(ChatColor.YELLOW + "Eternal day is disabled - watch out for zombies"); |
38 |
} |
39 |
|
40 |
|
41 |
return true; |
42 |
} |
43 |
|
44 |
class EternalDayRunner implements Runnable { |
45 |
|
46 |
// 1000=1 hour, 0 is 06:00 so 12000 is 18:00 |
47 |
@Override |
48 |
public void run() { |
49 |
if (world.getTime() > 12000) { |
50 |
world.setTime(0); |
51 |
} |
52 |
} |
53 |
|
54 |
} |
55 |
|
56 |
} |