SHOW:
|
|
- or go back to the newest paste.
1 | /* | |
2 | ||
3 | * This program is free software: you can redistribute it and/or modify it under | |
4 | ||
5 | * the terms of the GNU General Public License as published by the Free Software | |
6 | ||
7 | * Foundation, either version 3 of the License, or (at your option) any later | |
8 | ||
9 | * version. | |
10 | ||
11 | * | |
12 | ||
13 | * This program is distributed in the hope that it will be useful, but WITHOUT | |
14 | ||
15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | |
16 | ||
17 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more | |
18 | ||
19 | * details. | |
20 | ||
21 | * | |
22 | ||
23 | * You should have received a copy of the GNU General Public License along with | |
24 | ||
25 | * this program. If not, see <http://www.gnu.org/licenses/>. | |
26 | ||
27 | */ | |
28 | ||
29 | package net.sf.l2j.gameserver.customs; | |
30 | ||
31 | ||
32 | ||
33 | import java.util.Calendar; | |
34 | ||
35 | ||
36 | ||
37 | import net.sf.l2j.gameserver.ThreadPoolManager; | |
38 | ||
39 | ||
40 | ||
41 | /** | |
42 | ||
43 | * @author Anarchy | |
44 | ||
45 | * | |
46 | ||
47 | */ | |
48 | ||
49 | public class TaskScheduler | |
50 | ||
51 | { | |
52 | ||
53 | public static void scheduleTask(final Runnable task, final String times) | |
54 | ||
55 | { | |
56 | ||
57 | Calendar cld = Calendar.getInstance(); | |
58 | ||
59 | ||
60 | ||
61 | String[] times_splitted = times.split(";"); | |
62 | ||
63 | ||
64 | ||
65 | int i = times_splitted.length; | |
66 | ||
67 | ||
68 | ||
69 | for (String time : times_splitted) | |
70 | ||
71 | { | |
72 | ||
73 | String[] time_splitted = time.split(":"); | |
74 | ||
75 | ||
76 | ||
77 | int hour = Integer.parseInt(time_splitted[0]), | |
78 | ||
79 | minutes = Integer.parseInt(time_splitted[1]); | |
80 | ||
81 | ||
82 | ||
83 | cld.set(Calendar.HOUR_OF_DAY, hour); | |
84 | ||
85 | cld.set(Calendar.MINUTE, minutes); | |
86 | ||
87 | cld.set(Calendar.SECOND, 0); | |
88 | ||
89 | ||
90 | ||
91 | if (System.currentTimeMillis() > cld.getTimeInMillis()) | |
92 | ||
93 | { | |
94 | ||
95 | cld.set(Calendar.DAY_OF_MONTH, cld.get(Calendar.DAY_OF_MONTH)+1); | |
96 | ||
97 | cld.set(Calendar.HOUR_OF_DAY, hour); | |
98 | ||
99 | cld.set(Calendar.MINUTE, minutes); | |
100 | ||
101 | cld.set(Calendar.SECOND, 0); | |
102 | ||
103 | } | |
104 | ||
105 | ||
106 | ||
107 | ThreadPoolManager.getInstance().scheduleGeneral(task, cld.getTimeInMillis()-System.currentTimeMillis()); | |
108 | ||
109 | ||
110 | ||
111 | i--; | |
112 | ||
113 | ||
114 | ||
115 | if (i == 0) | |
116 | ||
117 | { | |
118 | ||
119 | ThreadPoolManager.getInstance().scheduleGeneral(new Runnable() | |
120 | ||
121 | { | |
122 | ||
123 | @Override | |
124 | ||
125 | public void run() | |
126 | ||
127 | { | |
128 | ||
129 | scheduleTask(task, times); | |
130 | ||
131 | } | |
132 | ||
133 | }, cld.getTimeInMillis()-System.currentTimeMillis()); | |
134 | ||
135 | } | |
136 | ||
137 | } | |
138 | ||
139 | } | |
140 | ||
141 | } |