Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * This program is free software: you can redistribute it and/or modify it under
- * the terms of the GNU General Public License as published by the Free Software
- * Foundation, either version 3 of the License, or (at your option) any later
- * version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
- * details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program. If not, see <http://www.gnu.org/licenses/>.
- */
- package net.sf.l2j.gameserver.customs;
- import java.util.Calendar;
- import net.sf.l2j.gameserver.ThreadPoolManager;
- /**
- * @author Anarchy
- *
- */
- public class TaskScheduler
- {
- public static void scheduleTask(final Runnable task, final String times)
- {
- Calendar cld = Calendar.getInstance();
- String[] times_splitted = times.split(";");
- int i = times_splitted.length;
- for (String time : times_splitted)
- {
- String[] time_splitted = time.split(":");
- int hour = Integer.parseInt(time_splitted[0]),
- minutes = Integer.parseInt(time_splitted[1]);
- cld.set(Calendar.HOUR_OF_DAY, hour);
- cld.set(Calendar.MINUTE, minutes);
- cld.set(Calendar.SECOND, 0);
- if (System.currentTimeMillis() > cld.getTimeInMillis())
- {
- cld.set(Calendar.DAY_OF_MONTH, cld.get(Calendar.DAY_OF_MONTH)+1);
- cld.set(Calendar.HOUR_OF_DAY, hour);
- cld.set(Calendar.MINUTE, minutes);
- cld.set(Calendar.SECOND, 0);
- }
- ThreadPoolManager.getInstance().scheduleGeneral(task, cld.getTimeInMillis()-System.currentTimeMillis());
- i--;
- if (i == 0)
- {
- ThreadPoolManager.getInstance().scheduleGeneral(new Runnable()
- {
- @Override
- public void run()
- {
- scheduleTask(task, times);
- }
- }, cld.getTimeInMillis()-System.currentTimeMillis());
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement